The hardcoded expected skip_cnt/error_cnt in test_prog_tests_framework()
mismatch the real count when the binary is run with -t or -n filters,
since some subtests are not selected. Count the executed subtests and
compare against that value instead.

Fixes: 2324257dbd68 ("selftests/bpf: Refactor prog_tests logging and test 
execution")
Signed-off-by: KaFai Wan <[email protected]>
---
 .../selftests/bpf/prog_tests/prog_tests_framework.c    | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c 
b/tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c
index d111fe1054476..53347f3799245 100644
--- a/tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c
+++ b/tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c
@@ -13,6 +13,7 @@ static void clear_test_state(struct test_state *state)
 void test_prog_tests_framework(void)
 {
        struct test_state *state = env.test_state;
+       int subtest_cnt;
 
        /* 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
@@ -30,25 +31,30 @@ void test_prog_tests_framework(void)
                return;
        clear_test_state(state);
 
+       subtest_cnt = 0;
        if (test__start_subtest("test_skip_subtest")) {
                test__skip();
                test__end_subtest();
+               subtest_cnt++;
        }
        if (test__start_subtest("test_skip_subtest")) {
                test__skip();
                test__end_subtest();
+               subtest_cnt++;
        }
-       if (!ASSERT_EQ(state->skip_cnt, 2, "skip_cnt_check"))
+       if (!ASSERT_EQ(state->skip_cnt, subtest_cnt, "skip_cnt_check"))
                return;
        if (!ASSERT_EQ(state->subtest_num, 3, "subtest_num_check"))
                return;
        clear_test_state(state);
 
+       subtest_cnt = 0;
        if (test__start_subtest("test_fail_subtest")) {
                test__fail();
                test__end_subtest();
+               subtest_cnt++;
        }
-       if (!ASSERT_EQ(state->error_cnt, 1, "error_cnt_check"))
+       if (!ASSERT_EQ(state->error_cnt, subtest_cnt, "error_cnt_check"))
                return;
        if (!ASSERT_EQ(state->subtest_num, 4, "subtest_num_check"))
                return;
-- 
2.43.0


Reply via email to