1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Base unit test (KUnit) API.
5 * Copyright (C) 2019, Google LLC.
6 * Author: Brendan Higgins <brendanhiggins@google.com>
12 #include <kunit/assert.h>
13 #include <kunit/try-catch.h>
15 #include <linux/compiler.h>
16 #include <linux/container_of.h>
17 #include <linux/err.h>
18 #include <linux/init.h>
19 #include <linux/jump_label.h>
20 #include <linux/kconfig.h>
21 #include <linux/kref.h>
22 #include <linux/list.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/spinlock.h>
26 #include <linux/string.h>
27 #include <linux/types.h>
29 #include <asm/rwonce.h>
31 /* Static key: true if any KUnit tests are currently running */
32 DECLARE_STATIC_KEY_FALSE(kunit_running);
36 /* Size of log associated with test. */
37 #define KUNIT_LOG_SIZE 2048
39 /* Maximum size of parameter description string. */
40 #define KUNIT_PARAM_DESC_SIZE 128
42 /* Maximum size of a status comment. */
43 #define KUNIT_STATUS_COMMENT_SIZE 256
46 * TAP specifies subtest stream indentation of 4 spaces, 8 spaces for a
47 * sub-subtest. See the "Subtests" section in
48 * https://node-tap.org/tap-protocol/
50 #define KUNIT_INDENT_LEN 4
51 #define KUNIT_SUBTEST_INDENT " "
52 #define KUNIT_SUBSUBTEST_INDENT " "
55 * enum kunit_status - Type of result for a test or test suite
56 * @KUNIT_SUCCESS: Denotes the test suite has not failed nor been skipped
57 * @KUNIT_FAILURE: Denotes the test has failed.
58 * @KUNIT_SKIPPED: Denotes the test has been skipped.
66 /* Holds attributes for each test case and suite */
67 struct kunit_attributes {};
70 * struct kunit_case - represents an individual test case.
72 * @run_case: the function representing the actual test case.
73 * @name: the name of the test case.
74 * @generate_params: the generator function for parameterized tests.
75 * @attr: the attributes associated with the test
77 * A test case is a function with the signature,
78 * ``void (*)(struct kunit *)``
79 * that makes expectations and assertions (see KUNIT_EXPECT_TRUE() and
80 * KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated
81 * with a &struct kunit_suite and will be run after the suite's init
82 * function and followed by the suite's exit function.
84 * A test case should be static and should only be created with the
85 * KUNIT_CASE() macro; additionally, every array of test cases should be
86 * terminated with an empty test case.
92 * void add_test_basic(struct kunit *test)
94 * KUNIT_EXPECT_EQ(test, 1, add(1, 0));
95 * KUNIT_EXPECT_EQ(test, 2, add(1, 1));
96 * KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
97 * KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
98 * KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
101 * static struct kunit_case example_test_cases[] = {
102 * KUNIT_CASE(add_test_basic),
108 void (*run_case)(struct kunit *test);
110 const void* (*generate_params)(const void *prev, char *desc);
111 struct kunit_attributes attr;
113 /* private: internal use only. */
114 enum kunit_status status;
118 static inline char *kunit_status_to_ok_not_ok(enum kunit_status status)
131 * KUNIT_CASE - A helper for creating a &struct kunit_case
133 * @test_name: a reference to a test case function.
135 * Takes a symbol for a function representing a test case and creates a
136 * &struct kunit_case object from it. See the documentation for
137 * &struct kunit_case for an example on how to use it.
139 #define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }
142 * KUNIT_CASE_ATTR - A helper for creating a &struct kunit_case
145 * @test_name: a reference to a test case function.
146 * @attributes: a reference to a struct kunit_attributes object containing
149 #define KUNIT_CASE_ATTR(test_name, attributes) \
150 { .run_case = test_name, .name = #test_name, \
154 * KUNIT_CASE_PARAM - A helper for creation a parameterized &struct kunit_case
156 * @test_name: a reference to a test case function.
157 * @gen_params: a reference to a parameter generator function.
159 * The generator function::
161 * const void* gen_params(const void *prev, char *desc)
163 * is used to lazily generate a series of arbitrarily typed values that fit into
164 * a void*. The argument @prev is the previously returned value, which should be
165 * used to derive the next value; @prev is set to NULL on the initial generator
166 * call. When no more values are available, the generator must return NULL.
167 * Optionally write a string into @desc (size of KUNIT_PARAM_DESC_SIZE)
168 * describing the parameter.
170 #define KUNIT_CASE_PARAM(test_name, gen_params) \
171 { .run_case = test_name, .name = #test_name, \
172 .generate_params = gen_params }
175 * KUNIT_CASE_PARAM_ATTR - A helper for creating a parameterized &struct
176 * kunit_case with attributes
178 * @test_name: a reference to a test case function.
179 * @gen_params: a reference to a parameter generator function.
180 * @attributes: a reference to a struct kunit_attributes object containing
183 #define KUNIT_CASE_PARAM_ATTR(test_name, gen_params, attributes) \
184 { .run_case = test_name, .name = #test_name, \
185 .generate_params = gen_params, \
189 * struct kunit_suite - describes a related collection of &struct kunit_case
191 * @name: the name of the test. Purely informational.
192 * @suite_init: called once per test suite before the test cases.
193 * @suite_exit: called once per test suite after all test cases.
194 * @init: called before every test case.
195 * @exit: called after every test case.
196 * @test_cases: a null terminated array of test cases.
197 * @attr: the attributes associated with the test suite
199 * A kunit_suite is a collection of related &struct kunit_case s, such that
200 * @init is called before every test case and @exit is called after every
201 * test case, similar to the notion of a *test fixture* or a *test class*
202 * in other unit testing frameworks like JUnit or Googletest.
204 * Note that @exit and @suite_exit will run even if @init or @suite_init
205 * fail: make sure they can handle any inconsistent state which may result.
207 * Every &struct kunit_case must be associated with a kunit_suite for KUnit
211 const char name[256];
212 int (*suite_init)(struct kunit_suite *suite);
213 void (*suite_exit)(struct kunit_suite *suite);
214 int (*init)(struct kunit *test);
215 void (*exit)(struct kunit *test);
216 struct kunit_case *test_cases;
217 struct kunit_attributes attr;
219 /* private: internal use only */
220 char status_comment[KUNIT_STATUS_COMMENT_SIZE];
221 struct dentry *debugfs;
227 * struct kunit - represents a running instance of a test.
229 * @priv: for user to store arbitrary data. Commonly used to pass data
230 * created in the init function (see &struct kunit_suite).
232 * Used to store information about the current context under which the test
233 * is running. Most of this data is private and should only be accessed
234 * indirectly via public functions; the one exception is @priv which can be
235 * used by the test writer to store arbitrary data.
240 /* private: internal use only. */
241 const char *name; /* Read only after initialization! */
242 char *log; /* Points at case log after initialization */
243 struct kunit_try_catch try_catch;
244 /* param_value is the current parameter value for a test case. */
245 const void *param_value;
246 /* param_index stores the index of the parameter in parameterized tests. */
249 * success starts as true, and may only be set to false during a
250 * test case; thus, it is safe to update this across multiple
251 * threads using WRITE_ONCE; however, as a consequence, it may only
252 * be read after the test case finishes once all threads associated
253 * with the test case have terminated.
255 spinlock_t lock; /* Guards all mutable test state. */
256 enum kunit_status status; /* Read only after test_case finishes! */
258 * Because resources is a list that may be updated multiple times (with
259 * new resources) from any thread associated with a test case, we must
260 * protect it with some type of lock.
262 struct list_head resources; /* Protected by lock. */
264 char status_comment[KUNIT_STATUS_COMMENT_SIZE];
267 static inline void kunit_set_failure(struct kunit *test)
269 WRITE_ONCE(test->status, KUNIT_FAILURE);
272 bool kunit_enabled(void);
274 void kunit_init_test(struct kunit *test, const char *name, char *log);
276 int kunit_run_tests(struct kunit_suite *suite);
278 size_t kunit_suite_num_test_cases(struct kunit_suite *suite);
280 unsigned int kunit_test_case_num(struct kunit_suite *suite,
281 struct kunit_case *test_case);
283 int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites);
285 void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites);
287 #if IS_BUILTIN(CONFIG_KUNIT)
288 int kunit_run_all_tests(void);
290 static inline int kunit_run_all_tests(void)
294 #endif /* IS_BUILTIN(CONFIG_KUNIT) */
296 #define __kunit_test_suites(unique_array, ...) \
297 static struct kunit_suite *unique_array[] \
298 __aligned(sizeof(struct kunit_suite *)) \
299 __used __section(".kunit_test_suites") = { __VA_ARGS__ }
302 * kunit_test_suites() - used to register one or more &struct kunit_suite
305 * @__suites: a statically allocated list of &struct kunit_suite.
307 * Registers @suites with the test framework.
308 * This is done by placing the array of struct kunit_suite * in the
309 * .kunit_test_suites ELF section.
311 * When builtin, KUnit tests are all run via the executor at boot, and when
312 * built as a module, they run on module load.
315 #define kunit_test_suites(__suites...) \
316 __kunit_test_suites(__UNIQUE_ID(array), \
319 #define kunit_test_suite(suite) kunit_test_suites(&suite)
322 * kunit_test_init_section_suites() - used to register one or more &struct
323 * kunit_suite containing init functions or
326 * @__suites: a statically allocated list of &struct kunit_suite.
328 * This functions identically as kunit_test_suites() except that it suppresses
329 * modpost warnings for referencing functions marked __init or data marked
330 * __initdata; this is OK because currently KUnit only runs tests upon boot
331 * during the init phase or upon loading a module during the init phase.
333 * NOTE TO KUNIT DEVS: If we ever allow KUnit tests to be run after boot, these
334 * tests must be excluded.
336 * The only thing this macro does that's different from kunit_test_suites is
337 * that it suffixes the array and suite declarations it makes with _probe;
338 * modpost suppresses warnings about referencing init data for symbols named in
341 #define kunit_test_init_section_suites(__suites...) \
342 __kunit_test_suites(CONCATENATE(__UNIQUE_ID(array), _probe), \
345 #define kunit_test_init_section_suite(suite) \
346 kunit_test_init_section_suites(&suite)
348 #define kunit_suite_for_each_test_case(suite, test_case) \
349 for (test_case = suite->test_cases; test_case->run_case; test_case++)
351 enum kunit_status kunit_suite_has_succeeded(struct kunit_suite *suite);
354 * kunit_kmalloc_array() - Like kmalloc_array() except the allocation is *test managed*.
355 * @test: The test context object.
356 * @n: number of elements.
357 * @size: The size in bytes of the desired memory.
358 * @gfp: flags passed to underlying kmalloc().
360 * Just like `kmalloc_array(...)`, except the allocation is managed by the test case
361 * and is automatically cleaned up after the test case concludes. See kunit_add_action()
362 * for more information.
364 * Note that some internal context data is also allocated with GFP_KERNEL,
365 * regardless of the gfp passed in.
367 void *kunit_kmalloc_array(struct kunit *test, size_t n, size_t size, gfp_t gfp);
370 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
371 * @test: The test context object.
372 * @size: The size in bytes of the desired memory.
373 * @gfp: flags passed to underlying kmalloc().
375 * See kmalloc() and kunit_kmalloc_array() for more information.
377 * Note that some internal context data is also allocated with GFP_KERNEL,
378 * regardless of the gfp passed in.
380 static inline void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp)
382 return kunit_kmalloc_array(test, 1, size, gfp);
386 * kunit_kfree() - Like kfree except for allocations managed by KUnit.
387 * @test: The test case to which the resource belongs.
388 * @ptr: The memory allocation to free.
390 void kunit_kfree(struct kunit *test, const void *ptr);
393 * kunit_kzalloc() - Just like kunit_kmalloc(), but zeroes the allocation.
394 * @test: The test context object.
395 * @size: The size in bytes of the desired memory.
396 * @gfp: flags passed to underlying kmalloc().
398 * See kzalloc() and kunit_kmalloc_array() for more information.
400 static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp)
402 return kunit_kmalloc(test, size, gfp | __GFP_ZERO);
406 * kunit_kcalloc() - Just like kunit_kmalloc_array(), but zeroes the allocation.
407 * @test: The test context object.
408 * @n: number of elements.
409 * @size: The size in bytes of the desired memory.
410 * @gfp: flags passed to underlying kmalloc().
412 * See kcalloc() and kunit_kmalloc_array() for more information.
414 static inline void *kunit_kcalloc(struct kunit *test, size_t n, size_t size, gfp_t gfp)
416 return kunit_kmalloc_array(test, n, size, gfp | __GFP_ZERO);
419 void kunit_cleanup(struct kunit *test);
421 void __printf(2, 3) kunit_log_append(char *log, const char *fmt, ...);
424 * kunit_mark_skipped() - Marks @test_or_suite as skipped
426 * @test_or_suite: The test context object.
427 * @fmt: A printk() style format string.
429 * Marks the test as skipped. @fmt is given output as the test status
430 * comment, typically the reason the test was skipped.
432 * Test execution continues after kunit_mark_skipped() is called.
434 #define kunit_mark_skipped(test_or_suite, fmt, ...) \
436 WRITE_ONCE((test_or_suite)->status, KUNIT_SKIPPED); \
437 scnprintf((test_or_suite)->status_comment, \
438 KUNIT_STATUS_COMMENT_SIZE, \
439 fmt, ##__VA_ARGS__); \
443 * kunit_skip() - Marks @test_or_suite as skipped
445 * @test_or_suite: The test context object.
446 * @fmt: A printk() style format string.
448 * Skips the test. @fmt is given output as the test status
449 * comment, typically the reason the test was skipped.
451 * Test execution is halted after kunit_skip() is called.
453 #define kunit_skip(test_or_suite, fmt, ...) \
455 kunit_mark_skipped((test_or_suite), fmt, ##__VA_ARGS__);\
456 kunit_try_catch_throw(&((test_or_suite)->try_catch)); \
460 * printk and log to per-test or per-suite log buffer. Logging only done
461 * if CONFIG_KUNIT_DEBUGFS is 'y'; if it is 'n', no log is allocated/used.
463 #define kunit_log(lvl, test_or_suite, fmt, ...) \
465 printk(lvl fmt, ##__VA_ARGS__); \
466 kunit_log_append((test_or_suite)->log, fmt, \
470 #define kunit_printk(lvl, test, fmt, ...) \
471 kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \
472 (test)->name, ##__VA_ARGS__)
475 * kunit_info() - Prints an INFO level message associated with @test.
477 * @test: The test context object.
478 * @fmt: A printk() style format string.
480 * Prints an info level message associated with the test suite being run.
481 * Takes a variable number of format parameters just like printk().
483 #define kunit_info(test, fmt, ...) \
484 kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
487 * kunit_warn() - Prints a WARN level message associated with @test.
489 * @test: The test context object.
490 * @fmt: A printk() style format string.
492 * Prints a warning level message.
494 #define kunit_warn(test, fmt, ...) \
495 kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
498 * kunit_err() - Prints an ERROR level message associated with @test.
500 * @test: The test context object.
501 * @fmt: A printk() style format string.
503 * Prints an error level message.
505 #define kunit_err(test, fmt, ...) \
506 kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
509 * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
510 * @test: The test context object.
512 * The opposite of KUNIT_FAIL(), it is an expectation that cannot fail. In other
513 * words, it does nothing and only exists for code clarity. See
514 * KUNIT_EXPECT_TRUE() for more information.
516 #define KUNIT_SUCCEED(test) do {} while (0)
518 void __noreturn __kunit_abort(struct kunit *test);
520 void __kunit_do_failed_assertion(struct kunit *test,
521 const struct kunit_loc *loc,
522 enum kunit_assert_type type,
523 const struct kunit_assert *assert,
524 assert_format_t assert_format,
525 const char *fmt, ...);
527 #define _KUNIT_FAILED(test, assert_type, assert_class, assert_format, INITIALIZER, fmt, ...) do { \
528 static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \
529 const struct assert_class __assertion = INITIALIZER; \
530 __kunit_do_failed_assertion(test, \
533 &__assertion.assert, \
537 if (assert_type == KUNIT_ASSERTION) \
538 __kunit_abort(test); \
542 #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \
543 _KUNIT_FAILED(test, \
546 kunit_fail_assert_format, \
552 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
553 * @test: The test context object.
554 * @fmt: an informational message to be printed when the assertion is made.
555 * @...: string format arguments.
557 * The opposite of KUNIT_SUCCEED(), it is an expectation that always fails. In
558 * other words, it always results in a failed expectation, and consequently
559 * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
560 * for more information.
562 #define KUNIT_FAIL(test, fmt, ...) \
563 KUNIT_FAIL_ASSERTION(test, \
568 /* Helper to safely pass around an initializer list to other macros. */
569 #define KUNIT_INIT_ASSERT(initializers...) { initializers }
571 #define KUNIT_UNARY_ASSERTION(test, \
578 if (likely(!!(condition_) == !!expected_true_)) \
581 _KUNIT_FAILED(test, \
583 kunit_unary_assert, \
584 kunit_unary_assert_format, \
585 KUNIT_INIT_ASSERT(.condition = #condition_, \
586 .expected_true = expected_true_), \
591 #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
592 KUNIT_UNARY_ASSERTION(test, \
599 #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
600 KUNIT_UNARY_ASSERTION(test, \
608 * A factory macro for defining the assertions and expectations for the basic
609 * comparisons defined for the built in types.
611 * Unfortunately, there is no common type that all types can be promoted to for
612 * which all the binary operators behave the same way as for the actual types
613 * (for example, there is no type that long long and unsigned long long can
614 * both be cast to where the comparison result is preserved for all values). So
615 * the best we can do is do the comparison in the original types and then coerce
616 * everything to long long for printing; this way, the comparison behaves
617 * correctly and the printed out value usually makes sense without
618 * interpretation, but can always be interpreted to figure out the actual
621 #define KUNIT_BASE_BINARY_ASSERTION(test, \
631 const typeof(left) __left = (left); \
632 const typeof(right) __right = (right); \
633 static const struct kunit_binary_assert_text __text = { \
635 .left_text = #left, \
636 .right_text = #right, \
639 if (likely(__left op __right)) \
642 _KUNIT_FAILED(test, \
646 KUNIT_INIT_ASSERT(.text = &__text, \
647 .left_value = __left, \
648 .right_value = __right), \
653 #define KUNIT_BINARY_INT_ASSERTION(test, \
660 KUNIT_BASE_BINARY_ASSERTION(test, \
661 kunit_binary_assert, \
662 kunit_binary_assert_format, \
668 #define KUNIT_BINARY_PTR_ASSERTION(test, \
675 KUNIT_BASE_BINARY_ASSERTION(test, \
676 kunit_binary_ptr_assert, \
677 kunit_binary_ptr_assert_format, \
683 #define KUNIT_BINARY_STR_ASSERTION(test, \
691 const char *__left = (left); \
692 const char *__right = (right); \
693 static const struct kunit_binary_assert_text __text = { \
695 .left_text = #left, \
696 .right_text = #right, \
699 if (likely(strcmp(__left, __right) op 0)) \
703 _KUNIT_FAILED(test, \
705 kunit_binary_str_assert, \
706 kunit_binary_str_assert_format, \
707 KUNIT_INIT_ASSERT(.text = &__text, \
708 .left_value = __left, \
709 .right_value = __right), \
714 #define KUNIT_MEM_ASSERTION(test, \
723 const void *__left = (left); \
724 const void *__right = (right); \
725 const size_t __size = (size_); \
726 static const struct kunit_binary_assert_text __text = { \
728 .left_text = #left, \
729 .right_text = #right, \
732 if (likely(__left && __right)) \
733 if (likely(memcmp(__left, __right, __size) op 0)) \
736 _KUNIT_FAILED(test, \
739 kunit_mem_assert_format, \
740 KUNIT_INIT_ASSERT(.text = &__text, \
741 .left_value = __left, \
742 .right_value = __right, \
748 #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
754 const typeof(ptr) __ptr = (ptr); \
756 if (!IS_ERR_OR_NULL(__ptr)) \
759 _KUNIT_FAILED(test, \
761 kunit_ptr_not_err_assert, \
762 kunit_ptr_not_err_assert_format, \
763 KUNIT_INIT_ASSERT(.text = #ptr, .value = __ptr), \
769 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
770 * @test: The test context object.
771 * @condition: an arbitrary boolean expression. The test fails when this does
772 * not evaluate to true.
774 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
775 * to fail when the specified condition is not met; however, it will not prevent
776 * the test case from continuing to run; this is otherwise known as an
777 * *expectation failure*.
779 #define KUNIT_EXPECT_TRUE(test, condition) \
780 KUNIT_EXPECT_TRUE_MSG(test, condition, NULL)
782 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
783 KUNIT_TRUE_MSG_ASSERTION(test, \
790 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
791 * @test: The test context object.
792 * @condition: an arbitrary boolean expression. The test fails when this does
793 * not evaluate to false.
795 * Sets an expectation that @condition evaluates to false. See
796 * KUNIT_EXPECT_TRUE() for more information.
798 #define KUNIT_EXPECT_FALSE(test, condition) \
799 KUNIT_EXPECT_FALSE_MSG(test, condition, NULL)
801 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
802 KUNIT_FALSE_MSG_ASSERTION(test, \
809 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
810 * @test: The test context object.
811 * @left: an arbitrary expression that evaluates to a primitive C type.
812 * @right: an arbitrary expression that evaluates to a primitive C type.
814 * Sets an expectation that the values that @left and @right evaluate to are
815 * equal. This is semantically equivalent to
816 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
819 #define KUNIT_EXPECT_EQ(test, left, right) \
820 KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
822 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
823 KUNIT_BINARY_INT_ASSERTION(test, \
830 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
831 * @test: The test context object.
832 * @left: an arbitrary expression that evaluates to a pointer.
833 * @right: an arbitrary expression that evaluates to a pointer.
835 * Sets an expectation that the values that @left and @right evaluate to are
836 * equal. This is semantically equivalent to
837 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
840 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
841 KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
843 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
844 KUNIT_BINARY_PTR_ASSERTION(test, \
851 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
852 * @test: The test context object.
853 * @left: an arbitrary expression that evaluates to a primitive C type.
854 * @right: an arbitrary expression that evaluates to a primitive C type.
856 * Sets an expectation that the values that @left and @right evaluate to are not
857 * equal. This is semantically equivalent to
858 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
861 #define KUNIT_EXPECT_NE(test, left, right) \
862 KUNIT_EXPECT_NE_MSG(test, left, right, NULL)
864 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
865 KUNIT_BINARY_INT_ASSERTION(test, \
872 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
873 * @test: The test context object.
874 * @left: an arbitrary expression that evaluates to a pointer.
875 * @right: an arbitrary expression that evaluates to a pointer.
877 * Sets an expectation that the values that @left and @right evaluate to are not
878 * equal. This is semantically equivalent to
879 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
882 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
883 KUNIT_EXPECT_PTR_NE_MSG(test, left, right, NULL)
885 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
886 KUNIT_BINARY_PTR_ASSERTION(test, \
893 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
894 * @test: The test context object.
895 * @left: an arbitrary expression that evaluates to a primitive C type.
896 * @right: an arbitrary expression that evaluates to a primitive C type.
898 * Sets an expectation that the value that @left evaluates to is less than the
899 * value that @right evaluates to. This is semantically equivalent to
900 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
903 #define KUNIT_EXPECT_LT(test, left, right) \
904 KUNIT_EXPECT_LT_MSG(test, left, right, NULL)
906 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
907 KUNIT_BINARY_INT_ASSERTION(test, \
914 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
915 * @test: The test context object.
916 * @left: an arbitrary expression that evaluates to a primitive C type.
917 * @right: an arbitrary expression that evaluates to a primitive C type.
919 * Sets an expectation that the value that @left evaluates to is less than or
920 * equal to the value that @right evaluates to. Semantically this is equivalent
921 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
924 #define KUNIT_EXPECT_LE(test, left, right) \
925 KUNIT_EXPECT_LE_MSG(test, left, right, NULL)
927 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
928 KUNIT_BINARY_INT_ASSERTION(test, \
935 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
936 * @test: The test context object.
937 * @left: an arbitrary expression that evaluates to a primitive C type.
938 * @right: an arbitrary expression that evaluates to a primitive C type.
940 * Sets an expectation that the value that @left evaluates to is greater than
941 * the value that @right evaluates to. This is semantically equivalent to
942 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
945 #define KUNIT_EXPECT_GT(test, left, right) \
946 KUNIT_EXPECT_GT_MSG(test, left, right, NULL)
948 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
949 KUNIT_BINARY_INT_ASSERTION(test, \
956 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
957 * @test: The test context object.
958 * @left: an arbitrary expression that evaluates to a primitive C type.
959 * @right: an arbitrary expression that evaluates to a primitive C type.
961 * Sets an expectation that the value that @left evaluates to is greater than
962 * the value that @right evaluates to. This is semantically equivalent to
963 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
966 #define KUNIT_EXPECT_GE(test, left, right) \
967 KUNIT_EXPECT_GE_MSG(test, left, right, NULL)
969 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
970 KUNIT_BINARY_INT_ASSERTION(test, \
977 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
978 * @test: The test context object.
979 * @left: an arbitrary expression that evaluates to a null terminated string.
980 * @right: an arbitrary expression that evaluates to a null terminated string.
982 * Sets an expectation that the values that @left and @right evaluate to are
983 * equal. This is semantically equivalent to
984 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
985 * for more information.
987 #define KUNIT_EXPECT_STREQ(test, left, right) \
988 KUNIT_EXPECT_STREQ_MSG(test, left, right, NULL)
990 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
991 KUNIT_BINARY_STR_ASSERTION(test, \
998 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
999 * @test: The test context object.
1000 * @left: an arbitrary expression that evaluates to a null terminated string.
1001 * @right: an arbitrary expression that evaluates to a null terminated string.
1003 * Sets an expectation that the values that @left and @right evaluate to are
1004 * not equal. This is semantically equivalent to
1005 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1006 * for more information.
1008 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
1009 KUNIT_EXPECT_STRNEQ_MSG(test, left, right, NULL)
1011 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
1012 KUNIT_BINARY_STR_ASSERTION(test, \
1013 KUNIT_EXPECTATION, \
1019 * KUNIT_EXPECT_MEMEQ() - Expects that the first @size bytes of @left and @right are equal.
1020 * @test: The test context object.
1021 * @left: An arbitrary expression that evaluates to the specified size.
1022 * @right: An arbitrary expression that evaluates to the specified size.
1023 * @size: Number of bytes compared.
1025 * Sets an expectation that the values that @left and @right evaluate to are
1026 * equal. This is semantically equivalent to
1027 * KUNIT_EXPECT_TRUE(@test, !memcmp((@left), (@right), (@size))). See
1028 * KUNIT_EXPECT_TRUE() for more information.
1030 * Although this expectation works for any memory block, it is not recommended
1031 * for comparing more structured data, such as structs. This expectation is
1032 * recommended for comparing, for example, data arrays.
1034 #define KUNIT_EXPECT_MEMEQ(test, left, right, size) \
1035 KUNIT_EXPECT_MEMEQ_MSG(test, left, right, size, NULL)
1037 #define KUNIT_EXPECT_MEMEQ_MSG(test, left, right, size, fmt, ...) \
1038 KUNIT_MEM_ASSERTION(test, \
1039 KUNIT_EXPECTATION, \
1046 * KUNIT_EXPECT_MEMNEQ() - Expects that the first @size bytes of @left and @right are not equal.
1047 * @test: The test context object.
1048 * @left: An arbitrary expression that evaluates to the specified size.
1049 * @right: An arbitrary expression that evaluates to the specified size.
1050 * @size: Number of bytes compared.
1052 * Sets an expectation that the values that @left and @right evaluate to are
1053 * not equal. This is semantically equivalent to
1054 * KUNIT_EXPECT_TRUE(@test, memcmp((@left), (@right), (@size))). See
1055 * KUNIT_EXPECT_TRUE() for more information.
1057 * Although this expectation works for any memory block, it is not recommended
1058 * for comparing more structured data, such as structs. This expectation is
1059 * recommended for comparing, for example, data arrays.
1061 #define KUNIT_EXPECT_MEMNEQ(test, left, right, size) \
1062 KUNIT_EXPECT_MEMNEQ_MSG(test, left, right, size, NULL)
1064 #define KUNIT_EXPECT_MEMNEQ_MSG(test, left, right, size, fmt, ...) \
1065 KUNIT_MEM_ASSERTION(test, \
1066 KUNIT_EXPECTATION, \
1073 * KUNIT_EXPECT_NULL() - Expects that @ptr is null.
1074 * @test: The test context object.
1075 * @ptr: an arbitrary pointer.
1077 * Sets an expectation that the value that @ptr evaluates to is null. This is
1078 * semantically equivalent to KUNIT_EXPECT_PTR_EQ(@test, ptr, NULL).
1079 * See KUNIT_EXPECT_TRUE() for more information.
1081 #define KUNIT_EXPECT_NULL(test, ptr) \
1082 KUNIT_EXPECT_NULL_MSG(test, \
1086 #define KUNIT_EXPECT_NULL_MSG(test, ptr, fmt, ...) \
1087 KUNIT_BINARY_PTR_ASSERTION(test, \
1088 KUNIT_EXPECTATION, \
1094 * KUNIT_EXPECT_NOT_NULL() - Expects that @ptr is not null.
1095 * @test: The test context object.
1096 * @ptr: an arbitrary pointer.
1098 * Sets an expectation that the value that @ptr evaluates to is not null. This
1099 * is semantically equivalent to KUNIT_EXPECT_PTR_NE(@test, ptr, NULL).
1100 * See KUNIT_EXPECT_TRUE() for more information.
1102 #define KUNIT_EXPECT_NOT_NULL(test, ptr) \
1103 KUNIT_EXPECT_NOT_NULL_MSG(test, \
1107 #define KUNIT_EXPECT_NOT_NULL_MSG(test, ptr, fmt, ...) \
1108 KUNIT_BINARY_PTR_ASSERTION(test, \
1109 KUNIT_EXPECTATION, \
1115 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
1116 * @test: The test context object.
1117 * @ptr: an arbitrary pointer.
1119 * Sets an expectation that the value that @ptr evaluates to is not null and not
1120 * an errno stored in a pointer. This is semantically equivalent to
1121 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
1124 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
1125 KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
1127 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1128 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1129 KUNIT_EXPECTATION, \
1134 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
1135 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
1138 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
1139 * @test: The test context object.
1140 * @condition: an arbitrary boolean expression. The test fails and aborts when
1141 * this does not evaluate to true.
1143 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1144 * fail *and immediately abort* when the specified condition is not met. Unlike
1145 * an expectation failure, it will prevent the test case from continuing to run;
1146 * this is otherwise known as an *assertion failure*.
1148 #define KUNIT_ASSERT_TRUE(test, condition) \
1149 KUNIT_ASSERT_TRUE_MSG(test, condition, NULL)
1151 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
1152 KUNIT_TRUE_MSG_ASSERTION(test, \
1159 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
1160 * @test: The test context object.
1161 * @condition: an arbitrary boolean expression.
1163 * Sets an assertion that the value that @condition evaluates to is false. This
1164 * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
1165 * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1167 #define KUNIT_ASSERT_FALSE(test, condition) \
1168 KUNIT_ASSERT_FALSE_MSG(test, condition, NULL)
1170 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
1171 KUNIT_FALSE_MSG_ASSERTION(test, \
1178 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
1179 * @test: The test context object.
1180 * @left: an arbitrary expression that evaluates to a primitive C type.
1181 * @right: an arbitrary expression that evaluates to a primitive C type.
1183 * Sets an assertion that the values that @left and @right evaluate to are
1184 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1185 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1187 #define KUNIT_ASSERT_EQ(test, left, right) \
1188 KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
1190 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
1191 KUNIT_BINARY_INT_ASSERTION(test, \
1198 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1199 * @test: The test context object.
1200 * @left: an arbitrary expression that evaluates to a pointer.
1201 * @right: an arbitrary expression that evaluates to a pointer.
1203 * Sets an assertion that the values that @left and @right evaluate to are
1204 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1205 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1207 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
1208 KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, NULL)
1210 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1211 KUNIT_BINARY_PTR_ASSERTION(test, \
1218 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
1219 * @test: The test context object.
1220 * @left: an arbitrary expression that evaluates to a primitive C type.
1221 * @right: an arbitrary expression that evaluates to a primitive C type.
1223 * Sets an assertion that the values that @left and @right evaluate to are not
1224 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1225 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1227 #define KUNIT_ASSERT_NE(test, left, right) \
1228 KUNIT_ASSERT_NE_MSG(test, left, right, NULL)
1230 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
1231 KUNIT_BINARY_INT_ASSERTION(test, \
1238 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
1239 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1240 * @test: The test context object.
1241 * @left: an arbitrary expression that evaluates to a pointer.
1242 * @right: an arbitrary expression that evaluates to a pointer.
1244 * Sets an assertion that the values that @left and @right evaluate to are not
1245 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1246 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1248 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
1249 KUNIT_ASSERT_PTR_NE_MSG(test, left, right, NULL)
1251 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
1252 KUNIT_BINARY_PTR_ASSERTION(test, \
1258 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
1259 * @test: The test context object.
1260 * @left: an arbitrary expression that evaluates to a primitive C type.
1261 * @right: an arbitrary expression that evaluates to a primitive C type.
1263 * Sets an assertion that the value that @left evaluates to is less than the
1264 * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
1265 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1268 #define KUNIT_ASSERT_LT(test, left, right) \
1269 KUNIT_ASSERT_LT_MSG(test, left, right, NULL)
1271 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
1272 KUNIT_BINARY_INT_ASSERTION(test, \
1278 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
1279 * @test: The test context object.
1280 * @left: an arbitrary expression that evaluates to a primitive C type.
1281 * @right: an arbitrary expression that evaluates to a primitive C type.
1283 * Sets an assertion that the value that @left evaluates to is less than or
1284 * equal to the value that @right evaluates to. This is the same as
1285 * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
1286 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1288 #define KUNIT_ASSERT_LE(test, left, right) \
1289 KUNIT_ASSERT_LE_MSG(test, left, right, NULL)
1291 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
1292 KUNIT_BINARY_INT_ASSERTION(test, \
1299 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
1300 * @test: The test context object.
1301 * @left: an arbitrary expression that evaluates to a primitive C type.
1302 * @right: an arbitrary expression that evaluates to a primitive C type.
1304 * Sets an assertion that the value that @left evaluates to is greater than the
1305 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
1306 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1309 #define KUNIT_ASSERT_GT(test, left, right) \
1310 KUNIT_ASSERT_GT_MSG(test, left, right, NULL)
1312 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
1313 KUNIT_BINARY_INT_ASSERTION(test, \
1320 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
1321 * @test: The test context object.
1322 * @left: an arbitrary expression that evaluates to a primitive C type.
1323 * @right: an arbitrary expression that evaluates to a primitive C type.
1325 * Sets an assertion that the value that @left evaluates to is greater than the
1326 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
1327 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1330 #define KUNIT_ASSERT_GE(test, left, right) \
1331 KUNIT_ASSERT_GE_MSG(test, left, right, NULL)
1333 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
1334 KUNIT_BINARY_INT_ASSERTION(test, \
1341 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
1342 * @test: The test context object.
1343 * @left: an arbitrary expression that evaluates to a null terminated string.
1344 * @right: an arbitrary expression that evaluates to a null terminated string.
1346 * Sets an assertion that the values that @left and @right evaluate to are
1347 * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
1348 * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1350 #define KUNIT_ASSERT_STREQ(test, left, right) \
1351 KUNIT_ASSERT_STREQ_MSG(test, left, right, NULL)
1353 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
1354 KUNIT_BINARY_STR_ASSERTION(test, \
1361 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
1362 * @test: The test context object.
1363 * @left: an arbitrary expression that evaluates to a null terminated string.
1364 * @right: an arbitrary expression that evaluates to a null terminated string.
1366 * Sets an expectation that the values that @left and @right evaluate to are
1367 * not equal. This is semantically equivalent to
1368 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1369 * for more information.
1371 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
1372 KUNIT_ASSERT_STRNEQ_MSG(test, left, right, NULL)
1374 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
1375 KUNIT_BINARY_STR_ASSERTION(test, \
1382 * KUNIT_ASSERT_NULL() - Asserts that pointers @ptr is null.
1383 * @test: The test context object.
1384 * @ptr: an arbitrary pointer.
1386 * Sets an assertion that the values that @ptr evaluates to is null. This is
1387 * the same as KUNIT_EXPECT_NULL(), except it causes an assertion
1388 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1390 #define KUNIT_ASSERT_NULL(test, ptr) \
1391 KUNIT_ASSERT_NULL_MSG(test, \
1395 #define KUNIT_ASSERT_NULL_MSG(test, ptr, fmt, ...) \
1396 KUNIT_BINARY_PTR_ASSERTION(test, \
1403 * KUNIT_ASSERT_NOT_NULL() - Asserts that pointers @ptr is not null.
1404 * @test: The test context object.
1405 * @ptr: an arbitrary pointer.
1407 * Sets an assertion that the values that @ptr evaluates to is not null. This
1408 * is the same as KUNIT_EXPECT_NOT_NULL(), except it causes an assertion
1409 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1411 #define KUNIT_ASSERT_NOT_NULL(test, ptr) \
1412 KUNIT_ASSERT_NOT_NULL_MSG(test, \
1416 #define KUNIT_ASSERT_NOT_NULL_MSG(test, ptr, fmt, ...) \
1417 KUNIT_BINARY_PTR_ASSERTION(test, \
1424 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
1425 * @test: The test context object.
1426 * @ptr: an arbitrary pointer.
1428 * Sets an assertion that the value that @ptr evaluates to is not null and not
1429 * an errno stored in a pointer. This is the same as
1430 * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
1431 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1433 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
1434 KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
1436 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1437 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1444 * KUNIT_ARRAY_PARAM() - Define test parameter generator from an array.
1445 * @name: prefix for the test parameter generator function.
1446 * @array: array of test parameters.
1447 * @get_desc: function to convert param to description; NULL to use default
1449 * Define function @name_gen_params which uses @array to generate parameters.
1451 #define KUNIT_ARRAY_PARAM(name, array, get_desc) \
1452 static const void *name##_gen_params(const void *prev, char *desc) \
1454 typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \
1455 if (__next - (array) < ARRAY_SIZE((array))) { \
1456 void (*__get_desc)(typeof(__next), char *) = get_desc; \
1458 __get_desc(__next, desc); \
1464 // TODO(dlatypov@google.com): consider eventually migrating users to explicitly
1465 // include resource.h themselves if they need it.
1466 #include <kunit/resource.h>
1468 #endif /* _KUNIT_TEST_H */