Skip to contentSkip to conversation

Add kselftest harness selftest with variant

PATCH In review Wei Yang 3 participants 8 messages Jun 20, 2025 – Aug 18, 2025

Subsystems (2)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

v2 cover Add kselftest harness selftest with variant

We already have a selftest for harness, while there is not usage of FIXTURE_VARIANT.

Patch 2 add FIXTURE_VARIANT usage in the selftest.

Patch 1 is a typo fix.

v2:
* drop patch 2 in v1
* adjust patch 2 based on Thomas comment

Wei Yang (2):
selftests: harness: correct typo of __constructor_order_forward in
comment
selftests: harness: Add kselftest harness selftest with variant

 tools/testing/selftests/kselftest_harness.h   |  2 +-
 .../kselftest_harness/harness-selftest.c      | 30 +++++++++++++++++++
 .../harness-selftest.expected                 | 20 ++++++++++---
 3 files changed, 47 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/2 selftests: harness: correct typo of __constructor_order_forward in comment

The name is __constructor_order_forward.

Just correct it.

Cc Muhammad Usama Anjum <[email protected]>
Cc Thomas Weißschuh <[email protected]>
---
 tools/testing/selftests/kselftest_harness.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kselftest_harness.h +1 -1
index 2925e47db995..674a6112e6e1 100644
@@ -936,7 +936,7 @@ static inline bool __test_passed(struct __test_metadata *metadata)
  * list so tests are run in source declaration order.
  * https://gcc.gnu.org/onlinedocs/gccint/Initialization.html
  * However, it seems not all toolchains do this correctly, so use
- * __constructor_order_foward to detect which direction is called first
+ * __constructor_order_forward to detect which direction is called first
  * and adjust list building logic to get things running in the right
  * direction.
  */
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 2/2 selftests: harness: Add kselftest harness selftest with variant

In reply to Wei Yang

Each fixture could support variant. Add fixture with variant to verify the behavior, so we can validate for further change.

Cc Muhammad Usama Anjum <[email protected]>
Cc Thomas Weißschuh <[email protected]>

---
v2:
* remove testpid
* print value in teardown and test itself

---
 .../kselftest_harness/harness-selftest.c      | 30 +++++++++++++++++++
 .../harness-selftest.expected                 | 20 ++++++++++---
 2 files changed, 46 insertions(+), 4 deletions(-)
tools/testing/selftests/kselftest_harness/harness-selftest.c +30 -0
index b555493bdb4d..2a2a91717fce 100644
@@ -118,6 +118,36 @@ TEST_F(fixture_setup_failure, pass) {
 	TH_LOG("after");
 }
 
