stdio_hijack_init() does not set subtest_state->stdout_saved when
running with -v in non-parallel mode, since output goes straight to
stdout. In that case subtest_state->log_buf is left NULL, so the
expected-messages subtests crash when inspecting it. Skip them when
stdout was not saved.

Fixes: 34c513be3dad ("selftests/bpf: __not_msg() tag for test_loader framework")
Signed-off-by: KaFai Wan <[email protected]>
---
 .../testing/selftests/bpf/prog_tests/prog_tests_framework.c | 6 ++++++
 1 file changed, 6 insertions(+)

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 53347f3799245..b4cd7c7ff4391 100644
--- a/tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c
+++ b/tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c
@@ -169,6 +169,12 @@ void test_prog_tests_framework_expected_msgs(void)
 
        for (i = 0; i < ARRAY_SIZE(cases); i++) {
                if (test__start_subtest(cases[i].name)) {
+                       if (!env.subtest_state->stdout_saved) {
+                               test__skip();
+                               test__end_subtest();
+                               continue;
+                       }
+
                        error_cnt = env.subtest_state->error_cnt;
                        msgs.patterns = cases[i].pats;
                        msgs.cnt = 0;
-- 
2.43.0


Reply via email to