Lines Matching full:test
3 * Base unit test (KUnit) API.
37 /* Size of log associated with test. */
56 * enum kunit_status - Type of result for a test or test suite
57 * @KUNIT_SUCCESS: Denotes the test suite has not failed nor been skipped
58 * @KUNIT_FAILURE: Denotes the test has failed.
59 * @KUNIT_SKIPPED: Denotes the test has been skipped.
84 /* Holds attributes for each test case and suite */
90 * struct kunit_case - represents an individual test case.
92 * @run_case: the function representing the actual test case.
93 * @name: the name of the test case.
95 * @attr: the attributes associated with the test
97 * A test case is a function with the signature,
100 * KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated
104 * A test case should be static and should only be created with the
105 * KUNIT_CASE() macro; additionally, every array of test cases should be
106 * terminated with an empty test case.
112 * void add_test_basic(struct kunit *test)
114 * KUNIT_EXPECT_EQ(test, 1, add(1, 0));
115 * KUNIT_EXPECT_EQ(test, 2, add(1, 1));
116 * KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
117 * KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
118 * KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
128 void (*run_case)(struct kunit *test);
154 * @test_name: a reference to a test case function.
156 * Takes a symbol for a function representing a test case and creates a
168 * @test_name: a reference to a test case function.
170 * test attributes
180 * @test_name: a reference to a test case function.
190 * @test_name: a reference to a test case function.
212 * @test_name: a reference to a test case function.
215 * test attributes
225 * @name: the name of the test. Purely informational.
226 * @suite_init: called once per test suite before the test cases.
227 * @suite_exit: called once per test suite after all test cases.
228 * @init: called before every test case.
229 * @exit: called after every test case.
230 * @test_cases: a null terminated array of test cases.
231 * @attr: the attributes associated with the test suite
234 * @init is called before every test case and @exit is called after every
235 * test case, similar to the notion of a *test fixture* or a *test class*
248 int (*init)(struct kunit *test);
249 void (*exit)(struct kunit *test);
267 * struct kunit - represents a running instance of a test.
272 * Used to store information about the current context under which the test
275 * used by the test writer to store arbitrary data.
284 /* param_value is the current parameter value for a test case. */
290 * test case; thus, it is safe to update this across multiple
292 * be read after the test case finishes once all threads associated
293 * with the test case have terminated.
295 spinlock_t lock; /* Guards all mutable test state. */
299 * new resources) from any thread associated with a test case, we must
307 static inline void kunit_set_failure(struct kunit *test) in kunit_set_failure() argument
309 WRITE_ONCE(test->status, KUNIT_FAILURE); in kunit_set_failure()
318 void kunit_init_test(struct kunit *test, const char *name, char *log);
362 * Registers @suites with the test framework.
409 * kunit_kmalloc_array() - Like kmalloc_array() except the allocation is *test managed*.
410 * @test: The test context object.
415 * Just like `kmalloc_array(...)`, except the allocation is managed by the test case
416 * and is automatically cleaned up after the test case concludes. See kunit_add_action()
422 void *kunit_kmalloc_array(struct kunit *test, size_t n, size_t size, gfp_t gfp);
425 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
426 * @test: The test context object.
435 static inline void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp) in kunit_kmalloc() argument
437 return kunit_kmalloc_array(test, 1, size, gfp); in kunit_kmalloc()
442 * @test: The test case to which the resource belongs.
445 void kunit_kfree(struct kunit *test, const void *ptr);
449 * @test: The test context object.
455 static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp) in kunit_kzalloc() argument
457 return kunit_kmalloc(test, size, gfp | __GFP_ZERO); in kunit_kzalloc()
462 * @test: The test context object.
469 static inline void *kunit_kcalloc(struct kunit *test, size_t n, size_t size, gfp_t gfp) in kunit_kcalloc() argument
471 return kunit_kmalloc_array(test, n, size, gfp | __GFP_ZERO); in kunit_kcalloc()
474 void kunit_cleanup(struct kunit *test);
481 * @test_or_suite: The test context object.
484 * Marks the test as skipped. @fmt is given output as the test status
485 * comment, typically the reason the test was skipped.
487 * Test execution continues after kunit_mark_skipped() is called.
500 * @test_or_suite: The test context object.
503 * Skips the test. @fmt is given output as the test status
504 * comment, typically the reason the test was skipped.
506 * Test execution is halted after kunit_skip() is called.
515 * printk and log to per-test or per-suite log buffer. Logging only done
525 #define kunit_printk(lvl, test, fmt, ...) \ argument
526 kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \
527 (test)->name, ##__VA_ARGS__)
530 * kunit_info() - Prints an INFO level message associated with @test.
532 * @test: The test context object.
535 * Prints an info level message associated with the test suite being run.
538 #define kunit_info(test, fmt, ...) \ argument
539 kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
542 * kunit_warn() - Prints a WARN level message associated with @test.
544 * @test: The test context object.
549 #define kunit_warn(test, fmt, ...) \ argument
550 kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
553 * kunit_err() - Prints an ERROR level message associated with @test.
555 * @test: The test context object.
560 #define kunit_err(test, fmt, ...) \ argument
561 kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
565 * @test: The test context object.
571 #define KUNIT_SUCCEED(test) do {} while (0) argument
573 void __noreturn __kunit_abort(struct kunit *test);
575 void __kunit_do_failed_assertion(struct kunit *test,
582 #define _KUNIT_FAILED(test, assert_type, assert_class, assert_format, INITIALIZER, fmt, ...) do { \ argument
585 __kunit_do_failed_assertion(test, \
593 __kunit_abort(test); \
597 #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \ argument
598 _KUNIT_FAILED(test, \
607 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
608 * @test: The test context object.
614 * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
617 #define KUNIT_FAIL(test, fmt, ...) \ argument
618 KUNIT_FAIL_ASSERTION(test, \
626 #define KUNIT_UNARY_ASSERTION(test, \ argument
636 _KUNIT_FAILED(test, \
646 #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \ argument
647 KUNIT_UNARY_ASSERTION(test, \
654 #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \ argument
655 KUNIT_UNARY_ASSERTION(test, \
676 #define KUNIT_BASE_BINARY_ASSERTION(test, \ argument
697 _KUNIT_FAILED(test, \
708 #define KUNIT_BINARY_INT_ASSERTION(test, \ argument
715 KUNIT_BASE_BINARY_ASSERTION(test, \
723 #define KUNIT_BINARY_PTR_ASSERTION(test, \ argument
730 KUNIT_BASE_BINARY_ASSERTION(test, \
738 #define KUNIT_BINARY_STR_ASSERTION(test, \ argument
758 _KUNIT_FAILED(test, \
769 #define KUNIT_MEM_ASSERTION(test, \ argument
791 _KUNIT_FAILED(test, \
803 #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \ argument
814 _KUNIT_FAILED(test, \
824 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
825 * @test: The test context object.
826 * @condition: an arbitrary boolean expression. The test fails when this does
829 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
831 * the test case from continuing to run; this is otherwise known as an
834 #define KUNIT_EXPECT_TRUE(test, condition) \ argument
835 KUNIT_EXPECT_TRUE_MSG(test, condition, NULL)
837 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \ argument
838 KUNIT_TRUE_MSG_ASSERTION(test, \
845 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
846 * @test: The test context object.
847 * @condition: an arbitrary boolean expression. The test fails when this does
853 #define KUNIT_EXPECT_FALSE(test, condition) \ argument
854 KUNIT_EXPECT_FALSE_MSG(test, condition, NULL)
856 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \ argument
857 KUNIT_FALSE_MSG_ASSERTION(test, \
865 * @test: The test context object.
871 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
874 #define KUNIT_EXPECT_EQ(test, left, right) \ argument
875 KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
877 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \ argument
878 KUNIT_BINARY_INT_ASSERTION(test, \
886 * @test: The test context object.
892 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
895 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \ argument
896 KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
898 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \ argument
899 KUNIT_BINARY_PTR_ASSERTION(test, \
907 * @test: The test context object.
913 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
916 #define KUNIT_EXPECT_NE(test, left, right) \ argument
917 KUNIT_EXPECT_NE_MSG(test, left, right, NULL)
919 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \ argument
920 KUNIT_BINARY_INT_ASSERTION(test, \
928 * @test: The test context object.
934 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
937 #define KUNIT_EXPECT_PTR_NE(test, left, right) \ argument
938 KUNIT_EXPECT_PTR_NE_MSG(test, left, right, NULL)
940 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \ argument
941 KUNIT_BINARY_PTR_ASSERTION(test, \
949 * @test: The test context object.
955 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
958 #define KUNIT_EXPECT_LT(test, left, right) \ argument
959 KUNIT_EXPECT_LT_MSG(test, left, right, NULL)
961 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \ argument
962 KUNIT_BINARY_INT_ASSERTION(test, \
970 * @test: The test context object.
976 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
979 #define KUNIT_EXPECT_LE(test, left, right) \ argument
980 KUNIT_EXPECT_LE_MSG(test, left, right, NULL)
982 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \ argument
983 KUNIT_BINARY_INT_ASSERTION(test, \
991 * @test: The test context object.
997 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
1000 #define KUNIT_EXPECT_GT(test, left, right) \ argument
1001 KUNIT_EXPECT_GT_MSG(test, left, right, NULL)
1003 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \ argument
1004 KUNIT_BINARY_INT_ASSERTION(test, \
1012 * @test: The test context object.
1018 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
1021 #define KUNIT_EXPECT_GE(test, left, right) \ argument
1022 KUNIT_EXPECT_GE_MSG(test, left, right, NULL)
1024 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \ argument
1025 KUNIT_BINARY_INT_ASSERTION(test, \
1033 * @test: The test context object.
1039 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1042 #define KUNIT_EXPECT_STREQ(test, left, right) \ argument
1043 KUNIT_EXPECT_STREQ_MSG(test, left, right, NULL)
1045 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \ argument
1046 KUNIT_BINARY_STR_ASSERTION(test, \
1054 * @test: The test context object.
1060 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1063 #define KUNIT_EXPECT_STRNEQ(test, left, right) \ argument
1064 KUNIT_EXPECT_STRNEQ_MSG(test, left, right, NULL)
1066 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \ argument
1067 KUNIT_BINARY_STR_ASSERTION(test, \
1075 * @test: The test context object.
1082 * KUNIT_EXPECT_TRUE(@test, !memcmp((@left), (@right), (@size))). See
1089 #define KUNIT_EXPECT_MEMEQ(test, left, right, size) \ argument
1090 KUNIT_EXPECT_MEMEQ_MSG(test, left, right, size, NULL)
1092 #define KUNIT_EXPECT_MEMEQ_MSG(test, left, right, size, fmt, ...) \ argument
1093 KUNIT_MEM_ASSERTION(test, \
1102 * @test: The test context object.
1109 * KUNIT_EXPECT_TRUE(@test, memcmp((@left), (@right), (@size))). See
1116 #define KUNIT_EXPECT_MEMNEQ(test, left, right, size) \ argument
1117 KUNIT_EXPECT_MEMNEQ_MSG(test, left, right, size, NULL)
1119 #define KUNIT_EXPECT_MEMNEQ_MSG(test, left, right, size, fmt, ...) \ argument
1120 KUNIT_MEM_ASSERTION(test, \
1129 * @test: The test context object.
1133 * semantically equivalent to KUNIT_EXPECT_PTR_EQ(@test, ptr, NULL).
1136 #define KUNIT_EXPECT_NULL(test, ptr) \ argument
1137 KUNIT_EXPECT_NULL_MSG(test, \
1141 #define KUNIT_EXPECT_NULL_MSG(test, ptr, fmt, ...) \ argument
1142 KUNIT_BINARY_PTR_ASSERTION(test, \
1150 * @test: The test context object.
1154 * is semantically equivalent to KUNIT_EXPECT_PTR_NE(@test, ptr, NULL).
1157 #define KUNIT_EXPECT_NOT_NULL(test, ptr) \ argument
1158 KUNIT_EXPECT_NOT_NULL_MSG(test, \
1162 #define KUNIT_EXPECT_NOT_NULL_MSG(test, ptr, fmt, ...) \ argument
1163 KUNIT_BINARY_PTR_ASSERTION(test, \
1171 * @test: The test context object.
1176 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
1179 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \ argument
1180 KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
1182 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \ argument
1183 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1189 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \ argument
1190 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
1194 * @test: The test context object.
1195 * @condition: an arbitrary boolean expression. The test fails and aborts when
1198 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1200 * an expectation failure, it will prevent the test case from continuing to run;
1203 #define KUNIT_ASSERT_TRUE(test, condition) \ argument
1204 KUNIT_ASSERT_TRUE_MSG(test, condition, NULL)
1206 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \ argument
1207 KUNIT_TRUE_MSG_ASSERTION(test, \
1215 * @test: The test context object.
1222 #define KUNIT_ASSERT_FALSE(test, condition) \ argument
1223 KUNIT_ASSERT_FALSE_MSG(test, condition, NULL)
1225 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \ argument
1226 KUNIT_FALSE_MSG_ASSERTION(test, \
1234 * @test: The test context object.
1242 #define KUNIT_ASSERT_EQ(test, left, right) \ argument
1243 KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
1245 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \ argument
1246 KUNIT_BINARY_INT_ASSERTION(test, \
1254 * @test: The test context object.
1262 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \ argument
1263 KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, NULL)
1265 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \ argument
1266 KUNIT_BINARY_PTR_ASSERTION(test, \
1274 * @test: The test context object.
1282 #define KUNIT_ASSERT_NE(test, left, right) \ argument
1283 KUNIT_ASSERT_NE_MSG(test, left, right, NULL)
1285 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \ argument
1286 KUNIT_BINARY_INT_ASSERTION(test, \
1295 * @test: The test context object.
1303 #define KUNIT_ASSERT_PTR_NE(test, left, right) \ argument
1304 KUNIT_ASSERT_PTR_NE_MSG(test, left, right, NULL)
1306 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \ argument
1307 KUNIT_BINARY_PTR_ASSERTION(test, \
1314 * @test: The test context object.
1323 #define KUNIT_ASSERT_LT(test, left, right) \ argument
1324 KUNIT_ASSERT_LT_MSG(test, left, right, NULL)
1326 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \ argument
1327 KUNIT_BINARY_INT_ASSERTION(test, \
1334 * @test: The test context object.
1343 #define KUNIT_ASSERT_LE(test, left, right) \ argument
1344 KUNIT_ASSERT_LE_MSG(test, left, right, NULL)
1346 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \ argument
1347 KUNIT_BINARY_INT_ASSERTION(test, \
1355 * @test: The test context object.
1364 #define KUNIT_ASSERT_GT(test, left, right) \ argument
1365 KUNIT_ASSERT_GT_MSG(test, left, right, NULL)
1367 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \ argument
1368 KUNIT_BINARY_INT_ASSERTION(test, \
1376 * @test: The test context object.
1385 #define KUNIT_ASSERT_GE(test, left, right) \ argument
1386 KUNIT_ASSERT_GE_MSG(test, left, right, NULL)
1388 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \ argument
1389 KUNIT_BINARY_INT_ASSERTION(test, \
1397 * @test: The test context object.
1405 #define KUNIT_ASSERT_STREQ(test, left, right) \ argument
1406 KUNIT_ASSERT_STREQ_MSG(test, left, right, NULL)
1408 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \ argument
1409 KUNIT_BINARY_STR_ASSERTION(test, \
1417 * @test: The test context object.
1423 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1426 #define KUNIT_ASSERT_STRNEQ(test, left, right) \ argument
1427 KUNIT_ASSERT_STRNEQ_MSG(test, left, right, NULL)
1429 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \ argument
1430 KUNIT_BINARY_STR_ASSERTION(test, \
1438 * @test: The test context object.
1445 #define KUNIT_ASSERT_NULL(test, ptr) \ argument
1446 KUNIT_ASSERT_NULL_MSG(test, \
1450 #define KUNIT_ASSERT_NULL_MSG(test, ptr, fmt, ...) \ argument
1451 KUNIT_BINARY_PTR_ASSERTION(test, \
1459 * @test: The test context object.
1466 #define KUNIT_ASSERT_NOT_NULL(test, ptr) \ argument
1467 KUNIT_ASSERT_NOT_NULL_MSG(test, \
1471 #define KUNIT_ASSERT_NOT_NULL_MSG(test, ptr, fmt, ...) \ argument
1472 KUNIT_BINARY_PTR_ASSERTION(test, \
1480 * @test: The test context object.
1488 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \ argument
1489 KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
1491 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \ argument
1492 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1499 * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array.
1500 * @name: prefix for the test parameter generator function.
1501 * @array: array of test parameters.