Commit 2b61582a authored by Michal Wajdeczko's avatar Michal Wajdeczko Committed by Shuah Khan

kunit: Add example for using test->priv

In a test->priv field the user can store arbitrary data.
Add example how to use this feature in the test code.
Signed-off-by: default avatarMichal Wajdeczko <michal.wajdeczko@intel.com>
Cc: David Gow <davidgow@google.com>
Cc: Rae Moar <rmoar@google.com>
Reviewed-by: default avatarDavid Gow <davidgow@google.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent d393acce
......@@ -221,6 +221,20 @@ static void example_params_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, param->value % param->value, 0);
}
/*
* This test shows the use of test->priv.
*/
static void example_priv_test(struct kunit *test)
{
/* unless setup in suite->init(), test->priv is NULL */
KUNIT_ASSERT_NULL(test, test->priv);
/* but can be used to pass arbitrary data to other functions */
test->priv = kunit_kzalloc(test, 1, GFP_KERNEL);
KUNIT_EXPECT_NOT_NULL(test, test->priv);
KUNIT_ASSERT_PTR_EQ(test, test->priv, kunit_get_current_test()->priv);
}
/*
* This test should always pass. Can be used to practice filtering attributes.
*/
......@@ -245,6 +259,7 @@ static struct kunit_case example_test_cases[] = {
KUNIT_CASE(example_mark_skipped_test),
KUNIT_CASE(example_all_expect_macros_test),
KUNIT_CASE(example_static_stub_test),
KUNIT_CASE(example_priv_test),
KUNIT_CASE_PARAM(example_params_test, example_gen_params),
KUNIT_CASE_SLOW(example_slow_test),
{}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment