summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVaibhav Jain <vaibhav@linux.ibm.com>2026-06-26 14:28:07 +0530
committerShuah Khan <skhan@linuxfoundation.org>2026-06-29 15:48:26 -0600
commit643ec8ff7d8ed15881bd05d71de24208ce0dadcb (patch)
tree9aee46fb87451d9204ee6e6e9615f07bae5cb905
parent0efe609ef5b6ab286ec296369365efd2b9ce774f (diff)
downloadlinux-643ec8ff7d8ed15881bd05d71de24208ce0dadcb.tar.gz
linux-643ec8ff7d8ed15881bd05d71de24208ce0dadcb.zip
kunit: Add example of test suite that can be skipped at runtime
Add an example test suite name 'example_test_skip_suite' to 'kunit-example-test.c' that shows how to skip an entire test suite based on runtime conditions. The example suite 'example_skip_suite' provides a 'suite_init' callback named example_skip_suite_init() which marks the entire suite as skipped using kunit_mark_skipped(). This demonstrates a way for conditionally skipping test suites when any prerequisites for kunit_suite execution are not met. The 'suite_init' callback can perform any necessary checks and mark the suite as skipped, preventing all test cases from executing while also indicating why the suite was skipped. Link: https://lore.kernel.org/r/20260626085811.151133-3-vaibhav@linux.ibm.com Reviewed-by: David Gow <david@davidgow.net> Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
-rw-r--r--lib/kunit/kunit-example-test.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c
index 0bae7b7ca0b0..b8ded54fa46d 100644
--- a/lib/kunit/kunit-example-test.c
+++ b/lib/kunit/kunit-example-test.c
@@ -591,5 +591,34 @@ static struct kunit_suite example_init_test_suite = {
*/
kunit_test_init_section_suites(&example_init_test_suite);
+/*
+ * This test should always be skipped.
+ */
+static void example_skip_suite_test(struct kunit *test)
+{
+ /* This line should never be seen */
+ KUNIT_FAIL(test, "You should not see a this.");
+}
+
+static struct kunit_case example_skip_suite_test_cases[] = {
+ KUNIT_CASE(example_skip_suite_test),
+ {}
+};
+
+static int example_skip_suite_init(struct kunit_suite *suite)
+{
+ kunit_mark_skipped(suite, "Test suite expected to be skipped");
+ return 0;
+}
+
+static struct kunit_suite example_test_skip_suite = {
+ .name = "example_skip_suite",
+ .suite_init = example_skip_suite_init,
+ .test_cases = example_skip_suite_test_cases,
+};
+
+/* This registers a test suite that will be skipped */
+kunit_test_suite(example_test_skip_suite);
+
MODULE_DESCRIPTION("Example KUnit test suite");
MODULE_LICENSE("GPL v2");