Lines Matching refs:test

20 	struct kunit *test = data;  in kunit_test_successful_try()  local
21 struct kunit_try_catch_test_context *ctx = test->priv; in kunit_test_successful_try()
28 struct kunit *test = data; in kunit_test_no_catch() local
30 KUNIT_FAIL(test, "Catch should not be called\n"); in kunit_test_no_catch()
33 static void kunit_test_try_catch_successful_try_no_catch(struct kunit *test) in kunit_test_try_catch_successful_try_no_catch() argument
35 struct kunit_try_catch_test_context *ctx = test->priv; in kunit_test_try_catch_successful_try_no_catch()
39 test, in kunit_test_try_catch_successful_try_no_catch()
42 kunit_try_catch_run(try_catch, test); in kunit_test_try_catch_successful_try_no_catch()
44 KUNIT_EXPECT_TRUE(test, ctx->function_called); in kunit_test_try_catch_successful_try_no_catch()
49 struct kunit *test = data; in kunit_test_unsuccessful_try() local
50 struct kunit_try_catch_test_context *ctx = test->priv; in kunit_test_unsuccessful_try()
54 KUNIT_FAIL(test, "This line should never be reached\n"); in kunit_test_unsuccessful_try()
59 struct kunit *test = data; in kunit_test_catch() local
60 struct kunit_try_catch_test_context *ctx = test->priv; in kunit_test_catch()
65 static void kunit_test_try_catch_unsuccessful_try_does_catch(struct kunit *test) in kunit_test_try_catch_unsuccessful_try_does_catch() argument
67 struct kunit_try_catch_test_context *ctx = test->priv; in kunit_test_try_catch_unsuccessful_try_does_catch()
71 test, in kunit_test_try_catch_unsuccessful_try_does_catch()
74 kunit_try_catch_run(try_catch, test); in kunit_test_try_catch_unsuccessful_try_does_catch()
76 KUNIT_EXPECT_TRUE(test, ctx->function_called); in kunit_test_try_catch_unsuccessful_try_does_catch()
79 static int kunit_try_catch_test_init(struct kunit *test) in kunit_try_catch_test_init() argument
83 ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); in kunit_try_catch_test_init()
84 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); in kunit_try_catch_test_init()
85 test->priv = ctx; in kunit_try_catch_test_init()
87 ctx->try_catch = kunit_kmalloc(test, in kunit_try_catch_test_init()
90 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->try_catch); in kunit_try_catch_test_init()
112 struct kunit test; member
134 static void kunit_resource_test_init_resources(struct kunit *test) in kunit_resource_test_init_resources() argument
136 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_init_resources()
138 kunit_init_test(&ctx->test, "testing_test_init_test", NULL); in kunit_resource_test_init_resources()
140 KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_init_resources()
143 static void kunit_resource_test_alloc_resource(struct kunit *test) in kunit_resource_test_alloc_resource() argument
145 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_alloc_resource()
149 res = kunit_alloc_and_get_resource(&ctx->test, in kunit_resource_test_alloc_resource()
155 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, res); in kunit_resource_test_alloc_resource()
156 KUNIT_EXPECT_PTR_EQ(test, in kunit_resource_test_alloc_resource()
159 KUNIT_EXPECT_TRUE(test, list_is_last(&res->node, &ctx->test.resources)); in kunit_resource_test_alloc_resource()
160 KUNIT_EXPECT_PTR_EQ(test, free, res->free); in kunit_resource_test_alloc_resource()
165 static inline bool kunit_resource_instance_match(struct kunit *test, in kunit_resource_instance_match() argument
180 static void kunit_resource_test_destroy_resource(struct kunit *test) in kunit_resource_test_destroy_resource() argument
182 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_destroy_resource()
184 &ctx->test, in kunit_resource_test_destroy_resource()
192 KUNIT_ASSERT_FALSE(test, in kunit_resource_test_destroy_resource()
193 kunit_destroy_resource(&ctx->test, in kunit_resource_test_destroy_resource()
197 KUNIT_EXPECT_FALSE(test, ctx->is_resource_initialized); in kunit_resource_test_destroy_resource()
198 KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_destroy_resource()
201 static void kunit_resource_test_remove_resource(struct kunit *test) in kunit_resource_test_remove_resource() argument
203 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_remove_resource()
205 &ctx->test, in kunit_resource_test_remove_resource()
212 KUNIT_EXPECT_FALSE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_remove_resource()
217 kunit_remove_resource(test, res); in kunit_resource_test_remove_resource()
218 KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_remove_resource()
220 KUNIT_EXPECT_TRUE(test, ctx->is_resource_initialized); in kunit_resource_test_remove_resource()
223 kunit_remove_resource(test, res); in kunit_resource_test_remove_resource()
224 KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_remove_resource()
228 KUNIT_EXPECT_TRUE(test, ctx->is_resource_initialized); in kunit_resource_test_remove_resource()
232 KUNIT_EXPECT_FALSE(test, ctx->is_resource_initialized); in kunit_resource_test_remove_resource()
235 static void kunit_resource_test_cleanup_resources(struct kunit *test) in kunit_resource_test_cleanup_resources() argument
238 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_cleanup_resources()
242 resources[i] = kunit_alloc_and_get_resource(&ctx->test, in kunit_resource_test_cleanup_resources()
250 kunit_cleanup(&ctx->test); in kunit_resource_test_cleanup_resources()
252 KUNIT_EXPECT_TRUE(test, list_empty(&ctx->test.resources)); in kunit_resource_test_cleanup_resources()
295 res2 = kunit_alloc_and_get_resource(&ctx->test, in fake_resource_1_init()
322 static void kunit_resource_test_proper_free_ordering(struct kunit *test) in kunit_resource_test_proper_free_ordering() argument
324 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_proper_free_ordering()
328 res = kunit_alloc_and_get_resource(&ctx->test, in kunit_resource_test_proper_free_ordering()
339 KUNIT_EXPECT_EQ(test, ctx->allocate_order[0], 2); in kunit_resource_test_proper_free_ordering()
340 KUNIT_EXPECT_EQ(test, ctx->allocate_order[1], 1); in kunit_resource_test_proper_free_ordering()
344 kunit_cleanup(&ctx->test); in kunit_resource_test_proper_free_ordering()
351 KUNIT_EXPECT_EQ(test, ctx->free_order[0], 1); in kunit_resource_test_proper_free_ordering()
352 KUNIT_EXPECT_EQ(test, ctx->free_order[1], 2); in kunit_resource_test_proper_free_ordering()
355 static void kunit_resource_test_static(struct kunit *test) in kunit_resource_test_static() argument
360 KUNIT_EXPECT_EQ(test, kunit_add_resource(test, NULL, NULL, &res, &ctx), in kunit_resource_test_static()
363 KUNIT_EXPECT_PTR_EQ(test, res.data, (void *)&ctx); in kunit_resource_test_static()
365 kunit_cleanup(test); in kunit_resource_test_static()
367 KUNIT_EXPECT_TRUE(test, list_empty(&test->resources)); in kunit_resource_test_static()
370 static void kunit_resource_test_named(struct kunit *test) in kunit_resource_test_named() argument
375 KUNIT_EXPECT_EQ(test, in kunit_resource_test_named()
376 kunit_add_named_resource(test, NULL, NULL, &res1, in kunit_resource_test_named()
379 KUNIT_EXPECT_PTR_EQ(test, res1.data, (void *)&ctx); in kunit_resource_test_named()
381 KUNIT_EXPECT_EQ(test, in kunit_resource_test_named()
382 kunit_add_named_resource(test, NULL, NULL, &res1, in kunit_resource_test_named()
386 KUNIT_EXPECT_EQ(test, in kunit_resource_test_named()
387 kunit_add_named_resource(test, NULL, NULL, &res2, in kunit_resource_test_named()
391 found = kunit_find_named_resource(test, "resource_1"); in kunit_resource_test_named()
393 KUNIT_EXPECT_PTR_EQ(test, found, &res1); in kunit_resource_test_named()
398 KUNIT_EXPECT_EQ(test, kunit_destroy_named_resource(test, "resource_2"), in kunit_resource_test_named()
401 kunit_cleanup(test); in kunit_resource_test_named()
403 KUNIT_EXPECT_TRUE(test, list_empty(&test->resources)); in kunit_resource_test_named()
412 static void kunit_resource_test_action(struct kunit *test) in kunit_resource_test_action() argument
416 kunit_add_action(test, increment_int, &num_actions); in kunit_resource_test_action()
417 KUNIT_EXPECT_EQ(test, num_actions, 0); in kunit_resource_test_action()
418 kunit_cleanup(test); in kunit_resource_test_action()
419 KUNIT_EXPECT_EQ(test, num_actions, 1); in kunit_resource_test_action()
422 kunit_cleanup(test); in kunit_resource_test_action()
423 KUNIT_EXPECT_EQ(test, num_actions, 1); in kunit_resource_test_action()
426 kunit_add_action(test, increment_int, &num_actions); in kunit_resource_test_action()
427 kunit_add_action(test, increment_int, &num_actions); in kunit_resource_test_action()
428 kunit_cleanup(test); in kunit_resource_test_action()
429 KUNIT_EXPECT_EQ(test, num_actions, 3); in kunit_resource_test_action()
431 static void kunit_resource_test_remove_action(struct kunit *test) in kunit_resource_test_remove_action() argument
435 kunit_add_action(test, increment_int, &num_actions); in kunit_resource_test_remove_action()
436 KUNIT_EXPECT_EQ(test, num_actions, 0); in kunit_resource_test_remove_action()
438 kunit_remove_action(test, increment_int, &num_actions); in kunit_resource_test_remove_action()
439 kunit_cleanup(test); in kunit_resource_test_remove_action()
440 KUNIT_EXPECT_EQ(test, num_actions, 0); in kunit_resource_test_remove_action()
442 static void kunit_resource_test_release_action(struct kunit *test) in kunit_resource_test_release_action() argument
446 kunit_add_action(test, increment_int, &num_actions); in kunit_resource_test_release_action()
447 KUNIT_EXPECT_EQ(test, num_actions, 0); in kunit_resource_test_release_action()
449 kunit_release_action(test, increment_int, &num_actions); in kunit_resource_test_release_action()
450 KUNIT_EXPECT_EQ(test, num_actions, 1); in kunit_resource_test_release_action()
453 kunit_cleanup(test); in kunit_resource_test_release_action()
454 KUNIT_EXPECT_EQ(test, num_actions, 1); in kunit_resource_test_release_action()
470 static void kunit_resource_test_action_ordering(struct kunit *test) in kunit_resource_test_action_ordering() argument
472 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_action_ordering()
474 kunit_add_action(test, action_order_1, ctx); in kunit_resource_test_action_ordering()
475 kunit_add_action(test, action_order_2, ctx); in kunit_resource_test_action_ordering()
476 kunit_add_action(test, action_order_1, ctx); in kunit_resource_test_action_ordering()
477 kunit_add_action(test, action_order_2, ctx); in kunit_resource_test_action_ordering()
478 kunit_remove_action(test, action_order_1, ctx); in kunit_resource_test_action_ordering()
479 kunit_release_action(test, action_order_2, ctx); in kunit_resource_test_action_ordering()
480 kunit_cleanup(test); in kunit_resource_test_action_ordering()
483 KUNIT_EXPECT_EQ(test, ctx->free_order[0], 2); in kunit_resource_test_action_ordering()
484 KUNIT_EXPECT_EQ(test, ctx->free_order[1], 2); in kunit_resource_test_action_ordering()
485 KUNIT_EXPECT_EQ(test, ctx->free_order[2], 1); in kunit_resource_test_action_ordering()
488 static int kunit_resource_test_init(struct kunit *test) in kunit_resource_test_init() argument
493 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); in kunit_resource_test_init()
495 test->priv = ctx; in kunit_resource_test_init()
497 kunit_init_test(&ctx->test, "test_test_context", NULL); in kunit_resource_test_init()
502 static void kunit_resource_test_exit(struct kunit *test) in kunit_resource_test_exit() argument
504 struct kunit_test_resource_context *ctx = test->priv; in kunit_resource_test_exit()
506 kunit_cleanup(&ctx->test); in kunit_resource_test_exit()
533 static void kunit_log_test(struct kunit *test) in kunit_log_test() argument
537 suite.log = kunit_kzalloc(test, KUNIT_LOG_SIZE, GFP_KERNEL); in kunit_log_test()
538 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, suite.log); in kunit_log_test()
540 kunit_log(KERN_INFO, test, "put this in log."); in kunit_log_test()
541 kunit_log(KERN_INFO, test, "this too."); in kunit_log_test()
546 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, in kunit_log_test()
547 strstr(test->log, "put this in log.")); in kunit_log_test()
548 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, in kunit_log_test()
549 strstr(test->log, "this too.")); in kunit_log_test()
550 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, in kunit_log_test()
552 KUNIT_EXPECT_NOT_ERR_OR_NULL(test, in kunit_log_test()
555 KUNIT_EXPECT_NULL(test, test->log); in kunit_log_test()
559 static void kunit_log_newline_test(struct kunit *test) in kunit_log_newline_test() argument
561 kunit_info(test, "Add newline\n"); in kunit_log_newline_test()
562 if (test->log) { in kunit_log_newline_test()
563 KUNIT_ASSERT_NOT_NULL_MSG(test, strstr(test->log, "Add newline\n"), in kunit_log_newline_test()
564 "Missing log line, full log:\n%s", test->log); in kunit_log_newline_test()
565 KUNIT_EXPECT_NULL(test, strstr(test->log, "Add newline\n\n")); in kunit_log_newline_test()
567 kunit_skip(test, "only useful when debugfs is enabled"); in kunit_log_newline_test()
582 static void kunit_status_set_failure_test(struct kunit *test) in kunit_status_set_failure_test() argument
588 KUNIT_EXPECT_EQ(test, fake.status, (enum kunit_status)KUNIT_SUCCESS); in kunit_status_set_failure_test()
590 KUNIT_EXPECT_EQ(test, fake.status, (enum kunit_status)KUNIT_FAILURE); in kunit_status_set_failure_test()
593 static void kunit_status_mark_skipped_test(struct kunit *test) in kunit_status_mark_skipped_test() argument
600 KUNIT_EXPECT_EQ(test, fake.status, KUNIT_SUCCESS); in kunit_status_mark_skipped_test()
601 KUNIT_EXPECT_STREQ(test, fake.status_comment, ""); in kunit_status_mark_skipped_test()
607 KUNIT_EXPECT_EQ(test, fake.status, (enum kunit_status)KUNIT_SKIPPED); in kunit_status_mark_skipped_test()
608 KUNIT_EXPECT_STREQ(test, fake.status_comment, "Accepts format string: YES"); in kunit_status_mark_skipped_test()
622 static void kunit_current_test(struct kunit *test) in kunit_current_test() argument
627 KUNIT_EXPECT_PTR_EQ(test, test, current->kunit_test); in kunit_current_test()
628 KUNIT_EXPECT_PTR_EQ(test, test, kunit_get_current_test()); in kunit_current_test()
631 static void kunit_current_fail_test(struct kunit *test) in kunit_current_fail_test() argument
636 KUNIT_EXPECT_EQ(test, fake.status, KUNIT_SUCCESS); in kunit_current_fail_test()
642 KUNIT_EXPECT_EQ(test, fake.status, (enum kunit_status)KUNIT_FAILURE); in kunit_current_fail_test()
646 current->kunit_test = test; in kunit_current_fail_test()