From: Joe Fradley <joefradley@google.com>
To: Jonathan Corbet <corbet@lwn.net>,
Brendan Higgins <brendan.higgins@linux.dev>,
David Gow <davidgow@google.com>
Cc: Joe Fradley <joefradley@google.com>,
kernel-team@android.com, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
kunit-dev@googlegroups.com
Subject: [PATCH 1/2] kunit: add kunit.enable to enable/disable KUnit test
Date: Wed, 17 Aug 2022 09:48:49 -0700 [thread overview]
Message-ID: <20220817164851.3574140-2-joefradley@google.com> (raw)
In-Reply-To: <20220817164851.3574140-1-joefradley@google.com>
This patch adds the kunit.enable module parameter that will need to be
set to true in addition to KUNIT being enabled for KUnit tests to run.
The default value is true giving backwards compatibility. However, for
the production+testing use case the new config option
KUNIT_ENABLE_DEFAULT_DISABLED can be enabled to default kunit.enable to
false requiring the tester to opt-in by passing kunit.enable=1 to
the kernel.
Signed-off-by: Joe Fradley <joefradley@google.com>
---
.../admin-guide/kernel-parameters.txt | 6 ++++++
lib/kunit/Kconfig | 8 ++++++++
lib/kunit/test.c | 20 +++++++++++++++++++
3 files changed, 34 insertions(+)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index d7f30902fda0..ab4c7d133c38 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2436,6 +2436,12 @@
0: force disabled
1: force enabled
+ kunit.enable= [KUNIT] Enable executing KUnit tests. Requires
+ CONFIG_KUNIT to be set to be fully enabled. The
+ default value can be overridden to disabled via
+ KUNIT_ENABLE_DEFAULT_DISABLED.
+ Default is 1 (enabled)
+
kvm.ignore_msrs=[KVM] Ignore guest accesses to unhandled MSRs.
Default is 0 (don't ignore, but inject #GP)
diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig
index 0b5dfb001bac..5d6db58dbe9b 100644
--- a/lib/kunit/Kconfig
+++ b/lib/kunit/Kconfig
@@ -59,4 +59,12 @@ config KUNIT_ALL_TESTS
If unsure, say N.
+config KUNIT_ENABLE_DEFAULT_DISABLED
+ bool "Require boot parameter to enable KUnit test execution"
+ help
+ Sets the default value of the kernel parameter kunit.enable to 0
+ (disabled). This means to fully enable kunit, config KUNIT needs
+ to be enabled along with `kunit.enable=1` passed to the kernel. This
+ allows KUnit to be opt-in at boot time.
+
endif # KUNIT
diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index b73d5bb5c473..e6f98e16e8ae 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -54,6 +54,17 @@ void __kunit_fail_current_test(const char *file, int line, const char *fmt, ...)
EXPORT_SYMBOL_GPL(__kunit_fail_current_test);
#endif
+/*
+ * Enable KUnit tests to run.
+ */
+#ifdef CONFIG_KUNIT_ENABLE_DEFAULT_DISABLED
+static bool enable_param;
+#else
+static bool enable_param = true;
+#endif
+module_param_named(enable, enable_param, bool, 0);
+MODULE_PARM_DESC(enable, "Enable KUnit tests to run");
+
/*
* KUnit statistic mode:
* 0 - disabled
@@ -590,6 +601,12 @@ int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_
{
unsigned int i;
+ if (!enable_param && num_suites > 0) {
+ pr_info("kunit: deactivated, cannot load %s\n",
+ suites != NULL && suites[0] != NULL ? suites[0]->name : "NULL");
+ return -EPERM;
+ }
+
for (i = 0; i < num_suites; i++) {
kunit_init_suite(suites[i]);
kunit_run_tests(suites[i]);
@@ -607,6 +624,9 @@ void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites)
{
unsigned int i;
+ if (!enable_param)
+ return;
+
for (i = 0; i < num_suites; i++)
kunit_exit_suite(suites[i]);
--
2.37.1.595.g718a3a8f04-goog
next prev parent reply other threads:[~2022-08-17 16:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-17 16:48 [PATCH 0/2] kunit: add boot time parameter to enable KUnit Joe Fradley
2022-08-17 16:48 ` Joe Fradley [this message]
2022-08-19 8:16 ` [PATCH 1/2] kunit: add kunit.enable to enable/disable KUnit test David Gow
2022-08-22 20:37 ` Joe Fradley
2022-08-17 16:48 ` [PATCH 2/2] kunit: no longer call module_info(test, "Y") for kunit modules Joe Fradley
2022-08-19 8:34 ` David Gow
2022-08-22 20:47 ` Joe Fradley
2022-08-22 20:57 ` Brendan Higgins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220817164851.3574140-2-joefradley@google.com \
--to=joefradley@google.com \
--cc=brendan.higgins@linux.dev \
--cc=corbet@lwn.net \
--cc=davidgow@google.com \
--cc=kernel-team@android.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox