mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
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>
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user