From: Sun Jian <sun.jian.kdev@gmail.com>
To: netdev@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
kuba@kernel.org, pabeni@redhat.com, edumazet@google.com,
davem@davemloft.net, horms@kernel.org, shuah@kernel.org,
kees@kernel.org, luto@amacapital.net, wad@chromium.org,
Sun Jian <sun.jian.kdev@gmail.com>
Subject: [PATCH 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors
Date: Tue, 24 Feb 2026 18:44:33 +0800 [thread overview]
Message-ID: <20260224104434.14912-1-sun.jian.kdev@gmail.com> (raw)
In-Reply-To: <20260222111847.692325-1-sun.jian.kdev@gmail.com>
TEST_F() allocates and registers its struct __test_metadata via mmap()
inside its constructor, and only then assigns the
_##fixture_##test##_object pointer.
XFAIL_ADD() runs in a constructor too and reads
_##fixture_##test##_object to initialize xfail->test. If XFAIL_ADD runs
first, xfail->test can be NULL and the expected failure will be reported
as FAIL.
Use constructor priorities to ensure TEST_F registration runs before
XFAIL_ADD, without adding extra state or runtime lookups.
Fixes: 2709473c9386 ("selftests: kselftest_harness: support using xfail")
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
v2:
- Switch from name-based fallback matching to ctor priorities.
- Drop the extra xfail state and runtime matching.
---
tools/testing/selftests/kselftest_harness.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 16a119a4656c..afcba0c4e98d 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -175,6 +175,9 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
*
* EXPECT_* and ASSERT_* are valid in a TEST() { } context.
*/
+#define KSELFTEST_PRIO_TEST_F 20000
+#define KSELFTEST_PRIO_XFAIL 20001
+
#define TEST_SIGNAL(test_name, signal) __TEST_IMPL(test_name, signal)
#define __TEST_IMPL(test_name, _signal) \
@@ -465,7 +468,7 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
fixture_name##_teardown(_metadata, self, variant); \
} \
static struct __test_metadata *_##fixture_name##_##test_name##_object; \
- static void __attribute__((constructor)) \
+ static void __attribute__((constructor(KSELFTEST_PRIO_TEST_F))) \
_register_##fixture_name##_##test_name(void) \
{ \
struct __test_metadata *object = mmap(NULL, sizeof(*object), \
@@ -880,7 +883,7 @@ struct __test_xfail {
.fixture = &_##fixture_name##_fixture_object, \
.variant = &_##fixture_name##_##variant_name##_object, \
}; \
- static void __attribute__((constructor)) \
+ static void __attribute__((constructor(KSELFTEST_PRIO_XFAIL))) \
_register_##fixture_name##_##variant_name##_##test_name##_xfail(void) \
{ \
_##fixture_name##_##variant_name##_##test_name##_xfail.test = \
base-commit: 7dff99b354601dd01829e1511711846e04340a69
--
2.43.0
next prev parent reply other threads:[~2026-02-24 10:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Sun Jian [this message]
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=20260224104434.14912-1-sun.jian.kdev@gmail.com \
--to=sun.jian.kdev@gmail.com \
--cc=davem@davemloft.net \
--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=luto@amacapital.net \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=wad@chromium.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