Skip to contentSkip to conversation

siphash: Convert selftest to KUnit

PATCH In review Kees Cook 3 participants 5 messages Oct 18, 2022 – Oct 19, 2022 Library code

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 siphash: Convert selftest to KUnit

Convert the siphash self-test to KUnit so it will be included in "all KUnit tests" coverage, and can be run individually still:

$ ./tools/testing/kunit/kunit.py run siphash
...
[02:58:45] Starting KUnit Kernel (1/1)...
[02:58:45] ============================================================
[02:58:45] =================== siphash (1 subtest) ====================
[02:58:45] [PASSED] siphash_test
[02:58:45] ===================== [PASSED] siphash =====================
[02:58:45] ============================================================
[02:58:45] Testing complete. Ran 1 tests: passed: 1
[02:58:45] Elapsed time: 21.421s total, 4.306s configuring, 16.947s building, 0.148s running
Cc "Jason A. Donenfeld" <[email protected]>
Cc David Gow <[email protected]>
---
 MAINTAINERS                             |   2 +-
 lib/Kconfig.debug                       |  20 +--
 lib/Makefile                            |   2 +-
 lib/{test_siphash.c => siphash_kunit.c} | 165 ++++++++++--------------
 4 files changed, 83 insertions(+), 106 deletions(-)
 rename lib/{test_siphash.c => siphash_kunit.c} (60%)
MAINTAINERS +1 -1
index cf0f18502372..037466b9a027 100644
@@ -18862,7 +18862,7 @@ M:	Jason A. Donenfeld <[email protected]>
 S:	Maintained
 F:	include/linux/siphash.h
 F:	lib/siphash.c
-F:	lib/test_siphash.c
+F:	lib/siphash_kunit.c
 
 SIS 190 ETHERNET DRIVER
 M:	Francois Romieu <[email protected]>
lib/Kconfig.debug +11 -9
index 3fc7abffc7aa..65593675cd5a 100644
@@ -2247,15 +2247,6 @@ config TEST_RHASHTABLE
 
 	  If unsure, say N.
 
-config TEST_SIPHASH
-	tristate "Perform selftest on siphash functions"
-	help
-	  Enable this option to test the kernel's siphash (<linux/siphash.h>) hash
-	  functions on boot (or module load).
-
-	  This is intended to help people writing architecture-specific
-	  optimized versions.  If unsure, say N.
-
 config TEST_IDA
 	tristate "Perform selftest on IDA functions"
 
@@ -2583,6 +2574,17 @@ config HW_BREAKPOINT_KUNIT_TEST
 
 	  If unsure, say N.
 
+config SIPHASH_KUNIT_TEST
+	tristate "Perform selftest on siphash functions" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  Enable this option to test the kernel's siphash (<linux/siphash.h>) hash
+	  functions on boot (or module load).
+
+	  This is intended to help people writing architecture-specific
+	  optimized versions.  If unsure, say N.
+
 config TEST_UDELAY
 	tristate "udelay test driver"
 	help
lib/Makefile +1 -1
index 161d6a724ff7..bca02ac1adf8 100644
@@ -62,7 +62,6 @@ obj-$(CONFIG_TEST_BITOPS) += test_bitops.o
 CFLAGS_test_bitops.o += -Werror
 obj-$(CONFIG_CPUMASK_KUNIT_TEST) += cpumask_kunit.o
 obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o
-obj-$(CONFIG_TEST_SIPHASH) += test_siphash.o
 obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
 obj-$(CONFIG_TEST_IDA) += test_ida.o
 obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o
@@ -380,6 +379,7 @@ obj-$(CONFIG_OVERFLOW_KUNIT_TEST) += overflow_kunit.o
 CFLAGS_stackinit_kunit.o += $(call cc-disable-warning, switch-unreachable)
 obj-$(CONFIG_STACKINIT_KUNIT_TEST) += stackinit_kunit.o
 obj-$(CONFIG_FORTIFY_KUNIT_TEST) += fortify_kunit.o
+obj-$(CONFIG_SIPHASH_KUNIT_TEST) += siphash_kunit.o
 
 obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o
 
lib/siphash_kunit.c renamed from lib/test_siphash.c +70 -95

190 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw
Quoted 14 lines · Kees Cook

Convert the siphash self-test to KUnit so it will be included in "all KUnit tests" coverage, and can be run individually still:

$ ./tools/testing/kunit/kunit.py run siphash
...
[02:58:45] Starting KUnit Kernel (1/1)...
[02:58:45] ============================================================
[02:58:45] =================== siphash (1 subtest) ====================
[02:58:45] [PASSED] siphash_test
[02:58:45] ===================== [PASSED] siphash =====================
[02:58:45] ============================================================
[02:58:45] Testing complete. Ran 1 tests: passed: 1
[02:58:45] Elapsed time: 21.421s total, 4.306s configuring, 16.947s building, 0.148s running
Quoted 3 lines
Cc "Jason A. Donenfeld" <[email protected]>
Cc David Gow <[email protected]>

I'll queue this up. Thanks for the conversion. Appears to work well.

Jason

author
#2 lore raw
Quoted 15 lines · Jason A. Donenfeld
Quoted 14 lines · Kees Cook

Convert the siphash self-test to KUnit so it will be included in "all KUnit tests" coverage, and can be run individually still:

$ ./tools/testing/kunit/kunit.py run siphash
...
[02:58:45] Starting KUnit Kernel (1/1)...
[02:58:45] ============================================================
[02:58:45] =================== siphash (1 subtest) ====================
[02:58:45] [PASSED] siphash_test
[02:58:45] ===================== [PASSED] siphash =====================
[02:58:45] ============================================================
[02:58:45] Testing complete. Ran 1 tests: passed: 1
[02:58:45] Elapsed time: 21.421s total, 4.306s configuring, 16.947s building, 0.148s running
Quoted 5 lines
Quoted 3 lines
Cc "Jason A. Donenfeld" <[email protected]>
Cc David Gow <[email protected]>

I'll queue this up. Thanks for the conversion. Appears to work well.

Cool! Thanks for looking it over. If we want to avoid some tree collisions, I could carry it in my tree? I've got some other conversions in progress. Though maybe this begs the question of "how should kunit tests be ordered in the Kconfig and Makefile?" so that collisions are obvious about how to order...

Signature · 1 line
Kees Cook
#3 lore raw
Quoted 21 lines · Kees Cook
Quoted 19 lines · Jason A. Donenfeld
Quoted 17 lines · Kees Cook

Convert the siphash self-test to KUnit so it will be included in "all KUnit tests" coverage, and can be run individually still:

$ ./tools/testing/kunit/kunit.py run siphash
...
[02:58:45] Starting KUnit Kernel (1/1)...
[02:58:45] ============================================================
[02:58:45] =================== siphash (1 subtest) ====================
[02:58:45] [PASSED] siphash_test
[02:58:45] ===================== [PASSED] siphash =====================
[02:58:45] ============================================================
[02:58:45] Testing complete. Ran 1 tests: passed: 1
[02:58:45] Elapsed time: 21.421s total, 4.306s configuring, 16.947s building, 0.148s running
Cc "Jason A. Donenfeld" <[email protected]>
Cc David Gow <[email protected]>
Quoted 7 lines
Quoted 1 line

I'll queue this up. Thanks for the conversion. Appears to work well.

Cool! Thanks for looking it over. If we want to avoid some tree collisions, I could carry it in my tree? I've got some other conversions in progress. Though maybe this begs the question of "how should kunit tests be ordered in the Kconfig and Makefile?" so that collisions are obvious about how to order...

No problem:

Please use a lowercase "convert" in the commit subject, like the other siphash commits.

Jason

Tested-by on v1 1/1
#4 lore raw
In reply to Kees Cook
Quoted 15 lines · Kees Cook

Convert the siphash self-test to KUnit so it will be included in "all KUnit tests" coverage, and can be run individually still:

$ ./tools/testing/kunit/kunit.py run siphash
...
[02:58:45] Starting KUnit Kernel (1/1)...
[02:58:45] ============================================================
[02:58:45] =================== siphash (1 subtest) ====================
[02:58:45] [PASSED] siphash_test
[02:58:45] ===================== [PASSED] siphash =====================
[02:58:45] ============================================================
[02:58:45] Testing complete. Ran 1 tests: passed: 1
[02:58:45] Elapsed time: 21.421s total, 4.306s configuring, 16.947s building, 0.148s running
Quoted 4 lines
Cc "Jason A. Donenfeld" <[email protected]>
Cc David Gow <[email protected]>

---

Works fine here, and looks good from a KUnit point-of-view.

Cheers,
-- David