fix(navigator)!: reject a DO_JUMP that targets a DO_JUMP before a waypoint (#29566)

Assisted-by: Claude:claude-opus-5-5
This commit is contained in:
Jonas Perolini authored and GitHub committed 2026-11-10 18:45:08 +01:00
1 parent 8d5be2b9cb
commit 4f7e35a06a
11 files changed
+150 -197

No files matched your search

+2
View File
@@ -150,8 +150,10 @@ Mission Items:
- [MAV_CMD_DO_JUMP](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_JUMP)
- _Param1_ (sequence number) must refer to an earlier mission item.
A mission is rejected if a jump targets itself or a later item, even if its repeat count is 0.
It is also rejected if the items from the target reach a `DO_JUMP` before a waypoint, the jump itself included, even if its repeat count is 0: a jump cannot target another jump, and a loop needs a waypoint.
- _Param2_ (repeat count) must be from 0 to 65535.
A mission with a negative or larger repeat count is rejected.
- Up to 9 `DO_JUMP` items in a row are supported: with more, the mission ends there once the first 9 have used up their repeats.
- [MAV_CMD_NAV_ROI](https://mavlink.io/en/messages/common.html#MAV_CMD_NAV_ROI)
- [MAV_CMD_DO_SET_ROI](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_ROI)
- [MAV_CMD_DO_SET_ROI_LOCATION](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_ROI_LOCATION)
+2
View File
@@ -152,8 +152,10 @@ Mission Items:
- [MAV_CMD_DO_JUMP](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_JUMP)
- _Param1_ (sequence number) must refer to an earlier mission item.
A mission is rejected if a jump targets itself or a later item, even if its repeat count is 0.
It is also rejected if the items from the target reach a `DO_JUMP` before a waypoint, the jump itself included, even if its repeat count is 0: a jump cannot target another jump, and a loop needs a waypoint.
- _Param2_ (repeat count) must be from 0 to 65535.
A mission with a negative or larger repeat count is rejected.
- Up to 9 `DO_JUMP` items in a row are supported: with more, the mission ends there once the first 9 have used up their repeats.
- [MAV_CMD_NAV_ROI](https://mavlink.io/en/messages/common.html#MAV_CMD_NAV_ROI)
- [MAV_CMD_DO_SET_ROI](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_ROI)
- [MAV_CMD_DO_SET_ROI_LOCATION](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_ROI_LOCATION)
+4 -2
View File
@@ -55,8 +55,10 @@ Please continue reading for [upgrade instructions](#upgrade-guide).
The new options `5` and `6` are the same as `3` and `4` without distance-aware return (they only warn).
`COM_FLTT_LOW_ACT` is not migrated: if you use `COM_LOW_BAT_ACT` `3` or `4` and do not want distance-aware return, change it to `5` or `6`.
Distance-aware return is not available together with `COM_LOW_BAT_ACT` `0` (Warning) or `2` (Land), and the warning can no longer be disabled (previously `COM_FLTT_LOW_ACT=0`). ([PX4-Autopilot#26955](https://github.com/PX4/PX4-Autopilot/pull/26955))
- **`DO_JUMP` can only loop back and its repeat count must fit.**
A mission is now rejected if a `DO_JUMP` targets itself or a later mission item, even if its repeat count is 0, and if its repeat count is negative, above 65535 or not a number (it is no longer narrowed to a different count).
- **`DO_JUMP` can only loop back to a waypoint and its repeat count must fit.**
A mission is now rejected if a `DO_JUMP` targets itself or a later mission item, or if scanning forward from its target reaches a `DO_JUMP` before a waypoint, including the original jump.
These target rules apply even if the repeat count is 0.
A mission is also rejected if the repeat count is negative, above 65535 or not a number (it is no longer narrowed to a different count).
Missions stored on the vehicle with such jumps must be edited and uploaded again.
- **`MAV_CMD_MISSION_START` no longer arms the vehicle.**
The command switches to [Mission mode](../flight_modes_mc/mission.md) at the requested item, and the mission starts once the vehicle is armed.
+3 -3
View File
@@ -1119,9 +1119,9 @@ int MissionBase::getNonJumpItem(int32_t &mission_index, mission_item_s &mission,
}
if (new_mission.nav_cmd == NAV_CMD_DO_JUMP) {
// Ran out of iterations while still on a DO_JUMP (e.g. a jump loop or a chain longer than
// MAX_JUMP_ITERATION). Report failure instead of returning an unresolved jump as a valid
// item, which would otherwise be loaded as the current mission item.
// Ran out of iterations while still on a DO_JUMP (MAX_JUMP_ITERATION DO_JUMPs in a row, or the
// loop or chain of a mission that failed its check). Report failure instead of returning an
// unresolved jump as a valid item, which would otherwise be loaded as the current mission item.
PX4_ERR("Do Jump could not be resolved within %u iterations.", MAX_JUMP_ITERATION);
return PX4_ERROR;
}
+1 -1
View File
@@ -476,7 +476,7 @@ private:
* @brief Maximum number of jump mission items iterations
*
*/
static constexpr uint16_t MAX_JUMP_ITERATION{NAV_MAX_JUMP_ITERATION};
static constexpr uint16_t MAX_JUMP_ITERATION{10u};
/**
* @brief Update Dataman cache
*
@@ -89,6 +89,10 @@ MissionFeasibilityChecker::checkMissionFeasible(const mission_s &mission)
break;
}
if (_checked_item.nav_cmd == NAV_CMD_DO_JUMP && !checkJumpTarget(mission, _checked_item, i)) {
failed = true;
break;
}
}
failed |= _feasibility_checker.someCheckFailed();
@@ -139,7 +143,7 @@ MissionFeasibilityChecker::checkMissionAgainstGeofence(const mission_s &mission,
#endif // CONFIG_NAVIGATOR_GEOFENCE_PATH_CHECKS
for (size_t i = 0; i < mission.count; i++) {
mission_item_s missionitem; // fully written by a successful read
mission_item_s &missionitem = _checked_item;
if (!readSyncMissionItem(mission, i, missionitem)) {
failure = Failure::DatamanRead;
@@ -150,7 +154,24 @@ MissionFeasibilityChecker::checkMissionAgainstGeofence(const mission_s &mission,
#if defined(CONFIG_NAVIGATOR_GEOFENCE_PATH_CHECKS)
if (missionitem.nav_cmd == NAV_CMD_DO_JUMP) {
if (!checkJumpDestinations(mission, missionitem, i, have_previous_position ? &previous_position : nullptr, batch)) {
// Only a jump with repeats flies its leg; checkJumpTarget() checks every target.
// Ignore do_jump_current_count: a mission reset re-arms a spent jump.
if (missionitem.do_jump_repeat_count == 0 || !have_previous_position) {
continue;
}
size_t index = 0;
const JumpTarget target = findJumpTarget(mission, missionitem.do_jump_mission_index, i, index, _jump_candidate);
if (target == JumpTarget::ReadFailed) {
failure = Failure::DatamanRead;
failed_item = index;
break;
}
// The mission check rejects a target that reaches a jump instead of a position.
if (target == JumpTarget::Position
&& !addGeofencePath(batch, previous_position, {_jump_candidate.lat, _jump_candidate.lon}, i, 0.f, true)) {
return false;
}
@@ -281,105 +302,57 @@ MissionFeasibilityChecker::checkMissionAgainstGeofence(const mission_s &mission,
return false;
}
#if defined(CONFIG_NAVIGATOR_GEOFENCE_PATH_CHECKS)
bool MissionFeasibilityChecker::checkJumpDestinations(const mission_s &mission, const mission_item_s &jump_item,
size_t jump_index, const matrix::Vector2d *previous_position, GeofencePathBatch &batch)
MissionFeasibilityChecker::JumpTarget MissionFeasibilityChecker::findJumpTarget(const mission_s &mission,
int32_t target_index, size_t jump_index, size_t &index, mission_item_s &item)
{
const auto in_range = [&mission](int32_t index) {
return index >= 0 && index < mission.count;
};
// A target outside [0, jump_index) fails the item checks; it reaches no position here.
for (int32_t i = target_index; i >= 0 && i < static_cast<int32_t>(jump_index); ++i) {
index = static_cast<size_t>(i);
// Execution checks the target even when the jump never repeats.
if (!in_range(jump_item.do_jump_mission_index)) {
return rejectGeofenceJump(batch, jump_index);
}
if (!readSyncMissionItem(mission, index, item)) {
return JumpTarget::ReadFailed;
}
// Ignore do_jump_current_count: activation and index changes reset it.
// Check every jump with a nonzero configured repeat count, even if currently spent.
if (jump_item.do_jump_repeat_count == 0) {
return true;
}
if (item.nav_cmd == NAV_CMD_DO_JUMP) {
return JumpTarget::Jump;
}
// Bound memory and reads so branching jump chains or loops cannot stall validation.
size_t pending_count = 1;
_pending_branches[0] = {static_cast<uint16_t>(jump_item.do_jump_mission_index), 1};
size_t items_read = 0;
const size_t read_limit = static_cast<size_t>(mission.count) * kMaxJumpBranches;
while (pending_count > 0) {
const JumpBranch branch = _pending_branches[--pending_count];
int32_t index = branch.index;
uint16_t consecutive_jumps = branch.consecutive_jumps;
while (in_range(index)) {
if (items_read++ >= read_limit) {
return rejectGeofenceJump(batch, jump_index);
}
if (!readSyncMissionItem(mission, index, _jump_candidate)) {
if (checkGeofencePathBatch(batch)) {
logDatamanReadFailure(index, mission.mission_dataman_id);
}
return false;
}
if (_jump_candidate.nav_cmd == NAV_CMD_DO_JUMP) {
// getNonJumpItem() gives up after this many jump reads without a non-jump item.
if (++consecutive_jumps >= NAV_MAX_JUMP_ITERATION) {
return rejectGeofenceJump(batch, jump_index);
}
if (!in_range(_jump_candidate.do_jump_mission_index)) {
return rejectGeofenceJump(batch, index);
}
// Zero configured repeats always fall through; a target at the next item follows the same path.
if (_jump_candidate.do_jump_repeat_count == 0 || _jump_candidate.do_jump_mission_index == index + 1) {
++index;
continue;
}
if (pending_count >= kMaxJumpBranches) {
return rejectGeofenceJump(batch, jump_index);
}
// Check the active target first, then its exhausted fallthrough from the same source.
_pending_branches[pending_count++] = {static_cast<uint16_t>(index + 1), consecutive_jumps};
index = _jump_candidate.do_jump_mission_index;
continue;
}
// A non-jump item completes one resolution; the next one starts a new count.
consecutive_jumps = 0;
if (mission_item_contains_position(_jump_candidate)) {
if (previous_position
&& !addGeofencePath(batch, *previous_position, {_jump_candidate.lat, _jump_candidate.lon}, jump_index,
0.f, true)) {
return false;
}
break;
}
++index;
if (mission_item_contains_position(item)) {
return JumpTarget::Position;
}
}
// Reaching the mission end leaves no further leg to check.
return true;
return JumpTarget::Jump;
}
bool MissionFeasibilityChecker::rejectGeofenceJump(GeofencePathBatch &batch, size_t jump_index)
// Reject a DO_JUMP reached before a position, the checked jump included, even with 0 repeats:
// a loop of commands hangs the lookahead, and a chain of jumps can end the mission early.
bool MissionFeasibilityChecker::checkJumpTarget(const mission_s &mission, const mission_item_s &jump_item,
size_t jump_index)
{
if (checkGeofencePathBatch(batch)) {
logUnresolvedJump(jump_index);
size_t index = 0;
switch (findJumpTarget(mission, jump_item.do_jump_mission_index, jump_index, index, _jump_candidate)) {
case JumpTarget::Position:
return true;
case JumpTarget::Jump:
mavlink_log_critical(_navigator->get_mavlink_log_pub(),
"Mission rejected: DO_JUMP %zu target reaches a DO_JUMP before a waypoint\t", jump_index + 1);
events::send<uint16_t>(events::ID("navigator_mis_jump_no_waypoint"), {events::Log::Error, events::LogInternal::Info},
"Mission rejected: DO_JUMP {1} target reaches a DO_JUMP before a waypoint",
static_cast<uint16_t>(jump_index + 1));
return false;
case JumpTarget::ReadFailed:
logDatamanReadFailure(index, mission.mission_dataman_id);
return false;
}
return false;
}
#if defined(CONFIG_NAVIGATOR_GEOFENCE_PATH_CHECKS)
bool MissionFeasibilityChecker::addGeofencePath(GeofencePathBatch &batch, const matrix::Vector2d &start,
const matrix::Vector2d &end, size_t mission_index, float end_radius, bool is_jump)
{
@@ -444,16 +417,6 @@ void MissionFeasibilityChecker::logGeofencePathBreach(const GeofencePathBatch &b
}
}
// Keep out of rejectGeofenceJump(): inlined, the event buffers would stay
// on its stack while it flushes the path batch.
void MissionFeasibilityChecker::logUnresolvedJump(size_t jump_index)
{
mavlink_log_critical(_navigator->get_mavlink_log_pub(), "Mission rejected: DO_JUMP %zu path cannot be resolved\t",
jump_index + 1);
events::send<uint16_t>(events::ID("navigator_mis_do_jump_invalid"),
{events::Log::Error, events::LogInternal::Info},
"Mission rejected: DO_JUMP {1} path cannot be resolved", static_cast<uint16_t>(jump_index + 1));
}
#endif // CONFIG_NAVIGATOR_GEOFENCE_PATH_CHECKS
bool MissionFeasibilityChecker::readSyncMissionItem(const mission_s &mission, size_t index, mission_item_s &item)
@@ -62,14 +62,10 @@ private:
bool is_jump[kGeofencePathBatchSize];
size_t count{0};
};
static constexpr size_t kMaxJumpBranches = 16;
struct JumpBranch {
uint16_t index; // validated target or fallthrough, at most mission.count
uint16_t consecutive_jumps;
};
#endif // CONFIG_NAVIGATOR_GEOFENCE_PATH_CHECKS
enum class JumpTarget { Position, Jump, ReadFailed };
Navigator *_navigator{nullptr};
DatamanClient &_dataman_client;
FeasibilityChecker _feasibility_checker;
@@ -77,21 +73,21 @@ private:
// Members, not locals, so they are not on the stack during the nested geofence path checks.
// Left uninitialized to save flash: each call writes them before reading them.
mission_item_s _checked_item;
#if defined(CONFIG_NAVIGATOR_GEOFENCE_PATH_CHECKS)
mission_item_s _jump_candidate;
JumpBranch _pending_branches[kMaxJumpBranches];
#endif // CONFIG_NAVIGATOR_GEOFENCE_PATH_CHECKS
/**
* Read from a DO_JUMP's target to the first position item or DO_JUMP, the jump itself included.
* @param index The position item, or the item that could not be read.
*/
JumpTarget findJumpTarget(const mission_s &mission, int32_t target_index, size_t jump_index, size_t &index,
mission_item_s &item);
bool checkJumpTarget(const mission_s &mission, const mission_item_s &jump_item, size_t jump_index);
bool checkMissionAgainstGeofence(const mission_s &mission, float home_alt, bool home_valid);
#if defined(CONFIG_NAVIGATOR_GEOFENCE_PATH_CHECKS)
bool checkJumpDestinations(const mission_s &mission, const mission_item_s &jump_item, size_t jump_index,
const matrix::Vector2d *previous_position, GeofencePathBatch &batch);
bool rejectGeofenceJump(GeofencePathBatch &batch, size_t jump_index);
bool addGeofencePath(GeofencePathBatch &batch, const matrix::Vector2d &start, const matrix::Vector2d &end,
size_t mission_index, float end_radius = 0.f, bool is_jump = false);
bool checkGeofencePathBatch(GeofencePathBatch &batch);
void logGeofencePathBreach(const GeofencePathBatch &batch, size_t index);
void logUnresolvedJump(size_t jump_index);
#endif // CONFIG_NAVIGATOR_GEOFENCE_PATH_CHECKS
bool readSyncMissionItem(const mission_s &mission, size_t index, mission_item_s &item);
void logGeofenceUnavailable();
@@ -63,7 +63,8 @@ public:
* Callers supply path restrictions through the checker; geometry-only callers may omit it.
*
* Planning calls reuse a shared scratch buffer and must not run at the same time.
* Jump targets may include non-position commands before their waypoint. Jump chains are not supported.
* Jump targets may include non-position commands before their waypoint, but no DO_JUMP: the mission check
* rejects those.
*/
explicit MissionRoutePlanner(const mission_route::Provider &provider,
const mission_route::PathChecker *path_checker = nullptr);
@@ -430,8 +430,8 @@ void RouteSegmentCursor::prepareNominalSegment(const SegmentEndpoint &end, const
_positions.start = _positions.end;
}
// Returns false without failing for a jump with no position at or after its target, such as a
// camera loop after the last waypoint: it adds no edge.
// Returns false without failing for a jump with no position at or after its target: it adds no edge.
// The mission check rejects such a jump.
bool RouteSegmentCursor::prepareJumpSegment(int32_t index, const mission_item_s &jump_item,
RouteSegmentView &view)
{
-3
View File
@@ -46,9 +46,6 @@
#include <stdint.h>
#include <stdbool.h>
/** Consecutive DO_JUMP items the mission resolves before giving up on the chain. */
static constexpr uint16_t NAV_MAX_JUMP_ITERATION{10u};
/* compatible to mavlink MAV_CMD */
enum NAV_CMD {
NAV_CMD_IDLE = 0,
@@ -437,13 +437,11 @@ TEST_F(MissionFeasibilityGeofenceTest, UnreadableMissionStorageRejectsUpload)
class MissionGeofenceJumpTest : public MissionFeasibilityGeofenceTest
{
protected:
void expectJumpFailure(uint16_t item, bool invalid = false)
void expectJumpFailure(uint16_t item)
{
const std::string message = invalid ? "Mission rejected: DO_JUMP " + std::to_string(item) + " path cannot be resolved" :
"Geofence breach on DO_JUMP " + std::to_string(item) + " path";
const std::string message = "Geofence breach on DO_JUMP " + std::to_string(item) + " path";
EXPECT_TRUE(logContains(message.c_str()));
EXPECT_TRUE(waypointEvent(invalid ? events::ID("navigator_mis_do_jump_invalid") :
events::ID("navigator_mis_geofence_jump_breach"), item));
EXPECT_TRUE(waypointEvent(events::ID("navigator_mis_geofence_jump_breach"), item));
}
};
@@ -498,6 +496,17 @@ INSTANTIATE_TEST_SUITE_P(MissionJumpRepeats, MissionGeofenceJumpRepeatTest, ::te
return test_info.param.name;
});
// The jump edge ends at the waypoint after a command at the jump target.
TEST_F(MissionGeofenceJumpTest, JumpEdgeEndsAtTheWaypointAfterTheTargetCommand)
{
ASSERT_TRUE(loadFence(exclusionSquare()));
EXPECT_FALSE(missionFeasible({
changeSpeed(), waypoint({300.f, 500.f}), waypoint({300.f, 100.f}), waypoint({-300.f, 100.f}),
navigator_test::makeDoJump(0, 1)
}));
expectJumpFailure(5);
}
TEST_F(MissionGeofenceJumpTest, FallthroughLegIsReportedWithItsWaypoint)
{
ASSERT_TRUE(loadFence(exclusionSquare()));
@@ -508,95 +517,76 @@ TEST_F(MissionGeofenceJumpTest, FallthroughLegIsReportedWithItsWaypoint)
expectPathViolation(3);
}
TEST_F(MissionGeofenceJumpTest, ChecksCommandAndChainedDestination)
{
ASSERT_TRUE(loadFence(exclusionSquare()));
// Item 6 reaches the southwest corner through an earlier command and jump.
EXPECT_FALSE(missionFeasible({
waypoint({-300.f, 100.f}), changeSpeed(), navigator_test::makeDoJump(0, 1),
waypoint({300.f, 100.f}), waypoint({300.f, 500.f}), navigator_test::makeDoJump(1, 1)
}));
expectJumpFailure(6);
}
class MissionGeofenceNestedJumpTest : public MissionGeofenceJumpTest,
public ::testing::WithParamInterface<bool> {};
TEST_P(MissionGeofenceNestedJumpTest, ChecksFallthroughAfterNestedJumpExhausts)
{
ASSERT_TRUE(loadFence(exclusionSquare()));
const bool spent_counter = GetParam();
// Item 2 jumps to the southeast corner while active, then falls through to the
// southwest corner. That second destination makes item 6's backward jump cross the square.
// A stored counter does not change this: the check ignores execution state.
EXPECT_FALSE(missionFeasible({
waypoint({-300.f, 500.f}), navigator_test::makeDoJump(0, 1, spent_counter ? 1 : 0),
waypoint({-300.f, 100.f}), waypoint({300.f, 100.f}), waypoint({300.f, 500.f}),
navigator_test::makeDoJump(1, 2)
}));
expectJumpFailure(6);
}
INSTANTIATE_TEST_SUITE_P(MissionNestedJumps, MissionGeofenceNestedJumpTest, ::testing::Bool(),
[](const ::testing::TestParamInfo<bool> &test_info)
{
return test_info.param ? "SpentCounterIgnored" : "ExhaustsOnLaterVisit";
});
struct MissionJumpChainCase {
const char *name;
unsigned jumps;
bool commands_between;
bool feasible;
// The DO_JUMP rule needs no fence: the mission check applies it on every board.
struct JumpTargetItem {
char kind; // W: waypoint, C: command, J: DO_JUMP
int16_t target;
uint16_t repeats;
};
class MissionGeofenceJumpChainTest : public MissionGeofenceJumpTest,
public ::testing::WithParamInterface<MissionJumpChainCase> {};
struct JumpTargetCase {
const char *name;
std::vector<JumpTargetItem> items;
uint16_t rejected_jump; // mission item number, 0 when the mission is accepted
};
TEST_P(MissionGeofenceJumpChainTest, ResolvesChainsLikeTheMission)
class MissionJumpTargetTest : public MissionFeasibilityGeofenceTest,
public ::testing::WithParamInterface<JumpTargetCase> {};
TEST_P(MissionJumpTargetTest, RejectsTargetThatReachesAJumpBeforeAWaypoint)
{
const MissionJumpChainCase &test = GetParam();
ASSERT_TRUE(loadFence(inclusionSquare()));
std::vector<mission_item_s> items{waypoint({0.f, 0.f})};
const JumpTargetCase &test = GetParam();
std::vector<mission_item_s> items;
// The final backward jump targets a chain of disabled jumps leading to a safe waypoint.
// Every target is earlier, and even disabled jumps count towards NAV_MAX_JUMP_ITERATION.
// Non-jump commands between them start a new resolution count.
for (unsigned i = 1; i < test.jumps; ++i) {
items.push_back(navigator_test::makeDoJump(0, 0));
for (const JumpTargetItem &item : test.items) {
switch (item.kind) {
case 'W':
items.push_back(waypoint({100.f * items.size(), 0.f}));
break;
if (test.commands_between) {
case 'C':
items.push_back(changeSpeed());
break;
default:
items.push_back(navigator_test::makeDoJump(item.target, item.repeats));
break;
}
}
items.push_back(waypoint({0.f, 100.f}));
const uint16_t jump_index = items.size();
items.push_back(navigator_test::makeDoJump(1, 1));
EXPECT_EQ(missionFeasible(items), test.feasible);
EXPECT_EQ(missionFeasible(items), test.rejected_jump == 0);
if (!test.feasible) {
expectJumpFailure(jump_index + 1, true);
if (test.rejected_jump != 0) {
const std::string message = "Mission rejected: DO_JUMP " + std::to_string(test.rejected_jump)
+ " target reaches a DO_JUMP before a waypoint";
EXPECT_TRUE(logContains(message.c_str()));
EXPECT_TRUE(waypointEvent(events::ID("navigator_mis_jump_no_waypoint"), test.rejected_jump));
}
}
INSTANTIATE_TEST_SUITE_P(MissionJumpChains, MissionGeofenceJumpChainTest, ::testing::Values(
MissionJumpChainCase{"LongestResolvableChain", NAV_MAX_JUMP_ITERATION - 1, false, true},
MissionJumpChainCase{"UnresolvableChain", NAV_MAX_JUMP_ITERATION, false, false},
MissionJumpChainCase{"CommandsBetweenJumps", NAV_MAX_JUMP_ITERATION + 1, true, true}),
[](const ::testing::TestParamInfo<MissionJumpChainCase> &test_info)
static const JumpTargetCase kJumpTargetCases[] {
// The lookahead follows the active jump back to the command forever, so Navigator hangs.
{"CommandOnlyLoop", {{'W'}, {'C'}, {'J', 1, 5}, {'W'}}, 3},
{"CommandOnlyLoopAtMissionEnd", {{'W'}, {'C'}, {'J', 1, 5}}, 3},
// With only DO_JUMPs in between, the outer jump spins on the spent inner one and ends the mission early.
{"JumpRightAfterItsTarget", {{'W'}, {'J', 0, 1}, {'J', 1, 4}, {'W'}}, 3},
// A jump to a jump is rejected also when execution would continue, directly or through commands.
{"TargetIsAJump", {{'W'}, {'J', 0, 1}, {'W'}, {'J', 1, 1}}, 4},
{"CommandThenJump", {{'W'}, {'C'}, {'J', 0, 1}, {'W'}, {'J', 1, 1}}, 5},
// Rejected although execution steps over a jump without repeats.
{"JumpWithoutRepeatsOnTheWay", {{'W'}, {'C'}, {'J', 0, 0}, {'W'}, {'J', 1, 1}}, 5},
// Like the earlier-target rule, the check ignores the repeat count of the checked jump.
{"CheckedJumpWithoutRepeats", {{'W'}, {'C'}, {'J', 1, 0}, {'W'}}, 3},
{"CommandsBeforeTheWaypoint", {{'W'}, {'C'}, {'W'}, {'J', 1, 2}, {'W'}}, 0},
{"NestedLoops", {{'W'}, {'W'}, {'J', 1, 2}, {'W'}, {'J', 0, 1}}, 0},
};
INSTANTIATE_TEST_SUITE_P(JumpTargets, MissionJumpTargetTest, ::testing::ValuesIn(kJumpTargetCases),
[](const ::testing::TestParamInfo<JumpTargetCase> &test_info)
{
return test_info.param.name;
});
TEST_F(MissionGeofenceJumpTest, RejectsLoopThroughACommand)
{
ASSERT_TRUE(loadFence(inclusionSquare()));
// The traversal limit must also stop a loop containing a non-position command.
EXPECT_FALSE(missionFeasible({changeSpeed(), navigator_test::makeDoJump(0, 1)}));
expectJumpFailure(2, true);
}
class MissionGeofenceJumpOrderTest : public MissionGeofenceJumpTest,
public ::testing::WithParamInterface<bool> {};