Lines Matching +full:left +full:-
1 /* SPDX-License-Identifier: GPL-2.0 */
13 #include <kunit/try-catch.h>
47 * sub-subtest. See the "Subtests" section in
48 * https://node-tap.org/tap-protocol/
55 * enum kunit_status - Type of result for a test or test suite
89 * struct kunit_case - represents an individual test case.
109 * .. code-block:: c
115 * KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
117 * KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
151 * KUNIT_CASE - A helper for creating a &struct kunit_case
164 * KUNIT_CASE_ATTR - A helper for creating a &struct kunit_case
176 * KUNIT_CASE_SLOW - A helper for creating a &struct kunit_case
187 * KUNIT_CASE_PARAM - A helper for creation a parameterized &struct kunit_case
208 * KUNIT_CASE_PARAM_ATTR - A helper for creating a parameterized &struct
222 * struct kunit_suite - describes a related collection of &struct kunit_case
267 * struct kunit - represents a running instance of a test.
311 WRITE_ONCE(test->status, KUNIT_FAILURE); in kunit_set_failure()
364 * kunit_test_suites() - used to register one or more &struct kunit_suite
389 * kunit_test_init_section_suites() - used to register one or more &struct
416 for (test_case = suite->test_cases; test_case->run_case; test_case++)
421 * kunit_kmalloc_array() - Like kmalloc_array() except the allocation is *test managed*.
437 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
453 * kunit_kfree() - Like kfree except for allocations managed by KUnit.
460 * kunit_kzalloc() - Just like kunit_kmalloc(), but zeroes the allocation.
473 * kunit_kcalloc() - Just like kunit_kmalloc_array(), but zeroes the allocation.
488 * kunit_kfree_const() - conditionally free test managed memory
498 * kunit_kstrdup() - Duplicates a string into a test managed allocation.
501 * @str: The NULL-terminated string to duplicate.
522 * kunit_kstrdup_const() - Conditionally duplicates a string into a test managed allocation.
525 * @str: The NULL-terminated string to duplicate.
529 * kunit_kfree_const() -- not kunit_kfree().
535 * kunit_vm_mmap() - Allocate KUnit-tracked vm_mmap() area
556 * kunit_mark_skipped() - Marks @test_or_suite as skipped
568 WRITE_ONCE((test_or_suite)->status, KUNIT_SKIPPED); \
569 scnprintf((test_or_suite)->status_comment, \
575 * kunit_skip() - Marks @test_or_suite as skipped
588 kunit_try_catch_throw(&((test_or_suite)->try_catch)); \
592 * printk and log to per-test or per-suite log buffer. Logging only done
598 kunit_log_append((test_or_suite)->log, fmt, \
604 (test)->name, ##__VA_ARGS__)
607 * kunit_info() - Prints an INFO level message associated with @test.
619 * kunit_warn() - Prints a WARN level message associated with @test.
630 * kunit_err() - Prints an ERROR level message associated with @test.
645 WRITE_ONCE(test->last_seen.file, __FILE__); \
646 WRITE_ONCE(test->last_seen.line, __LINE__); \
650 * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
695 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
769 left, \ argument
775 const typeof(left) __left = (left); \
779 .left_text = #left, \
800 left, \ argument
809 left, op, right, \
815 left, \ argument
824 left, op, right, \
830 left, \ argument
836 const char *__left = (left); \
840 .left_text = #left, \
862 left, \ argument
869 const void *__left = (left); \
874 .left_text = #left, \
917 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
938 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
957 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
959 * @left: an arbitrary expression that evaluates to a primitive C type.
962 * Sets an expectation that the values that @left and @right evaluate to are
964 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
967 #define KUNIT_EXPECT_EQ(test, left, right) \ argument
968 KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
970 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \ argument
973 left, ==, right, \
978 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
980 * @left: an arbitrary expression that evaluates to a pointer.
983 * Sets an expectation that the values that @left and @right evaluate to are
985 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
988 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \ argument
989 KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
991 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \ argument
994 left, ==, right, \
999 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
1001 * @left: an arbitrary expression that evaluates to a primitive C type.
1004 * Sets an expectation that the values that @left and @right evaluate to are not
1006 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1009 #define KUNIT_EXPECT_NE(test, left, right) \ argument
1010 KUNIT_EXPECT_NE_MSG(test, left, right, NULL)
1012 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \ argument
1015 left, !=, right, \
1020 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
1022 * @left: an arbitrary expression that evaluates to a pointer.
1025 * Sets an expectation that the values that @left and @right evaluate to are not
1027 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1030 #define KUNIT_EXPECT_PTR_NE(test, left, right) \ argument
1031 KUNIT_EXPECT_PTR_NE_MSG(test, left, right, NULL)
1033 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \ argument
1036 left, !=, right, \
1041 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
1043 * @left: an arbitrary expression that evaluates to a primitive C type.
1046 * Sets an expectation that the value that @left evaluates to is less than the
1048 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
1051 #define KUNIT_EXPECT_LT(test, left, right) \ argument
1052 KUNIT_EXPECT_LT_MSG(test, left, right, NULL)
1054 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \ argument
1057 left, <, right, \
1062 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
1064 * @left: an arbitrary expression that evaluates to a primitive C type.
1067 * Sets an expectation that the value that @left evaluates to is less than or
1069 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
1072 #define KUNIT_EXPECT_LE(test, left, right) \ argument
1073 KUNIT_EXPECT_LE_MSG(test, left, right, NULL)
1075 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \ argument
1078 left, <=, right, \
1083 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
1085 * @left: an arbitrary expression that evaluates to a primitive C type.
1088 * Sets an expectation that the value that @left evaluates to is greater than
1090 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
1093 #define KUNIT_EXPECT_GT(test, left, right) \ argument
1094 KUNIT_EXPECT_GT_MSG(test, left, right, NULL)
1096 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \ argument
1099 left, >, right, \
1104 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
1106 * @left: an arbitrary expression that evaluates to a primitive C type.
1109 * Sets an expectation that the value that @left evaluates to is greater than
1111 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
1114 #define KUNIT_EXPECT_GE(test, left, right) \ argument
1115 KUNIT_EXPECT_GE_MSG(test, left, right, NULL)
1117 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \ argument
1120 left, >=, right, \
1125 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
1127 * @left: an arbitrary expression that evaluates to a null terminated string.
1130 * Sets an expectation that the values that @left and @right evaluate to are
1132 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1135 #define KUNIT_EXPECT_STREQ(test, left, right) \ argument
1136 KUNIT_EXPECT_STREQ_MSG(test, left, right, NULL)
1138 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \ argument
1141 left, ==, right, \
1146 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
1148 * @left: an arbitrary expression that evaluates to a null terminated string.
1151 * Sets an expectation that the values that @left and @right evaluate to are
1153 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1156 #define KUNIT_EXPECT_STRNEQ(test, left, right) \ argument
1157 KUNIT_EXPECT_STRNEQ_MSG(test, left, right, NULL)
1159 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \ argument
1162 left, !=, right, \
1167 * KUNIT_EXPECT_MEMEQ() - Expects that the first @size bytes of @left and @right are equal.
1169 * @left: An arbitrary expression that evaluates to the specified size.
1173 * Sets an expectation that the values that @left and @right evaluate to are
1175 * KUNIT_EXPECT_TRUE(@test, !memcmp((@left), (@right), (@size))). See
1182 #define KUNIT_EXPECT_MEMEQ(test, left, right, size) \ argument
1183 KUNIT_EXPECT_MEMEQ_MSG(test, left, right, size, NULL)
1185 #define KUNIT_EXPECT_MEMEQ_MSG(test, left, right, size, fmt, ...) \ argument
1188 left, ==, right, \
1194 * KUNIT_EXPECT_MEMNEQ() - Expects that the first @size bytes of @left and @right are not equal.
1196 * @left: An arbitrary expression that evaluates to the specified size.
1200 * Sets an expectation that the values that @left and @right evaluate to are
1202 * KUNIT_EXPECT_TRUE(@test, memcmp((@left), (@right), (@size))). See
1209 #define KUNIT_EXPECT_MEMNEQ(test, left, right, size) \ argument
1210 KUNIT_EXPECT_MEMNEQ_MSG(test, left, right, size, NULL)
1212 #define KUNIT_EXPECT_MEMNEQ_MSG(test, left, right, size, fmt, ...) \ argument
1215 left, !=, right, \
1221 * KUNIT_EXPECT_NULL() - Expects that @ptr is null.
1242 * KUNIT_EXPECT_NOT_NULL() - Expects that @ptr is not null.
1263 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
1283 * KUNIT_FAIL_AND_ABORT() - Always causes a test to fail and abort when evaluated.
1297 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
1318 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
1337 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
1339 * @left: an arbitrary expression that evaluates to a primitive C type.
1342 * Sets an assertion that the values that @left and @right evaluate to are
1346 #define KUNIT_ASSERT_EQ(test, left, right) \ argument
1347 KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
1349 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \ argument
1352 left, ==, right, \
1357 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1359 * @left: an arbitrary expression that evaluates to a pointer.
1362 * Sets an assertion that the values that @left and @right evaluate to are
1366 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \ argument
1367 KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, NULL)
1369 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \ argument
1372 left, ==, right, \
1377 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
1379 * @left: an arbitrary expression that evaluates to a primitive C type.
1382 * Sets an assertion that the values that @left and @right evaluate to are not
1386 #define KUNIT_ASSERT_NE(test, left, right) \ argument
1387 KUNIT_ASSERT_NE_MSG(test, left, right, NULL)
1389 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \ argument
1392 left, !=, right, \
1397 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
1398 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1400 * @left: an arbitrary expression that evaluates to a pointer.
1403 * Sets an assertion that the values that @left and @right evaluate to are not
1407 #define KUNIT_ASSERT_PTR_NE(test, left, right) \ argument
1408 KUNIT_ASSERT_PTR_NE_MSG(test, left, right, NULL)
1410 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \ argument
1413 left, !=, right, \
1417 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
1419 * @left: an arbitrary expression that evaluates to a primitive C type.
1422 * Sets an assertion that the value that @left evaluates to is less than the
1427 #define KUNIT_ASSERT_LT(test, left, right) \ argument
1428 KUNIT_ASSERT_LT_MSG(test, left, right, NULL)
1430 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \ argument
1433 left, <, right, \
1437 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
1439 * @left: an arbitrary expression that evaluates to a primitive C type.
1442 * Sets an assertion that the value that @left evaluates to is less than or
1447 #define KUNIT_ASSERT_LE(test, left, right) \ argument
1448 KUNIT_ASSERT_LE_MSG(test, left, right, NULL)
1450 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \ argument
1453 left, <=, right, \
1458 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
1460 * @left: an arbitrary expression that evaluates to a primitive C type.
1463 * Sets an assertion that the value that @left evaluates to is greater than the
1468 #define KUNIT_ASSERT_GT(test, left, right) \ argument
1469 KUNIT_ASSERT_GT_MSG(test, left, right, NULL)
1471 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \ argument
1474 left, >, right, \
1479 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
1481 * @left: an arbitrary expression that evaluates to a primitive C type.
1484 * Sets an assertion that the value that @left evaluates to is greater than the
1489 #define KUNIT_ASSERT_GE(test, left, right) \ argument
1490 KUNIT_ASSERT_GE_MSG(test, left, right, NULL)
1492 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \ argument
1495 left, >=, right, \
1500 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
1502 * @left: an arbitrary expression that evaluates to a null terminated string.
1505 * Sets an assertion that the values that @left and @right evaluate to are
1509 #define KUNIT_ASSERT_STREQ(test, left, right) \ argument
1510 KUNIT_ASSERT_STREQ_MSG(test, left, right, NULL)
1512 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \ argument
1515 left, ==, right, \
1520 * KUNIT_ASSERT_STRNEQ() - An assertion that strings @left and @right are not equal.
1522 * @left: an arbitrary expression that evaluates to a null terminated string.
1525 * Sets an assertion that the values that @left and @right evaluate to are
1527 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1530 #define KUNIT_ASSERT_STRNEQ(test, left, right) \ argument
1531 KUNIT_ASSERT_STRNEQ_MSG(test, left, right, NULL)
1533 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \ argument
1536 left, !=, right, \
1541 * KUNIT_ASSERT_MEMEQ() - Asserts that the first @size bytes of @left and @right are equal.
1543 * @left: An arbitrary expression that evaluates to the specified size.
1547 * Sets an assertion that the values that @left and @right evaluate to are
1549 * KUNIT_ASSERT_TRUE(@test, !memcmp((@left), (@right), (@size))). See
1556 #define KUNIT_ASSERT_MEMEQ(test, left, right, size) \ argument
1557 KUNIT_ASSERT_MEMEQ_MSG(test, left, right, size, NULL)
1559 #define KUNIT_ASSERT_MEMEQ_MSG(test, left, right, size, fmt, ...) \ argument
1562 left, ==, right, \
1568 * KUNIT_ASSERT_MEMNEQ() - Asserts that the first @size bytes of @left and @right are not equal.
1570 * @left: An arbitrary expression that evaluates to the specified size.
1574 * Sets an assertion that the values that @left and @right evaluate to are
1576 * KUNIT_ASSERT_TRUE(@test, memcmp((@left), (@right), (@size))). See
1583 #define KUNIT_ASSERT_MEMNEQ(test, left, right, size) \ argument
1584 KUNIT_ASSERT_MEMNEQ_MSG(test, left, right, size, NULL)
1586 #define KUNIT_ASSERT_MEMNEQ_MSG(test, left, right, size, fmt, ...) \ argument
1589 left, !=, right, \
1595 * KUNIT_ASSERT_NULL() - Asserts that pointers @ptr is null.
1616 * KUNIT_ASSERT_NOT_NULL() - Asserts that pointers @ptr is not null.
1637 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
1657 * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array.
1668 if (__next - (array) < ARRAY_SIZE((array))) { \
1678 * KUNIT_ARRAY_PARAM_DESC() - Define test parameter generator from an array.
1689 if (__next - (array) < ARRAY_SIZE((array))) { \
1690 strscpy(desc, __next->desc_member, KUNIT_PARAM_DESC_SIZE); \