diff --git a/userspace/include/unit/args.h b/userspace/include/unit/args.h index e02cd60a4..0f9741952 100644 --- a/userspace/include/unit/args.h +++ b/userspace/include/unit/args.h @@ -48,6 +48,7 @@ struct unit_fw_args { const char *unit_name; const char *unit_load_path; + const char *unit_to_run; }; int core_parse_args(struct unit_fw *fw, int argc, char **argv); diff --git a/userspace/src/args.c b/userspace/src/args.c index 79eb83340..44f079616 100644 --- a/userspace/src/args.c +++ b/userspace/src/args.c @@ -155,5 +155,13 @@ int core_parse_args(struct unit_fw *fw, int argc, char **argv) } } + /* + * If there is an extra argument after the command-line options, then + * it is a unit test name that need to be specifically run. + */ + if (optind < argc) { + args->unit_to_run = argv[optind]; + } + return 0; } diff --git a/userspace/src/module.c b/userspace/src/module.c index 836d36abd..d88b392cd 100644 --- a/userspace/src/module.c +++ b/userspace/src/module.c @@ -77,6 +77,14 @@ static struct unit_module *load_one_module(struct unit_fw *fw, core_vbs(fw, 1, "Loading: %s\n", dent->d_name); + if (fw->args->unit_to_run != NULL) { + if (strstr(dent->d_name, fw->args->unit_to_run) == NULL) { + core_vbs(fw, 1, " Skipping unit (not *%s*)\n", + fw->args->unit_to_run); + return NULL; + } + } + lib_handle = dlopen(dent->d_name, RTLD_NOW); if (lib_handle == NULL) { core_err(fw, "Failed to load %s: %s\n", diff --git a/userspace/src/unit_main.c b/userspace/src/unit_main.c index c69683848..e1c25e3d5 100644 --- a/userspace/src/unit_main.c +++ b/userspace/src/unit_main.c @@ -70,15 +70,25 @@ int main(int argc, char **argv) if (ret != 0) return ret; + if (fw->results == NULL) { + core_msg(fw, "No tests were run!\n"); + return -1; + } + core_print_test_status(fw); - if (fw->results->nr_tests == 0) { - /* No tests were run */ - return -1; - } else if ((fw->results->nr_tests - fw->results->nr_passing) != 0) { + if ((fw->results->nr_tests - fw->results->nr_passing) != 0) { /* Some tests failed */ return -1; } + if (fw->args->unit_to_run != NULL) { + /* + * Just in case (especially when running in automation), return + * a failure if only executed a subset of the units + */ + return -2; + } + return 0; }