Commit 643e7233 authored by Jesper Dangaard Brouer's avatar Jesper Dangaard Brouer Committed by Alexei Starovoitov

selftests/bpf: Test_progs option for getting number of tests

It can be practial to get the number of tests that test_progs contain.
This could for example be used to create a shell for-loop construct that
runs the individual tests.

Like:
 for N in $(seq 1 $(./test_progs -c)); do
   ./test_progs -n $N 2>&1 > result_test_${N}.log &
 done ; wait

V2: Add the ability to return the count for the selected tests. This is
useful for getting a count e.g. after excluding some tests with option -b.
The current beakers test script like to report the max test count upfront.
Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/159363985244.930467.12617117873058936829.stgit@firesoul
parent 6c92bd5c
...@@ -366,6 +366,7 @@ enum ARG_KEYS { ...@@ -366,6 +366,7 @@ enum ARG_KEYS {
ARG_TEST_NAME_BLACKLIST = 'b', ARG_TEST_NAME_BLACKLIST = 'b',
ARG_VERIFIER_STATS = 's', ARG_VERIFIER_STATS = 's',
ARG_VERBOSE = 'v', ARG_VERBOSE = 'v',
ARG_GET_TEST_CNT = 'c',
}; };
static const struct argp_option opts[] = { static const struct argp_option opts[] = {
...@@ -379,6 +380,8 @@ static const struct argp_option opts[] = { ...@@ -379,6 +380,8 @@ static const struct argp_option opts[] = {
"Output verifier statistics", }, "Output verifier statistics", },
{ "verbose", ARG_VERBOSE, "LEVEL", OPTION_ARG_OPTIONAL, { "verbose", ARG_VERBOSE, "LEVEL", OPTION_ARG_OPTIONAL,
"Verbose output (use -vv or -vvv for progressively verbose output)" }, "Verbose output (use -vv or -vvv for progressively verbose output)" },
{ "count", ARG_GET_TEST_CNT, NULL, 0,
"Get number of selected top-level tests " },
{}, {},
}; };
...@@ -511,6 +514,9 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state) ...@@ -511,6 +514,9 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
} }
} }
break; break;
case ARG_GET_TEST_CNT:
env->get_test_cnt = true;
break;
case ARGP_KEY_ARG: case ARGP_KEY_ARG:
argp_usage(state); argp_usage(state);
break; break;
...@@ -654,6 +660,11 @@ int main(int argc, char **argv) ...@@ -654,6 +660,11 @@ int main(int argc, char **argv)
test->test_num, test->test_name)) test->test_num, test->test_name))
continue; continue;
if (env.get_test_cnt) {
env.succ_cnt++;
continue;
}
test->run_test(); test->run_test();
/* ensure last sub-test is finalized properly */ /* ensure last sub-test is finalized properly */
if (test->subtest_name) if (test->subtest_name)
...@@ -677,9 +688,16 @@ int main(int argc, char **argv) ...@@ -677,9 +688,16 @@ int main(int argc, char **argv)
cleanup_cgroup_environment(); cleanup_cgroup_environment();
} }
stdio_restore(); stdio_restore();
if (env.get_test_cnt) {
printf("%d\n", env.succ_cnt);
goto out;
}
fprintf(stdout, "Summary: %d/%d PASSED, %d SKIPPED, %d FAILED\n", fprintf(stdout, "Summary: %d/%d PASSED, %d SKIPPED, %d FAILED\n",
env.succ_cnt, env.sub_succ_cnt, env.skip_cnt, env.fail_cnt); env.succ_cnt, env.sub_succ_cnt, env.skip_cnt, env.fail_cnt);
out:
free_str_set(&env.test_selector.blacklist); free_str_set(&env.test_selector.blacklist);
free_str_set(&env.test_selector.whitelist); free_str_set(&env.test_selector.whitelist);
free(env.test_selector.num_set); free(env.test_selector.num_set);
......
...@@ -66,6 +66,7 @@ struct test_env { ...@@ -66,6 +66,7 @@ struct test_env {
enum verbosity verbosity; enum verbosity verbosity;
bool jit_enabled; bool jit_enabled;
bool get_test_cnt;
struct prog_test_def *test; struct prog_test_def *test;
FILE *stdout; FILE *stdout;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment