Currently we can pass any number of tests as arguments - be that in
oneshot mode or not.
At the same time, oneshot requires only one test while normal mode can
have up-to one.
Fix that up and as a bonus we no longer need the exit() in
test_run_spawned() \o/
While in here, add a few comments around our arg/argc handling.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/376
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
}
}
+ if (oneshot) {
+ if ((optind + 1) != argc) {
+ ERR("Too many arguments provided. Only one is supported - the testname\n");
+ return -1;
+ }
+ } else {
+ if (optind != argc && (optind + 1) != argc) {
+ ERR("Invalid number of arguments provided. One optional can be provided - the testname\n");
+ return -1;
+ }
+ }
+
if (isatty(STDOUT_FILENO) == 0) {
ANSI_HIGHLIGHT_OFF = "";
ANSI_HIGHLIGHT_RED_ON = "";
return EXIT_FAILURE;
}
-static noreturn int test_run_spawned(const struct test *t)
+static int test_run_spawned(const struct test *t)
{
- exit(t->func());
+ return t->func();
}
int test_spawn_prog(const char *prog, const char *const args[])
int fdmonitor[2];
if (oneshot)
- test_run_spawned(t);
+ return test_run_spawned(t);
if (t->output.out != NULL) {
if (pipe(fdout) != 0) {
int arg, ret = EXIT_SUCCESS; \
\
arg = test_init(__start_kmod_tests, __stop_kmod_tests, argc, argv); \
- if (arg == 0) \
- return 0; \
+ /* Invalid arguments */ \
if (arg < 0) \
return EXIT_FAILURE; \
+ /* Print and exit options - list, help */ \
+ if (arg == 0) \
+ return 0; \
\
if (arg < argc) { \
t = test_find(__start_kmod_tests, __stop_kmod_tests, argv[arg]); \