File: prog_tests_framework.c

package info (click to toggle)
linux 6.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,488,076 kB
  • sloc: ansic: 23,401,844; asm: 266,744; sh: 108,976; makefile: 49,705; python: 36,927; perl: 36,810; cpp: 6,044; yacc: 4,904; lex: 2,722; awk: 1,440; ruby: 25; sed: 5
file content (56 lines) | stat: -rw-r--r-- 1,447 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)

#include "test_progs.h"
#include "testing_helpers.h"

static void clear_test_state(struct test_state *state)
{
	state->error_cnt = 0;
	state->sub_succ_cnt = 0;
	state->skip_cnt = 0;
}

void test_prog_tests_framework(void)
{
	struct test_state *state = env.test_state;

	/* in all the ASSERT calls below we need to return on the first
	 * error due to the fact that we are cleaning the test state after
	 * each dummy subtest
	 */

	/* test we properly count skipped tests with subtests */
	if (test__start_subtest("test_good_subtest"))
		test__end_subtest();
	if (!ASSERT_EQ(state->skip_cnt, 0, "skip_cnt_check"))
		return;
	if (!ASSERT_EQ(state->error_cnt, 0, "error_cnt_check"))
		return;
	if (!ASSERT_EQ(state->subtest_num, 1, "subtest_num_check"))
		return;
	clear_test_state(state);

	if (test__start_subtest("test_skip_subtest")) {
		test__skip();
		test__end_subtest();
	}
	if (test__start_subtest("test_skip_subtest")) {
		test__skip();
		test__end_subtest();
	}
	if (!ASSERT_EQ(state->skip_cnt, 2, "skip_cnt_check"))
		return;
	if (!ASSERT_EQ(state->subtest_num, 3, "subtest_num_check"))
		return;
	clear_test_state(state);

	if (test__start_subtest("test_fail_subtest")) {
		test__fail();
		test__end_subtest();
	}
	if (!ASSERT_EQ(state->error_cnt, 1, "error_cnt_check"))
		return;
	if (!ASSERT_EQ(state->subtest_num, 4, "subtest_num_check"))
		return;
	clear_test_state(state);
}