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
compare_text_mismatch subtest crashes when inspecting it. Skip it when
stdout was not saved.
Fixes: bd71904697c6 ("selftests/bpf: Add compare_text_to_expected() helper")
Signed-off-by: KaFai Wan <[email protected]>
---
.../bpf/prog_tests/prog_tests_framework.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 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 b4cd7c7ff4391..ddb6cdc1579f1 100644
--- a/tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c
+++ b/tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c
@@ -203,14 +203,18 @@ void test_prog_tests_framework_compare_text(void)
}
if (test__start_subtest("compare_text_mismatch")) {
- err = compare_text_to_expected("line two\n", "line one\n");
- fflush(stdout);
+ if (!env.subtest_state->stdout_saved) {
+ test__skip();
+ } else {
+ err = compare_text_to_expected("line two\n", "line
one\n");
+ fflush(stdout);
- ASSERT_EQ(err, -1, "mismatch_rc");
- ASSERT_HAS_SUBSTR(env.subtest_state->log_buf, "-line one",
- "diff_has_expected");
- ASSERT_HAS_SUBSTR(env.subtest_state->log_buf, "+line two",
- "diff_has_actual");
+ ASSERT_EQ(err, -1, "mismatch_rc");
+ ASSERT_HAS_SUBSTR(env.subtest_state->log_buf, "-line
one",
+ "diff_has_expected");
+ ASSERT_HAS_SUBSTR(env.subtest_state->log_buf, "+line
two",
+ "diff_has_actual");
+ }
test__end_subtest();
}
}
--
2.43.0