testing cleanup

This commit is contained in:
Daniel Agar 2016-04-24 13:26:27 -04:00 committed by Lorenz Meier
parent 12165ba5a4
commit 008354f935
11 changed files with 153 additions and 145 deletions

View File

@ -250,7 +250,7 @@ ifeq ($(VECTORCONTROL),1)
@rm -rf ROMFS/px4fmu_common/uavcan
endif
unittest: posix_sitl_default
unittest: posix_sitl_test
@(mkdir -p build_unittests && cd build_unittests && cmake -G$(PX4_CMAKE_GENERATOR) ../unittests && $(PX4_MAKE) $(PX4_MAKE_ARGS) && ctest -j2 --output-on-failure)
package_firmware:

View File

@ -38,6 +38,11 @@ fi
# Start a minimal system
#
#
# Start the ORB (first app to start)
#
uorb start
#
# Load parameters
#
@ -104,43 +109,6 @@ then
tests mount
fi
#
# Run unit tests at board boot, reporting failure as needed.
# Add new unit tests using the same pattern as below.
#
if mavlink_tests
then
else
set unit_test_failure 1
set unit_test_failure_list "${unit_test_failure_list} mavlink_tests"
fi
# TODO: commander_tests is currently broken
#if commander_tests
#then
#else
# set unit_test_failure 1
# set unit_test_failure_list "${unit_test_failure_list} commander_tests"
#fi
if controllib_test
then
else
set unit_test_failure 1
set unit_test_failure_list "${unit_test_failure_list} controllib_tests"
fi
if uorb test
then
else
set unit_test_failure 1
set unit_test_failure_list "${unit_test_failure_list} uorb_tests"
fi
#
# Sensors System (start before Commander so Preflight checks are properly run)
#
sh /etc/init.d/rc.sensors
# Check for flow sensor
@ -152,6 +120,60 @@ if ll40ls start
then
fi
#
# Run unit tests at board boot, reporting failure as needed.
# Add new unit tests using the same pattern as below.
#
echo
echo "--------------------------------------------------------------------------------"
echo "[mavlink_tests] STARTING TEST"
if mavlink_tests
then
echo "[mavlink_tests] PASS"
else
set unit_test_failure 1
set unit_test_failure_list "${unit_test_failure_list} mavlink_tests"
echo "[mavlink_tests] FAILED"
fi
echo "--------------------------------------------------------------------------------"
echo
echo "--------------------------------------------------------------------------------"
echo "[commander_tests] STARTING TEST"
if commander_tests
then
echo "[commander_tests] PASS"
else
set unit_test_failure 1
set unit_test_failure_list "${unit_test_failure_list} commander_tests"
echo "[commander_tests] FAILED"
fi
echo "--------------------------------------------------------------------------------"
echo
echo "--------------------------------------------------------------------------------"
echo "[controllib_test] STARTING TEST"
if controllib_test
then
echo "[controllib_test] PASS"
else
set unit_test_failure 1
set unit_test_failure_list "${unit_test_failure_list} controllib_tests"
echo "[controllib_test] FAILED"
fi
echo "--------------------------------------------------------------------------------"
echo
echo "--------------------------------------------------------------------------------"
echo "[uorb_tests] STARTING TEST"
if uorb_tests
then
echo "[uorb_tests] PASS"
else
set unit_test_failure 1
set unit_test_failure_list "${unit_test_failure_list} uorb_tests"
echo "[uorb_tests] FAILED"
fi
echo "--------------------------------------------------------------------------------"
if tests all
then
else

View File

