diff mbox series

lib/tests: Make RANDSTRUCT_KUNIT_TEST depend on RANDSTRUCT

Message ID 22d9c2fa9e751a9de3c599aa082be588ea82a7a0.1748875640.git.geert@linux-m68k.org
State New
Headers show
Series lib/tests: Make RANDSTRUCT_KUNIT_TEST depend on RANDSTRUCT | expand

Commit Message

Geert Uytterhoeven June 2, 2025, 2:49 p.m. UTC
When CONFIG_RANDSTRUCT is not enabled, all randstruct tests are skipped.
Move this logic from run-time to config-time, to avoid people building
and running tests that do not do anything.

Fixes: b370f7eacdcfe1dd ("lib/tests: Add randstruct KUnit test")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
FTR, after adding "select HAVE_GCC_PLUGINS" to arch/m68k/Kconfig and
installing gcc-13-plugin-dev-m68k-linux-gnu, I could enable
CONFIG_RANDSTRUCT_FULL and run the tests (all passed!), so probably I
should send a patch to select HAVE_GCC_PLUGINS?
---
 lib/Kconfig.debug            | 4 ++--
 lib/tests/randstruct_kunit.c | 9 ---------
 2 files changed, 2 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index a8b4febad716a4be..407f2ed7fcb3e94c 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2895,10 +2895,10 @@  config OVERFLOW_KUNIT_TEST
 config RANDSTRUCT_KUNIT_TEST
 	tristate "Test randstruct structure layout randomization at runtime" if !KUNIT_ALL_TESTS
 	depends on KUNIT
+	depends on RANDSTRUCT
 	default KUNIT_ALL_TESTS
 	help
-	  Builds unit tests for the checking CONFIG_RANDSTRUCT=y, which
-	  randomizes structure layouts.
+	  Builds unit tests for checking structure layout randomization.
 
 config STACKINIT_KUNIT_TEST
 	tristate "Test level of stack variable initialization" if !KUNIT_ALL_TESTS
diff --git a/lib/tests/randstruct_kunit.c b/lib/tests/randstruct_kunit.c
index f3a2d63c4cfbe7dc..2c95eca76d2411bc 100644
--- a/lib/tests/randstruct_kunit.c
+++ b/lib/tests/randstruct_kunit.c
@@ -305,14 +305,6 @@  static void randstruct_initializers(struct kunit *test)
 #undef init_members
 }
 
-static int randstruct_test_init(struct kunit *test)
-{
-	if (!IS_ENABLED(CONFIG_RANDSTRUCT))
-		kunit_skip(test, "Not built with CONFIG_RANDSTRUCT=y");
-
-	return 0;
-}
-
 static struct kunit_case randstruct_test_cases[] = {
 	KUNIT_CASE(randstruct_layout_same),
 	KUNIT_CASE(randstruct_layout_mixed),
@@ -324,7 +316,6 @@  static struct kunit_case randstruct_test_cases[] = {
 
 static struct kunit_suite randstruct_test_suite = {
 	.name = "randstruct",
-	.init = randstruct_test_init,
 	.test_cases = randstruct_test_cases,
 };