Skip to content

Commit

Permalink
kunit: test: Add example tests which are always skipped
Browse files Browse the repository at this point in the history
Add two new tests to the example test suite, both of which are always
skipped. This is used as an example for how to write tests which are
skipped, and to demonstrate the difference between kunit_skip() and
kunit_mark_skipped().

Note that these tests are enabled by default, so a default run of KUnit
will have two skipped tests.

Signed-off-by: David Gow <[email protected]>
Reviewed-by: Daniel Latypov <[email protected]>
Reviewed-by: Brendan Higgins <[email protected]>
Reviewed-by: Marco Elver <[email protected]>
Signed-off-by: Shuah Khan <[email protected]>
  • Loading branch information
sulix authored and shuahkh committed Jun 25, 2021
1 parent 5acaf60 commit d99ea67
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/kunit/kunit-example-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ static int example_test_init(struct kunit *test)
return 0;
}

/*
* This test should always be skipped.
*/
static void example_skip_test(struct kunit *test)
{
/* This line should run */
kunit_info(test, "You should not see a line below.");

/* Skip (and abort) the test */
kunit_skip(test, "this test should be skipped");

/* This line should not execute */
KUNIT_FAIL(test, "You should not see this line.");
}

/*
* This test should always be marked skipped.
*/
static void example_mark_skipped_test(struct kunit *test)
{
/* This line should run */
kunit_info(test, "You should see a line below.");

/* Skip (but do not abort) the test */
kunit_mark_skipped(test, "this test should be skipped");

/* This line should run */
kunit_info(test, "You should see this line.");
}
/*
* Here we make a list of all the test cases we want to add to the test suite
* below.
Expand All @@ -52,6 +81,8 @@ static struct kunit_case example_test_cases[] = {
* test suite.
*/
KUNIT_CASE(example_simple_test),
KUNIT_CASE(example_skip_test),
KUNIT_CASE(example_mark_skipped_test),
{}
};

Expand Down

0 comments on commit d99ea67

Please sign in to comment.