@ -1,47 +1,9 @@
uorb start
simulator start -s
param load
param set MAV_TYPE 2
param set MC_PITCHRATE_P 0.15
param set MC_PITCH_P 7
param set MC_ROLL_P 7
param set MC_ROLLRATE_P 0.15
param set MC_YAW_P 2.8
param set MC_YAWRATE_P 0.35
param set SYS_AUTOSTART 4010
param set SYS_RESTART_TYPE 2
dataman start
param set CAL_GYRO0_ID 2293768
param set CAL_ACC0_ID 1376264
param set CAL_ACC1_ID 1310728
param set CAL_MAG0_ID 196616
param set CAL_GYRO0_XOFF 0.01
param set CAL_ACC0_XOFF 0.01
param set CAL_ACC0_YOFF -0.01
param set CAL_ACC0_ZOFF 0.01
param set CAL_ACC0_XSCALE 1.01
param set CAL_ACC0_YSCALE 1.01
param set CAL_ACC0_ZSCALE 1.01
param set CAL_ACC1_XOFF 0.01
param set CAL_MAG0_XOFF 0.01
param set MPC_XY_P 0.4
param set MPC_XY_VEL_P 0.2
param set MPC_XY_VEL_D 0.005
param set SENS_BOARD_ROT 0
param set SENS_BOARD_X_OFF 0.000001
param set COM_RC_IN_MODE 1
param set COM_DL_LOSS_EN 1
param set COM_DISARM_LAND 3
param set NAV_ACC_RAD 2.0
param set RTL_RETURN_ALT 30.0
param set RTL_DESCEND_ALT 10.0
param set RTL_LAND_DELAY 0
param set MIS_TAKEOFF_ALT 2.5
param set MPC_HOLD_MAX_Z 2.0
param set MPC_HOLD_XY_DZ 0.1
param set MPC_HOLD_Z_DZ 0.1
param set MPC_Z_VEL_MAX 2.0
param set MPC_Z_VEL_P 0.4
simulator start -s
rgbledsim start
tone_alarm start
gyrosim start
@ -52,10 +14,11 @@ gpssim start
pwm_out_sim mode_pwm
sleep 1
sensors start
commander start
commander_tests
controllib_test
uorb test
uorb_tests
tests all
ver all

View File

@ -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;
}

View File

@ -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;
}

View File

