BPF List
 help / color / mirror / Atom feed
From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: bpf@vger.kernel.org, Alan Maguire <alan.maguire@oracle.com>
Subject: [PATCH bpf-next v2 3/5] selftests/bpf: Add ASSERT_TEXT_EQ()
Date: Tue, 29 Sep 2026 16:46:06 -0700	[thread overview]
Message-ID: <20260929234608.48503-4-ihor.solodrai@linux.dev> (raw)
In-Reply-To: <20260929234608.48503-1-ihor.solodrai@linux.dev>

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 <eddyz87@gmail.com>
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
 .../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


  parent reply	other threads:[~2026-09-29 23:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 23:46 [PATCH bpf-next v2 0/5] libbpf: Render decl_tags in btf_dump Ihor Solodrai
2026-09-29 23:46 ` [PATCH bpf-next v2 1/5] libbpf: Walk types in btf_dump_resize(), not in mark_referenced() Ihor Solodrai
2026-09-29 23:46 ` [PATCH bpf-next v2 2/5] libbpf: Render decl_tags in btf_dump Ihor Solodrai
2026-09-29 23:46 ` Ihor Solodrai [this message]
2026-09-29 23:46 ` [PATCH bpf-next v2 4/5] selftests/bpf: Test btf_dump rendering of decl_tags Ihor Solodrai
2026-09-29 23:46 ` [PATCH bpf-next v2 5/5] selftests/bpf: Show the tag kflag in the raw BTF dump helper Ihor Solodrai
2026-09-30  9:10 ` [PATCH bpf-next v2 0/5] libbpf: Render decl_tags in btf_dump patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260929234608.48503-4-ihor.solodrai@linux.dev \
    --to=ihor.solodrai@linux.dev \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=memxor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox