From: Emil Velikov Date: Mon, 16 Jun 2025 16:00:42 +0000 (+0100) Subject: testsuite: fixup argument handling X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dd77977c2997826cad72221237540ee21c47ffbf;p=thirdparty%2Fkmod.git testsuite: fixup argument handling 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 Link: https://github.com/kmod-project/kmod/pull/376 Signed-off-by: Lucas De Marchi --- diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index b8cfdfcf..7388066f 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -108,6 +108,18 @@ int test_init(const struct test *start, const struct test *stop, int argc, } } + 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 = ""; @@ -140,9 +152,9 @@ static int test_spawn_test(const struct test *t) 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[]) @@ -1144,7 +1156,7 @@ int test_run(const struct test *t) int fdmonitor[2]; if (oneshot) - test_run_spawned(t); + return test_run_spawned(t); if (t->output.out != NULL) { if (pipe(fdout) != 0) { diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index 714af724..4ce0c22c 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -144,10 +144,12 @@ int test_run(const struct test *t); 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]); \