From: Sun Jian <sun.jian.kdev@gmail.com>
To: shuah@kernel.org, linux-kselftest@vger.kernel.org,
netdev@vger.kernel.org
Cc: kuba@kernel.org, pabeni@redhat.com, edumazet@google.com,
horms@kernel.org, kees@kernel.org, linux-kernel@vger.kernel.org,
Sun Jian <sun.jian.kdev@gmail.com>
Subject: [PATCH 1/2] selftests/harness: fix XFAIL_ADD matching when test metadata is not initialized
Date: Sun, 22 Feb 2026 19:18:46 +0800 [thread overview]
Message-ID: <20260222111847.692325-1-sun.jian.kdev@gmail.com> (raw)
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
next reply other threads:[~2026-02-22 11:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-22 11:18 Sun Jian [this message]
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
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=20260222111847.692325-1-sun.jian.kdev@gmail.com \
--to=sun.jian.kdev@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/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