* [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
* [PATCH 2/2] selftests: net: tun: don't abort XFAIL cases
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 ` Sun Jian
2026-02-24 1:22 ` [PATCH 1/2] selftests/harness: fix XFAIL_ADD matching when test metadata is not initialized Jakub Kicinski
` (2 subsequent siblings)
3 siblings, 0 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
The tun UDP tunnel GSO fixture contains XFAIL-marked variants intended to
exercise failure paths (e.g. EMSGSIZE / "Message too long").
Using ASSERT_EQ() in these tests aborts the subtest, which prevents the
harness from classifying them as XFAIL and can make the overall net: tun
test fail.
Switch the relevant ASSERT_EQ() checks to EXPECT_EQ() so the subtests
continue running and the failures are correctly reported and accounted
as XFAIL where applicable.
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
tools/testing/selftests/net/tun.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c
index 8a5cd5cb5472..cf106a49b55e 100644
--- a/tools/testing/selftests/net/tun.c
+++ b/tools/testing/selftests/net/tun.c
@@ -944,8 +944,8 @@ TEST_F(tun_vnet_udptnl, send_gso_packet)
ASSERT_EQ(ret, off);
ret = receive_gso_packet_from_tunnel(self, variant, &r_num_mss);
- ASSERT_EQ(ret, variant->data_size);
- ASSERT_EQ(r_num_mss, variant->r_num_mss);
+ EXPECT_EQ(ret, variant->data_size);
+ EXPECT_EQ(r_num_mss, variant->r_num_mss);
}
TEST_F(tun_vnet_udptnl, recv_gso_packet)
@@ -955,18 +955,18 @@ TEST_F(tun_vnet_udptnl, recv_gso_packet)
int ret, gso_type = VIRTIO_NET_HDR_GSO_UDP_L4;
ret = send_gso_packet_into_tunnel(self, variant);
- ASSERT_EQ(ret, variant->data_size);
+ EXPECT_EQ(ret, variant->data_size);
memset(&vnet_hdr, 0, sizeof(vnet_hdr));
ret = receive_gso_packet_from_tun(self, variant, &vnet_hdr);
- ASSERT_EQ(ret, variant->data_size);
+ EXPECT_EQ(ret, variant->data_size);
if (!variant->no_gso) {
- ASSERT_EQ(vh->gso_size, variant->gso_size);
+ EXPECT_EQ(vh->gso_size, variant->gso_size);
gso_type |= (variant->tunnel_type & UDP_TUNNEL_OUTER_IPV4) ?
(VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV4) :
(VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV6);
- ASSERT_EQ(vh->gso_type, gso_type);
+ EXPECT_EQ(vh->gso_type, gso_type);
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] selftests/harness: fix XFAIL_ADD matching when test metadata is not initialized
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 ` Jakub Kicinski
2026-02-24 2:43 ` sun jian
2026-02-24 10:44 ` [PATCH 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors Sun Jian
2026-02-24 11:38 ` [PATCH v2 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors Sun Jian
3 siblings, 1 reply; 13+ messages in thread
From: Jakub Kicinski @ 2026-02-24 1:22 UTC (permalink / raw)
To: Sun Jian
Cc: shuah, linux-kselftest, netdev, pabeni, edumazet, horms, kees,
linux-kernel
On Sun, 22 Feb 2026 19:18:46 +0800 Sun Jian wrote:
> 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.
This looks a bit inelegant, what compiler is this failing on for you?
Constructors seem to have a concept of priority so if we have to,
we should probably used those for the fix.
--
pw-bot: cr
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] selftests/harness: fix XFAIL_ADD matching when test metadata is not initialized
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
0 siblings, 1 reply; 13+ messages in thread
From: sun jian @ 2026-02-24 2:43 UTC (permalink / raw)
To: Jakub Kicinski
Cc: shuah, linux-kselftest, netdev, pabeni, edumazet, horms, kees,
linux-kernel
On Tue, Feb 24, 2026 at 9:22 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Sun, 22 Feb 2026 19:18:46 +0800 Sun Jian wrote:
> > 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.
>
> This looks a bit inelegant, what compiler is this failing on for you?
Hi Jakub,
I hit this with clang + lld (LLVM=1) in a virtme-ng based net selftests run.
In that setup the XFAIL_ADD() constructor runs before the corresponding
_*_test_object is initialized, so xfail->test ends up NULL and we never
classify XFAIL/XPASS.
> Constructors seem to have a concept of priority so if we have to,
> we should probably used those for the fix.
I considered constructor priorities, but I'd prefer to avoid relying on
toolchain/linker specific init ordering here. (The harness is userspace
and we already see different behavior with clang/lld.)
If you prefer a cleaner approach, I can rework this to avoid adding any
new field and avoid priorities: keep xfail->test as a cached pointer, but
populate it lazily at runtime on first use by looking up the test metadata
by name within the fixture’s test list, then do the original pointer match.
That removes the dependency on constructor ordering and keeps the matching
semantics pointer-based after the first lookup.
Let me know if that direction sounds better and I'll send a v2.
Thanks,
sun jian
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] selftests/harness: fix XFAIL_ADD matching when test metadata is not initialized
2026-02-24 2:43 ` sun jian
@ 2026-02-24 2:53 ` Jakub Kicinski
2026-02-24 5:01 ` sun jian
0 siblings, 1 reply; 13+ messages in thread
From: Jakub Kicinski @ 2026-02-24 2:53 UTC (permalink / raw)
To: sun jian
Cc: shuah, linux-kselftest, netdev, pabeni, edumazet, horms, kees,
linux-kernel
On Tue, 24 Feb 2026 10:43:15 +0800 sun jian wrote:
> > Constructors seem to have a concept of priority so if we have to,
> > we should probably used those for the fix.
>
> I considered constructor priorities, but I'd prefer to avoid relying on
> toolchain/linker specific init ordering here.
I thought constructor priorities were specifically created to avoid the
problem you are seeing. What it is the point of constructor priorities
if not to order constructors??
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] selftests/harness: fix XFAIL_ADD matching when test metadata is not initialized
2026-02-24 2:53 ` Jakub Kicinski
@ 2026-02-24 5:01 ` sun jian
2026-02-24 8:05 ` sun jian
0 siblings, 1 reply; 13+ messages in thread
From: sun jian @ 2026-02-24 5:01 UTC (permalink / raw)
To: Jakub Kicinski
Cc: shuah, linux-kselftest, netdev, pabeni, edumazet, horms, kees,
linux-kernel
On Tue, Feb 24, 2026 at 10:53 AM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Tue, 24 Feb 2026 10:43:15 +0800 sun jian wrote:
> > > Constructors seem to have a concept of priority so if we have to,
> > > we should probably used those for the fix.
> >
> > I considered constructor priorities, but I'd prefer to avoid relying on
> > toolchain/linker specific init ordering here.
>
> I thought constructor priorities were specifically created to avoid the
> problem you are seeing. What it is the point of constructor priorities
> if not to order constructors??
You're right that ctor priorities exist to order constructors.
With clang+lld (LLVM=1) I can reproduce xfail nodes being attached to
variant->xfails but with xfail->test == NULL, so the pointer wasn't
available at XFAIL_ADD() registration time.
I don't object to ctor priorities per se. My concern is that fixing this
via priorities likely requires ordering the entire registration chain, not
just XFAIL_ADD(): kselftest_harness.h has multiple constructor-based
registration sites (I see at least 5 macro-generated ctor blocks plus the
constructor-order helper), so we'd need to thread and maintain explicit
priorities across the relevant registration macros to guarantee that the
test/fixture/variant metadata is fully registered before XFAIL_ADD() runs.
To avoid relying on init order, I'm happy to send a v2 which doesn't add new
state and doesn't rely on ctor ordering: keep xfail->test as a cached pointer,
but resolve it lazily at runtime on first use by looking up the test metadata
by name within the fixture's test list, then use the original pointer match
thereafter. This resolution happens at most once per xfail entry and keeps the
hot path pointer-based.
If you prefer ctor priorities, I'm also happy to respin that way — but I'd
appreciate guidance on which ctor(s)/registration macros you want ordered
against XFAIL_ADD() so we can keep the change minimal.
Thanks,
sun jian
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/2] selftests/harness: fix XFAIL_ADD matching when test metadata is not initialized
2026-02-24 5:01 ` sun jian
@ 2026-02-24 8:05 ` sun jian
0 siblings, 0 replies; 13+ messages in thread
From: sun jian @ 2026-02-24 8:05 UTC (permalink / raw)
To: Jakub Kicinski
Cc: shuah, linux-kselftest, netdev, pabeni, edumazet, horms, kees,
linux-kernel
On Tue, 24 Feb 2026 10:43:15 +0800 Jakub Kicinski wrote:
> I thought constructor priorities were specifically created to avoid the
> problem you are seeing. What it is the point of constructor priorities
> if not to order constructors??
Hi Jakub,
You're right. Looking closer at the harness ctor ordering, the NULL comes
from TEST_F() setting _##fixture##_##test##_object inside its constructor
(after the mmap() allocation), while XFAIL_ADD() reads that pointer in its
constructor. If XFAIL_ADD runs first, xfail->test can be NULL.
Using constructor priorities should fix this cleanly by ordering the TEST_F
registration ctor before XFAIL_ADD, without adding new fields or runtime
lookups.
I'll respin a v2 along those lines and drop the fallback approach.
Thanks,
sun jian
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors
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 10:44 ` 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
3 siblings, 1 reply; 13+ messages in thread
From: Sun Jian @ 2026-02-24 10:44 UTC (permalink / raw)
To: netdev
Cc: linux-kselftest, linux-kernel, kuba, pabeni, edumazet, davem,
horms, shuah, kees, luto, wad, Sun Jian
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
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/2] selftests: net: tun: don't abort XFAIL cases
2026-02-24 10:44 ` [PATCH 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors Sun Jian
@ 2026-02-24 10:44 ` Sun Jian
0 siblings, 0 replies; 13+ messages in thread
From: Sun Jian @ 2026-02-24 10:44 UTC (permalink / raw)
To: netdev
Cc: linux-kselftest, linux-kernel, kuba, pabeni, edumazet, davem,
horms, shuah, kees, luto, wad, Sun Jian
The tun UDP tunnel GSO fixture contains XFAIL-marked variants intended to
exercise failure paths (e.g. EMSGSIZE / "Message too long").
Using ASSERT_EQ() in these tests aborts the subtest, which prevents the
harness from classifying them as XFAIL and can make the overall net: tun
test fail.
Switch the relevant ASSERT_EQ() checks to EXPECT_EQ() so the subtests
continue running and the failures are correctly reported and accounted
as XFAIL where applicable.
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
tools/testing/selftests/net/tun.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c
index 8a5cd5cb5472..cf106a49b55e 100644
--- a/tools/testing/selftests/net/tun.c
+++ b/tools/testing/selftests/net/tun.c
@@ -944,8 +944,8 @@ TEST_F(tun_vnet_udptnl, send_gso_packet)
ASSERT_EQ(ret, off);
ret = receive_gso_packet_from_tunnel(self, variant, &r_num_mss);
- ASSERT_EQ(ret, variant->data_size);
- ASSERT_EQ(r_num_mss, variant->r_num_mss);
+ EXPECT_EQ(ret, variant->data_size);
+ EXPECT_EQ(r_num_mss, variant->r_num_mss);
}
TEST_F(tun_vnet_udptnl, recv_gso_packet)
@@ -955,18 +955,18 @@ TEST_F(tun_vnet_udptnl, recv_gso_packet)
int ret, gso_type = VIRTIO_NET_HDR_GSO_UDP_L4;
ret = send_gso_packet_into_tunnel(self, variant);
- ASSERT_EQ(ret, variant->data_size);
+ EXPECT_EQ(ret, variant->data_size);
memset(&vnet_hdr, 0, sizeof(vnet_hdr));
ret = receive_gso_packet_from_tun(self, variant, &vnet_hdr);
- ASSERT_EQ(ret, variant->data_size);
+ EXPECT_EQ(ret, variant->data_size);
if (!variant->no_gso) {
- ASSERT_EQ(vh->gso_size, variant->gso_size);
+ EXPECT_EQ(vh->gso_size, variant->gso_size);
gso_type |= (variant->tunnel_type & UDP_TUNNEL_OUTER_IPV4) ?
(VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV4) :
(VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV6);
- ASSERT_EQ(vh->gso_type, gso_type);
+ EXPECT_EQ(vh->gso_type, gso_type);
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors
2026-02-22 11:18 [PATCH 1/2] selftests/harness: fix XFAIL_ADD matching when test metadata is not initialized Sun Jian
` (2 preceding siblings ...)
2026-02-24 10:44 ` [PATCH 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors Sun Jian
@ 2026-02-24 11:38 ` 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
3 siblings, 2 replies; 13+ messages in thread
From: Sun Jian @ 2026-02-24 11:38 UTC (permalink / raw)
To: netdev
Cc: linux-kselftest, linux-kernel, kuba, pabeni, edumazet, davem,
horms, shuah, kees, luto, wad, Sun Jian
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
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 2/2] selftests: net: tun: don't abort XFAIL cases
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 ` Sun Jian
2026-02-24 23:44 ` [PATCH v2 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors Jakub Kicinski
1 sibling, 0 replies; 13+ messages in thread
From: Sun Jian @ 2026-02-24 11:39 UTC (permalink / raw)
To: netdev
Cc: linux-kselftest, linux-kernel, kuba, pabeni, edumazet, davem,
horms, shuah, kees, luto, wad, Sun Jian
The tun UDP tunnel GSO fixture contains XFAIL-marked variants intended to
exercise failure paths (e.g. EMSGSIZE / "Message too long").
Using ASSERT_EQ() in these tests aborts the subtest, which prevents the
harness from classifying them as XFAIL and can make the overall net: tun
test fail.
Switch the relevant ASSERT_EQ() checks to EXPECT_EQ() so the subtests
continue running and the failures are correctly reported and accounted
as XFAIL where applicable.
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
tools/testing/selftests/net/tun.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c
index 8a5cd5cb5472..cf106a49b55e 100644
--- a/tools/testing/selftests/net/tun.c
+++ b/tools/testing/selftests/net/tun.c
@@ -944,8 +944,8 @@ TEST_F(tun_vnet_udptnl, send_gso_packet)
ASSERT_EQ(ret, off);
ret = receive_gso_packet_from_tunnel(self, variant, &r_num_mss);
- ASSERT_EQ(ret, variant->data_size);
- ASSERT_EQ(r_num_mss, variant->r_num_mss);
+ EXPECT_EQ(ret, variant->data_size);
+ EXPECT_EQ(r_num_mss, variant->r_num_mss);
}
TEST_F(tun_vnet_udptnl, recv_gso_packet)
@@ -955,18 +955,18 @@ TEST_F(tun_vnet_udptnl, recv_gso_packet)
int ret, gso_type = VIRTIO_NET_HDR_GSO_UDP_L4;
ret = send_gso_packet_into_tunnel(self, variant);
- ASSERT_EQ(ret, variant->data_size);
+ EXPECT_EQ(ret, variant->data_size);
memset(&vnet_hdr, 0, sizeof(vnet_hdr));
ret = receive_gso_packet_from_tun(self, variant, &vnet_hdr);
- ASSERT_EQ(ret, variant->data_size);
+ EXPECT_EQ(ret, variant->data_size);
if (!variant->no_gso) {
- ASSERT_EQ(vh->gso_size, variant->gso_size);
+ EXPECT_EQ(vh->gso_size, variant->gso_size);
gso_type |= (variant->tunnel_type & UDP_TUNNEL_OUTER_IPV4) ?
(VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV4) :
(VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV6);
- ASSERT_EQ(vh->gso_type, gso_type);
+ EXPECT_EQ(vh->gso_type, gso_type);
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors
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 ` Jakub Kicinski
2026-02-25 2:10 ` sun jian
1 sibling, 1 reply; 13+ messages in thread
From: Jakub Kicinski @ 2026-02-24 23:44 UTC (permalink / raw)
To: Sun Jian
Cc: netdev, linux-kselftest, linux-kernel, pabeni, edumazet, davem,
horms, shuah, kees, luto, wad
On Tue, 24 Feb 2026 19:38:59 +0800 Sun Jian wrote:
> *
> * 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)
You inserted these defines between the kdoc for TEST_SIGNAL() and its
definition.
When you respin, two notes:
- please wait 24h after the previous version before sending a new one,
to allow people in all timezones to comment and avoid splintering
the discussion
- please start a new thread for each submission, and refer to the
previous one with a link in the changelog:
v2:
- bla
- bla
v1: https://lore.kernel.org/20260224104434.14912-1-sun.jian.kdev@gmail.com
--
pw-bot: cr
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] selftests/harness: order TEST_F and XFAIL_ADD constructors
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
0 siblings, 0 replies; 13+ messages in thread
From: sun jian @ 2026-02-25 2:10 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, linux-kselftest, linux-kernel, pabeni, edumazet, davem,
horms, shuah, kees, luto, wad
On Tue, Feb 24, 2026 at 07:38:59PM +0800, Sun Jian wrote:
> You inserted these defines between the kdoc for TEST_SIGNAL() and its
> definition.
Ack. I'll move the KSELFTEST_PRIO_* defines out of the TEST_SIGNAL() KDoc
block so the comment stays adjacent to the macro it documents.
> When you respin, two notes:
> - please wait 24h after the previous version before sending a new one,
> to allow people in all timezones to comment and avoid splintering
> the discussion
> - please start a new thread for each submission, and refer to the
> previous one with a link in the changelog:
Ack as well. I'll wait at least 24h before respinning, and I'll send v3
as a new thread with lore links to v1/v2 in the changelog.
Thanks,
Sun Jian
^ permalink raw reply [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