Skip to content

Commit 02788eb

Browse files
committed
lib: stackinit: Convert to KUnit
Convert stackinit unit tests to KUnit, for better integration into the kernel self test framework. Includes a rename of test_stackinit.c to stackinit_kunit.c, and CONFIG_TEST_STACKINIT to CONFIG_STACKINIT_KUNIT_TEST. Adjust expected test results based on which stack initialization method was chosen: $ CMD="./tools/testing/kunit/kunit.py run stackinit --raw_output \ --arch=x86_64 --kconfig_add" $ $CMD | grep stackinit: # stackinit: pass:36 fail:0 skip:29 total:65 $ $CMD CONFIG_GCC_PLUGIN_STRUCTLEAK_USER=y | grep stackinit: # stackinit: pass:37 fail:0 skip:28 total:65 $ $CMD CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF=y | grep stackinit: # stackinit: pass:55 fail:0 skip:10 total:65 $ $CMD CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL=y | grep stackinit: # stackinit: pass:62 fail:0 skip:3 total:65 $ $CMD CONFIG_INIT_STACK_ALL_PATTERN=y --make_option LLVM=1 | grep stackinit: # stackinit: pass:60 fail:0 skip:5 total:65 $ $CMD CONFIG_INIT_STACK_ALL_ZERO=y --make_option LLVM=1 | grep stackinit: # stackinit: pass:60 fail:0 skip:5 total:65 Temporarily remove the userspace-build mode, which will be restored in a later patch. Expand the size of the pre-case switch variable so it doesn't get accidentally cleared. Cc: David Gow <davidgow@google.com> Cc: Daniel Latypov <dlatypov@google.com> Cc: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Kees Cook <keescook@chromium.org> --- v1: https://lore.kernel.org/lkml/20220224055145.1853657-1-keescook@chromium.org v2: - split "userspace KUnit stub" into separate header and patch (Daniel) - Improve commit log and comments (David) - Provide mapping of expected XFAIL tests to CONFIGs (David)
1 parent c7500c1 commit 02788eb

3 files changed

Lines changed: 121 additions & 174 deletions

File tree

lib/Kconfig.debug

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,17 @@ config OVERFLOW_KUNIT_TEST
25112511

25122512
If unsure, say N.
25132513

2514+
config STACKINIT_KUNIT_TEST
2515+
tristate "Test level of stack variable initialization" if !KUNIT_ALL_TESTS
2516+
depends on KUNIT
2517+
default KUNIT_ALL_TESTS
2518+
help
2519+
Test if the kernel is zero-initializing stack variables and
2520+
padding. Coverage is controlled by compiler flags,
2521+
CONFIG_INIT_STACK_ALL_PATTERN, CONFIG_INIT_STACK_ALL_ZERO,
2522+
CONFIG_GCC_PLUGIN_STRUCTLEAK, CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF,
2523+
or CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL.
2524+
25142525
config TEST_UDELAY
25152526
tristate "udelay test driver"
25162527
help
@@ -2602,17 +2613,6 @@ config TEST_OBJAGG
26022613
Enable this option to test object aggregation manager on boot
26032614
(or module load).
26042615

2605-
2606-
config TEST_STACKINIT
2607-
tristate "Test level of stack variable initialization"
2608-
help
2609-
Test if the kernel is zero-initializing stack variables and
2610-
padding. Coverage is controlled by compiler flags,
2611-
CONFIG_GCC_PLUGIN_STRUCTLEAK, CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF,
2612-
or CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL.
2613-
2614-
If unsure, say N.
2615-
26162616
config TEST_MEMINIT
26172617
tristate "Test heap/page initialization"
26182618
help

lib/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ obj-$(CONFIG_TEST_KMOD) += test_kmod.o
9393
obj-$(CONFIG_TEST_DEBUG_VIRTUAL) += test_debug_virtual.o
9494
obj-$(CONFIG_TEST_MEMCAT_P) += test_memcat_p.o
9595
obj-$(CONFIG_TEST_OBJAGG) += test_objagg.o
96-
CFLAGS_test_stackinit.o += $(call cc-disable-warning, switch-unreachable)
97-
obj-$(CONFIG_TEST_STACKINIT) += test_stackinit.o
9896
obj-$(CONFIG_TEST_BLACKHOLE_DEV) += test_blackhole_dev.o
9997
obj-$(CONFIG_TEST_MEMINIT) += test_meminit.o
10098
obj-$(CONFIG_TEST_LOCKUP) += test_lockup.o
@@ -363,6 +361,8 @@ obj-$(CONFIG_CMDLINE_KUNIT_TEST) += cmdline_kunit.o
363361
obj-$(CONFIG_SLUB_KUNIT_TEST) += slub_kunit.o
364362
obj-$(CONFIG_MEMCPY_KUNIT_TEST) += memcpy_kunit.o
365363
obj-$(CONFIG_OVERFLOW_KUNIT_TEST) += overflow_kunit.o
364+
CFLAGS_stackinit_kunit.o += $(call cc-disable-warning, switch-unreachable)
365+
obj-$(CONFIG_STACKINIT_KUNIT_TEST) += stackinit_kunit.o
366366

367367
obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o
368368

0 commit comments

Comments
 (0)