Skip to content

Commit fd74b79

Browse files
Domenico Cerasuoloanakryiko
authored andcommitted
selftests: Fix test group SKIPPED result
When showing the result of a test group, if one of the subtests was skipped, while still having passing subtests, the group result was marked as SKIP. E.g.: 223/1 usdt/basic:SKIP 223/2 usdt/multispec:OK 223/3 usdt/urand_auto_attach:OK 223/4 usdt/urand_pid_attach:OK 223 usdt:SKIP The test result of usdt in the example above should be OK instead of SKIP, because the test group did have passing tests and it would be considered in "normal" state. With this change, only if all of the subtests were skipped, the group test is marked as SKIP. When only some of the subtests are skipped, a more detailed result is given, stating how many of the subtests were skipped. E.g: 223/1 usdt/basic:SKIP 223/2 usdt/multispec:OK 223/3 usdt/urand_auto_attach:OK 223/4 usdt/urand_pid_attach:OK 223 usdt:OK (SKIP: 1/4) Signed-off-by: Domenico Cerasuolo <dceras@meta.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20221109184039.3514033-1-cerasuolodomenico@gmail.com
1 parent 15157d2 commit fd74b79

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

tools/testing/selftests/bpf/test_progs.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,26 @@ static char *test_result(bool failed, bool skipped)
222222
return failed ? "FAIL" : (skipped ? "SKIP" : "OK");
223223
}
224224

225+
#define TEST_NUM_WIDTH 7
226+
227+
static void print_test_result(const struct prog_test_def *test, const struct test_state *test_state)
228+
{
229+
int skipped_cnt = test_state->skip_cnt;
230+
int subtests_cnt = test_state->subtest_num;
231+
232+
fprintf(env.stdout, "#%-*d %s:", TEST_NUM_WIDTH, test->test_num, test->test_name);
233+
if (test_state->error_cnt)
234+
fprintf(env.stdout, "FAIL");
235+
else if (!skipped_cnt)
236+
fprintf(env.stdout, "OK");
237+
else if (skipped_cnt == subtests_cnt || !subtests_cnt)
238+
fprintf(env.stdout, "SKIP");
239+
else
240+
fprintf(env.stdout, "OK (SKIP: %d/%d)", skipped_cnt, subtests_cnt);
241+
242+
fprintf(env.stdout, "\n");
243+
}
244+
225245
static void print_test_log(char *log_buf, size_t log_cnt)
226246
{
227247
log_buf[log_cnt] = '\0';
@@ -230,18 +250,6 @@ static void print_test_log(char *log_buf, size_t log_cnt)
230250
fprintf(env.stdout, "\n");
231251
}
232252

233-
#define TEST_NUM_WIDTH 7
234-
235-
static void print_test_name(int test_num, const char *test_name, char *result)
236-
{
237-
fprintf(env.stdout, "#%-*d %s", TEST_NUM_WIDTH, test_num, test_name);
238-
239-
if (result)
240-
fprintf(env.stdout, ":%s", result);
241-
242-
fprintf(env.stdout, "\n");
243-
}
244-
245253
static void print_subtest_name(int test_num, int subtest_num,
246254
const char *test_name, char *subtest_name,
247255
char *result)
@@ -307,8 +315,7 @@ static void dump_test_log(const struct prog_test_def *test,
307315
subtest_state->skipped));
308316
}
309317

310-
print_test_name(test->test_num, test->test_name,
311-
test_result(test_failed, test_state->skip_cnt));
318+
print_test_result(test, test_state);
312319
}
313320

314321
static void stdio_restore(void);
@@ -1070,8 +1077,7 @@ static void run_one_test(int test_num)
10701077
state->tested = true;
10711078

10721079
if (verbose() && env.worker_id == -1)
1073-
print_test_name(test_num + 1, test->test_name,
1074-
test_result(state->error_cnt, state->skip_cnt));
1080+
print_test_result(test, state);
10751081

10761082
reset_affinity();
10771083
restore_netns();

0 commit comments

Comments
 (0)