Re: [PATCH 2/2] kunit: Add example of test suite that can be skipped at runtime
Vaibhav Jain <[email protected]> Mon, 08 Jun 2026 14:11:15 +0530
| Newsgroups | org.kernel.vger.kvm-ppc,org.kernel.vger.kvm,org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest,org.ozlabs.lists.linuxppc-dev |
|---|---|
| Message-ID | <[email protected]> |
David Gow <[email protected]> writes: > Le 05/06/2026 =C3=A0 12:28 AM, Vaibhav Jain a =C3=A9crit=C2=A0: >> 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. >>=20 >> 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(). >>=20 >> 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. >>=20 >> Signed-off-by: Vaibhav Jain <[email protected]> >> --- > > Thanks! > > Reviewed-by: David Gow <[email protected]> Awesome, thanks Will add your RB to v2 of the patch series > > Cheers, > -- David > >> lib/kunit/kunit-example-test.c | 29 +++++++++++++++++++++++++++++ >> 1 file changed, 29 insertions(+) >>=20 >> diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-te= st.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 = =3D { >> */ >> kunit_test_init_section_suites(&example_init_test_suite); >>=20=20 >> +/* >> + * 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[] =3D { >> + 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 =3D { >> + .name =3D "example_skip_suite", >> + .suite_init =3D example_skip_suite_init, >> + .test_cases =3D 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"); > --=20 Cheers ~ Vaibhav