Skip to content

Commit 5374709

Browse files
mykola-lysenkoKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
selftests/bpf: consolidate common code in run_one_test function
This is a pre-req to add separate logging for each subtest. 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 <[email protected]>
1 parent 9fc3f3c commit 5374709

File tree

3 files changed

+195
-193
lines changed

3 files changed

+195
-193
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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_result(struct test_result *result)
7+
{
8+
result->error_cnt = 0;
9+
result->sub_succ_cnt = 0;
10+
result->skip_cnt = 0;
11+
}
12+
13+
void test_prog_tests_framework(void)
14+
{
15+
struct test_result *result = env.test_result;
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+
// test we properly count skipped tests with subtests
22+
if (test__start_subtest("test_good_subtest"))
23+
test__end_subtest();
24+
if (!ASSERT_EQ(result->skip_cnt, 0, "skip_cnt_check"))
25+
return;
26+
if (!ASSERT_EQ(result->error_cnt, 0, "error_cnt_check"))
27+
return;
28+
if (!ASSERT_EQ(result->subtest_num, 1, "subtest_num_check"))
29+
return;
30+
clear_test_result(result);
31+
32+
if (test__start_subtest("test_skip_subtest")) {
33+
test__skip();
34+
test__end_subtest();
35+
}
36+
if (test__start_subtest("test_skip_subtest")) {
37+
test__skip();
38+
test__end_subtest();
39+
}
40+
if (!ASSERT_EQ(result->skip_cnt, 2, "skip_cnt_check"))
41+
return;
42+
if (!ASSERT_EQ(result->subtest_num, 3, "subtest_num_check"))
43+
return;
44+
clear_test_result(result);
45+
46+
if (test__start_subtest("test_fail_subtest")) {
47+
test__fail();
48+
test__end_subtest();
49+
}
50+
if (!ASSERT_EQ(result->error_cnt, 1, "error_cnt_check"))
51+
return;
52+
if (!ASSERT_EQ(result->subtest_num, 4, "subtest_num_check"))
53+
return;
54+
clear_test_result(result);
55+
}

0 commit comments

Comments
 (0)