Lines Matching full:test

3  * KUnit test for core test infrastructure.
8 #include <kunit/test.h>
19 struct kunit *test = data; in kunit_test_successful_try() local
20 struct kunit_try_catch_test_context *ctx = test->priv; in kunit_test_successful_try()
27 struct kunit *test = data; in kunit_test_no_catch() local
29 KUNIT_FAIL(test, "Catch should not be called\n"); in kunit_test_no_catch()
32 static void kunit_test_try_catch_successful_try_no_catch(struct kunit *test) in kunit_test_try_catch_successful_try_no_catch() argument
34 struct kunit_try_catch_test_context *ctx = test->priv; in kunit_test_try_catch_successful_try_no_catch()
38 test, in kunit_test_try_catch_successful_try_no_catch()
41 kunit_try_catch_run(try_catch, test); in kunit_test_try_catch_successful_try_no_catch()
43 KUNIT_EXPECT_TRUE(test, ctx->function_called); in kunit_test_try_catch_successful_try_no_catch()
48 struct kunit *test = data; in kunit_test_unsuccessful_try() local
49 struct kunit_try_catch_test_context *ctx = test->priv; in kunit_test_unsuccessful_try()
53 KUNIT_FAIL(test, "This line should never be reached\n"); in kunit_test_unsuccessful_try()
58 struct kunit *test = data; in kunit_test_catch() local
59 struct kunit_try_catch_test_context *ctx = test->priv; in kunit_test_catch()
64 static void kunit_test_try_catch_unsuccessful_try_does_catch(struct kunit *test) in kunit_test_try_catch_unsuccessful_try_does_catch() argument
66 struct kunit_try_catch_test_context *ctx = test->priv; in kunit_test_try_catch_unsuccessful_try_does_catch()
70 test, in kunit_test_try_catch_unsuccessful_try_does_catch()
73 kunit_try_catch_run(try_catch, test); in kunit_test_try_catch_unsuccessful_try_does_catch()
75 KUNIT_EXPECT_TRUE(test, ctx->function_called); in kunit_test_try_catch_unsuccessful_try_does_catch()
78 static int kunit_try_catch_test_init(struct kunit *test) in kunit_try_catch_test_init() argument
82 ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); in kunit_try_catch_test_init()
83 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); in kunit_try_catch_test_init()
84 test->priv = ctx; in kunit_try_catch_test_init()
86 ctx->try_catch = kunit_kmalloc(test, in kunit_try_catch_test_init()
89 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->try_catch); in kunit_try_catch_test_init()
101 .name = "kunit-try-catch-test",
107 * Context for testing test managed resources
108 * is_resource_initialized is used to test arbitrary resources
111 struct kunit test; member
133 static void kunit_resource_test_init_resources(struct kunit *test) in kunit_resource_test_init_resources() argument
135 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_init_resources()
137 kunit_init_test(&ctx->test, "testing_test_init_test", NULL); in kunit_resource_test_init_resources()
139 KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_init_resources()
142 static void kunit_resource_test_alloc_resource(struct kunit *test) in kunit_resource_test_alloc_resource() argument
144 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_alloc_resource()
148 res = kunit_alloc_and_get_resource(&ctx->test, in kunit_resource_test_alloc_resource()
154 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, res); in kunit_resource_test_alloc_resource()
155 KUNIT_EXPECT_PTR_EQ(test, in kunit_resource_test_alloc_resource()
158 KUNIT_EXPECT_TRUE(test, list_is_last(&res->node, &ctx->test.resources)); in kunit_resource_test_alloc_resource()
159 KUNIT_EXPECT_PTR_EQ(test, free, res->free); in kunit_resource_test_alloc_resource()
164 static inline bool kunit_resource_instance_match(struct kunit *test, in kunit_resource_instance_match() argument
179 static void kunit_resource_test_destroy_resource(struct kunit *test) in kunit_resource_test_destroy_resource() argument
181 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_destroy_resource()
183 &ctx->test, in kunit_resource_test_destroy_resource()
191 KUNIT_ASSERT_FALSE(test, in kunit_resource_test_destroy_resource()
192 kunit_destroy_resource(&ctx->test, in kunit_resource_test_destroy_resource()
196 KUNIT_EXPECT_FALSE(test, ctx->is_resource_initialized); in kunit_resource_test_destroy_resource()
197 KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_destroy_resource()
200 static void kunit_resource_test_remove_resource(struct kunit *test) in kunit_resource_test_remove_resource() argument
202 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_remove_resource()
204 &ctx->test, in kunit_resource_test_remove_resource()
211 KUNIT_EXPECT_FALSE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_remove_resource()
216 kunit_remove_resource(test, res); in kunit_resource_test_remove_resource()
217 KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_remove_resource()
219 KUNIT_EXPECT_TRUE(test, ctx->is_resource_initialized); in kunit_resource_test_remove_resource()
222 kunit_remove_resource(test, res); in kunit_resource_test_remove_resource()
223 KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_remove_resource()
227 KUNIT_EXPECT_TRUE(test, ctx->is_resource_initialized); in kunit_resource_test_remove_resource()
231 KUNIT_EXPECT_FALSE(test, ctx->is_resource_initialized); in kunit_resource_test_remove_resource()
234 static void kunit_resource_test_cleanup_resources(struct kunit *test) in kunit_resource_test_cleanup_resources() argument
237 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_cleanup_resources()
241 resources[i] = kunit_alloc_and_get_resource(&ctx->test, in kunit_resource_test_cleanup_resources()
249 kunit_cleanup(&ctx->test); in kunit_resource_test_cleanup_resources()
251 KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_cleanup_resources()
294 res2 = kunit_alloc_and_get_resource(&ctx->test, in fake_resource_1_init()
321 static void kunit_resource_test_proper_free_ordering(struct kunit *test) in kunit_resource_test_proper_free_ordering() argument
323 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_proper_free_ordering()
327 res = kunit_alloc_and_get_resource(&ctx->test, in kunit_resource_test_proper_free_ordering()
338 KUNIT_EXPECT_EQ(test, ctx->allocate_order[0], 2); in kunit_resource_test_proper_free_ordering()
339 KUNIT_EXPECT_EQ(test, ctx->allocate_order[1], 1); in kunit_resource_test_proper_free_ordering()
343 kunit_cleanup(&ctx->test); in kunit_resource_test_proper_free_ordering()
350 KUNIT_EXPECT_EQ(test, ctx->free_order[0], 1); in kunit_resource_test_proper_free_ordering()
351 KUNIT_EXPECT_EQ(test, ctx->free_order[1], 2); in kunit_resource_test_proper_free_ordering()
354 static void kunit_resource_test_static(struct kunit *test) in kunit_resource_test_static() argument
359 KUNIT_EXPECT_EQ(test, kunit_add_resource(test, NULL, NULL, &res, &ctx), in kunit_resource_test_static()
362 KUNIT_EXPECT_PTR_EQ(test, res.data, (void *)&ctx); in kunit_resource_test_static()
364 kunit_cleanup(test); in kunit_resource_test_static()
366 KUNIT_EXPECT_TRUE(test, list_empty(&test->resources)); in kunit_resource_test_static()
369 static void kunit_resource_test_named(struct kunit *test) in kunit_resource_test_named() argument
374 KUNIT_EXPECT_EQ(test, in kunit_resource_test_named()
375 kunit_add_named_resource(test, NULL, NULL, &res1, in kunit_resource_test_named()
378 KUNIT_EXPECT_PTR_EQ(test, res1.data, (void *)&ctx); in kunit_resource_test_named()
380 KUNIT_EXPECT_EQ(test, in kunit_resource_test_named()
381 kunit_add_named_resource(test, NULL, NULL, &res1, in kunit_resource_test_named()
385 KUNIT_EXPECT_EQ(test, in kunit_resource_test_named()
386 kunit_add_named_resource(test, NULL, NULL, &res2, in kunit_resource_test_named()
390 found = kunit_find_named_resource(test, "resource_1"); in kunit_resource_test_named()
392 KUNIT_EXPECT_PTR_EQ(test, found, &res1); in kunit_resource_test_named()
397 KUNIT_EXPECT_EQ(test, kunit_destroy_named_resource(test, "resource_2"), in kunit_resource_test_named()
400 kunit_cleanup(test); in kunit_resource_test_named()
402 KUNIT_EXPECT_TRUE(test, list_empty(&test->resources)); in kunit_resource_test_named()
405 static int kunit_resource_test_init(struct kunit *test) in kunit_resource_test_init() argument
410 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); in kunit_resource_test_init()
412 test->priv = ctx; in kunit_resource_test_init()
414 kunit_init_test(&ctx->test, "test_test_context", NULL); in kunit_resource_test_init()
419 static void kunit_resource_test_exit(struct kunit *test) in kunit_resource_test_exit() argument
421 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_exit()
423 kunit_cleanup(&ctx->test); in kunit_resource_test_exit()
440 .name = "kunit-resource-test",
446 static void kunit_log_test(struct kunit *test);
454 .name = "kunit-log-test",
458 static void kunit_log_test(struct kunit *test) in kunit_log_test() argument
462 suite.log = kunit_kzalloc(test, KUNIT_LOG_SIZE, GFP_KERNEL); in kunit_log_test()
463 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, suite.log); in kunit_log_test()
465 kunit_log(KERN_INFO, test, "put this in log."); in kunit_log_test()
466 kunit_log(KERN_INFO, test, "this too."); in kunit_log_test()
471 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, in kunit_log_test()
472 strstr(test->log, "put this in log.")); in kunit_log_test()
473 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, in kunit_log_test()
474 strstr(test->log, "this too.")); in kunit_log_test()
475 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, in kunit_log_test()
477 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, in kunit_log_test()
480 KUNIT_EXPECT_NULL(test, test->log); in kunit_log_test()
484 static void kunit_status_set_failure_test(struct kunit *test) in kunit_status_set_failure_test() argument
488 kunit_init_test(&fake, "fake test", NULL); in kunit_status_set_failure_test()
490 KUNIT_EXPECT_EQ(test, fake.status, (enum kunit_status)KUNIT_SUCCESS); in kunit_status_set_failure_test()
492 KUNIT_EXPECT_EQ(test, fake.status, (enum kunit_status)KUNIT_FAILURE); in kunit_status_set_failure_test()
495 static void kunit_status_mark_skipped_test(struct kunit *test) in kunit_status_mark_skipped_test() argument
499 kunit_init_test(&fake, "fake test", NULL); in kunit_status_mark_skipped_test()
502 KUNIT_EXPECT_EQ(test, fake.status, KUNIT_SUCCESS); in kunit_status_mark_skipped_test()
503 KUNIT_EXPECT_STREQ(test, fake.status_comment, ""); in kunit_status_mark_skipped_test()
505 /* Mark the test as skipped. */ in kunit_status_mark_skipped_test()
509 KUNIT_EXPECT_EQ(test, fake.status, (enum kunit_status)KUNIT_SKIPPED); in kunit_status_mark_skipped_test()
510 KUNIT_EXPECT_STREQ(test, fake.status_comment, "Accepts format string: YES"); in kunit_status_mark_skipped_test()