+FIXTURE(fixture_variant) {
+};
+
+FIXTURE_VARIANT(fixture_variant)
+{
+	int value;
+};
+
+FIXTURE_VARIANT_ADD(fixture_variant, v32)
+{
+	.value = 32,
+};
+
+FIXTURE_VARIANT_ADD(fixture_variant, v64)
+{
+	.value = 64,
+};
+
+FIXTURE_SETUP(fixture_variant) {
+	TH_LOG("setup %d", variant->value);
+}
+
+FIXTURE_TEARDOWN(fixture_variant) {
+	TH_LOG("teardown %d", variant->value);
+}
+
+TEST_F(fixture_variant, pass) {
+	TH_LOG("test function %d", variant->value);
+}
+
 int main(int argc, char **argv)
 {
 	/*
tools/testing/selftests/kselftest_harness/harness-selftest.expected +16 -4
index 97e1418c1c7e..0c19794e018d 100644
@@ -1,6 +1,6 @@
 TAP version 13
-1..9
-# Starting 9 tests from 4 test cases.
+1..11
+# Starting 11 tests from 6 test cases.
 #  RUN           global.standalone_pass ...
 # harness-selftest.c:19:standalone_pass:before
 # harness-selftest.c:23:standalone_pass:after
@@ -60,5 +60,17 @@ ok 8 fixture_parent.pass
 # pass: Test terminated by assertion
 #          FAIL  fixture_setup_failure.pass
 not ok 9 fixture_setup_failure.pass
-# FAILED: 4 / 9 tests passed.
-# Totals: pass:4 fail:5 xfail:0 xpass:0 skip:0 error:0
+#  RUN           fixture_variant.v32.pass ...
+# harness-selftest.c:140:pass:setup 32
+# harness-selftest.c:148:pass:test function 32
+# harness-selftest.c:144:pass:teardown 32
+#            OK  fixture_variant.v32.pass
+ok 10 fixture_variant.v32.pass
+#  RUN           fixture_variant.v64.pass ...
+# harness-selftest.c:140:pass:setup 64
+# harness-selftest.c:148:pass:test function 64
+# harness-selftest.c:144:pass:teardown 64
+#            OK  fixture_variant.v64.pass
+ok 11 fixture_variant.v64.pass
+# FAILED: 6 / 11 tests passed.
+# Totals: pass:6 fail:5 xfail:0 xpass:0 skip:0 error:0
Signature · 1 line
2.34.1
Reviewed-by on v2 2/2
#3 lore raw

Re: [Patch v2 2/2] selftests: harness: Add kselftest harness selftest with variant

Quoted 5 lines · Wei Yang

Each fixture could support variant. Add fixture with variant to verify the behavior, so we can validate for further change.

Cc Muhammad Usama Anjum <[email protected]>
Quoted 8 lines

---
v2:
* remove testpid
* print value in teardown and test itself

---
 .../kselftest_harness/harness-selftest.c      | 30 +++++++++++++++++++
 .../harness-selftest.expected                 | 20 ++++++++++---
 2 files changed, 46 insertions(+), 4 deletions(-)

<snip>

author
#4 lore raw

Re: [Patch v2 2/2] selftests: harness: Add kselftest harness selftest with variant

Quoted 9 lines · Thomas Weißschuh
Quoted 5 lines · Wei Yang

Each fixture could support variant. Add fixture with variant to verify the behavior, so we can validate for further change.

Cc Muhammad Usama Anjum <[email protected]>

Thanks

Quoted 10 lines
Quoted 8 lines

---
v2:
* remove testpid
* print value in teardown and test itself

---
 .../kselftest_harness/harness-selftest.c      | 30 +++++++++++++++++++
 .../harness-selftest.expected                 | 20 ++++++++++---
 2 files changed, 46 insertions(+), 4 deletions(-)

<snip>

Signature · 2 lines
Wei Yang
Help you, Help me
Reviewed-by on v2 2/2
#5 lore raw

Re: [Patch v2 2/2] selftests: harness: Add kselftest harness selftest with variant

In reply to Wei Yang
Quoted 44 lines · Wei Yang

Each fixture could support variant. Add fixture with variant to verify the behavior, so we can validate for further change.

Cc Muhammad Usama Anjum <[email protected]>
Cc Thomas Weißschuh <[email protected]>

---
v2:
* remove testpid
* print value in teardown and test itself

---
 .../kselftest_harness/harness-selftest.c      | 30 +++++++++++++++++++
 .../harness-selftest.expected                 | 20 ++++++++++---
 2 files changed, 46 insertions(+), 4 deletions(-)
tools/testing/selftests/kselftest_harness/harness-selftest.c +20 -0
index b555493bdb4d..2a2a91717fce 100644
@@ -118,6 +118,36 @@ TEST_F(fixture_setup_failure, pass) {
 	TH_LOG("after");
 }
 
+FIXTURE(fixture_variant) {
+};
+
+FIXTURE_VARIANT(fixture_variant)
+{
+	int value;
+};
+
+FIXTURE_VARIANT_ADD(fixture_variant, v32)
+{
+	.value = 32,
+};
+
+FIXTURE_VARIANT_ADD(fixture_variant, v64)
+{
+	.value = 64,
+};
+
+FIXTURE_SETUP(fixture_variant) {
+	TH_LOG("setup %d", variant->value);

tools/testing/selftests/kselftest_harness/harness-selftest.c TEST_F(fixture_setup_failure, pass) { · line 150

Quoted 10 lines
tools/testing/selftests/kselftest_harness/harness-selftest.c +10 -0
+}
+
+FIXTURE_TEARDOWN(fixture_variant) {
+	TH_LOG("teardown %d", variant->value);
+}
+
+TEST_F(fixture_variant, pass) {
+	TH_LOG("test function %d", variant->value);
+}
+
Quoted 36 lines
tools/testing/selftests/kselftest_harness/harness-selftest.c +0 -0
 int main(int argc, char **argv)
 {
 	/*
tools/testing/selftests/kselftest_harness/harness-selftest.expected +16 -4
index 97e1418c1c7e..0c19794e018d 100644
@@ -1,6 +1,6 @@
 TAP version 13
-1..9
-# Starting 9 tests from 4 test cases.
+1..11
+# Starting 11 tests from 6 test cases.
 #  RUN           global.standalone_pass ...
 # harness-selftest.c:19:standalone_pass:before
 # harness-selftest.c:23:standalone_pass:after
@@ -60,5 +60,17 @@ ok 8 fixture_parent.pass
 # pass: Test terminated by assertion
 #          FAIL  fixture_setup_failure.pass
 not ok 9 fixture_setup_failure.pass
-# FAILED: 4 / 9 tests passed.
-# Totals: pass:4 fail:5 xfail:0 xpass:0 skip:0 error:0
+#  RUN           fixture_variant.v32.pass ...
+# harness-selftest.c:140:pass:setup 32
+# harness-selftest.c:148:pass:test function 32
+# harness-selftest.c:144:pass:teardown 32
+#            OK  fixture_variant.v32.pass
+ok 10 fixture_variant.v32.pass
+#  RUN           fixture_variant.v64.pass ...
+# harness-selftest.c:140:pass:setup 64
+# harness-selftest.c:148:pass:test function 64
+# harness-selftest.c:144:pass:teardown 64
+#            OK  fixture_variant.v64.pass
+ok 11 fixture_variant.v64.pass
+# FAILED: 6 / 11 tests passed.
+# Totals: pass:6 fail:5 xfail:0 xpass:0 skip:0 error:0
author
#6 lore raw

Re: [Patch v2 2/2] selftests: harness: Add kselftest harness selftest with variant

On Fri, Jun 20, 2025 at 12:12:40PM +0500, Muhammad Usama Anjum wrote:
[...]

Quoted 24 lines
Quoted 24 lines
tools/testing/selftests/kselftest_harness/harness-selftest.c +23 -0
+FIXTURE(fixture_variant) {
+};
+
+FIXTURE_VARIANT(fixture_variant)
+{
+	int value;
+};
+
+FIXTURE_VARIANT_ADD(fixture_variant, v32)
+{
+	.value = 32,
+};
+
+FIXTURE_VARIANT_ADD(fixture_variant, v64)
+{
+	.value = 64,
+};
+
+FIXTURE_SETUP(fixture_variant) {
+	TH_LOG("setup %d", variant->value);
+}
+
+FIXTURE_TEARDOWN(fixture_variant) {
Quoted 9 lines

tools/testing/selftests/kselftest_harness/harness-selftest.c TEST_F(fixture_setup_failure, pass) { · line 150

Quoted 7 lines
tools/testing/selftests/kselftest_harness/harness-selftest.c +7 -0
+	TH_LOG("teardown %d", variant->value);
+}
+
+TEST_F(fixture_variant, pass) {
+	TH_LOG("test function %d", variant->value);
+}
+

Thanks, Muhammad :-)

Signature · 2 lines
Wei Yang
Help you, Help me
author
#7 lore raw
In reply to Wei Yang
Quoted 6 lines · Wei Yang

We already have a selftest for harness, while there is not usage of FIXTURE_VARIANT.

Patch 2 add FIXTURE_VARIANT usage in the selftest.

Patch 1 is a typo fix.

Ping...

Would someone pick it up?

Quoted 17 lines

v2:
* drop patch 2 in v1
* adjust patch 2 based on Thomas comment

Wei Yang (2):
selftests: harness: correct typo of __constructor_order_forward in
comment
selftests: harness: Add kselftest harness selftest with variant

tools/testing/selftests/kselftest_harness.h   |  2 +-
.../kselftest_harness/harness-selftest.c      | 30 +++++++++++++++++++
.../harness-selftest.expected                 | 20 ++++++++++---
3 files changed, 47 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
Signature · 2 lines
Wei Yang
Help you, Help me