43 #include "../state_machine_helper.h" 45 #include "../Arming/PreFlightCheck/PreFlightCheck.hpp" 70 } ArmingTransitionVolatileState_t;
76 const char *assertMsg;
77 ArmingTransitionVolatileState_t current_state;
80 condition_system_sensors_initialized;
81 bool safety_switch_available;
84 ArmingTransitionVolatileState_t expected_state;
86 } ArmingTransitionTest_t;
89 #define ATT_ARMED true 90 #define ATT_DISARMED false 91 #define ATT_READY_TO_ARM true 92 #define ATT_NOT_READY_TO_ARM false 93 #define ATT_SENSORS_INITIALIZED true 94 #define ATT_SENSORS_NOT_INITIALIZED false 95 #define ATT_SAFETY_AVAILABLE true 96 #define ATT_SAFETY_NOT_AVAILABLE true 97 #define ATT_SAFETY_OFF true 98 #define ATT_SAFETY_ON false 101 static const ArmingTransitionTest_t rgArmingTransitionTests[] = {
105 "no transition: identical states",
107 vehicle_status_s::ARMING_STATE_INIT,
116 "transition: init to standby",
118 vehicle_status_s::ARMING_STATE_STANDBY,
123 "transition: init to standby error",
125 vehicle_status_s::ARMING_STATE_STANDBY_ERROR,
126 { vehicle_status_s::ARMING_STATE_STANDBY_ERROR,
ATT_DISARMED, ATT_NOT_READY_TO_ARM }, TRANSITION_CHANGED
130 "transition: init to reboot",
132 vehicle_status_s::ARMING_STATE_SHUTDOWN,
133 { vehicle_status_s::ARMING_STATE_SHUTDOWN,
ATT_DISARMED, ATT_NOT_READY_TO_ARM }, TRANSITION_CHANGED
137 "transition: standby to init",
139 vehicle_status_s::ARMING_STATE_INIT,
144 "transition: standby to standby error",
146 vehicle_status_s::ARMING_STATE_STANDBY_ERROR,
151 "transition: standby to reboot",
153 vehicle_status_s::ARMING_STATE_SHUTDOWN,
158 "transition: armed to standby",
160 vehicle_status_s::ARMING_STATE_STANDBY,
161 { vehicle_status_s::ARMING_STATE_STANDBY,
ATT_DISARMED, ATT_READY_TO_ARM }, TRANSITION_CHANGED
165 "transition: standby error to reboot",
167 vehicle_status_s::ARMING_STATE_SHUTDOWN,
168 { vehicle_status_s::ARMING_STATE_SHUTDOWN,
ATT_DISARMED, ATT_NOT_READY_TO_ARM }, TRANSITION_CHANGED
172 "transition: in air restore to armed",
174 vehicle_status_s::ARMING_STATE_ARMED,
175 { vehicle_status_s::ARMING_STATE_ARMED,
ATT_ARMED, ATT_READY_TO_ARM }, TRANSITION_CHANGED
179 "transition: in air restore to reboot",
181 vehicle_status_s::ARMING_STATE_SHUTDOWN,
188 "transition: standby error to standby, hil on",
190 vehicle_status_s::ARMING_STATE_STANDBY,
197 "transition: standby to armed, no safety switch",
199 vehicle_status_s::ARMING_STATE_ARMED,
200 { vehicle_status_s::ARMING_STATE_ARMED,
ATT_ARMED, ATT_READY_TO_ARM }, TRANSITION_CHANGED
204 "transition: standby to armed, safety switch off",
206 vehicle_status_s::ARMING_STATE_ARMED,
207 { vehicle_status_s::ARMING_STATE_ARMED,
ATT_ARMED, ATT_READY_TO_ARM }, TRANSITION_CHANGED
215 "no transition: init to armed",
217 vehicle_status_s::ARMING_STATE_ARMED,
222 "no transition: armed to init",
224 vehicle_status_s::ARMING_STATE_INIT,
225 { vehicle_status_s::ARMING_STATE_ARMED,
ATT_ARMED, ATT_READY_TO_ARM }, TRANSITION_DENIED
229 "no transition: armed to reboot",
231 vehicle_status_s::ARMING_STATE_SHUTDOWN,
232 { vehicle_status_s::ARMING_STATE_ARMED,
ATT_ARMED, ATT_READY_TO_ARM }, TRANSITION_DENIED
236 "no transition: standby error to armed",
238 vehicle_status_s::ARMING_STATE_ARMED,
239 { vehicle_status_s::ARMING_STATE_STANDBY_ERROR,
ATT_DISARMED, ATT_NOT_READY_TO_ARM }, TRANSITION_DENIED
243 "no transition: standby error to standby",
245 vehicle_status_s::ARMING_STATE_STANDBY,
246 { vehicle_status_s::ARMING_STATE_STANDBY_ERROR,
ATT_DISARMED, ATT_NOT_READY_TO_ARM }, TRANSITION_DENIED
250 "no transition: reboot to armed",
252 vehicle_status_s::ARMING_STATE_ARMED,
253 { vehicle_status_s::ARMING_STATE_SHUTDOWN,
ATT_DISARMED, ATT_NOT_READY_TO_ARM }, TRANSITION_DENIED
257 "no transition: in air restore to standby",
259 vehicle_status_s::ARMING_STATE_STANDBY,
260 { vehicle_status_s::ARMING_STATE_IN_AIR_RESTORE,
ATT_DISARMED, ATT_NOT_READY_TO_ARM }, TRANSITION_DENIED
273 "no transition: init to armed, safety switch on",
275 vehicle_status_s::ARMING_STATE_ARMED,
276 { vehicle_status_s::ARMING_STATE_STANDBY,
ATT_DISARMED, ATT_READY_TO_ARM }, TRANSITION_DENIED
285 size_t cArmingTransitionTests =
sizeof(rgArmingTransitionTests) /
sizeof(rgArmingTransitionTests[0]);
287 for (
size_t i = 0; i < cArmingTransitionTests; i++) {
288 const ArmingTransitionTest_t *
test = &rgArmingTransitionTests[i];
290 const bool check_gps =
false;
300 armed.
armed = test->current_state.armed;
313 ut_compare(test->assertMsg, test->expected_transition_result, result);
326 const char *assertMsg;
327 uint8_t condition_bits;
331 } MainTransitionTest_t;
334 #define MTT_ALL_NOT_VALID 0 335 #define MTT_ROTARY_WING 1 << 0 336 #define MTT_LOC_ALT_VALID 1 << 1 337 #define MTT_LOC_POS_VALID 1 << 2 338 #define MTT_HOME_POS_VALID 1 << 3 339 #define MTT_GLOBAL_POS_VALID 1 << 4 341 static const MainTransitionTest_t rgMainTransitionTests[] = {
346 "no transition: identical states",
354 "transition: MANUAL to ACRO - rotary",
356 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_ACRO,
TRANSITION_CHANGED 360 "transition: MANUAL to ACRO - not rotary",
362 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_ACRO, TRANSITION_CHANGED
366 "transition: ACRO to MANUAL",
368 commander_state_s::MAIN_STATE_ACRO, commander_state_s::MAIN_STATE_MANUAL, TRANSITION_CHANGED
372 "transition: MANUAL to AUTO_MISSION - global position valid, home position valid",
374 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_AUTO_MISSION, TRANSITION_CHANGED
378 "transition: AUTO_MISSION to MANUAL - global position valid, home position valid",
380 commander_state_s::MAIN_STATE_AUTO_MISSION, commander_state_s::MAIN_STATE_MANUAL, TRANSITION_CHANGED
384 "transition: MANUAL to AUTO_LOITER - global position valid",
386 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_AUTO_LOITER, TRANSITION_CHANGED
390 "transition: AUTO_LOITER to MANUAL - global position valid",
392 commander_state_s::MAIN_STATE_AUTO_LOITER, commander_state_s::MAIN_STATE_MANUAL, TRANSITION_CHANGED
396 "transition: MANUAL to AUTO_RTL - global position valid, home position valid",
398 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_AUTO_RTL, TRANSITION_CHANGED
402 "transition: AUTO_RTL to MANUAL - global position valid, home position valid",
404 commander_state_s::MAIN_STATE_AUTO_RTL, commander_state_s::MAIN_STATE_MANUAL, TRANSITION_CHANGED
408 "transition: MANUAL to ALTCTL - not rotary",
410 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_ALTCTL, TRANSITION_CHANGED
414 "transition: MANUAL to ALTCTL - rotary, global position not valid, local altitude valid",
416 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_ALTCTL, TRANSITION_CHANGED
420 "transition: MANUAL to ALTCTL - rotary, global position valid, local altitude not valid",
422 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_ALTCTL, TRANSITION_CHANGED
426 "transition: ALTCTL to MANUAL - local altitude valid",
428 commander_state_s::MAIN_STATE_ALTCTL, commander_state_s::MAIN_STATE_MANUAL, TRANSITION_CHANGED
432 "transition: MANUAL to POSCTL - local position not valid, global position valid",
434 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_POSCTL, TRANSITION_CHANGED
438 "transition: MANUAL to POSCTL - local position valid, global position not valid",
440 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_POSCTL, TRANSITION_CHANGED
444 "transition: POSCTL to MANUAL - local position valid, global position valid",
446 commander_state_s::MAIN_STATE_POSCTL, commander_state_s::MAIN_STATE_MANUAL, TRANSITION_CHANGED
452 "no transition: MANUAL to AUTO_MISSION - global position not valid",
454 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_AUTO_MISSION,
TRANSITION_DENIED 458 "no transition: MANUAL to AUTO_LOITER - global position not valid",
460 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_AUTO_LOITER, TRANSITION_DENIED
464 "no transition: MANUAL to AUTO_RTL - global position not valid, home position not valid",
466 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_AUTO_RTL, TRANSITION_DENIED
470 "no transition: MANUAL to AUTO_RTL - global position not valid, home position valid",
472 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_AUTO_RTL, TRANSITION_DENIED
476 "no transition: MANUAL to AUTO_RTL - global position valid, home position not valid",
478 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_AUTO_RTL, TRANSITION_DENIED
482 "transition: MANUAL to ALTCTL - not rotary",
484 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_ALTCTL, TRANSITION_DENIED
488 "no transition: MANUAL to ALTCTL - rotary, global position not valid, local altitude not valid",
490 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_ALTCTL, TRANSITION_DENIED
494 "no transition: MANUAL to POSCTL - local position not valid, global position not valid",
496 commander_state_s::MAIN_STATE_MANUAL, commander_state_s::MAIN_STATE_POSCTL, TRANSITION_DENIED
500 size_t cMainTransitionTests =
sizeof(rgMainTransitionTests) /
sizeof(rgMainTransitionTests[0]);
502 for (
size_t i = 0; i < cMainTransitionTests; i++) {
503 const MainTransitionTest_t *
test = &rgMainTransitionTests[i];
510 current_commander_state.
main_state = test->from_state;
521 ¤t_commander_state);
524 ut_compare(test->assertMsg, test->expected_transition_result, result);
526 if (test->expected_transition_result == result) {
#define VEHICLE_TYPE_FIXED_WING
#define ut_declare_test(test_function, test_class)
Macro to create a function which will run a unit test class and print results.
#define ATT_SAFETY_AVAILABLE
#define MTT_LOC_ALT_VALID
#define MTT_HOME_POS_VALID
bool circuit_breaker_engaged_power_check
Base class to be used for unit tests.
bool safety_switch_available
#define MTT_GLOBAL_POS_VALID
bool condition_global_position_valid
#define ATT_SENSORS_INITIALIZED
~StateMachineHelperTest() override=default
bool armingStateTransitionTest()
bool condition_home_position_valid
int _tests_failed
The number of unit tests which failed.
bool condition_system_sensors_initialized
bool condition_local_altitude_valid
static struct actuator_armed_s armed
bool condition_auto_mission_available
void test(enum LPS25H_BUS busid)
Perform some basic functional tests on the driver; make sure we can collect data from the sensor in p...
bool is_safe(const safety_s &safety, const actuator_armed_s &armed)
#define MTT_LOC_POS_VALID
StateMachineHelperTest()=default
#define ATT_SAFETY_NOT_AVAILABLE
bool stateMachineHelperTest(void)
#define ut_compare(message, v1, v2)
Used to compare two integer values within a unit test.
transition_result_t main_state_transition(const vehicle_status_s &status, const main_state_t new_main_state, const vehicle_status_flags_s &status_flags, commander_state_s *internal_state)
#define ut_run_test(test)
Runs a single unit test.
transition_result_t arming_state_transition(vehicle_status_s *status, const safety_s &safety, const arming_state_t new_arming_state, actuator_armed_s *armed, const bool fRunPreArmChecks, orb_advert_t *mavlink_log_pub, vehicle_status_flags_s *status_flags, const uint8_t arm_requirements, const hrt_abstime &time_since_boot)
#define MTT_ALL_NOT_VALID
bool condition_local_position_valid
bool mainStateTransitionTest()
#define ATT_NOT_READY_TO_ARM
bool run_tests() override
Override to run your unit tests.