mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-30 12:16:17 +08:00
Added audio tune signals for unit tests passing and failing.
This commit is contained in:
@@ -72,16 +72,18 @@ int test_tone(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
if (tune_control.tune_id <= 20) {
|
|
||||||
tune_control.tune_id = atoi(argv[1]);
|
tune_control.tune_id = atoi(argv[1]);
|
||||||
PX4_INFO("Testing TuneID: %d", tune_control.tune_id);
|
|
||||||
|
if (tune_control.tune_id <= 20) {
|
||||||
|
PX4_INFO("TuneID: %d", tune_control.tune_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
|
int volume = 40;
|
||||||
Tunes tunes{};
|
Tunes tunes{};
|
||||||
tunes.set_string(argv[2], 40);
|
tunes.set_string(argv[2], volume);
|
||||||
PX4_INFO("Testing custom tune.");
|
PX4_INFO("Custom tune.");
|
||||||
}
|
}
|
||||||
|
|
||||||
tune_control.strength = 40;
|
tune_control.strength = 40;
|
||||||
|
|||||||
@@ -51,11 +51,11 @@
|
|||||||
#define TESTS_EIGEN_DISABLE
|
#define TESTS_EIGEN_DISABLE
|
||||||
|
|
||||||
|
|
||||||
static int test_all(int argc, char *argv[]);
|
|
||||||
static int test_help(int argc, char *argv[]);
|
static int test_help(int argc, char *argv[]);
|
||||||
static int test_jig(int argc, char *argv[]);
|
|
||||||
static int test_runner(unsigned option);
|
static int test_runner(unsigned option);
|
||||||
|
|
||||||
|
static int test_all(int argc, char *argv[]);
|
||||||
|
static int test_jig(int argc, char *argv[]);
|
||||||
|
|
||||||
const struct {
|
const struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
@@ -65,8 +65,8 @@ const struct {
|
|||||||
#define OPT_NOALLTEST (1<<1)
|
#define OPT_NOALLTEST (1<<1)
|
||||||
#define OPT_NOJIGTEST (1<<2)
|
#define OPT_NOJIGTEST (1<<2)
|
||||||
} tests[] = {
|
} tests[] = {
|
||||||
{"all", test_all, OPT_NOALLTEST | OPT_NOJIGTEST},
|
|
||||||
{"help", test_help, OPT_NOALLTEST | OPT_NOHELP | OPT_NOJIGTEST},
|
{"help", test_help, OPT_NOALLTEST | OPT_NOHELP | OPT_NOJIGTEST},
|
||||||
|
{"all", test_all, OPT_NOALLTEST | OPT_NOJIGTEST},
|
||||||
{"jig", test_jig, OPT_NOJIGTEST | OPT_NOALLTEST},
|
{"jig", test_jig, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||||
#ifdef __PX4_NUTTX
|
#ifdef __PX4_NUTTX
|
||||||
{"adc", test_adc, OPT_NOJIGTEST},
|
{"adc", test_adc, OPT_NOJIGTEST},
|
||||||
@@ -78,27 +78,29 @@ const struct {
|
|||||||
{"uart_break", test_uart_break, OPT_NOJIGTEST | OPT_NOALLTEST},
|
{"uart_break", test_uart_break, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||||
{"uart_console", test_uart_console, OPT_NOJIGTEST | OPT_NOALLTEST},
|
{"uart_console", test_uart_console, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||||
#else
|
#else
|
||||||
{"mavlink", mavlink_tests_main, 0},
|
|
||||||
{"rc", rc_tests_main, 0},
|
{"rc", rc_tests_main, 0},
|
||||||
#endif /* __PX4_NUTTX */
|
#endif /* __PX4_NUTTX */
|
||||||
|
|
||||||
/* external tests */
|
/* external tests */
|
||||||
{"commander", commander_tests_main, 0},
|
{"commander", commander_tests_main, 0},
|
||||||
{"controllib", controllib_test_main, 0},
|
{"controllib", controllib_test_main, 0},
|
||||||
|
#ifndef __PX4_NUTTX
|
||||||
|
{"mavlink", mavlink_tests_main, 0},
|
||||||
|
#endif
|
||||||
{"sf0x", sf0x_tests_main, 0},
|
{"sf0x", sf0x_tests_main, 0},
|
||||||
{"uorb", uorb_tests_main, 0},
|
{"uorb", uorb_tests_main, 0},
|
||||||
|
{"hysteresis", test_hysteresis, 0},
|
||||||
|
|
||||||
|
{"mixer", test_mixer, OPT_NOJIGTEST},
|
||||||
{"autodeclination", test_autodeclination, 0},
|
{"autodeclination", test_autodeclination, 0},
|
||||||
{"bezier", test_bezierQuad, 0},
|
{"bezier", test_bezierQuad, 0},
|
||||||
{"bson", test_bson, 0},
|
{"bson", test_bson, 0},
|
||||||
{"conv", test_conv, 0},
|
{"conv", test_conv, 0},
|
||||||
{"ctlmath", test_controlmath, 0},
|
|
||||||
{"dataman", test_dataman, OPT_NOJIGTEST | OPT_NOALLTEST},
|
{"dataman", test_dataman, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||||
{"file2", test_file2, OPT_NOJIGTEST},
|
{"file2", test_file2, OPT_NOJIGTEST},
|
||||||
{"float", test_float, 0},
|
{"float", test_float, 0},
|
||||||
{"hott_telemetry", test_hott_telemetry, OPT_NOJIGTEST | OPT_NOALLTEST},
|
{"hott_telemetry", test_hott_telemetry, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||||
{"hrt", test_hrt, OPT_NOJIGTEST | OPT_NOALLTEST},
|
{"hrt", test_hrt, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||||
{"hysteresis", test_hysteresis, 0},
|
|
||||||
{"int", test_int, 0},
|
{"int", test_int, 0},
|
||||||
{"jig_voltages", test_jig_voltages, OPT_NOALLTEST},
|
{"jig_voltages", test_jig_voltages, OPT_NOALLTEST},
|
||||||
{"mathlib", test_mathlib, 0},
|
{"mathlib", test_mathlib, 0},
|
||||||
@@ -107,7 +109,6 @@ const struct {
|
|||||||
{"microbench_math", test_microbench_math, 0},
|
{"microbench_math", test_microbench_math, 0},
|
||||||
{"microbench_matrix", test_microbench_matrix, 0},
|
{"microbench_matrix", test_microbench_matrix, 0},
|
||||||
{"microbench_uorb", test_microbench_uorb, 0},
|
{"microbench_uorb", test_microbench_uorb, 0},
|
||||||
{"mixer", test_mixer, OPT_NOJIGTEST},
|
|
||||||
{"mount", test_mount, OPT_NOJIGTEST | OPT_NOALLTEST},
|
{"mount", test_mount, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||||
{"param", test_param, 0},
|
{"param", test_param, 0},
|
||||||
{"parameters", test_parameters, 0},
|
{"parameters", test_parameters, 0},
|
||||||
@@ -118,34 +119,37 @@ const struct {
|
|||||||
{"search_min", test_search_min, 0},
|
{"search_min", test_search_min, 0},
|
||||||
{"servo", test_servo, OPT_NOJIGTEST | OPT_NOALLTEST},
|
{"servo", test_servo, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||||
{"sleep", test_sleep, OPT_NOJIGTEST},
|
{"sleep", test_sleep, OPT_NOJIGTEST},
|
||||||
{"smooth_z", test_smooth_z, 0},
|
|
||||||
{"tone", test_tone, 0},
|
{"tone", test_tone, 0},
|
||||||
{"uart_loopback", test_uart_loopback, OPT_NOJIGTEST | OPT_NOALLTEST},
|
{"uart_loopback", test_uart_loopback, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||||
{"uart_send", test_uart_send, OPT_NOJIGTEST | OPT_NOALLTEST},
|
{"uart_send", test_uart_send, OPT_NOJIGTEST | OPT_NOALLTEST},
|
||||||
{"versioning", test_versioning, 0},
|
{"versioning", test_versioning, 0},
|
||||||
|
{"ctlmath", test_controlmath, 0},
|
||||||
|
{"smoothz", test_smooth_z, 0},
|
||||||
{NULL, NULL, 0}
|
{NULL, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NTESTS (sizeof(tests) / sizeof(tests[0]))
|
#define NTESTS (sizeof(tests) / sizeof(tests[0]))
|
||||||
|
|
||||||
static int
|
|
||||||
test_all(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
return test_runner(OPT_NOALLTEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
test_help(int argc, char *argv[])
|
test_help(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
printf("Available tests:\n");
|
printf("Available tests:\n");
|
||||||
|
|
||||||
for (size_t i = 0; tests[i].name; i++) {
|
for (i = 0; tests[i].name; i++) {
|
||||||
printf(" %s\n", tests[i].name);
|
printf(" %s\n", tests[i].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
test_all(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
return test_runner(OPT_NOALLTEST);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
test_jig(int argc, char *argv[])
|
test_jig(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@@ -155,24 +159,22 @@ test_jig(int argc, char *argv[])
|
|||||||
static int
|
static int
|
||||||
test_runner(unsigned option)
|
test_runner(unsigned option)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i;
|
||||||
char *args[2] = {"all", NULL};
|
char *args[2] = {"all", NULL};
|
||||||
unsigned int failcount = 0;
|
unsigned int failcount = 0;
|
||||||
unsigned int testcount = 0;
|
unsigned int testcount = 0;
|
||||||
unsigned passed[NTESTS] = {};
|
unsigned int passed[NTESTS];
|
||||||
|
|
||||||
printf("\nRunning all tests...\n\n");
|
printf("\nRunning all tests...\n\n");
|
||||||
|
|
||||||
for (i = 0; tests[i].name; i++) {
|
for (i = 0; tests[i].name; i++) {
|
||||||
/* Only run tests that are not excluded */
|
// Only run tests that are not excluded.
|
||||||
if (!(tests[i].options & option)) {
|
if (!(tests[i].options & option)) {
|
||||||
for (int j = 0; j < 80; j++) {
|
for (int j = 0; j < 80; j++) {
|
||||||
printf("-");
|
printf("-");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n [%s] \t\tSTARTING TEST\n", tests[i].name);
|
||||||
|
|
||||||
printf(" [%s] \t\tSTARTING TEST\n", tests[i].name);
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
/* Execute test */
|
/* Execute test */
|
||||||
@@ -192,22 +194,19 @@ test_runner(unsigned option)
|
|||||||
printf("-");
|
printf("-");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n\n");
|
|
||||||
|
|
||||||
testcount++;
|
testcount++;
|
||||||
|
printf("\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print summary */
|
// Print summary.
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
for (unsigned j = 0; j < 80; j++) {
|
for (size_t j = 0; j < 80; j++) {
|
||||||
printf("#");
|
printf("#");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n\n");
|
printf("\n\n T E S T S U M M A R Y\n\n");
|
||||||
|
|
||||||
printf(" T E S T S U M M A R Y\n\n");
|
|
||||||
|
|
||||||
if (failcount == 0) {
|
if (failcount == 0) {
|
||||||
printf(" ______ __ __ ______ __ __ \n");
|
printf(" ______ __ __ ______ __ __ \n");
|
||||||
@@ -216,7 +215,7 @@ test_runner(unsigned option)
|
|||||||
printf(" \\ \\_\\ \\_\\ \\ \\_____\\ \\ \\_____\\ \\ \\_____\\ \\ \\_\\ \\_\\ \n");
|
printf(" \\ \\_\\ \\_\\ \\ \\_____\\ \\ \\_____\\ \\ \\_____\\ \\ \\_\\ \\_\\ \n");
|
||||||
printf(" \\/_/\\/_/ \\/_____/ \\/_____/ \\/_____/ \\/_/\\/_/ \n");
|
printf(" \\/_/\\/_/ \\/_____/ \\/_____/ \\/_____/ \\/_/\\/_/ \n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" All tests passed (%d of %d)\n", testcount, testcount);
|
printf(" All tests passed (%d of %d)\n\n", testcount, testcount);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf(" ______ ______ __ __ \n");
|
printf(" ______ ______ __ __ \n");
|
||||||
@@ -225,24 +224,21 @@ test_runner(unsigned option)
|
|||||||
printf(" \\ \\_\\ \\ \\_\\ \\_\\ \\ \\_\\ \\ \\_____\\ \n");
|
printf(" \\ \\_\\ \\ \\_\\ \\_\\ \\ \\_\\ \\ \\_____\\ \n");
|
||||||
printf(" \\/_/ \\/_/\\/_/ \\/_/ \\/_____/ \n");
|
printf(" \\/_/ \\/_/\\/_/ \\/_/ \\/_____/ \n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" Some tests failed (%d of %d)\n", failcount, testcount);
|
printf(" Some tests failed (%d of %d)\n\n", failcount, testcount);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
// Print failed tests.
|
||||||
|
|
||||||
/* Print failed tests */
|
|
||||||
if (failcount > 0) {
|
if (failcount > 0) {
|
||||||
printf(" Failed tests:\n\n");
|
printf(" Failed tests:\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned k = 0; k < i; k++) {
|
for (size_t k = 0; k < i; k++) {
|
||||||
if (!passed[k] && !(tests[k].options & option)) {
|
if (!passed[k] && !(tests[k].options & option)) {
|
||||||
printf(" [%s] to obtain details, please re-run with\n\t nsh> tests %s\n\n", tests[k].name, tests[k].name);
|
printf(" [%s] to obtain details, please re-run with\n\t nsh> tests %s\n\n", tests[k].name, tests[k].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
return (failcount > 0);
|
return (failcount > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,13 +254,33 @@ int tests_main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tone_test_index = -1;
|
||||||
|
char *tone_test = {"tone"};
|
||||||
|
char *tone_fail[2] = {NULL, "2"};
|
||||||
|
char *tone_pass[2] = {NULL, "14"};
|
||||||
|
|
||||||
|
// Identify the tone test index for later use.
|
||||||
|
for (size_t i = 0; tests[i].name; i++) {
|
||||||
|
if (*tone_test == *tests[i].name) {
|
||||||
|
tone_test_index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; tests[i].name; i++) {
|
for (size_t i = 0; tests[i].name; i++) {
|
||||||
if (!strcmp(tests[i].name, argv[1])) {
|
if (!strcmp(tests[i].name, argv[1])) {
|
||||||
if (tests[i].fn(argc - 1, argv + 1) == 0) {
|
if (tests[i].fn(argc - 1, argv + 1) == 0) {
|
||||||
|
if (tone_test_index != -1) {
|
||||||
|
tests[tone_test_index].fn(2, tone_pass); // Play a notification.
|
||||||
|
}
|
||||||
|
|
||||||
printf("%s PASSED\n", tests[i].name);
|
printf("%s PASSED\n", tests[i].name);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
if (tone_test_index != -1) {
|
||||||
|
tests[tone_test_index].fn(2, tone_fail); // Play an error notification.
|
||||||
|
}
|
||||||
|
|
||||||
printf("%s FAILED\n", tests[i].name);
|
printf("%s FAILED\n", tests[i].name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user