From 251a40108d45dee27e46916c85cf3afd64391832 Mon Sep 17 00:00:00 2001 From: Sharvil Nanavati Date: Wed, 5 Nov 2014 02:09:42 -0800 Subject: [PATCH] Add a command line flag to skip sanity test suite. --- test/suite/main.c | 73 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/test/suite/main.c b/test/suite/main.c index 816836134..72ac41381 100644 --- a/test/suite/main.c +++ b/test/suite/main.c @@ -64,13 +64,18 @@ static void *watchdog_fn(void *arg) { } static void print_usage(const char *program_name) { - printf("Usage: %s [test name]\n", program_name); + printf("Usage: %s [options] [test name]\n", program_name); + printf("\n"); + printf("Options:\n"); + printf(" %-20sdisplay this help text.\n", "--help"); + printf(" %-20sdo not run sanity suite.\n", "--insanity"); + printf("\n"); printf("Valid test names are:\n"); for (size_t i = 0; i < sanity_suite_size; ++i) { - printf("%s\n", sanity_suite[i].function_name); + printf(" %s\n", sanity_suite[i].function_name); } for (size_t i = 0; i < test_suite_size; ++i) { - printf("%s\n", test_suite[i].function_name); + printf(" %s\n", test_suite[i].function_name); } } @@ -89,10 +94,33 @@ static bool is_valid(const char *test_name) { } int main(int argc, char **argv) { - if (argc > 2) { - printf("Error: invalid arguments.\n"); - print_usage(argv[0]); - return -1; + const char *test_name = NULL; + bool skip_sanity_suite = false; + + for (int i = 1; i < argc; ++i) { + if (!strcmp("--help", argv[i])) { + print_usage(argv[0]); + return 0; + } + + if (!strcmp("--insanity", argv[i])) { + skip_sanity_suite = true; + continue; + } + + if (!is_valid(argv[i])) { + printf("Error: invalid test name.\n"); + print_usage(argv[0]); + return -1; + } + + if (test_name != NULL) { + printf("Error: invalid arguments.\n"); + print_usage(argv[0]); + return -1; + } + + test_name = argv[i]; } config_t *config = config_new(CONFIG_FILE_PATH); @@ -117,13 +145,6 @@ int main(int argc, char **argv) { return -1; } - const char *test_name = (argc == 3) ? argv[2] : NULL; - if (test_name && !is_valid(test_name)) { - printf("Error: invalid test name.\n"); - print_usage(argv[0]); - return -1; - } - if (!hal_open(callbacks_get_adapter_struct())) { printf("Unable to open Bluetooth HAL.\n"); return 1; @@ -157,18 +178,20 @@ int main(int argc, char **argv) { // If test name is specified, run that specific test. // Otherwise run through the sanity suite. - for (size_t i = 0; i < sanity_suite_size; ++i) { - if (!test_name || !strcmp(test_name, sanity_suite[i].function_name)) { - callbacks_init(); - if (sanity_suite[i].function()) { - printf("[%4d] %-64s [%sPASS%s]\n", ++case_num, sanity_suite[i].function_name, GREEN, DEFAULT); - ++pass; - } else { - printf("[%4d] %-64s [%sFAIL%s]\n", ++case_num, sanity_suite[i].function_name, RED, DEFAULT); - ++fail; + if (!skip_sanity_suite) { + for (size_t i = 0; i < sanity_suite_size; ++i) { + if (!test_name || !strcmp(test_name, sanity_suite[i].function_name)) { + callbacks_init(); + if (sanity_suite[i].function()) { + printf("[%4d] %-64s [%sPASS%s]\n", ++case_num, sanity_suite[i].function_name, GREEN, DEFAULT); + ++pass; + } else { + printf("[%4d] %-64s [%sFAIL%s]\n", ++case_num, sanity_suite[i].function_name, RED, DEFAULT); + ++fail; + } + callbacks_cleanup(); + ++watchdog_id; } - callbacks_cleanup(); - ++watchdog_id; } } -- 2.11.0