Lines Matching refs:test

3  * Base unit test (KUnit) API.
54 * enum kunit_status - Type of result for a test or test suite
55 * @KUNIT_SUCCESS: Denotes the test suite has not failed nor been skipped
56 * @KUNIT_FAILURE: Denotes the test has failed.
57 * @KUNIT_SKIPPED: Denotes the test has been skipped.
82 /* Holds attributes for each test case and suite */
88 * struct kunit_case - represents an individual test case.
90 * @run_case: the function representing the actual test case.
91 * @name: the name of the test case.
93 * @attr: the attributes associated with the test
95 * A test case is a function with the signature,
98 * KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated
102 * A test case should be static and should only be created with the
103 * KUNIT_CASE() macro; additionally, every array of test cases should be
104 * terminated with an empty test case.
110 * void add_test_basic(struct kunit *test)
112 * KUNIT_EXPECT_EQ(test, 1, add(1, 0));
113 * KUNIT_EXPECT_EQ(test, 2, add(1, 1));
114 * KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
115 * KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
116 * KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
126 void (*run_case)(struct kunit *test);
152 * @test_name: a reference to a test case function.
154 * Takes a symbol for a function representing a test case and creates a
166 * @test_name: a reference to a test case function.
168 * test attributes
178 * @test_name: a reference to a test case function.
188 * @test_name: a reference to a test case function.
210 * @test_name: a reference to a test case function.
213 * test attributes
223 * @name: the name of the test. Purely informational.
224 * @suite_init: called once per test suite before the test cases.
225 * @suite_exit: called once per test suite after all test cases.
226 * @init: called before every test case.
227 * @exit: called after every test case.
228 * @test_cases: a null terminated array of test cases.
229 * @attr: the attributes associated with the test suite
232 * @init is called before every test case and @exit is called after every
233 * test case, similar to the notion of a *test fixture* or a *test class*
246 int (*init)(struct kunit *test);
247 void (*exit)(struct kunit *test);
266 * struct kunit - represents a running instance of a test.
271 * Used to store information about the current context under which the test
274 * used by the test writer to store arbitrary data.
283 /* param_value is the current parameter value for a test case. */
289 * test case; thus, it is safe to update this across multiple
291 * be read after the test case finishes once all threads associated
292 * with the test case have terminated.
294 spinlock_t lock; /* Guards all mutable test state. */
298 * new resources) from any thread associated with a test case, we must
304 /* Saves the last seen test. Useful to help with faults. */
308 static inline void kunit_set_failure(struct kunit *test)
310 WRITE_ONCE(test->status, KUNIT_FAILURE);
319 void kunit_init_test(struct kunit *test, const char *name, struct string_stream *log);
366 * Registers @suites with the test framework.
402 * Also, do not mark the suite or test case structs with __initdata because
418 * kunit_kmalloc_array() - Like kmalloc_array() except the allocation is *test managed*.
419 * @test: The test context object.
424 * Just like `kmalloc_array(...)`, except the allocation is managed by the test case
425 * and is automatically cleaned up after the test case concludes. See kunit_add_action()
431 void *kunit_kmalloc_array(struct kunit *test, size_t n, size_t size, gfp_t gfp);
434 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
435 * @test: The test context object.
444 static inline void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp)
446 return kunit_kmalloc_array(test, 1, size, gfp);
451 * @test: The test case to which the resource belongs.
454 void kunit_kfree(struct kunit *test, const void *ptr);
458 * @test: The test context object.
464 static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp)
466 return kunit_kmalloc(test, size, gfp | __GFP_ZERO);
471 * @test: The test context object.
478 static inline void *kunit_kcalloc(struct kunit *test, size_t n, size_t size, gfp_t gfp)
480 return kunit_kmalloc_array(test, n, size, gfp | __GFP_ZERO);
483 void kunit_cleanup(struct kunit *test);
490 * @test_or_suite: The test context object.
493 * Marks the test as skipped. @fmt is given output as the test status
494 * comment, typically the reason the test was skipped.
509 * @test_or_suite: The test context object.
512 * Skips the test. @fmt is given output as the test status
513 * comment, typically the reason the test was skipped.
524 * printk and log to per-test or per-suite log buffer. Logging only done
534 #define kunit_printk(lvl, test, fmt, ...) \
535 kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \
536 (test)->name, ##__VA_ARGS__)
539 * kunit_info() - Prints an INFO level message associated with @test.
541 * @test: The test context object.
544 * Prints an info level message associated with the test suite being run.
547 #define kunit_info(test, fmt, ...) \
548 kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
551 * kunit_warn() - Prints a WARN level message associated with @test.
553 * @test: The test context object.
558 #define kunit_warn(test, fmt, ...) \
559 kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
562 * kunit_err() - Prints an ERROR level message associated with @test.
564 * @test: The test context object.
569 #define kunit_err(test, fmt, ...) \
570 kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
576 #define _KUNIT_SAVE_LOC(test) do { \
577 WRITE_ONCE(test->last_seen.file, __FILE__); \
578 WRITE_ONCE(test->last_seen.line, __LINE__); \
583 * @test: The test context object.
589 #define KUNIT_SUCCEED(test) _KUNIT_SAVE_LOC(test)
591 void __noreturn __kunit_abort(struct kunit *test);
593 void __printf(6, 7) __kunit_do_failed_assertion(struct kunit *test,
600 #define _KUNIT_FAILED(test, assert_type, assert_class, assert_format, INITIALIZER, fmt, ...) do { \
603 __kunit_do_failed_assertion(test, \
611 __kunit_abort(test); \
615 #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) do { \
616 _KUNIT_SAVE_LOC(test); \
617 _KUNIT_FAILED(test, \
627 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
628 * @test: The test context object.
634 * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
637 #define KUNIT_FAIL(test, fmt, ...) \
638 KUNIT_FAIL_ASSERTION(test, \
646 #define KUNIT_UNARY_ASSERTION(test, \
653 _KUNIT_SAVE_LOC(test); \
657 _KUNIT_FAILED(test, \
667 #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
668 KUNIT_UNARY_ASSERTION(test, \
675 #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
676 KUNIT_UNARY_ASSERTION(test, \
697 #define KUNIT_BASE_BINARY_ASSERTION(test, \
715 _KUNIT_SAVE_LOC(test); \
719 _KUNIT_FAILED(test, \
730 #define KUNIT_BINARY_INT_ASSERTION(test, \
737 KUNIT_BASE_BINARY_ASSERTION(test, \
745 #define KUNIT_BINARY_PTR_ASSERTION(test, \
752 KUNIT_BASE_BINARY_ASSERTION(test, \
760 #define KUNIT_BINARY_STR_ASSERTION(test, \
776 _KUNIT_SAVE_LOC(test); \
781 _KUNIT_FAILED(test, \
792 #define KUNIT_MEM_ASSERTION(test, \
810 _KUNIT_SAVE_LOC(test); \
815 _KUNIT_FAILED(test, \
827 #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
835 _KUNIT_SAVE_LOC(test); \
839 _KUNIT_FAILED(test, \
849 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
850 * @test: The test context object.
851 * @condition: an arbitrary boolean expression. The test fails when this does
854 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
856 * the test case from continuing to run; this is otherwise known as an
859 #define KUNIT_EXPECT_TRUE(test, condition) \
860 KUNIT_EXPECT_TRUE_MSG(test, condition, NULL)
862 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
863 KUNIT_TRUE_MSG_ASSERTION(test, \
870 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
871 * @test: The test context object.
872 * @condition: an arbitrary boolean expression. The test fails when this does
878 #define KUNIT_EXPECT_FALSE(test, condition) \
879 KUNIT_EXPECT_FALSE_MSG(test, condition, NULL)
881 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
882 KUNIT_FALSE_MSG_ASSERTION(test, \
890 * @test: The test context object.
896 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
899 #define KUNIT_EXPECT_EQ(test, left, right) \
900 KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
902 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
903 KUNIT_BINARY_INT_ASSERTION(test, \
911 * @test: The test context object.
917 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
920 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
921 KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
923 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
924 KUNIT_BINARY_PTR_ASSERTION(test, \
932 * @test: The test context object.
938 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
941 #define KUNIT_EXPECT_NE(test, left, right) \
942 KUNIT_EXPECT_NE_MSG(test, left, right, NULL)
944 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
945 KUNIT_BINARY_INT_ASSERTION(test, \
953 * @test: The test context object.
959 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
962 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
963 KUNIT_EXPECT_PTR_NE_MSG(test, left, right, NULL)
965 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
966 KUNIT_BINARY_PTR_ASSERTION(test, \
974 * @test: The test context object.
980 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
983 #define KUNIT_EXPECT_LT(test, left, right) \
984 KUNIT_EXPECT_LT_MSG(test, left, right, NULL)
986 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
987 KUNIT_BINARY_INT_ASSERTION(test, \
995 * @test: The test context object.
1001 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
1004 #define KUNIT_EXPECT_LE(test, left, right) \
1005 KUNIT_EXPECT_LE_MSG(test, left, right, NULL)
1007 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
1008 KUNIT_BINARY_INT_ASSERTION(test, \
1016 * @test: The test context object.
1022 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
1025 #define KUNIT_EXPECT_GT(test, left, right) \
1026 KUNIT_EXPECT_GT_MSG(test, left, right, NULL)
1028 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
1029 KUNIT_BINARY_INT_ASSERTION(test, \
1037 * @test: The test context object.
1043 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
1046 #define KUNIT_EXPECT_GE(test, left, right) \
1047 KUNIT_EXPECT_GE_MSG(test, left, right, NULL)
1049 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
1050 KUNIT_BINARY_INT_ASSERTION(test, \
1058 * @test: The test context object.
1064 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1067 #define KUNIT_EXPECT_STREQ(test, left, right) \
1068 KUNIT_EXPECT_STREQ_MSG(test, left, right, NULL)
1070 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
1071 KUNIT_BINARY_STR_ASSERTION(test, \
1079 * @test: The test context object.
1085 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1088 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
1089 KUNIT_EXPECT_STRNEQ_MSG(test, left, right, NULL)
1091 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
1092 KUNIT_BINARY_STR_ASSERTION(test, \
1100 * @test: The test context object.
1107 * KUNIT_EXPECT_TRUE(@test, !memcmp((@left), (@right), (@size))). See
1114 #define KUNIT_EXPECT_MEMEQ(test, left, right, size) \
1115 KUNIT_EXPECT_MEMEQ_MSG(test, left, right, size, NULL)
1117 #define KUNIT_EXPECT_MEMEQ_MSG(test, left, right, size, fmt, ...) \
1118 KUNIT_MEM_ASSERTION(test, \
1127 * @test: The test context object.
1134 * KUNIT_EXPECT_TRUE(@test, memcmp((@left), (@right), (@size))). See
1141 #define KUNIT_EXPECT_MEMNEQ(test, left, right, size) \
1142 KUNIT_EXPECT_MEMNEQ_MSG(test, left, right, size, NULL)
1144 #define KUNIT_EXPECT_MEMNEQ_MSG(test, left, right, size, fmt, ...) \
1145 KUNIT_MEM_ASSERTION(test, \
1154 * @test: The test context object.
1158 * semantically equivalent to KUNIT_EXPECT_PTR_EQ(@test, ptr, NULL).
1161 #define KUNIT_EXPECT_NULL(test, ptr) \
1162 KUNIT_EXPECT_NULL_MSG(test, \
1166 #define KUNIT_EXPECT_NULL_MSG(test, ptr, fmt, ...) \
1167 KUNIT_BINARY_PTR_ASSERTION(test, \
1175 * @test: The test context object.
1179 * is semantically equivalent to KUNIT_EXPECT_PTR_NE(@test, ptr, NULL).
1182 #define KUNIT_EXPECT_NOT_NULL(test, ptr) \
1183 KUNIT_EXPECT_NOT_NULL_MSG(test, \
1187 #define KUNIT_EXPECT_NOT_NULL_MSG(test, ptr, fmt, ...) \
1188 KUNIT_BINARY_PTR_ASSERTION(test, \
1196 * @test: The test context object.
1201 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
1204 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
1205 KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
1207 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1208 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1214 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
1215 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
1219 * @test: The test context object.
1220 * @condition: an arbitrary boolean expression. The test fails and aborts when
1223 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1225 * an expectation failure, it will prevent the test case from continuing to run;
1228 #define KUNIT_ASSERT_TRUE(test, condition) \
1229 KUNIT_ASSERT_TRUE_MSG(test, condition, NULL)
1231 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
1232 KUNIT_TRUE_MSG_ASSERTION(test, \
1240 * @test: The test context object.
1247 #define KUNIT_ASSERT_FALSE(test, condition) \
1248 KUNIT_ASSERT_FALSE_MSG(test, condition, NULL)
1250 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
1251 KUNIT_FALSE_MSG_ASSERTION(test, \
1259 * @test: The test context object.
1267 #define KUNIT_ASSERT_EQ(test, left, right) \
1268 KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
1270 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
1271 KUNIT_BINARY_INT_ASSERTION(test, \
1279 * @test: The test context object.
1287 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
1288 KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, NULL)
1290 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1291 KUNIT_BINARY_PTR_ASSERTION(test, \
1299 * @test: The test context object.
1307 #define KUNIT_ASSERT_NE(test, left, right) \
1308 KUNIT_ASSERT_NE_MSG(test, left, right, NULL)
1310 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
1311 KUNIT_BINARY_INT_ASSERTION(test, \
1320 * @test: The test context object.
1328 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
1329 KUNIT_ASSERT_PTR_NE_MSG(test, left, right, NULL)
1331 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
1332 KUNIT_BINARY_PTR_ASSERTION(test, \
1339 * @test: The test context object.
1348 #define KUNIT_ASSERT_LT(test, left, right) \
1349 KUNIT_ASSERT_LT_MSG(test, left, right, NULL)
1351 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
1352 KUNIT_BINARY_INT_ASSERTION(test, \
1359 * @test: The test context object.
1368 #define KUNIT_ASSERT_LE(test, left, right) \
1369 KUNIT_ASSERT_LE_MSG(test, left, right, NULL)
1371 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
1372 KUNIT_BINARY_INT_ASSERTION(test, \
1380 * @test: The test context object.
1389 #define KUNIT_ASSERT_GT(test, left, right) \
1390 KUNIT_ASSERT_GT_MSG(test, left, right, NULL)
1392 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
1393 KUNIT_BINARY_INT_ASSERTION(test, \
1401 * @test: The test context object.
1410 #define KUNIT_ASSERT_GE(test, left, right) \
1411 KUNIT_ASSERT_GE_MSG(test, left, right, NULL)
1413 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
1414 KUNIT_BINARY_INT_ASSERTION(test, \
1422 * @test: The test context object.
1430 #define KUNIT_ASSERT_STREQ(test, left, right) \
1431 KUNIT_ASSERT_STREQ_MSG(test, left, right, NULL)
1433 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
1434 KUNIT_BINARY_STR_ASSERTION(test, \
1442 * @test: The test context object.
1448 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1451 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
1452 KUNIT_ASSERT_STRNEQ_MSG(test, left, right, NULL)
1454 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
1455 KUNIT_BINARY_STR_ASSERTION(test, \
1463 * @test: The test context object.
1470 #define KUNIT_ASSERT_NULL(test, ptr) \
1471 KUNIT_ASSERT_NULL_MSG(test, \
1475 #define KUNIT_ASSERT_NULL_MSG(test, ptr, fmt, ...) \
1476 KUNIT_BINARY_PTR_ASSERTION(test, \
1484 * @test: The test context object.
1491 #define KUNIT_ASSERT_NOT_NULL(test, ptr) \
1492 KUNIT_ASSERT_NOT_NULL_MSG(test, \
1496 #define KUNIT_ASSERT_NOT_NULL_MSG(test, ptr, fmt, ...) \
1497 KUNIT_BINARY_PTR_ASSERTION(test, \
1505 * @test: The test context object.
1513 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
1514 KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
1516 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1517 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1524 * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array.
1525 * @name: prefix for the test parameter generator function.
1526 * @array: array of test parameters.
1545 * KUNIT_ARRAY_PARAM_DESC() - Define test parameter generator from an array.
1546 * @name: prefix for the test parameter generator function.
1547 * @array: array of test parameters.