@ -2006,7 +2006,7 @@ Mavlink::task_main(int argc, char *argv[])
// allocated.
//fclose(fs);
} else {
warnx("open fd %d failed", _uart_fd);
PX4_WARN("open fd %d failed", _uart_fd);
}
/* reset param and save */
@ -2040,26 +2040,26 @@ Mavlink::task_main(int argc, char *argv[])
if (OK == configure_stream(_subscribe_to_stream, _subscribe_to_stream_rate)) {
if (_subscribe_to_stream_rate > 0.0f) {
if ( get_protocol() == SERIAL ) {
warnx("stream %s on device %s enabled with rate %.1f Hz", _subscribe_to_stream, _device_name,
PX4_INFO("stream %s on device %s enabled with rate %.1f Hz", _subscribe_to_stream, _device_name,
(double)_subscribe_to_stream_rate);
} else if ( get_protocol() == UDP ) {
warnx("stream %s on UDP port %d enabled with rate %.1f Hz", _subscribe_to_stream, _network_port,
PX4_INFO("stream %s on UDP port %d enabled with rate %.1f Hz", _subscribe_to_stream, _network_port,
(double)_subscribe_to_stream_rate);
}
} else {
if ( get_protocol() == SERIAL ) {
warnx("stream %s on device %s disabled", _subscribe_to_stream, _device_name);
PX4_WARN("stream %s on device %s disabled", _subscribe_to_stream, _device_name);
} else if ( get_protocol() == UDP ) {
warnx("stream %s on UDP port %d disabled", _subscribe_to_stream, _network_port);
PX4_WARN("stream %s on UDP port %d disabled", _subscribe_to_stream, _network_port);
}
}
} else {
if ( get_protocol() == SERIAL ) {
warnx("stream %s on device %s not found", _subscribe_to_stream, _device_name);
PX4_WARN("stream %s on device %s not found", _subscribe_to_stream, _device_name);
} else if ( get_protocol() == UDP ) {
warnx("stream %s on UDP port %d not found", _subscribe_to_stream, _network_port);
PX4_WARN("stream %s on UDP port %d not found", _subscribe_to_stream, _network_port);
}
}

View File

@ -128,7 +128,7 @@ int uORBTest::UnitTest::pubsublatency_main(void)
pubsubtest_passed = true;
if (static_cast<float>(latency_integral / maxruns) > 30.0f) {
if (static_cast<float>(latency_integral / maxruns) > 40.0f) {
pubsubtest_res = uORB::ERROR;
} else {

View File

@ -44,31 +44,38 @@ extern "C" { __EXPORT int uorb_tests_main(int argc, char *argv[]); }
static void usage()
{
PX4_INFO("Usage: uorb_test 'test', 'latency_test'");
PX4_INFO("Usage: uorb_test 'latency_test'");
}
int
uorb_tests_main(int argc, char *argv[])
{
if (argc < 2) {
usage();
return -EINVAL;
}
#ifndef __PX4_QURT
/*
* Test the driver/device.
*/
if (!strcmp(argv[1], "test")) {
if (argc == 1) {
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();
return t.test();
int rc = t.test();
if (rc == OK) {
fprintf(stdout, " [uORBTest] \t\tPASS\n");
fflush(stdout);
return 0;
} else {
fprintf(stderr, " [uORBTest] \t\tFAIL\n");
fflush(stderr);
return -1;
}
}
/*
* Test the latency.
*/
if (!strcmp(argv[1], "latency_test")) {
if (argc > 1 && !strcmp(argv[1], "latency_test")) {
uORBTest::UnitTest &t = uORBTest::UnitTest::instance();

View File

@ -51,26 +51,26 @@ UnitTest::~UnitTest()
void UnitTest::print_results(void)
{
if (_tests_failed) {
warnx("SOME TESTS FAILED");
PX4_ERR("SOME TESTS FAILED");
} else {
warnx("ALL TESTS PASSED");
PX4_INFO("ALL TESTS PASSED");
}
warnx(" Tests passed : %d", _tests_passed);
warnx(" Tests failed : %d", _tests_failed);
warnx(" Assertions : %d", _assertions);
PX4_INFO(" Tests passed : %d", _tests_passed);
PX4_INFO(" Tests failed : %d", _tests_failed);
PX4_INFO(" Assertions : %d", _assertions);
}
/// @brief Used internally to the ut_assert macro to print assert failures.
void UnitTest::_print_assert(const char *msg, const char *test, const char *file, int line)
{
warnx("Assertion failed: %s - %s (%s:%d)", msg, test, file, line);
PX4_ERR("Assertion failed: %s - %s (%s:%d)", msg, test, file, line);
}
/// @brief Used internally to the ut_compare macro to print assert failures.
void UnitTest::_print_compare(const char *msg, const char *v1_text, int v1, const char *v2_text, int v2,
const char *file, int line)
{
warnx("Compare failed: %s - (%s:%d) (%s:%d) (%s:%d)", msg, v1_text, v1, v2_text, v2, file, line);
PX4_ERR("Compare failed: %s - (%s:%d) (%s:%d) (%s:%d)", msg, v1_text, v1, v2_text, v2, file, line);
}

View File

@ -68,14 +68,14 @@ protected:
/// test should return true if it succeeded, false for fail.
#define ut_run_test(test) \
do { \
warnx("RUNNING TEST: %s", #test); \
PX4_INFO("RUNNING TEST: %s", #test); \
_tests_run++; \
_init(); \
if (!test()) { \
warnx("TEST FAILED: %s", #test); \
PX4_ERR("TEST FAILED: %s", #test); \
_tests_failed++; \
} else { \
warnx("TEST PASSED: %s", #test); \
PX4_INFO("TEST PASSED: %s", #test); \
_tests_passed++; \
} \
_cleanup(); \

View File

@ -78,16 +78,19 @@ const struct {
#define OPT_NOALLTEST (1<<1)
#define OPT_NOJIGTEST (1<<2)
} tests[] = {
#ifdef __PX4_NUTTX
{"led", test_led, 0},
{"time", test_time, OPT_NOJIGTEST},
{"sensors", test_sensors, 0},
{"adc", test_adc, OPT_NOJIGTEST},
#endif /* __PX4_NUTTX */
{"int", test_int, 0},
{"float", test_float, 0},
{"sensors", test_sensors, 0},
{"gpio", test_gpio, OPT_NOJIGTEST | OPT_NOALLTEST},
{"hrt", test_hrt, OPT_NOJIGTEST | OPT_NOALLTEST},
{"ppm", test_ppm, OPT_NOJIGTEST | OPT_NOALLTEST},
{"servo", test_servo, OPT_NOJIGTEST | OPT_NOALLTEST},
{"ppm_loopback", test_ppm_loopback, OPT_NOALLTEST},
{"adc", test_adc, OPT_NOJIGTEST},
{"jig_voltages", test_jig_voltages, OPT_NOALLTEST},
{"uart_loopback", test_uart_loopback, OPT_NOJIGTEST | OPT_NOALLTEST},
{"uart_baudchange", test_uart_baudchange, OPT_NOJIGTEST | OPT_NOALLTEST},
@ -96,9 +99,6 @@ const struct {
{"hott_telemetry", test_hott_telemetry, OPT_NOJIGTEST | OPT_NOALLTEST},
{"tone", test_tone, 0},
{"sleep", test_sleep, OPT_NOJIGTEST},
#ifdef __PX4_NUTTX
{"time", test_time, OPT_NOJIGTEST},
#endif
{"perf", test_perf, OPT_NOJIGTEST},
{"all", test_all, OPT_NOALLTEST | OPT_NOJIGTEST},
{"jig", test_jig, OPT_NOJIGTEST | OPT_NOALLTEST},
@ -150,23 +150,29 @@ test_all(int argc, char *argv[])
for (i = 0; tests[i].name; i++) {
/* Only run tests that are not excluded */
if (!(tests[i].options & OPT_NOALLTEST)) {
printf(" [%s] \t\t\tSTARTING TEST\n", tests[i].name);
for (int j = 0; j < 80; j++) {
printf("-");
}
printf("\n");
printf(" [%s] \t\tSTARTING TEST\n", tests[i].name);
fflush(stdout);
/* Execute test */
if (tests[i].fn(1, args) != 0) {
fprintf(stderr, " [%s] \t\t\tFAIL\n", tests[i].name);
fprintf(stderr, " [%s] \t\tFAIL\n", tests[i].name);
fflush(stderr);
failcount++;
passed[i] = false;
} else {
printf(" [%s] \t\t\tPASS\n", tests[i].name);
printf(" [%s] \t\tPASS\n", tests[i].name);
fflush(stdout);
passed[i] = true;
}
for (int j = 0; j < 40; j++) {
for (int j = 0; j < 80; j++) {
printf("-");
}
@ -179,8 +185,8 @@ test_all(int argc, char *argv[])
/* Print summary */
printf("\n");
for (int j = 0; j < 40; j++) {
printf("-");
for (int j = 0; j < 80; j++) {
printf("#");
}
printf("\n\n");
@ -269,31 +275,42 @@ int test_jig(int argc, char *argv[])
for (i = 0; tests[i].name; i++) {
/* Only run tests that are not excluded */
if (!(tests[i].options & OPT_NOJIGTEST)) {
printf(" [%s] \t\t\tSTARTING TEST\n", tests[i].name);
for (int j = 0; j < 80; j++) {
printf("-");
}
printf("\n");
printf(" [%s] \t\tSTARTING TEST\n", tests[i].name);
fflush(stdout);
/* Execute test */
if (tests[i].fn(1, args) != 0) {
fprintf(stderr, " [%s] \t\t\tFAIL\n", tests[i].name);
fprintf(stderr, " [%s] \t\tFAIL\n", tests[i].name);
fflush(stderr);
failcount++;
passed[i] = false;
} else {
printf(" [%s] \t\t\tPASS\n", tests[i].name);
printf(" [%s] \t\tPASS\n", tests[i].name);
fflush(stdout);
passed[i] = true;
}
for (int j = 0; j < 80; j++) {
printf("-");
}
printf("\n");
testcount++;
}
}
/* Print summary */
printf("\n");
int j;
for (j = 0; j < 40; j++) {
for (int j = 0; j < 80; j++) {
printf("-");
}
@ -325,9 +342,7 @@ int test_jig(int argc, char *argv[])
/* Print failed tests */
if (failcount > 0) { printf(" Failed tests:\n\n"); }
unsigned int k;
for (k = 0; k < i; k++) {
for (int k = 0; k < i; k++) {
if (!passed[i] && !(tests[k].options & OPT_NOJIGTEST)) {
printf(" [%s] to obtain details, please re-run with\n\t nsh> tests %s\n\n", tests[k].name, tests[k].name);
}