Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
0002 
0003 #include "test_progs.h"
0004 #include "testing_helpers.h"
0005 
0006 static void clear_test_state(struct test_state *state)
0007 {
0008     state->error_cnt = 0;
0009     state->sub_succ_cnt = 0;
0010     state->skip_cnt = 0;
0011 }
0012 
0013 void test_prog_tests_framework(void)
0014 {
0015     struct test_state *state = env.test_state;
0016 
0017     /* in all the ASSERT calls below we need to return on the first
0018      * error due to the fact that we are cleaning the test state after
0019      * each dummy subtest
0020      */
0021 
0022     /* test we properly count skipped tests with subtests */
0023     if (test__start_subtest("test_good_subtest"))
0024         test__end_subtest();
0025     if (!ASSERT_EQ(state->skip_cnt, 0, "skip_cnt_check"))
0026         return;
0027     if (!ASSERT_EQ(state->error_cnt, 0, "error_cnt_check"))
0028         return;
0029     if (!ASSERT_EQ(state->subtest_num, 1, "subtest_num_check"))
0030         return;
0031     clear_test_state(state);
0032 
0033     if (test__start_subtest("test_skip_subtest")) {
0034         test__skip();
0035         test__end_subtest();
0036     }
0037     if (test__start_subtest("test_skip_subtest")) {
0038         test__skip();
0039         test__end_subtest();
0040     }
0041     if (!ASSERT_EQ(state->skip_cnt, 2, "skip_cnt_check"))
0042         return;
0043     if (!ASSERT_EQ(state->subtest_num, 3, "subtest_num_check"))
0044         return;
0045     clear_test_state(state);
0046 
0047     if (test__start_subtest("test_fail_subtest")) {
0048         test__fail();
0049         test__end_subtest();
0050     }
0051     if (!ASSERT_EQ(state->error_cnt, 1, "error_cnt_check"))
0052         return;
0053     if (!ASSERT_EQ(state->subtest_num, 4, "subtest_num_check"))
0054         return;
0055     clear_test_state(state);
0056 }