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>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/types.h>
18 #include <linux/kref.h>
20 struct kunit_resource;
22 typedef int (*kunit_resource_init_t)(struct kunit_resource *, void *);
23 typedef void (*kunit_resource_free_t)(struct kunit_resource *);
26 * struct kunit_resource - represents a *test managed resource*
27 * @data: for the user to store arbitrary data.
28 * @free: a user supplied function to free the resource. Populated by
29 * kunit_resource_alloc().
31 * Represents a *test managed resource*, a resource which will automatically be
32 * cleaned up at the end of a test case.
34 * Resources are reference counted so if a resource is retrieved via
35 * kunit_alloc_and_get_resource() or kunit_find_resource(), we need
36 * to call kunit_put_resource() to reduce the resource reference count
37 * when finished with it. Note that kunit_alloc_resource() does not require a
38 * kunit_resource_put() because it does not retrieve the resource itself.
44 * struct kunit_kmalloc_params {
49 * static int kunit_kmalloc_init(struct kunit_resource *res, void *context)
51 * struct kunit_kmalloc_params *params = context;
52 * res->data = kmalloc(params->size, params->gfp);
60 * static void kunit_kmalloc_free(struct kunit_resource *res)
65 * void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp)
67 * struct kunit_kmalloc_params params;
72 * return kunit_alloc_resource(test, kunit_kmalloc_init,
73 * kunit_kmalloc_free, ¶ms);
76 * Resources can also be named, with lookup/removal done on a name
77 * basis also. kunit_add_named_resource(), kunit_find_named_resource()
78 * and kunit_destroy_named_resource(). Resource names must be
79 * unique within the test instance.
81 struct kunit_resource {
83 const char *name; /* optional name */
85 /* private: internal use only. */
86 kunit_resource_free_t free;
88 struct list_head node;
93 /* Size of log associated with test. */
94 #define KUNIT_LOG_SIZE 512
97 * TAP specifies subtest stream indentation of 4 spaces, 8 spaces for a
98 * sub-subtest. See the "Subtests" section in
99 * https://node-tap.org/tap-protocol/
101 #define KUNIT_SUBTEST_INDENT " "
102 #define KUNIT_SUBSUBTEST_INDENT " "
105 * struct kunit_case - represents an individual test case.
107 * @run_case: the function representing the actual test case.
108 * @name: the name of the test case.
110 * A test case is a function with the signature,
111 * ``void (*)(struct kunit *)``
112 * that makes expectations and assertions (see KUNIT_EXPECT_TRUE() and
113 * KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated
114 * with a &struct kunit_suite and will be run after the suite's init
115 * function and followed by the suite's exit function.
117 * A test case should be static and should only be created with the
118 * KUNIT_CASE() macro; additionally, every array of test cases should be
119 * terminated with an empty test case.
125 * void add_test_basic(struct kunit *test)
127 * KUNIT_EXPECT_EQ(test, 1, add(1, 0));
128 * KUNIT_EXPECT_EQ(test, 2, add(1, 1));
129 * KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
130 * KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
131 * KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
134 * static struct kunit_case example_test_cases[] = {
135 * KUNIT_CASE(add_test_basic),
141 void (*run_case)(struct kunit *test);
144 /* private: internal use only. */
149 static inline char *kunit_status_to_string(bool status)
151 return status ? "ok" : "not ok";
155 * KUNIT_CASE - A helper for creating a &struct kunit_case
157 * @test_name: a reference to a test case function.
159 * Takes a symbol for a function representing a test case and creates a
160 * &struct kunit_case object from it. See the documentation for
161 * &struct kunit_case for an example on how to use it.
163 #define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }
166 * struct kunit_suite - describes a related collection of &struct kunit_case
168 * @name: the name of the test. Purely informational.
169 * @init: called before every test case.
170 * @exit: called after every test case.
171 * @test_cases: a null terminated array of test cases.
173 * A kunit_suite is a collection of related &struct kunit_case s, such that
174 * @init is called before every test case and @exit is called after every
175 * test case, similar to the notion of a *test fixture* or a *test class*
176 * in other unit testing frameworks like JUnit or Googletest.
178 * Every &struct kunit_case must be associated with a kunit_suite for KUnit
182 const char name[256];
183 int (*init)(struct kunit *test);
184 void (*exit)(struct kunit *test);
185 struct kunit_case *test_cases;
187 /* private: internal use only */
188 struct dentry *debugfs;
193 * struct kunit - represents a running instance of a test.
195 * @priv: for user to store arbitrary data. Commonly used to pass data
196 * created in the init function (see &struct kunit_suite).
198 * Used to store information about the current context under which the test
199 * is running. Most of this data is private and should only be accessed
200 * indirectly via public functions; the one exception is @priv which can be
201 * used by the test writer to store arbitrary data.
206 /* private: internal use only. */
207 const char *name; /* Read only after initialization! */
208 char *log; /* Points at case log after initialization */
209 struct kunit_try_catch try_catch;
211 * success starts as true, and may only be set to false during a
212 * test case; thus, it is safe to update this across multiple
213 * threads using WRITE_ONCE; however, as a consequence, it may only
214 * be read after the test case finishes once all threads associated
215 * with the test case have terminated.
217 bool success; /* Read only after test_case finishes! */
218 spinlock_t lock; /* Guards all mutable test state. */
220 * Because resources is a list that may be updated multiple times (with
221 * new resources) from any thread associated with a test case, we must
222 * protect it with some type of lock.
224 struct list_head resources; /* Protected by lock. */
227 void kunit_init_test(struct kunit *test, const char *name, char *log);
229 int kunit_run_tests(struct kunit_suite *suite);
231 size_t kunit_suite_num_test_cases(struct kunit_suite *suite);
233 unsigned int kunit_test_case_num(struct kunit_suite *suite,
234 struct kunit_case *test_case);
236 int __kunit_test_suites_init(struct kunit_suite **suites);
238 void __kunit_test_suites_exit(struct kunit_suite **suites);
241 * kunit_test_suites() - used to register one or more &struct kunit_suite
244 * @suites_list...: a statically allocated list of &struct kunit_suite.
246 * Registers @suites_list with the test framework. See &struct kunit_suite for
249 * When builtin, KUnit tests are all run as late_initcalls; this means
250 * that they cannot test anything where tests must run at a different init
251 * phase. One significant restriction resulting from this is that KUnit
252 * cannot reliably test anything that is initialize in the late_init phase;
253 * another is that KUnit is useless to test things that need to be run in
254 * an earlier init phase.
256 * An alternative is to build the tests as a module. Because modules
257 * do not support multiple late_initcall()s, we need to initialize an
258 * array of suites for a module.
260 * TODO(brendanhiggins@google.com): Don't run all KUnit tests as
261 * late_initcalls. I have some future work planned to dispatch all KUnit
262 * tests from the same place, and at the very least to do so after
263 * everything else is definitely initialized.
265 #define kunit_test_suites(suites_list...) \
266 static struct kunit_suite *suites[] = {suites_list, NULL}; \
267 static int kunit_test_suites_init(void) \
269 return __kunit_test_suites_init(suites); \
271 late_initcall(kunit_test_suites_init); \
272 static void __exit kunit_test_suites_exit(void) \
274 return __kunit_test_suites_exit(suites); \
276 module_exit(kunit_test_suites_exit)
278 #define kunit_test_suite(suite) kunit_test_suites(&suite)
280 #define kunit_suite_for_each_test_case(suite, test_case) \
281 for (test_case = suite->test_cases; test_case->run_case; test_case++)
283 bool kunit_suite_has_succeeded(struct kunit_suite *suite);
286 * Like kunit_alloc_resource() below, but returns the struct kunit_resource
287 * object that contains the allocation. This is mostly for testing purposes.
289 struct kunit_resource *kunit_alloc_and_get_resource(struct kunit *test,
290 kunit_resource_init_t init,
291 kunit_resource_free_t free,
296 * kunit_get_resource() - Hold resource for use. Should not need to be used
297 * by most users as we automatically get resources
298 * retrieved by kunit_find_resource*().
301 static inline void kunit_get_resource(struct kunit_resource *res)
303 kref_get(&res->refcount);
307 * Called when refcount reaches zero via kunit_put_resources();
308 * should not be called directly.
310 static inline void kunit_release_resource(struct kref *kref)
312 struct kunit_resource *res = container_of(kref, struct kunit_resource,
315 /* If free function is defined, resource was dynamically allocated. */
323 * kunit_put_resource() - When caller is done with retrieved resource,
324 * kunit_put_resource() should be called to drop
325 * reference count. The resource list maintains
326 * a reference count on resources, so if no users
327 * are utilizing a resource and it is removed from
328 * the resource list, it will be freed via the
329 * associated free function (if any). Only
330 * needs to be used if we alloc_and_get() or
334 static inline void kunit_put_resource(struct kunit_resource *res)
336 kref_put(&res->refcount, kunit_release_resource);
340 * kunit_add_resource() - Add a *test managed resource*.
341 * @test: The test context object.
342 * @init: a user-supplied function to initialize the result (if needed). If
343 * none is supplied, the resource data value is simply set to @data.
344 * If an init function is supplied, @data is passed to it instead.
345 * @free: a user-supplied function to free the resource (if needed).
346 * @data: value to pass to init function or set in resource data field.
348 int kunit_add_resource(struct kunit *test,
349 kunit_resource_init_t init,
350 kunit_resource_free_t free,
351 struct kunit_resource *res,
355 * kunit_add_named_resource() - Add a named *test managed resource*.
356 * @test: The test context object.
357 * @init: a user-supplied function to initialize the resource data, if needed.
358 * @free: a user-supplied function to free the resource data, if needed.
359 * @name_data: name and data to be set for resource.
361 int kunit_add_named_resource(struct kunit *test,
362 kunit_resource_init_t init,
363 kunit_resource_free_t free,
364 struct kunit_resource *res,
369 * kunit_alloc_resource() - Allocates a *test managed resource*.
370 * @test: The test context object.
371 * @init: a user supplied function to initialize the resource.
372 * @free: a user supplied function to free the resource.
373 * @internal_gfp: gfp to use for internal allocations, if unsure, use GFP_KERNEL
374 * @context: for the user to pass in arbitrary data to the init function.
376 * Allocates a *test managed resource*, a resource which will automatically be
377 * cleaned up at the end of a test case. See &struct kunit_resource for an
380 * Note: KUnit needs to allocate memory for a kunit_resource object. You must
381 * specify an @internal_gfp that is compatible with the use context of your
384 static inline void *kunit_alloc_resource(struct kunit *test,
385 kunit_resource_init_t init,
386 kunit_resource_free_t free,
390 struct kunit_resource *res;
392 res = kzalloc(sizeof(*res), internal_gfp);
396 if (!kunit_add_resource(test, init, free, res, context))
402 typedef bool (*kunit_resource_match_t)(struct kunit *test,
403 struct kunit_resource *res,
407 * kunit_resource_instance_match() - Match a resource with the same instance.
408 * @test: Test case to which the resource belongs.
409 * @res: The resource.
410 * @match_data: The resource pointer to match against.
412 * An instance of kunit_resource_match_t that matches a resource whose
413 * allocation matches @match_data.
415 static inline bool kunit_resource_instance_match(struct kunit *test,
416 struct kunit_resource *res,
419 return res->data == match_data;
423 * kunit_resource_name_match() - Match a resource with the same name.
424 * @test: Test case to which the resource belongs.
425 * @res: The resource.
426 * @match_name: The name to match against.
428 static inline bool kunit_resource_name_match(struct kunit *test,
429 struct kunit_resource *res,
432 return res->name && strcmp(res->name, match_name) == 0;
436 * kunit_find_resource() - Find a resource using match function/data.
437 * @test: Test case to which the resource belongs.
438 * @match: match function to be applied to resources/match data.
439 * @match_data: data to be used in matching.
441 static inline struct kunit_resource *
442 kunit_find_resource(struct kunit *test,
443 kunit_resource_match_t match,
446 struct kunit_resource *res, *found = NULL;
448 spin_lock(&test->lock);
450 list_for_each_entry_reverse(res, &test->resources, node) {
451 if (match(test, res, (void *)match_data)) {
453 kunit_get_resource(found);
458 spin_unlock(&test->lock);
464 * kunit_find_named_resource() - Find a resource using match name.
465 * @test: Test case to which the resource belongs.
468 static inline struct kunit_resource *
469 kunit_find_named_resource(struct kunit *test,
472 return kunit_find_resource(test, kunit_resource_name_match,
477 * kunit_destroy_resource() - Find a kunit_resource and destroy it.
478 * @test: Test case to which the resource belongs.
479 * @match: Match function. Returns whether a given resource matches @match_data.
480 * @match_data: Data passed into @match.
483 * 0 if kunit_resource is found and freed, -ENOENT if not found.
485 int kunit_destroy_resource(struct kunit *test,
486 kunit_resource_match_t match,
489 static inline int kunit_destroy_named_resource(struct kunit *test,
492 return kunit_destroy_resource(test, kunit_resource_name_match,
497 * kunit_remove_resource: remove resource from resource list associated with
499 * @test: The test context object.
500 * @res: The resource to be removed.
502 * Note that the resource will not be immediately freed since it is likely
503 * the caller has a reference to it via alloc_and_get() or find();
504 * in this case a final call to kunit_put_resource() is required.
506 void kunit_remove_resource(struct kunit *test, struct kunit_resource *res);
509 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
510 * @test: The test context object.
511 * @size: The size in bytes of the desired memory.
512 * @gfp: flags passed to underlying kmalloc().
514 * Just like `kmalloc(...)`, except the allocation is managed by the test case
515 * and is automatically cleaned up after the test case concludes. See &struct
516 * kunit_resource for more information.
518 void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp);
521 * kunit_kfree() - Like kfree except for allocations managed by KUnit.
522 * @test: The test case to which the resource belongs.
523 * @ptr: The memory allocation to free.
525 void kunit_kfree(struct kunit *test, const void *ptr);
528 * kunit_kzalloc() - Just like kunit_kmalloc(), but zeroes the allocation.
529 * @test: The test context object.
530 * @size: The size in bytes of the desired memory.
531 * @gfp: flags passed to underlying kmalloc().
533 * See kzalloc() and kunit_kmalloc() for more information.
535 static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp)
537 return kunit_kmalloc(test, size, gfp | __GFP_ZERO);
540 void kunit_cleanup(struct kunit *test);
542 void kunit_log_append(char *log, const char *fmt, ...);
545 * printk and log to per-test or per-suite log buffer. Logging only done
546 * if CONFIG_KUNIT_DEBUGFS is 'y'; if it is 'n', no log is allocated/used.
548 #define kunit_log(lvl, test_or_suite, fmt, ...) \
550 printk(lvl fmt, ##__VA_ARGS__); \
551 kunit_log_append((test_or_suite)->log, fmt "\n", \
555 #define kunit_printk(lvl, test, fmt, ...) \
556 kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \
557 (test)->name, ##__VA_ARGS__)
560 * kunit_info() - Prints an INFO level message associated with @test.
562 * @test: The test context object.
563 * @fmt: A printk() style format string.
565 * Prints an info level message associated with the test suite being run.
566 * Takes a variable number of format parameters just like printk().
568 #define kunit_info(test, fmt, ...) \
569 kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
572 * kunit_warn() - Prints a WARN level message associated with @test.
574 * @test: The test context object.
575 * @fmt: A printk() style format string.
577 * Prints a warning level message.
579 #define kunit_warn(test, fmt, ...) \
580 kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
583 * kunit_err() - Prints an ERROR level message associated with @test.
585 * @test: The test context object.
586 * @fmt: A printk() style format string.
588 * Prints an error level message.
590 #define kunit_err(test, fmt, ...) \
591 kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
594 * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
595 * @test: The test context object.
597 * The opposite of KUNIT_FAIL(), it is an expectation that cannot fail. In other
598 * words, it does nothing and only exists for code clarity. See
599 * KUNIT_EXPECT_TRUE() for more information.
601 #define KUNIT_SUCCEED(test) do {} while (0)
603 void kunit_do_assertion(struct kunit *test,
604 struct kunit_assert *assert,
606 const char *fmt, ...);
608 #define KUNIT_ASSERTION(test, pass, assert_class, INITIALIZER, fmt, ...) do { \
609 struct assert_class __assertion = INITIALIZER; \
610 kunit_do_assertion(test, \
611 &__assertion.assert, \
618 #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \
619 KUNIT_ASSERTION(test, \
622 KUNIT_INIT_FAIL_ASSERT_STRUCT(test, assert_type), \
627 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
628 * @test: The test context object.
629 * @fmt: an informational message to be printed when the assertion is made.
630 * @...: string format arguments.
632 * The opposite of KUNIT_SUCCEED(), it is an expectation that always fails. In
633 * other words, it always results in a failed expectation, and consequently
634 * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
635 * for more information.
637 #define KUNIT_FAIL(test, fmt, ...) \
638 KUNIT_FAIL_ASSERTION(test, \
643 #define KUNIT_UNARY_ASSERTION(test, \
649 KUNIT_ASSERTION(test, \
650 !!(condition) == !!expected_true, \
651 kunit_unary_assert, \
652 KUNIT_INIT_UNARY_ASSERT_STRUCT(test, \
659 #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
660 KUNIT_UNARY_ASSERTION(test, \
667 #define KUNIT_TRUE_ASSERTION(test, assert_type, condition) \
668 KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, NULL)
670 #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
671 KUNIT_UNARY_ASSERTION(test, \
678 #define KUNIT_FALSE_ASSERTION(test, assert_type, condition) \
679 KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, NULL)
682 * A factory macro for defining the assertions and expectations for the basic
683 * comparisons defined for the built in types.
685 * Unfortunately, there is no common type that all types can be promoted to for
686 * which all the binary operators behave the same way as for the actual types
687 * (for example, there is no type that long long and unsigned long long can
688 * both be cast to where the comparison result is preserved for all values). So
689 * the best we can do is do the comparison in the original types and then coerce
690 * everything to long long for printing; this way, the comparison behaves
691 * correctly and the printed out value usually makes sense without
692 * interpretation, but can always be interpreted to figure out the actual
695 #define KUNIT_BASE_BINARY_ASSERTION(test, \
705 typeof(left) __left = (left); \
706 typeof(right) __right = (right); \
707 ((void)__typecheck(__left, __right)); \
709 KUNIT_ASSERTION(test, \
712 ASSERT_CLASS_INIT(test, \
723 #define KUNIT_BASE_EQ_MSG_ASSERTION(test, \
731 KUNIT_BASE_BINARY_ASSERTION(test, \
739 #define KUNIT_BASE_NE_MSG_ASSERTION(test, \
747 KUNIT_BASE_BINARY_ASSERTION(test, \
755 #define KUNIT_BASE_LT_MSG_ASSERTION(test, \
763 KUNIT_BASE_BINARY_ASSERTION(test, \
771 #define KUNIT_BASE_LE_MSG_ASSERTION(test, \
779 KUNIT_BASE_BINARY_ASSERTION(test, \
787 #define KUNIT_BASE_GT_MSG_ASSERTION(test, \
795 KUNIT_BASE_BINARY_ASSERTION(test, \
803 #define KUNIT_BASE_GE_MSG_ASSERTION(test, \
811 KUNIT_BASE_BINARY_ASSERTION(test, \
819 #define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
820 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
821 kunit_binary_assert, \
822 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
829 #define KUNIT_BINARY_EQ_ASSERTION(test, assert_type, left, right) \
830 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
836 #define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
842 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
843 kunit_binary_ptr_assert, \
844 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
851 #define KUNIT_BINARY_PTR_EQ_ASSERTION(test, assert_type, left, right) \
852 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
858 #define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
859 KUNIT_BASE_NE_MSG_ASSERTION(test, \
860 kunit_binary_assert, \
861 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
868 #define KUNIT_BINARY_NE_ASSERTION(test, assert_type, left, right) \
869 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
875 #define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
881 KUNIT_BASE_NE_MSG_ASSERTION(test, \
882 kunit_binary_ptr_assert, \
883 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
890 #define KUNIT_BINARY_PTR_NE_ASSERTION(test, assert_type, left, right) \
891 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
897 #define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
898 KUNIT_BASE_LT_MSG_ASSERTION(test, \
899 kunit_binary_assert, \
900 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
907 #define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right) \
908 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
914 #define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
920 KUNIT_BASE_LT_MSG_ASSERTION(test, \
921 kunit_binary_ptr_assert, \
922 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
929 #define KUNIT_BINARY_PTR_LT_ASSERTION(test, assert_type, left, right) \
930 KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
936 #define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
937 KUNIT_BASE_LE_MSG_ASSERTION(test, \
938 kunit_binary_assert, \
939 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
946 #define KUNIT_BINARY_LE_ASSERTION(test, assert_type, left, right) \
947 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
953 #define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
959 KUNIT_BASE_LE_MSG_ASSERTION(test, \
960 kunit_binary_ptr_assert, \
961 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
968 #define KUNIT_BINARY_PTR_LE_ASSERTION(test, assert_type, left, right) \
969 KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
975 #define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
976 KUNIT_BASE_GT_MSG_ASSERTION(test, \
977 kunit_binary_assert, \
978 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
985 #define KUNIT_BINARY_GT_ASSERTION(test, assert_type, left, right) \
986 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
992 #define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
998 KUNIT_BASE_GT_MSG_ASSERTION(test, \
999 kunit_binary_ptr_assert, \
1000 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
1007 #define KUNIT_BINARY_PTR_GT_ASSERTION(test, assert_type, left, right) \
1008 KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
1014 #define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
1015 KUNIT_BASE_GE_MSG_ASSERTION(test, \
1016 kunit_binary_assert, \
1017 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
1024 #define KUNIT_BINARY_GE_ASSERTION(test, assert_type, left, right) \
1025 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1031 #define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
1037 KUNIT_BASE_GE_MSG_ASSERTION(test, \
1038 kunit_binary_ptr_assert, \
1039 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
1046 #define KUNIT_BINARY_PTR_GE_ASSERTION(test, assert_type, left, right) \
1047 KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
1053 #define KUNIT_BINARY_STR_ASSERTION(test, \
1061 typeof(left) __left = (left); \
1062 typeof(right) __right = (right); \
1064 KUNIT_ASSERTION(test, \
1065 strcmp(__left, __right) op 0, \
1066 kunit_binary_str_assert, \
1067 KUNIT_INIT_BINARY_ASSERT_STRUCT(test, \
1078 #define KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1084 KUNIT_BINARY_STR_ASSERTION(test, \
1090 #define KUNIT_BINARY_STR_EQ_ASSERTION(test, assert_type, left, right) \
1091 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1097 #define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1103 KUNIT_BINARY_STR_ASSERTION(test, \
1109 #define KUNIT_BINARY_STR_NE_ASSERTION(test, assert_type, left, right) \
1110 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1116 #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1122 typeof(ptr) __ptr = (ptr); \
1124 KUNIT_ASSERTION(test, \
1125 !IS_ERR_OR_NULL(__ptr), \
1126 kunit_ptr_not_err_assert, \
1127 KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, \
1135 #define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \
1136 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1142 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
1143 * @test: The test context object.
1144 * @condition: an arbitrary boolean expression. The test fails when this does
1145 * not evaluate to true.
1147 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
1148 * to fail when the specified condition is not met; however, it will not prevent
1149 * the test case from continuing to run; this is otherwise known as an
1150 * *expectation failure*.
1152 #define KUNIT_EXPECT_TRUE(test, condition) \
1153 KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1155 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
1156 KUNIT_TRUE_MSG_ASSERTION(test, \
1157 KUNIT_EXPECTATION, \
1163 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
1164 * @test: The test context object.
1165 * @condition: an arbitrary boolean expression. The test fails when this does
1166 * not evaluate to false.
1168 * Sets an expectation that @condition evaluates to false. See
1169 * KUNIT_EXPECT_TRUE() for more information.
1171 #define KUNIT_EXPECT_FALSE(test, condition) \
1172 KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1174 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
1175 KUNIT_FALSE_MSG_ASSERTION(test, \
1176 KUNIT_EXPECTATION, \
1182 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
1183 * @test: The test context object.
1184 * @left: an arbitrary expression that evaluates to a primitive C type.
1185 * @right: an arbitrary expression that evaluates to a primitive C type.
1187 * Sets an expectation that the values that @left and @right evaluate to are
1188 * equal. This is semantically equivalent to
1189 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1192 #define KUNIT_EXPECT_EQ(test, left, right) \
1193 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1195 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
1196 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1197 KUNIT_EXPECTATION, \
1204 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
1205 * @test: The test context object.
1206 * @left: an arbitrary expression that evaluates to a pointer.
1207 * @right: an arbitrary expression that evaluates to a pointer.
1209 * Sets an expectation that the values that @left and @right evaluate to are
1210 * equal. This is semantically equivalent to
1211 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1214 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
1215 KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
1216 KUNIT_EXPECTATION, \
1220 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1221 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1222 KUNIT_EXPECTATION, \
1229 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
1230 * @test: The test context object.
1231 * @left: an arbitrary expression that evaluates to a primitive C type.
1232 * @right: an arbitrary expression that evaluates to a primitive C type.
1234 * Sets an expectation that the values that @left and @right evaluate to are not
1235 * equal. This is semantically equivalent to
1236 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1239 #define KUNIT_EXPECT_NE(test, left, right) \
1240 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1242 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
1243 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1244 KUNIT_EXPECTATION, \
1251 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
1252 * @test: The test context object.
1253 * @left: an arbitrary expression that evaluates to a pointer.
1254 * @right: an arbitrary expression that evaluates to a pointer.
1256 * Sets an expectation that the values that @left and @right evaluate to are not
1257 * equal. This is semantically equivalent to
1258 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1261 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
1262 KUNIT_BINARY_PTR_NE_ASSERTION(test, \
1263 KUNIT_EXPECTATION, \
1267 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
1268 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1269 KUNIT_EXPECTATION, \
1276 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
1277 * @test: The test context object.
1278 * @left: an arbitrary expression that evaluates to a primitive C type.
1279 * @right: an arbitrary expression that evaluates to a primitive C type.
1281 * Sets an expectation that the value that @left evaluates to is less than the
1282 * value that @right evaluates to. This is semantically equivalent to
1283 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
1286 #define KUNIT_EXPECT_LT(test, left, right) \
1287 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1289 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
1290 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1291 KUNIT_EXPECTATION, \
1298 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
1299 * @test: The test context object.
1300 * @left: an arbitrary expression that evaluates to a primitive C type.
1301 * @right: an arbitrary expression that evaluates to a primitive C type.
1303 * Sets an expectation that the value that @left evaluates to is less than or
1304 * equal to the value that @right evaluates to. Semantically this is equivalent
1305 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
1308 #define KUNIT_EXPECT_LE(test, left, right) \
1309 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1311 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
1312 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1313 KUNIT_EXPECTATION, \
1320 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @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 expectation that the value that @left evaluates to is greater than
1326 * the value that @right evaluates to. This is semantically equivalent to
1327 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
1330 #define KUNIT_EXPECT_GT(test, left, right) \
1331 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1333 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
1334 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1335 KUNIT_EXPECTATION, \
1342 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
1343 * @test: The test context object.
1344 * @left: an arbitrary expression that evaluates to a primitive C type.
1345 * @right: an arbitrary expression that evaluates to a primitive C type.
1347 * Sets an expectation that the value that @left evaluates to is greater than
1348 * the value that @right evaluates to. This is semantically equivalent to
1349 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
1352 #define KUNIT_EXPECT_GE(test, left, right) \
1353 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1355 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
1356 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1357 KUNIT_EXPECTATION, \
1364 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
1365 * @test: The test context object.
1366 * @left: an arbitrary expression that evaluates to a null terminated string.
1367 * @right: an arbitrary expression that evaluates to a null terminated string.
1369 * Sets an expectation that the values that @left and @right evaluate to are
1370 * equal. This is semantically equivalent to
1371 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1372 * for more information.
1374 #define KUNIT_EXPECT_STREQ(test, left, right) \
1375 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1377 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
1378 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1379 KUNIT_EXPECTATION, \
1386 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
1387 * @test: The test context object.
1388 * @left: an arbitrary expression that evaluates to a null terminated string.
1389 * @right: an arbitrary expression that evaluates to a null terminated string.
1391 * Sets an expectation that the values that @left and @right evaluate to are
1392 * not equal. This is semantically equivalent to
1393 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1394 * for more information.
1396 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
1397 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1399 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
1400 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1401 KUNIT_EXPECTATION, \
1408 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
1409 * @test: The test context object.
1410 * @ptr: an arbitrary pointer.
1412 * Sets an expectation that the value that @ptr evaluates to is not null and not
1413 * an errno stored in a pointer. This is semantically equivalent to
1414 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
1417 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
1418 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
1420 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1421 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1422 KUNIT_EXPECTATION, \
1427 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
1428 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
1431 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
1432 * @test: The test context object.
1433 * @condition: an arbitrary boolean expression. The test fails and aborts when
1434 * this does not evaluate to true.
1436 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1437 * fail *and immediately abort* when the specified condition is not met. Unlike
1438 * an expectation failure, it will prevent the test case from continuing to run;
1439 * this is otherwise known as an *assertion failure*.
1441 #define KUNIT_ASSERT_TRUE(test, condition) \
1442 KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
1444 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
1445 KUNIT_TRUE_MSG_ASSERTION(test, \
1452 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
1453 * @test: The test context object.
1454 * @condition: an arbitrary boolean expression.
1456 * Sets an assertion that the value that @condition evaluates to is false. This
1457 * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
1458 * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1460 #define KUNIT_ASSERT_FALSE(test, condition) \
1461 KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
1463 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
1464 KUNIT_FALSE_MSG_ASSERTION(test, \
1471 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
1472 * @test: The test context object.
1473 * @left: an arbitrary expression that evaluates to a primitive C type.
1474 * @right: an arbitrary expression that evaluates to a primitive C type.
1476 * Sets an assertion that the values that @left and @right evaluate to are
1477 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1478 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1480 #define KUNIT_ASSERT_EQ(test, left, right) \
1481 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1483 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
1484 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1492 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1493 * @test: The test context object.
1494 * @left: an arbitrary expression that evaluates to a pointer.
1495 * @right: an arbitrary expression that evaluates to a pointer.
1497 * Sets an assertion that the values that @left and @right evaluate to are
1498 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1499 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1501 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
1502 KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1504 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1505 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1513 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
1514 * @test: The test context object.
1515 * @left: an arbitrary expression that evaluates to a primitive C type.
1516 * @right: an arbitrary expression that evaluates to a primitive C type.
1518 * Sets an assertion that the values that @left and @right evaluate to are not
1519 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1520 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1522 #define KUNIT_ASSERT_NE(test, left, right) \
1523 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1525 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
1526 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1534 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
1535 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1536 * @test: The test context object.
1537 * @left: an arbitrary expression that evaluates to a pointer.
1538 * @right: an arbitrary expression that evaluates to a pointer.
1540 * Sets an assertion that the values that @left and @right evaluate to are not
1541 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1542 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1544 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
1545 KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1547 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
1548 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1555 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
1556 * @test: The test context object.
1557 * @left: an arbitrary expression that evaluates to a primitive C type.
1558 * @right: an arbitrary expression that evaluates to a primitive C type.
1560 * Sets an assertion that the value that @left evaluates to is less than the
1561 * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
1562 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1565 #define KUNIT_ASSERT_LT(test, left, right) \
1566 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1568 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
1569 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1576 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
1577 * @test: The test context object.
1578 * @left: an arbitrary expression that evaluates to a primitive C type.
1579 * @right: an arbitrary expression that evaluates to a primitive C type.
1581 * Sets an assertion that the value that @left evaluates to is less than or
1582 * equal to the value that @right evaluates to. This is the same as
1583 * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
1584 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1586 #define KUNIT_ASSERT_LE(test, left, right) \
1587 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1589 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
1590 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1598 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
1599 * @test: The test context object.
1600 * @left: an arbitrary expression that evaluates to a primitive C type.
1601 * @right: an arbitrary expression that evaluates to a primitive C type.
1603 * Sets an assertion that the value that @left evaluates to is greater than the
1604 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
1605 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1608 #define KUNIT_ASSERT_GT(test, left, right) \
1609 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1611 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
1612 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1620 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
1621 * @test: The test context object.
1622 * @left: an arbitrary expression that evaluates to a primitive C type.
1623 * @right: an arbitrary expression that evaluates to a primitive C type.
1625 * Sets an assertion that the value that @left evaluates to is greater than the
1626 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
1627 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1630 #define KUNIT_ASSERT_GE(test, left, right) \
1631 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1633 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
1634 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1642 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
1643 * @test: The test context object.
1644 * @left: an arbitrary expression that evaluates to a null terminated string.
1645 * @right: an arbitrary expression that evaluates to a null terminated string.
1647 * Sets an assertion that the values that @left and @right evaluate to are
1648 * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
1649 * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1651 #define KUNIT_ASSERT_STREQ(test, left, right) \
1652 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1654 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
1655 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1663 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
1664 * @test: The test context object.
1665 * @left: an arbitrary expression that evaluates to a null terminated string.
1666 * @right: an arbitrary expression that evaluates to a null terminated string.
1668 * Sets an expectation that the values that @left and @right evaluate to are
1669 * not equal. This is semantically equivalent to
1670 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1671 * for more information.
1673 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
1674 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1676 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
1677 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1685 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
1686 * @test: The test context object.
1687 * @ptr: an arbitrary pointer.
1689 * Sets an assertion that the value that @ptr evaluates to is not null and not
1690 * an errno stored in a pointer. This is the same as
1691 * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
1692 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1694 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
1695 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
1697 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1698 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1704 #endif /* _KUNIT_TEST_H */