Lines Matching full:test
3 * Base unit test (KUnit) API.
32 /* Size of log associated with test. */
50 * enum kunit_status - Type of result for a test or test suite
51 * @KUNIT_SUCCESS: Denotes the test suite has not failed nor been skipped
52 * @KUNIT_FAILURE: Denotes the test has failed.
53 * @KUNIT_SKIPPED: Denotes the test has been skipped.
62 * struct kunit_case - represents an individual test case.
64 * @run_case: the function representing the actual test case.
65 * @name: the name of the test case.
68 * A test case is a function with the signature,
71 * KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated
75 * A test case should be static and should only be created with the
76 * KUNIT_CASE() macro; additionally, every array of test cases should be
77 * terminated with an empty test case.
83 * void add_test_basic(struct kunit *test)
85 * KUNIT_EXPECT_EQ(test, 1, add(1, 0));
86 * KUNIT_EXPECT_EQ(test, 2, add(1, 1));
87 * KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
88 * KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
89 * KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
99 void (*run_case)(struct kunit *test);
123 * @test_name: a reference to a test case function.
125 * Takes a symbol for a function representing a test case and creates a
134 * @test_name: a reference to a test case function.
155 * @name: the name of the test. Purely informational.
156 * @suite_init: called once per test suite before the test cases.
157 * @suite_exit: called once per test suite after all test cases.
158 * @init: called before every test case.
159 * @exit: called after every test case.
160 * @test_cases: a null terminated array of test cases.
163 * @init is called before every test case and @exit is called after every
164 * test case, similar to the notion of a *test fixture* or a *test class*
174 int (*init)(struct kunit *test);
175 void (*exit)(struct kunit *test);
186 * struct kunit - represents a running instance of a test.
191 * Used to store information about the current context under which the test
194 * used by the test writer to store arbitrary data.
203 /* param_value is the current parameter value for a test case. */
209 * test case; thus, it is safe to update this across multiple
211 * be read after the test case finishes once all threads associated
212 * with the test case have terminated.
214 spinlock_t lock; /* Guards all mutable test state. */
218 * new resources) from any thread associated with a test case, we must
226 static inline void kunit_set_failure(struct kunit *test) in kunit_set_failure() argument
228 WRITE_ONCE(test->status, KUNIT_FAILURE); in kunit_set_failure()
233 void kunit_init_test(struct kunit *test, const char *name, char *log);
266 * Registers @suites with the test framework.
314 * kunit_kmalloc_array() - Like kmalloc_array() except the allocation is *test managed*.
315 * @test: The test context object.
320 * Just like `kmalloc_array(...)`, except the allocation is managed by the test case
321 * and is automatically cleaned up after the test case concludes. See &struct
324 void *kunit_kmalloc_array(struct kunit *test, size_t n, size_t size, gfp_t gfp);
327 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
328 * @test: The test context object.
334 static inline void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp) in kunit_kmalloc() argument
336 return kunit_kmalloc_array(test, 1, size, gfp); in kunit_kmalloc()
341 * @test: The test case to which the resource belongs.
344 void kunit_kfree(struct kunit *test, const void *ptr);
348 * @test: The test context object.
354 static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp) in kunit_kzalloc() argument
356 return kunit_kmalloc(test, size, gfp | __GFP_ZERO); in kunit_kzalloc()
361 * @test: The test context object.
368 static inline void *kunit_kcalloc(struct kunit *test, size_t n, size_t size, gfp_t gfp) in kunit_kcalloc() argument
370 return kunit_kmalloc_array(test, n, size, gfp | __GFP_ZERO); in kunit_kcalloc()
373 void kunit_cleanup(struct kunit *test);
380 * @test_or_suite: The test context object.
383 * Marks the test as skipped. @fmt is given output as the test status
384 * comment, typically the reason the test was skipped.
386 * Test execution continues after kunit_mark_skipped() is called.
399 * @test_or_suite: The test context object.
402 * Skips the test. @fmt is given output as the test status
403 * comment, typically the reason the test was skipped.
405 * Test execution is halted after kunit_skip() is called.
414 * printk and log to per-test or per-suite log buffer. Logging only done
424 #define kunit_printk(lvl, test, fmt, ...) \ argument
425 kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \
426 (test)->name, ##__VA_ARGS__)
429 * kunit_info() - Prints an INFO level message associated with @test.
431 * @test: The test context object.
434 * Prints an info level message associated with the test suite being run.
437 #define kunit_info(test, fmt, ...) \ argument
438 kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
441 * kunit_warn() - Prints a WARN level message associated with @test.
443 * @test: The test context object.
448 #define kunit_warn(test, fmt, ...) \ argument
449 kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
452 * kunit_err() - Prints an ERROR level message associated with @test.
454 * @test: The test context object.
459 #define kunit_err(test, fmt, ...) \ argument
460 kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
464 * @test: The test context object.
470 #define KUNIT_SUCCEED(test) do {} while (0) argument
472 void kunit_do_failed_assertion(struct kunit *test,
479 #define _KUNIT_FAILED(test, assert_type, assert_class, assert_format, INITIALIZER, fmt, ...) do { \ argument
482 kunit_do_failed_assertion(test, \
492 #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \ argument
493 _KUNIT_FAILED(test, \
502 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
503 * @test: The test context object.
509 * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
512 #define KUNIT_FAIL(test, fmt, ...) \ argument
513 KUNIT_FAIL_ASSERTION(test, \
518 #define KUNIT_UNARY_ASSERTION(test, \ argument
528 _KUNIT_FAILED(test, \
538 #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \ argument
539 KUNIT_UNARY_ASSERTION(test, \
546 #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \ argument
547 KUNIT_UNARY_ASSERTION(test, \
568 #define KUNIT_BASE_BINARY_ASSERTION(test, \ argument
589 _KUNIT_FAILED(test, \
600 #define KUNIT_BINARY_INT_ASSERTION(test, \ argument
607 KUNIT_BASE_BINARY_ASSERTION(test, \
615 #define KUNIT_BINARY_PTR_ASSERTION(test, \ argument
622 KUNIT_BASE_BINARY_ASSERTION(test, \
630 #define KUNIT_BINARY_STR_ASSERTION(test, \ argument
650 _KUNIT_FAILED(test, \
661 #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \ argument
672 _KUNIT_FAILED(test, \
682 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
683 * @test: The test context object.
684 * @condition: an arbitrary boolean expression. The test fails when this does
687 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
689 * the test case from continuing to run; this is otherwise known as an
692 #define KUNIT_EXPECT_TRUE(test, condition) \ argument
693 KUNIT_EXPECT_TRUE_MSG(test, condition, NULL)
695 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \ argument
696 KUNIT_TRUE_MSG_ASSERTION(test, \
703 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
704 * @test: The test context object.
705 * @condition: an arbitrary boolean expression. The test fails when this does
711 #define KUNIT_EXPECT_FALSE(test, condition) \ argument
712 KUNIT_EXPECT_FALSE_MSG(test, condition, NULL)
714 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \ argument
715 KUNIT_FALSE_MSG_ASSERTION(test, \
723 * @test: The test context object.
729 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
732 #define KUNIT_EXPECT_EQ(test, left, right) \ argument
733 KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
735 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \ argument
736 KUNIT_BINARY_INT_ASSERTION(test, \
744 * @test: The test context object.
750 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
753 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \ argument
754 KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
756 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \ argument
757 KUNIT_BINARY_PTR_ASSERTION(test, \
765 * @test: The test context object.
771 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
774 #define KUNIT_EXPECT_NE(test, left, right) \ argument
775 KUNIT_EXPECT_NE_MSG(test, left, right, NULL)
777 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \ argument
778 KUNIT_BINARY_INT_ASSERTION(test, \
786 * @test: The test context object.
792 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
795 #define KUNIT_EXPECT_PTR_NE(test, left, right) \ argument
796 KUNIT_EXPECT_PTR_NE_MSG(test, left, right, NULL)
798 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \ argument
799 KUNIT_BINARY_PTR_ASSERTION(test, \
807 * @test: The test context object.
813 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
816 #define KUNIT_EXPECT_LT(test, left, right) \ argument
817 KUNIT_EXPECT_LT_MSG(test, left, right, NULL)
819 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \ argument
820 KUNIT_BINARY_INT_ASSERTION(test, \
828 * @test: The test context object.
834 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
837 #define KUNIT_EXPECT_LE(test, left, right) \ argument
838 KUNIT_EXPECT_LE_MSG(test, left, right, NULL)
840 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \ argument
841 KUNIT_BINARY_INT_ASSERTION(test, \
849 * @test: The test context object.
855 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
858 #define KUNIT_EXPECT_GT(test, left, right) \ argument
859 KUNIT_EXPECT_GT_MSG(test, left, right, NULL)
861 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \ argument
862 KUNIT_BINARY_INT_ASSERTION(test, \
870 * @test: The test context object.
876 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
879 #define KUNIT_EXPECT_GE(test, left, right) \ argument
880 KUNIT_EXPECT_GE_MSG(test, left, right, NULL)
882 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \ argument
883 KUNIT_BINARY_INT_ASSERTION(test, \
891 * @test: The test context object.
897 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
900 #define KUNIT_EXPECT_STREQ(test, left, right) \ argument
901 KUNIT_EXPECT_STREQ_MSG(test, left, right, NULL)
903 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \ argument
904 KUNIT_BINARY_STR_ASSERTION(test, \
912 * @test: The test context object.
918 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
921 #define KUNIT_EXPECT_STRNEQ(test, left, right) \ argument
922 KUNIT_EXPECT_STRNEQ_MSG(test, left, right, NULL)
924 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \ argument
925 KUNIT_BINARY_STR_ASSERTION(test, \
933 * @test: The test context object.
937 * semantically equivalent to KUNIT_EXPECT_PTR_EQ(@test, ptr, NULL).
940 #define KUNIT_EXPECT_NULL(test, ptr) \ argument
941 KUNIT_EXPECT_NULL_MSG(test, \
945 #define KUNIT_EXPECT_NULL_MSG(test, ptr, fmt, ...) \ argument
946 KUNIT_BINARY_PTR_ASSERTION(test, \
954 * @test: The test context object.
958 * is semantically equivalent to KUNIT_EXPECT_PTR_NE(@test, ptr, NULL).
961 #define KUNIT_EXPECT_NOT_NULL(test, ptr) \ argument
962 KUNIT_EXPECT_NOT_NULL_MSG(test, \
966 #define KUNIT_EXPECT_NOT_NULL_MSG(test, ptr, fmt, ...) \ argument
967 KUNIT_BINARY_PTR_ASSERTION(test, \
975 * @test: The test context object.
980 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
983 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \ argument
984 KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
986 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \ argument
987 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
993 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \ argument
994 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
998 * @test: The test context object.
999 * @condition: an arbitrary boolean expression. The test fails and aborts when
1002 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1004 * an expectation failure, it will prevent the test case from continuing to run;
1007 #define KUNIT_ASSERT_TRUE(test, condition) \ argument
1008 KUNIT_ASSERT_TRUE_MSG(test, condition, NULL)
1010 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \ argument
1011 KUNIT_TRUE_MSG_ASSERTION(test, \
1019 * @test: The test context object.
1026 #define KUNIT_ASSERT_FALSE(test, condition) \ argument
1027 KUNIT_ASSERT_FALSE_MSG(test, condition, NULL)
1029 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \ argument
1030 KUNIT_FALSE_MSG_ASSERTION(test, \
1038 * @test: The test context object.
1046 #define KUNIT_ASSERT_EQ(test, left, right) \ argument
1047 KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
1049 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \ argument
1050 KUNIT_BINARY_INT_ASSERTION(test, \
1058 * @test: The test context object.
1066 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \ argument
1067 KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, NULL)
1069 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \ argument
1070 KUNIT_BINARY_PTR_ASSERTION(test, \
1078 * @test: The test context object.
1086 #define KUNIT_ASSERT_NE(test, left, right) \ argument
1087 KUNIT_ASSERT_NE_MSG(test, left, right, NULL)
1089 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \ argument
1090 KUNIT_BINARY_INT_ASSERTION(test, \
1099 * @test: The test context object.
1107 #define KUNIT_ASSERT_PTR_NE(test, left, right) \ argument
1108 KUNIT_ASSERT_PTR_NE_MSG(test, left, right, NULL)
1110 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \ argument
1111 KUNIT_BINARY_PTR_ASSERTION(test, \
1118 * @test: The test context object.
1127 #define KUNIT_ASSERT_LT(test, left, right) \ argument
1128 KUNIT_ASSERT_LT_MSG(test, left, right, NULL)
1130 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \ argument
1131 KUNIT_BINARY_INT_ASSERTION(test, \
1138 * @test: The test context object.
1147 #define KUNIT_ASSERT_LE(test, left, right) \ argument
1148 KUNIT_ASSERT_LE_MSG(test, left, right, NULL)
1150 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \ argument
1151 KUNIT_BINARY_INT_ASSERTION(test, \
1159 * @test: The test context object.
1168 #define KUNIT_ASSERT_GT(test, left, right) \ argument
1169 KUNIT_ASSERT_GT_MSG(test, left, right, NULL)
1171 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \ argument
1172 KUNIT_BINARY_INT_ASSERTION(test, \
1180 * @test: The test context object.
1189 #define KUNIT_ASSERT_GE(test, left, right) \ argument
1190 KUNIT_ASSERT_GE_MSG(test, left, right, NULL)
1192 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \ argument
1193 KUNIT_BINARY_INT_ASSERTION(test, \
1201 * @test: The test context object.
1209 #define KUNIT_ASSERT_STREQ(test, left, right) \ argument
1210 KUNIT_ASSERT_STREQ_MSG(test, left, right, NULL)
1212 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \ argument
1213 KUNIT_BINARY_STR_ASSERTION(test, \
1221 * @test: The test context object.
1227 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1230 #define KUNIT_ASSERT_STRNEQ(test, left, right) \ argument
1231 KUNIT_ASSERT_STRNEQ_MSG(test, left, right, NULL)
1233 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \ argument
1234 KUNIT_BINARY_STR_ASSERTION(test, \
1242 * @test: The test context object.
1249 #define KUNIT_ASSERT_NULL(test, ptr) \ argument
1250 KUNIT_ASSERT_NULL_MSG(test, \
1254 #define KUNIT_ASSERT_NULL_MSG(test, ptr, fmt, ...) \ argument
1255 KUNIT_BINARY_PTR_ASSERTION(test, \
1263 * @test: The test context object.
1270 #define KUNIT_ASSERT_NOT_NULL(test, ptr) \ argument
1271 KUNIT_ASSERT_NOT_NULL_MSG(test, \
1275 #define KUNIT_ASSERT_NOT_NULL_MSG(test, ptr, fmt, ...) \ argument
1276 KUNIT_BINARY_PTR_ASSERTION(test, \
1284 * @test: The test context object.
1292 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \ argument
1293 KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
1295 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \ argument
1296 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1303 * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array.
1304 * @name: prefix for the test parameter generator function.
1305 * @array: array of test parameters.