Skip to content

Commit 2324257

Browse files
mykola-lysenkoanakryiko
authored andcommitted
selftests/bpf: Refactor prog_tests logging and test execution
This is a pre-req to add separate logging for each subtest in test_progs. Move all the mutable test data to the test_result struct. Move per-test init/de-init into the run_one_test function. Consolidate data aggregation and final log output in calculate_and_print_summary function. As a side effect, this patch fixes double counting of errors for subtests and possible duplicate output of subtest log on failures. Also, add prog_tests_framework.c test to verify some of the counting logic. As part of verification, confirmed that number of reported tests is the same before and after the change for both parallel and sequential test execution. Signed-off-by: Mykola Lysenko <mykolal@fb.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20220418222507.1726259-1-mykolal@fb.com
1 parent 0fb53aa commit 2324257

File tree

4 files changed

+202
-221
lines changed

4 files changed

+202
-221
lines changed

tools/testing/selftests/bpf/prog_tests/bpf_mod_race.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ struct test_config {
3636
void (*bpf_destroy)(void *);
3737
};
3838

39-
enum test_state {
39+
enum bpf_test_state {
4040
_TS_INVALID,
4141
TS_MODULE_LOAD,
4242
TS_MODULE_LOAD_FAIL,
4343
};
4444

45-
static _Atomic enum test_state state = _TS_INVALID;
45+
static _Atomic enum bpf_test_state state = _TS_INVALID;
4646

4747
static int sys_finit_module(int fd, const char *param_values, int flags)
4848
{
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2+
3+
#include "test_progs.h"
4+
#include "testing_helpers.h"
5+
6+
static void clear_test_state(struct test_state *state)
7+
{
8+
state->error_cnt = 0;
9+
state->sub_succ_cnt = 0;
10+
state->skip_cnt = 0;
11+
}
12+
13+
void test_prog_tests_framework(void)
14+
{
15+
struct test_state *state = env.test_state;
16+
17+
/* in all the ASSERT calls below we need to return on the first
18+
* error due to the fact that we are cleaning the test state after
19+
* each dummy subtest
20+
*/
21+
22+
/* test we properly count skipped tests with subtests */
23+
if (test__start_subtest("test_good_subtest"))
24+
test__end_subtest();
25+
if (!ASSERT_EQ(state->skip_cnt, 0, "skip_cnt_check"))
26+
return;
27+
if (!ASSERT_EQ(state->error_cnt, 0, "error_cnt_check"))
28+
return;
29+
if (!ASSERT_EQ(state->subtest_num, 1, "subtest_num_check"))
30+
return;
31+
clear_test_state(state);
32+
33+
if (test__start_subtest("test_skip_subtest")) {
34+
test__skip();
35+
test__end_subtest();
36+
}
37+
if (test__start_subtest("test_skip_subtest")) {
38+
test__skip();
39+
test__end_subtest();
40+
}
41+
if (!ASSERT_EQ(state->skip_cnt, 2, "skip_cnt_check"))
42+
return;
43+
if (!ASSERT_EQ(state->subtest_num, 3, "subtest_num_check"))
44+
return;
45+
clear_test_state(state);
46+
47+
if (test__start_subtest("test_fail_subtest")) {
48+
test__fail();
49+
test__end_subtest();
50+
}
51+
if (!ASSERT_EQ(state->error_cnt, 1, "error_cnt_check"))
52+
return;
53+
if (!ASSERT_EQ(state->subtest_num, 4, "subtest_num_check"))
54+
return;
55+
clear_test_state(state);
56+
}

0 commit comments

Comments
 (0)