Text comparisons in test_progs repeat the same two statements: compare_text_to_expected() to print the diff, then an assert to record the failure. ASSERT_OK() on the raw return also appends a stale errno to the failure output. Add ASSERT_TEXT_EQ() after ASSERT_HAS_SUBSTR(). The assert cannot move into compare_text_to_expected() itself: the helper is linked into standalone binaries without test__fail(), and the framework unit test checks the raw mismatch return. Convert the 3 test_progs call sites plus test_ctx__dump_and_compare(), so multi-line dumps fail with a diff; prog_tests_framework.c keeps calling the helper directly. Suggested-by: Eduard Zingerman Signed-off-by: Ihor Solodrai --- .../testing/selftests/bpf/prog_tests/bpftool_btf_dump.c | 6 ++---- tools/testing/selftests/bpf/prog_tests/btf_dump.c | 9 ++------- tools/testing/selftests/bpf/test_progs.h | 3 +++ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c index abc62958b6ed..534aa79a4278 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c +++ b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c @@ -207,7 +207,6 @@ static void test_dump(const char *btf_path, bool sorted) { const char *exp_path; char *dump, *exp; - int err; exp_path = sorted ? EXPECTED_SORTED : EXPECTED_UNSORTED; @@ -219,8 +218,7 @@ static void test_dump(const char *btf_path, bool sorted) if (!exp) goto out_dump; - err = compare_text_to_expected(dump, exp); - ASSERT_OK(err, sorted ? "cmp_sorted" : "cmp_unsorted"); + ASSERT_TEXT_EQ(dump, exp, sorted ? "cmp_sorted" : "cmp_unsorted"); free(exp); out_dump: @@ -260,7 +258,7 @@ static void test_loc_dump(const char *btf_path) if (!dump) return; - ASSERT_OK(compare_text_to_expected(dump, expected), "cmp_loc_dump"); + ASSERT_TEXT_EQ(dump, expected, "cmp_loc_dump"); free(dump); } diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c index fe04a955d46c..838f7232f591 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c @@ -161,12 +161,7 @@ static int test_btf_dump_case(int n, struct btf_dump_test_case *t) goto done; } - /* - * The mismatch has already been reported, so this only has to - * register the failure. ASSERT_OK() would append a stale errno to it. - */ - err = compare_text_to_expected(dump, expected); - ASSERT_EQ(err, 0, "compare_text_to_expected"); + ASSERT_TEXT_EQ(dump, expected, "compare_text_to_expected"); done: free(expected); @@ -224,7 +219,7 @@ static void test_ctx__dump_and_compare(struct test_ctx *t, fflush(t->dump_buf_file); t->dump_buf[t->dump_buf_sz] = 0; /* some libc implementations don't do this */ - ASSERT_STREQ(t->dump_buf, expected_output, message); + ASSERT_TEXT_EQ(t->dump_buf, expected_output, message); } static void test_btf_dump_incremental(void) diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h index ea493c477fbd..adc18f5eceb6 100644 --- a/tools/testing/selftests/bpf/test_progs.h +++ b/tools/testing/selftests/bpf/test_progs.h @@ -349,6 +349,9 @@ void hexdump(const char *prefix, const void *buf, size_t len); ___ok; \ }) +#define ASSERT_TEXT_EQ(actual, expected, name) \ + ASSERT_TRUE(compare_text_to_expected(actual, expected) == 0, name) + #define ASSERT_MEMEQ(actual, expected, len, name) ({ \ static int duration = 0; \ const void *__act = actual; \ -- 2.50.1