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 }
57