On Wed, Feb 25, 2026 at 07:14:50PM +0800, Sun Jian wrote:
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 <redacted>
---
v3:
- Move KSELFTEST_PRIO_* definitions above the TEST_SIGNAL() kdoc block.
v2:
- Drop the lazy string-matching approach.
- Use constructor priorities to enforce initialization order.
Link:
https://lore.kernel.org/all/20260224113859.12345-1-sun.jian.kdev@gmail.com/
v1:
Link:
https://lore.kernel.org/all/20260222111846.12345-1-sun.jian.kdev@gmail.com/
---
tools/testing/selftests/kselftest_harness.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
FYI there is a selftest for the harness in
tools/testing/selftests/kselftest_harness/harness-selftest.c .
You could update this with your usecase to make sure, that this functionality
keeps working.
(...)