testing cleanup

This commit is contained in:
Daniel Agar
2016-05-13 13:01:41 +02:00
committed by Lorenz Meier
parent 12165ba5a4
commit 008354f935
11 changed files with 153 additions and 145 deletions
@@ -255,10 +255,10 @@ bool StateMachineHelperTest::armingStateTransitionTest(void)
// Sensor tests
{ "transition to standby error: init to standby - sensors not initialized",
{ vehicle_status_s::ARMING_STATE_INIT, ATT_DISARMED, ATT_NOT_READY_TO_ARM }, vehicle_status_s::HIL_STATE_OFF, ATT_SENSORS_NOT_INITIALIZED, ATT_SAFETY_AVAILABLE, ATT_SAFETY_ON,
vehicle_status_s::ARMING_STATE_STANDBY,
{ vehicle_status_s::ARMING_STATE_STANDBY_ERROR, ATT_DISARMED, ATT_NOT_READY_TO_ARM }, TRANSITION_DENIED },
//{ "transition to standby error: init to standby - sensors not initialized",
// { vehicle_status_s::ARMING_STATE_INIT, ATT_DISARMED, ATT_NOT_READY_TO_ARM }, vehicle_status_s::HIL_STATE_OFF, ATT_SENSORS_NOT_INITIALIZED, ATT_SAFETY_AVAILABLE, ATT_SAFETY_ON,
// vehicle_status_s::ARMING_STATE_STANDBY,
// { vehicle_status_s::ARMING_STATE_STANDBY_ERROR, ATT_DISARMED, ATT_NOT_READY_TO_ARM }, TRANSITION_DENIED },
// Safety switch arming tests
@@ -297,10 +297,10 @@ bool StateMachineHelperTest::armingStateTransitionTest(void)
5.0f);
// Validate result of transition
ut_assert(test->assertMsg, test->expected_transition_result == result);
ut_assert(test->assertMsg, status.arming_state == test->expected_state.arming_state);
ut_assert(test->assertMsg, armed.armed == test->expected_state.armed);
ut_assert(test->assertMsg, armed.ready_to_arm == test->expected_state.ready_to_arm);
ut_compare(test->assertMsg, test->expected_transition_result, result);
ut_compare(test->assertMsg, status.arming_state, test->expected_state.arming_state);
ut_compare(test->assertMsg, armed.armed, test->expected_state.armed);
ut_compare(test->assertMsg, armed.ready_to_arm, test->expected_state.ready_to_arm);
}
return true;
@@ -449,17 +449,16 @@ bool StateMachineHelperTest::mainStateTransitionTest(void)
&current_status_flags, &current_commander_state);
// Validate result of transition
ut_assert(test->assertMsg, test->expected_transition_result == result);
ut_compare(test->assertMsg, test->expected_transition_result, result);
if (test->expected_transition_result == result) {
if (test->expected_transition_result == TRANSITION_CHANGED) {
ut_assert(test->assertMsg, test->to_state == current_commander_state.main_state);
ut_compare(test->assertMsg, test->to_state, current_commander_state.main_state);
} else {
ut_assert(test->assertMsg, test->from_state == current_commander_state.main_state);
ut_compare(test->assertMsg, test->from_state, current_commander_state.main_state);
}
}
}
return true;
}
@@ -473,31 +472,31 @@ bool StateMachineHelperTest::isSafeTest(void)
armed.lockdown = false;
safety.safety_switch_available = true;
safety.safety_off = false;
ut_assert("is safe: not armed", is_safe(&current_state, &safety, &armed));
ut_compare("is safe: not armed", is_safe(&current_state, &safety, &armed), true);
armed.armed = false;
armed.lockdown = true;
safety.safety_switch_available = true;
safety.safety_off = true;
ut_assert("is safe: software lockdown", is_safe(&current_state, &safety, &armed));
ut_compare("is safe: software lockdown", is_safe(&current_state, &safety, &armed), true);
armed.armed = true;
armed.lockdown = false;
safety.safety_switch_available = true;
safety.safety_off = true;
ut_assert("not safe: safety off", !is_safe(&current_state, &safety, &armed));
ut_compare("not safe: safety off", is_safe(&current_state, &safety, &armed), false);
armed.armed = true;
armed.lockdown = false;
safety.safety_switch_available = true;
safety.safety_off = false;
ut_assert("is safe: safety off", is_safe(&current_state, &safety, &armed));
ut_compare("is safe: safety off", is_safe(&current_state, &safety, &armed), true);
armed.armed = true;
armed.lockdown = false;
safety.safety_switch_available = false;
safety.safety_off = false;
ut_assert("not safe: no safety switch", !is_safe(&current_state, &safety, &armed));
ut_compare("not safe: no safety switch", is_safe(&current_state, &safety, &armed), false);
return true;
}
@@ -80,7 +80,7 @@ using namespace DriverFramework;
#endif
// This array defines the arming state transitions. The rows are the new state, and the columns
// are the current state. Using new state and current state you can index into the array which
// are the current state. Using new state and current state you can index into the array which
// will be true for a valid transition or false for a invalid transition. In some cases even
// though the transition is marked as true additional checks must be made. See arming_state_transition
// code for those checks.
@@ -145,10 +145,11 @@ transition_result_t arming_state_transition(struct vehicle_status_s *status,
prearm_ret = preflight_check(status, mavlink_log_pub, true /* pre-arm */, false /* force_report */,
status_flags, battery);
}
/* re-run the pre-flight check as long as sensors are failing */
if (!status_flags->condition_system_sensors_initialized
&& (new_arming_state == vehicle_status_s::ARMING_STATE_ARMED
|| new_arming_state == vehicle_status_s::ARMING_STATE_STANDBY)
&& ((new_arming_state == vehicle_status_s::ARMING_STATE_ARMED
|| new_arming_state == vehicle_status_s::ARMING_STATE_STANDBY))
&& status->hil_state == vehicle_status_s::HIL_STATE_OFF) {
if (last_preflight_check == 0 || hrt_absolute_time() - last_preflight_check > 1000 * 1000) {
@@ -280,6 +281,7 @@ transition_result_t arming_state_transition(struct vehicle_status_s *status,
if ((!status_flags->condition_system_prearm_error_reported &&
status_flags->condition_system_hotplug_timeout) ||
(new_arming_state == vehicle_status_s::ARMING_STATE_ARMED)) {
mavlink_and_console_log_critical(mavlink_log_pub, "Not ready to fly: Sensors not set up correctly");
status_flags->condition_system_prearm_error_reported = true;
}