public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] selftests/harness: fix XFAIL_ADD matching when test metadata is not initialized
@ 2026-02-22 11:18 Sun Jian
  2026-02-22 11:18 ` [PATCH 2/2] selftests: net: tun: don't abort XFAIL cases Sun Jian
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Sun Jian @ 2026-02-22 11:18 UTC (permalink / raw)
  To: shuah, linux-kselftest, netdev
  Cc: kuba, pabeni, edumazet, horms, kees, linux-kernel, Sun Jian

XFAIL_ADD() registers expected failures using constructor order, but the
associated struct __test_metadata pointer may not be initialized yet.
As a result, xfail entries can end up with a NULL test pointer and never
match at runtime, causing expected failures to be reported as FAIL.

Store the test case name in the xfail entry and fall back to name-based
matching when the test pointer is unavailable, while keeping the original
pointer-based matching for compatibility.

Fixes: 2709473c9386 ("selftests: kselftest_harness: support using xfail")
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
 tools/testing/selftests/kselftest_harness.h | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 16a119a4656c..1082024b2d77 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -860,6 +860,7 @@ struct __test_xfail {
 	struct __fixture_metadata *fixture;
 	struct __fixture_variant_metadata *variant;
 	struct __test_metadata *test;
+	const char *case_name;
 	struct __test_xfail *prev, *next;
 };
 
@@ -873,19 +874,19 @@ struct __test_xfail {
  * to fail. Tests marked this way will report XPASS / XFAIL return codes,
  * instead of PASS / FAIL,and use respective counters.
  */
-#define XFAIL_ADD(fixture_name, variant_name, test_name) \
+#define XFAIL_ADD(fixture_name, variant_name, tc_name) \
 	static struct __test_xfail \
-		_##fixture_name##_##variant_name##_##test_name##_xfail = \
+		_##fixture_name##_##variant_name##_##tc_name##_xfail = \
 	{ \
 		.fixture = &_##fixture_name##_fixture_object, \
 		.variant = &_##fixture_name##_##variant_name##_object, \
 	}; \
 	static void __attribute__((constructor)) \
-		_register_##fixture_name##_##variant_name##_##test_name##_xfail(void) \
+		_register_##fixture_name##_##variant_name##_##tc_name##_xfail(void) \
 	{ \
-		_##fixture_name##_##variant_name##_##test_name##_xfail.test = \
-			_##fixture_name##_##test_name##_object; \
-		__register_xfail(&_##fixture_name##_##variant_name##_##test_name##_xfail); \
+		_##fixture_name##_##variant_name##_##tc_name##_xfail.case_name = \
+			#tc_name; \
+		__register_xfail(&_##fixture_name##_##variant_name##_##tc_name##_xfail); \
 	}
 
 static struct __fixture_metadata *__fixture_list = &_fixture_global;
@@ -1233,7 +1234,10 @@ static void __run_test(struct __fixture_metadata *f,
 
 	/* Check if we're expecting this test to fail */
 	for (xfail = variant->xfails; xfail; xfail = xfail->next)
-		if (xfail->test == t)
+		if (xfail->test == t ||
+		    (!xfail->test &&
+		     xfail->case_name && t->name &&
+		     !strcmp(xfail->case_name, t->name)))
 			break;
 	if (xfail)
 		t->exit_code = __test_passed(t) ? KSFT_XPASS : KSFT_XFAIL;

base-commit: 32a92f8c89326985e05dce8b22d3f0aa07a3e1bd
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-02-25  2:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-22 11:18 [PATCH 1/2] selftests/harness: fix XFAIL_ADD matching when test metadata is not initialized Sun Jian
2026-02-22 11:18 ` [PATCH 2/2] selftests: net: tun: don't abort XFAIL cases Sun Jian
2026-02-24  1:22 ` [PATCH 1/2] selftests/harness: fix XFAIL_ADD matching when test metadata is not initialized Jakub Kicinski
2026-02-24  2:43   ` sun jian
2026-02-24  2:53     ` Jakub Kicinski
2026-02-24  5:01       ` sun jian
2026-02-24  8:05         ` sun jian
2026-02-24 10:44 ` [PATCH 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors Sun Jian
2026-02-24 10:44   ` [PATCH 2/2] selftests: net: tun: don't abort XFAIL cases Sun Jian
2026-02-24 11:38 ` [PATCH v2 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors Sun Jian
2026-02-24 11:39   ` [PATCH v2 2/2] selftests: net: tun: don't abort XFAIL cases Sun Jian
2026-02-24 23:44   ` [PATCH v2 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors Jakub Kicinski
2026-02-25  2:10     ` sun jian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox