Skip to contentSkip to conversation

lib/glob: convert selftest to KUnit

PATCH Superseded Kir Chou 2 participants 2 messages Jan 5 – Jan 6

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Kir Chou

author
#0 lore raw

PATCH 1/1 lib/glob: convert selftest to KUnit

This patch converts the existing glob selftest (lib/globtest.c) to use the KUnit framework (lib/glob_kunit.c).

The new test:

- Migrates all 64 test cases from the original test to the KUnit suite.
- Removes the custom 'verbose' module parameter as KUnit handles logging.
- Updates Kconfig.debug and Makefile to support the new KUnit test.
- Updates Kconfig and Makefile to remove the original selftest.
- Updates GLOB_SELFTEST to GLOB_KUNIT_TEST for arch/m68k/configs.

This commit is verified by ./tools/testing/kunit/kunit.py run with the .kunit/.kunitconfig:

```
CONFIG_KUNIT=y
CONFIG_GLOB_KUNIT_TEST=y
```
---
 arch/m68k/configs/amiga_defconfig    |   2 +-
 arch/m68k/configs/apollo_defconfig   |   2 +-
 arch/m68k/configs/atari_defconfig    |   2 +-
 arch/m68k/configs/bvme6000_defconfig |   2 +-
 arch/m68k/configs/hp300_defconfig    |   2 +-
 arch/m68k/configs/mac_defconfig      |   2 +-
 arch/m68k/configs/multi_defconfig    |   2 +-
 arch/m68k/configs/mvme147_defconfig  |   2 +-
 arch/m68k/configs/mvme16x_defconfig  |   2 +-
 arch/m68k/configs/q40_defconfig      |   2 +-
 arch/m68k/configs/sun3_defconfig     |   2 +-
 arch/m68k/configs/sun3x_defconfig    |   2 +-
 lib/Kconfig                          |  13 ---
 lib/Kconfig.debug                    |  13 +++
 lib/Makefile                         |   2 +-
 lib/glob_kunit.c                     | 122 +++++++++++++++++++
 lib/globtest.c                       | 167 ---------------------------
 17 files changed, 148 insertions(+), 193 deletions(-)
 create mode 100644 lib/glob_kunit.c
 delete mode 100644 lib/globtest.c
arch/m68k/configs/amiga_defconfig +1 -1
index bfc1ee7c8..aba96f98b 100644
@@ -600,7 +600,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
arch/m68k/configs/apollo_defconfig +1 -1
index d9d1f3c4c..8fb7b2dfb 100644
@@ -557,7 +557,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
arch/m68k/configs/atari_defconfig +1 -1
index 523205adc..09766b692 100644
@@ -577,7 +577,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
arch/m68k/configs/bvme6000_defconfig +1 -1
index 7b0a4ef0b..882c01e8c 100644
@@ -549,7 +549,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
arch/m68k/configs/hp300_defconfig +1 -1
index 089c5c394..64bdd9c8a 100644
@@ -559,7 +559,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
arch/m68k/configs/mac_defconfig +1 -1
index 5f2484c36..e017cdfbb 100644
@@ -576,7 +576,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
arch/m68k/configs/multi_defconfig +1 -1
index 74f0a1f6d..4a450bce0 100644
@@ -663,7 +663,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
arch/m68k/configs/mvme147_defconfig +1 -1
index 4bee18c82..c2413bf6c 100644
@@ -549,7 +549,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
arch/m68k/configs/mvme16x_defconfig +1 -1
index 322c17e55..1186aafbc 100644
@@ -550,7 +550,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
arch/m68k/configs/q40_defconfig +1 -1
index 82f9baab8..7ecb99bfa 100644
@@ -566,7 +566,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
arch/m68k/configs/sun3_defconfig +1 -1
index f94ad226c..3ff8ac06d 100644
@@ -547,7 +547,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
arch/m68k/configs/sun3x_defconfig +1 -1
index a5ecfc505..e6999f78e 100644
@@ -547,7 +547,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m
lib/Kconfig +0 -13
index 2923924be..0f2fb9610 100644
@@ -430,19 +430,6 @@ config GLOB
 	  are compiling an out-of tree driver which tells you that it
 	  depends on this.
 
-config GLOB_SELFTEST
-	tristate "glob self-test on init"
-	depends on GLOB
-	help
-	  This option enables a simple self-test of the glob_match
-	  function on startup.	It is primarily useful for people
-	  working on the code to ensure they haven't introduced any
-	  regressions.
-
-	  It only adds a little bit of code and slows kernel boot (or
-	  module load) by a small amount, so you're welcome to play with
-	  it, but you probably don't need it.
-
 #
 # Netlink attribute parsing support is select'ed if needed
 #
lib/Kconfig.debug +13 -0
index ba36939fd..e4347e145 100644
@@ -3354,6 +3354,19 @@ config PRIME_NUMBERS_KUNIT_TEST
 
 	  If unsure, say N
 
+config GLOB_KUNIT_TEST
+	tristate "Glob matching test" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	select GLOB
+	help
+	  Enable this option to test the glob functions at runtime.
+
+	  This test suite verifies the correctness of glob_match() across various
+	  scenarios, including edge cases.
+
+	  If unsure, say N
+
 endif # RUNTIME_TESTING_MENU
 
 config ARCH_USE_MEMTEST
lib/Makefile +1 -1
index aaf677cf4..78d7deabe 100644
@@ -226,7 +226,7 @@ obj-$(CONFIG_CLOSURES) += closure.o
 obj-$(CONFIG_DQL) += dynamic_queue_limits.o
 
 obj-$(CONFIG_GLOB) += glob.o
-obj-$(CONFIG_GLOB_SELFTEST) += globtest.o
+obj-$(CONFIG_GLOB_KUNIT_TEST) += glob_kunit.o
 
 obj-$(CONFIG_DIMLIB) += dim/
 obj-$(CONFIG_SIGNATURE) += digsig.o
lib/glob_kunit.c new file +122 -0

122 lines not on this page · raw message

lib/globtest.c deleted +0 -167

167 lines not on this page · raw message

Signature · 1 line
2.52.0.351.gbe84eed79e-goog
#1 lore raw

Hi Kir,

Quoted 14 lines · Kir Chou

This patch converts the existing glob selftest (lib/globtest.c) to use the KUnit framework (lib/glob_kunit.c).

The new test:

- Migrates all 64 test cases from the original test to the KUnit suite.
- Removes the custom 'verbose' module parameter as KUnit handles logging.
- Updates Kconfig.debug and Makefile to support the new KUnit test.
- Updates Kconfig and Makefile to remove the original selftest.
- Updates GLOB_SELFTEST to GLOB_KUNIT_TEST for arch/m68k/configs.

This commit is verified by ./tools/testing/kunit/kunit.py run with the .kunit/.kunitconfig:

Quoted 6 lines
```
CONFIG_KUNIT=y
CONFIG_GLOB_KUNIT_TEST=y
```

Thanks for your patch!

arch/m68k/configs/amiga_defconfig CONFIG_CRYPTO_USER_API_AEAD=m · line 603

Quoted 8 lines
arch/m68k/configs/amiga_defconfig +1 -1
@@ -600,7 +600,7 @@ CONFIG_CRYPTO_USER_API_AEAD=m
 CONFIG_PRIME_NUMBERS=m
 CONFIG_CRC_BENCHMARK=y
 CONFIG_XZ_DEC_TEST=m
-CONFIG_GLOB_SELFTEST=m
+CONFIG_GLOB_KUNIT_TEST=m

This is not the correct location for CONFIG_GLOB_KUNIT_TEST. Please run "make savedefconfig" and inspect the resulting defconfig file.

However, given GLOB_KUNIT_TEST defaults to KUNIT_ALL_TESTS, which is set to "m" in the m68k defconfigs, there is no need to add "CONFIG_GLOB_KUNIT_TEST=m" at all.

arch/m68k/configs/amiga_defconfig CONFIG_CRYPTO_USER_API_AEAD=m · line 606

Quoted 3 lines
arch/m68k/configs/amiga_defconfig +0 -0
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_TEST_LOCKUP=m

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds