Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: David Gow <davidgow@google.com>
Cc: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Michal Wajdeczko and committed by
Shuah Khan
2b61582a d393acce

+15
+15
lib/kunit/kunit-example-test.c
··· 222 222 } 223 223 224 224 /* 225 + * This test shows the use of test->priv. 226 + */ 227 + static void example_priv_test(struct kunit *test) 228 + { 229 + /* unless setup in suite->init(), test->priv is NULL */ 230 + KUNIT_ASSERT_NULL(test, test->priv); 231 + 232 + /* but can be used to pass arbitrary data to other functions */ 233 + test->priv = kunit_kzalloc(test, 1, GFP_KERNEL); 234 + KUNIT_EXPECT_NOT_NULL(test, test->priv); 235 + KUNIT_ASSERT_PTR_EQ(test, test->priv, kunit_get_current_test()->priv); 236 + } 237 + 238 + /* 225 239 * This test should always pass. Can be used to practice filtering attributes. 226 240 */ 227 241 static void example_slow_test(struct kunit *test) ··· 259 245 KUNIT_CASE(example_mark_skipped_test), 260 246 KUNIT_CASE(example_all_expect_macros_test), 261 247 KUNIT_CASE(example_static_stub_test), 248 + KUNIT_CASE(example_priv_test), 262 249 KUNIT_CASE_PARAM(example_params_test, example_gen_params), 263 250 KUNIT_CASE_SLOW(example_slow_test), 264 251 {}