Skip to content

Commit 6be2681

Browse files
ahjf-07kuba-moo
authored andcommitted
selftests/harness: order TEST_F and XFAIL_ADD constructors
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: 2709473 ("selftests: kselftest_harness: support using xfail") Signed-off-by: Sun Jian <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3738097 commit 6be2681

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

tools/testing/selftests/kselftest_harness.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
7676
memset(s, c, n);
7777
}
7878

79+
#define KSELFTEST_PRIO_TEST_F 20000
80+
#define KSELFTEST_PRIO_XFAIL 20001
81+
7982
#define TEST_TIMEOUT_DEFAULT 30
8083

8184
/* Utilities exposed to the test definitions */
@@ -465,7 +468,7 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
465468
fixture_name##_teardown(_metadata, self, variant); \
466469
} \
467470
static struct __test_metadata *_##fixture_name##_##test_name##_object; \
468-
static void __attribute__((constructor)) \
471+
static void __attribute__((constructor(KSELFTEST_PRIO_TEST_F))) \
469472
_register_##fixture_name##_##test_name(void) \
470473
{ \
471474
struct __test_metadata *object = mmap(NULL, sizeof(*object), \
@@ -880,7 +883,7 @@ struct __test_xfail {
880883
.fixture = &_##fixture_name##_fixture_object, \
881884
.variant = &_##fixture_name##_##variant_name##_object, \
882885
}; \
883-
static void __attribute__((constructor)) \
886+
static void __attribute__((constructor(KSELFTEST_PRIO_XFAIL))) \
884887
_register_##fixture_name##_##variant_name##_##test_name##_xfail(void) \
885888
{ \
886889
_##fixture_name##_##variant_name##_##test_name##_xfail.test = \

0 commit comments

Comments
 (0)