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 static inline void kunit_set_failure(struct kunit *test)
229 WRITE_ONCE(test->success, false);
232 void kunit_init_test(struct kunit *test, const char *name, char *log);
234 int kunit_run_tests(struct kunit_suite *suite);
236 size_t kunit_suite_num_test_cases(struct kunit_suite *suite);
238 unsigned int kunit_test_case_num(struct kunit_suite *suite,
239 struct kunit_case *test_case);
241 int __kunit_test_suites_init(struct kunit_suite **suites);
243 void __kunit_test_suites_exit(struct kunit_suite **suites);
246 * kunit_test_suites() - used to register one or more &struct kunit_suite
249 * @suites_list...: a statically allocated list of &struct kunit_suite.
251 * Registers @suites_list with the test framework. See &struct kunit_suite for
254 * When builtin, KUnit tests are all run as late_initcalls; this means
255 * that they cannot test anything where tests must run at a different init
256 * phase. One significant restriction resulting from this is that KUnit
257 * cannot reliably test anything that is initialize in the late_init phase;
258 * another is that KUnit is useless to test things that need to be run in
259 * an earlier init phase.
261 * An alternative is to build the tests as a module. Because modules
262 * do not support multiple late_initcall()s, we need to initialize an
263 * array of suites for a module.
265 * TODO(brendanhiggins@google.com): Don't run all KUnit tests as
266 * late_initcalls. I have some future work planned to dispatch all KUnit
267 * tests from the same place, and at the very least to do so after
268 * everything else is definitely initialized.
270 #define kunit_test_suites(suites_list...) \
271 static struct kunit_suite *suites[] = {suites_list, NULL}; \
272 static int kunit_test_suites_init(void) \
274 return __kunit_test_suites_init(suites); \
276 late_initcall(kunit_test_suites_init); \
277 static void __exit kunit_test_suites_exit(void) \
279 return __kunit_test_suites_exit(suites); \
281 module_exit(kunit_test_suites_exit)
283 #define kunit_test_suite(suite) kunit_test_suites(&suite)
285 #define kunit_suite_for_each_test_case(suite, test_case) \
286 for (test_case = suite->test_cases; test_case->run_case; test_case++)
288 bool kunit_suite_has_succeeded(struct kunit_suite *suite);
291 * Like kunit_alloc_resource() below, but returns the struct kunit_resource
292 * object that contains the allocation. This is mostly for testing purposes.
294 struct kunit_resource *kunit_alloc_and_get_resource(struct kunit *test,
295 kunit_resource_init_t init,
296 kunit_resource_free_t free,
301 * kunit_get_resource() - Hold resource for use. Should not need to be used
302 * by most users as we automatically get resources
303 * retrieved by kunit_find_resource*().
306 static inline void kunit_get_resource(struct kunit_resource *res)
308 kref_get(&res->refcount);
312 * Called when refcount reaches zero via kunit_put_resources();
313 * should not be called directly.
315 static inline void kunit_release_resource(struct kref *kref)
317 struct kunit_resource *res = container_of(kref, struct kunit_resource,
320 /* If free function is defined, resource was dynamically allocated. */
328 * kunit_put_resource() - When caller is done with retrieved resource,
329 * kunit_put_resource() should be called to drop
330 * reference count. The resource list maintains
331 * a reference count on resources, so if no users
332 * are utilizing a resource and it is removed from
333 * the resource list, it will be freed via the
334 * associated free function (if any). Only
335 * needs to be used if we alloc_and_get() or
339 static inline void kunit_put_resource(struct kunit_resource *res)
341 kref_put(&res->refcount, kunit_release_resource);
345 * kunit_add_resource() - Add a *test managed resource*.
346 * @test: The test context object.
347 * @init: a user-supplied function to initialize the result (if needed). If
348 * none is supplied, the resource data value is simply set to @data.
349 * If an init function is supplied, @data is passed to it instead.
350 * @free: a user-supplied function to free the resource (if needed).
351 * @data: value to pass to init function or set in resource data field.
353 int kunit_add_resource(struct kunit *test,
354 kunit_resource_init_t init,
355 kunit_resource_free_t free,
356 struct kunit_resource *res,
360 * kunit_add_named_resource() - Add a named *test managed resource*.
361 * @test: The test context object.
362 * @init: a user-supplied function to initialize the resource data, if needed.
363 * @free: a user-supplied function to free the resource data, if needed.
364 * @name_data: name and data to be set for resource.
366 int kunit_add_named_resource(struct kunit *test,
367 kunit_resource_init_t init,
368 kunit_resource_free_t free,
369 struct kunit_resource *res,
374 * kunit_alloc_resource() - Allocates a *test managed resource*.
375 * @test: The test context object.
376 * @init: a user supplied function to initialize the resource.
377 * @free: a user supplied function to free the resource.
378 * @internal_gfp: gfp to use for internal allocations, if unsure, use GFP_KERNEL
379 * @context: for the user to pass in arbitrary data to the init function.
381 * Allocates a *test managed resource*, a resource which will automatically be
382 * cleaned up at the end of a test case. See &struct kunit_resource for an
385 * Note: KUnit needs to allocate memory for a kunit_resource object. You must
386 * specify an @internal_gfp that is compatible with the use context of your
389 static inline void *kunit_alloc_resource(struct kunit *test,
390 kunit_resource_init_t init,
391 kunit_resource_free_t free,
395 struct kunit_resource *res;
397 res = kzalloc(sizeof(*res), internal_gfp);
401 if (!kunit_add_resource(test, init, free, res, context))
407 typedef bool (*kunit_resource_match_t)(struct kunit *test,
408 struct kunit_resource *res,
412 * kunit_resource_instance_match() - Match a resource with the same instance.
413 * @test: Test case to which the resource belongs.
414 * @res: The resource.
415 * @match_data: The resource pointer to match against.
417 * An instance of kunit_resource_match_t that matches a resource whose
418 * allocation matches @match_data.
420 static inline bool kunit_resource_instance_match(struct kunit *test,
421 struct kunit_resource *res,
424 return res->data == match_data;
428 * kunit_resource_name_match() - Match a resource with the same name.
429 * @test: Test case to which the resource belongs.
430 * @res: The resource.
431 * @match_name: The name to match against.
433 static inline bool kunit_resource_name_match(struct kunit *test,
434 struct kunit_resource *res,
437 return res->name && strcmp(res->name, match_name) == 0;
441 * kunit_find_resource() - Find a resource using match function/data.
442 * @test: Test case to which the resource belongs.
443 * @match: match function to be applied to resources/match data.
444 * @match_data: data to be used in matching.
446 static inline struct kunit_resource *
447 kunit_find_resource(struct kunit *test,
448 kunit_resource_match_t match,
451 struct kunit_resource *res, *found = NULL;
453 spin_lock(&test->lock);
455 list_for_each_entry_reverse(res, &test->resources, node) {
456 if (match(test, res, (void *)match_data)) {
458 kunit_get_resource(found);
463 spin_unlock(&test->lock);
469 * kunit_find_named_resource() - Find a resource using match name.
470 * @test: Test case to which the resource belongs.
473 static inline struct kunit_resource *
474 kunit_find_named_resource(struct kunit *test,
477 return kunit_find_resource(test, kunit_resource_name_match,
482 * kunit_destroy_resource() - Find a kunit_resource and destroy it.
483 * @test: Test case to which the resource belongs.
484 * @match: Match function. Returns whether a given resource matches @match_data.
485 * @match_data: Data passed into @match.
488 * 0 if kunit_resource is found and freed, -ENOENT if not found.
490 int kunit_destroy_resource(struct kunit *test,
491 kunit_resource_match_t match,
494 static inline int kunit_destroy_named_resource(struct kunit *test,
497 return kunit_destroy_resource(test, kunit_resource_name_match,
502 * kunit_remove_resource: remove resource from resource list associated with
504 * @test: The test context object.
505 * @res: The resource to be removed.
507 * Note that the resource will not be immediately freed since it is likely
508 * the caller has a reference to it via alloc_and_get() or find();
509 * in this case a final call to kunit_put_resource() is required.
511 void kunit_remove_resource(struct kunit *test, struct kunit_resource *res);
514 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
515 * @test: The test context object.
516 * @size: The size in bytes of the desired memory.
517 * @gfp: flags passed to underlying kmalloc().
519 * Just like `kmalloc(...)`, except the allocation is managed by the test case
520 * and is automatically cleaned up after the test case concludes. See &struct
521 * kunit_resource for more information.
523 void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp);
526 * kunit_kfree() - Like kfree except for allocations managed by KUnit.
527 * @test: The test case to which the resource belongs.
528 * @ptr: The memory allocation to free.
530 void kunit_kfree(struct kunit *test, const void *ptr);
533 * kunit_kzalloc() - Just like kunit_kmalloc(), but zeroes the allocation.
534 * @test: The test context object.
535 * @size: The size in bytes of the desired memory.
536 * @gfp: flags passed to underlying kmalloc().
538 * See kzalloc() and kunit_kmalloc() for more information.
540 static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp)
542 return kunit_kmalloc(test, size, gfp | __GFP_ZERO);
545 void kunit_cleanup(struct kunit *test);
547 void kunit_log_append(char *log, const char *fmt, ...);
550 * printk and log to per-test or per-suite log buffer. Logging only done
551 * if CONFIG_KUNIT_DEBUGFS is 'y'; if it is 'n', no log is allocated/used.
553 #define kunit_log(lvl, test_or_suite, fmt, ...) \
555 printk(lvl fmt, ##__VA_ARGS__); \
556 kunit_log_append((test_or_suite)->log, fmt "\n", \
560 #define kunit_printk(lvl, test, fmt, ...) \
561 kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \
562 (test)->name, ##__VA_ARGS__)
565 * kunit_info() - Prints an INFO level message associated with @test.
567 * @test: The test context object.
568 * @fmt: A printk() style format string.
570 * Prints an info level message associated with the test suite being run.
571 * Takes a variable number of format parameters just like printk().
573 #define kunit_info(test, fmt, ...) \
574 kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
577 * kunit_warn() - Prints a WARN level message associated with @test.
579 * @test: The test context object.
580 * @fmt: A printk() style format string.
582 * Prints a warning level message.
584 #define kunit_warn(test, fmt, ...) \
585 kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
588 * kunit_err() - Prints an ERROR level message associated with @test.
590 * @test: The test context object.
591 * @fmt: A printk() style format string.
593 * Prints an error level message.
595 #define kunit_err(test, fmt, ...) \
596 kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
599 * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
600 * @test: The test context object.
602 * The opposite of KUNIT_FAIL(), it is an expectation that cannot fail. In other
603 * words, it does nothing and only exists for code clarity. See
604 * KUNIT_EXPECT_TRUE() for more information.
606 #define KUNIT_SUCCEED(test) do {} while (0)
608 void kunit_do_assertion(struct kunit *test,
609 struct kunit_assert *assert,
611 const char *fmt, ...);
613 #define KUNIT_ASSERTION(test, pass, assert_class, INITIALIZER, fmt, ...) do { \
614 struct assert_class __assertion = INITIALIZER; \
615 kunit_do_assertion(test, \
616 &__assertion.assert, \
623 #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \
624 KUNIT_ASSERTION(test, \
627 KUNIT_INIT_FAIL_ASSERT_STRUCT(test, assert_type), \
632 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
633 * @test: The test context object.
634 * @fmt: an informational message to be printed when the assertion is made.
635 * @...: string format arguments.
637 * The opposite of KUNIT_SUCCEED(), it is an expectation that always fails. In
638 * other words, it always results in a failed expectation, and consequently
639 * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
640 * for more information.
642 #define KUNIT_FAIL(test, fmt, ...) \
643 KUNIT_FAIL_ASSERTION(test, \
648 #define KUNIT_UNARY_ASSERTION(test, \
654 KUNIT_ASSERTION(test, \
655 !!(condition) == !!expected_true, \
656 kunit_unary_assert, \
657 KUNIT_INIT_UNARY_ASSERT_STRUCT(test, \
664 #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
665 KUNIT_UNARY_ASSERTION(test, \
672 #define KUNIT_TRUE_ASSERTION(test, assert_type, condition) \
673 KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, NULL)
675 #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
676 KUNIT_UNARY_ASSERTION(test, \
683 #define KUNIT_FALSE_ASSERTION(test, assert_type, condition) \
684 KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, NULL)
687 * A factory macro for defining the assertions and expectations for the basic
688 * comparisons defined for the built in types.
690 * Unfortunately, there is no common type that all types can be promoted to for
691 * which all the binary operators behave the same way as for the actual types
692 * (for example, there is no type that long long and unsigned long long can
693 * both be cast to where the comparison result is preserved for all values). So
694 * the best we can do is do the comparison in the original types and then coerce
695 * everything to long long for printing; this way, the comparison behaves
696 * correctly and the printed out value usually makes sense without
697 * interpretation, but can always be interpreted to figure out the actual
700 #define KUNIT_BASE_BINARY_ASSERTION(test, \
710 typeof(left) __left = (left); \
711 typeof(right) __right = (right); \
712 ((void)__typecheck(__left, __right)); \
714 KUNIT_ASSERTION(test, \
717 ASSERT_CLASS_INIT(test, \
728 #define KUNIT_BASE_EQ_MSG_ASSERTION(test, \
736 KUNIT_BASE_BINARY_ASSERTION(test, \
744 #define KUNIT_BASE_NE_MSG_ASSERTION(test, \
752 KUNIT_BASE_BINARY_ASSERTION(test, \
760 #define KUNIT_BASE_LT_MSG_ASSERTION(test, \
768 KUNIT_BASE_BINARY_ASSERTION(test, \
776 #define KUNIT_BASE_LE_MSG_ASSERTION(test, \
784 KUNIT_BASE_BINARY_ASSERTION(test, \
792 #define KUNIT_BASE_GT_MSG_ASSERTION(test, \
800 KUNIT_BASE_BINARY_ASSERTION(test, \
808 #define KUNIT_BASE_GE_MSG_ASSERTION(test, \
816 KUNIT_BASE_BINARY_ASSERTION(test, \
824 #define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
825 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
826 kunit_binary_assert, \
827 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
834 #define KUNIT_BINARY_EQ_ASSERTION(test, assert_type, left, right) \
835 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
841 #define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
847 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
848 kunit_binary_ptr_assert, \
849 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
856 #define KUNIT_BINARY_PTR_EQ_ASSERTION(test, assert_type, left, right) \
857 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
863 #define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
864 KUNIT_BASE_NE_MSG_ASSERTION(test, \
865 kunit_binary_assert, \
866 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
873 #define KUNIT_BINARY_NE_ASSERTION(test, assert_type, left, right) \
874 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
880 #define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
886 KUNIT_BASE_NE_MSG_ASSERTION(test, \
887 kunit_binary_ptr_assert, \
888 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
895 #define KUNIT_BINARY_PTR_NE_ASSERTION(test, assert_type, left, right) \
896 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
902 #define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
903 KUNIT_BASE_LT_MSG_ASSERTION(test, \
904 kunit_binary_assert, \
905 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
912 #define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right) \
913 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
919 #define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
925 KUNIT_BASE_LT_MSG_ASSERTION(test, \
926 kunit_binary_ptr_assert, \
927 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
934 #define KUNIT_BINARY_PTR_LT_ASSERTION(test, assert_type, left, right) \
935 KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
941 #define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
942 KUNIT_BASE_LE_MSG_ASSERTION(test, \
943 kunit_binary_assert, \
944 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
951 #define KUNIT_BINARY_LE_ASSERTION(test, assert_type, left, right) \
952 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
958 #define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
964 KUNIT_BASE_LE_MSG_ASSERTION(test, \
965 kunit_binary_ptr_assert, \
966 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
973 #define KUNIT_BINARY_PTR_LE_ASSERTION(test, assert_type, left, right) \
974 KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
980 #define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
981 KUNIT_BASE_GT_MSG_ASSERTION(test, \
982 kunit_binary_assert, \
983 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
990 #define KUNIT_BINARY_GT_ASSERTION(test, assert_type, left, right) \
991 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
997 #define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
1003 KUNIT_BASE_GT_MSG_ASSERTION(test, \
1004 kunit_binary_ptr_assert, \
1005 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
1012 #define KUNIT_BINARY_PTR_GT_ASSERTION(test, assert_type, left, right) \
1013 KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
1019 #define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
1020 KUNIT_BASE_GE_MSG_ASSERTION(test, \
1021 kunit_binary_assert, \
1022 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
1029 #define KUNIT_BINARY_GE_ASSERTION(test, assert_type, left, right) \
1030 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1036 #define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
1042 KUNIT_BASE_GE_MSG_ASSERTION(test, \
1043 kunit_binary_ptr_assert, \
1044 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
1051 #define KUNIT_BINARY_PTR_GE_ASSERTION(test, assert_type, left, right) \
1052 KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
1058 #define KUNIT_BINARY_STR_ASSERTION(test, \
1066 typeof(left) __left = (left); \
1067 typeof(right) __right = (right); \
1069 KUNIT_ASSERTION(test, \
1070 strcmp(__left, __right) op 0, \
1071 kunit_binary_str_assert, \
1072 KUNIT_INIT_BINARY_ASSERT_STRUCT(test, \
1083 #define KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1089 KUNIT_BINARY_STR_ASSERTION(test, \
1095 #define KUNIT_BINARY_STR_EQ_ASSERTION(test, assert_type, left, right) \
1096 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1102 #define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1108 KUNIT_BINARY_STR_ASSERTION(test, \
1114 #define KUNIT_BINARY_STR_NE_ASSERTION(test, assert_type, left, right) \
1115 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1121 #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1127 typeof(ptr) __ptr = (ptr); \
1129 KUNIT_ASSERTION(test, \
1130 !IS_ERR_OR_NULL(__ptr), \
1131 kunit_ptr_not_err_assert, \
1132 KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, \
1140 #define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \
1141 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1147 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
1148 * @test: The test context object.
1149 * @condition: an arbitrary boolean expression. The test fails when this does
1150 * not evaluate to true.
1152 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
1153 * to fail when the specified condition is not met; however, it will not prevent
1154 * the test case from continuing to run; this is otherwise known as an
1155 * *expectation failure*.
1157 #define KUNIT_EXPECT_TRUE(test, condition) \
1158 KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1160 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
1161 KUNIT_TRUE_MSG_ASSERTION(test, \
1162 KUNIT_EXPECTATION, \
1168 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
1169 * @test: The test context object.
1170 * @condition: an arbitrary boolean expression. The test fails when this does
1171 * not evaluate to false.
1173 * Sets an expectation that @condition evaluates to false. See
1174 * KUNIT_EXPECT_TRUE() for more information.
1176 #define KUNIT_EXPECT_FALSE(test, condition) \
1177 KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1179 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
1180 KUNIT_FALSE_MSG_ASSERTION(test, \
1181 KUNIT_EXPECTATION, \
1187 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
1188 * @test: The test context object.
1189 * @left: an arbitrary expression that evaluates to a primitive C type.
1190 * @right: an arbitrary expression that evaluates to a primitive C type.
1192 * Sets an expectation that the values that @left and @right evaluate to are
1193 * equal. This is semantically equivalent to
1194 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1197 #define KUNIT_EXPECT_EQ(test, left, right) \
1198 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1200 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
1201 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1202 KUNIT_EXPECTATION, \
1209 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
1210 * @test: The test context object.
1211 * @left: an arbitrary expression that evaluates to a pointer.
1212 * @right: an arbitrary expression that evaluates to a pointer.
1214 * Sets an expectation that the values that @left and @right evaluate to are
1215 * equal. This is semantically equivalent to
1216 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1219 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
1220 KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
1221 KUNIT_EXPECTATION, \
1225 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1226 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1227 KUNIT_EXPECTATION, \
1234 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
1235 * @test: The test context object.
1236 * @left: an arbitrary expression that evaluates to a primitive C type.
1237 * @right: an arbitrary expression that evaluates to a primitive C type.
1239 * Sets an expectation that the values that @left and @right evaluate to are not
1240 * equal. This is semantically equivalent to
1241 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1244 #define KUNIT_EXPECT_NE(test, left, right) \
1245 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1247 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
1248 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1249 KUNIT_EXPECTATION, \
1256 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
1257 * @test: The test context object.
1258 * @left: an arbitrary expression that evaluates to a pointer.
1259 * @right: an arbitrary expression that evaluates to a pointer.
1261 * Sets an expectation that the values that @left and @right evaluate to are not
1262 * equal. This is semantically equivalent to
1263 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1266 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
1267 KUNIT_BINARY_PTR_NE_ASSERTION(test, \
1268 KUNIT_EXPECTATION, \
1272 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
1273 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1274 KUNIT_EXPECTATION, \
1281 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
1282 * @test: The test context object.
1283 * @left: an arbitrary expression that evaluates to a primitive C type.
1284 * @right: an arbitrary expression that evaluates to a primitive C type.
1286 * Sets an expectation that the value that @left evaluates to is less than the
1287 * value that @right evaluates to. This is semantically equivalent to
1288 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
1291 #define KUNIT_EXPECT_LT(test, left, right) \
1292 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1294 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
1295 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1296 KUNIT_EXPECTATION, \
1303 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
1304 * @test: The test context object.
1305 * @left: an arbitrary expression that evaluates to a primitive C type.
1306 * @right: an arbitrary expression that evaluates to a primitive C type.
1308 * Sets an expectation that the value that @left evaluates to is less than or
1309 * equal to the value that @right evaluates to. Semantically this is equivalent
1310 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
1313 #define KUNIT_EXPECT_LE(test, left, right) \
1314 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1316 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
1317 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1318 KUNIT_EXPECTATION, \
1325 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
1326 * @test: The test context object.
1327 * @left: an arbitrary expression that evaluates to a primitive C type.
1328 * @right: an arbitrary expression that evaluates to a primitive C type.
1330 * Sets an expectation that the value that @left evaluates to is greater than
1331 * the value that @right evaluates to. This is semantically equivalent to
1332 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
1335 #define KUNIT_EXPECT_GT(test, left, right) \
1336 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1338 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
1339 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1340 KUNIT_EXPECTATION, \
1347 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
1348 * @test: The test context object.
1349 * @left: an arbitrary expression that evaluates to a primitive C type.
1350 * @right: an arbitrary expression that evaluates to a primitive C type.
1352 * Sets an expectation that the value that @left evaluates to is greater than
1353 * the value that @right evaluates to. This is semantically equivalent to
1354 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
1357 #define KUNIT_EXPECT_GE(test, left, right) \
1358 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1360 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
1361 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1362 KUNIT_EXPECTATION, \
1369 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
1370 * @test: The test context object.
1371 * @left: an arbitrary expression that evaluates to a null terminated string.
1372 * @right: an arbitrary expression that evaluates to a null terminated string.
1374 * Sets an expectation that the values that @left and @right evaluate to are
1375 * equal. This is semantically equivalent to
1376 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1377 * for more information.
1379 #define KUNIT_EXPECT_STREQ(test, left, right) \
1380 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1382 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
1383 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1384 KUNIT_EXPECTATION, \
1391 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
1392 * @test: The test context object.
1393 * @left: an arbitrary expression that evaluates to a null terminated string.
1394 * @right: an arbitrary expression that evaluates to a null terminated string.
1396 * Sets an expectation that the values that @left and @right evaluate to are
1397 * not equal. This is semantically equivalent to
1398 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1399 * for more information.
1401 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
1402 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1404 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
1405 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1406 KUNIT_EXPECTATION, \
1413 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
1414 * @test: The test context object.
1415 * @ptr: an arbitrary pointer.
1417 * Sets an expectation that the value that @ptr evaluates to is not null and not
1418 * an errno stored in a pointer. This is semantically equivalent to
1419 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
1422 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
1423 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
1425 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1426 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1427 KUNIT_EXPECTATION, \
1432 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
1433 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
1436 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
1437 * @test: The test context object.
1438 * @condition: an arbitrary boolean expression. The test fails and aborts when
1439 * this does not evaluate to true.
1441 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1442 * fail *and immediately abort* when the specified condition is not met. Unlike
1443 * an expectation failure, it will prevent the test case from continuing to run;
1444 * this is otherwise known as an *assertion failure*.
1446 #define KUNIT_ASSERT_TRUE(test, condition) \
1447 KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
1449 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
1450 KUNIT_TRUE_MSG_ASSERTION(test, \
1457 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
1458 * @test: The test context object.
1459 * @condition: an arbitrary boolean expression.
1461 * Sets an assertion that the value that @condition evaluates to is false. This
1462 * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
1463 * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1465 #define KUNIT_ASSERT_FALSE(test, condition) \
1466 KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
1468 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
1469 KUNIT_FALSE_MSG_ASSERTION(test, \
1476 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
1477 * @test: The test context object.
1478 * @left: an arbitrary expression that evaluates to a primitive C type.
1479 * @right: an arbitrary expression that evaluates to a primitive C type.
1481 * Sets an assertion that the values that @left and @right evaluate to are
1482 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1483 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1485 #define KUNIT_ASSERT_EQ(test, left, right) \
1486 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1488 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
1489 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1497 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1498 * @test: The test context object.
1499 * @left: an arbitrary expression that evaluates to a pointer.
1500 * @right: an arbitrary expression that evaluates to a pointer.
1502 * Sets an assertion that the values that @left and @right evaluate to are
1503 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1504 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1506 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
1507 KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1509 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1510 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1518 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
1519 * @test: The test context object.
1520 * @left: an arbitrary expression that evaluates to a primitive C type.
1521 * @right: an arbitrary expression that evaluates to a primitive C type.
1523 * Sets an assertion that the values that @left and @right evaluate to are not
1524 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1525 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1527 #define KUNIT_ASSERT_NE(test, left, right) \
1528 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1530 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
1531 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1539 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
1540 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1541 * @test: The test context object.
1542 * @left: an arbitrary expression that evaluates to a pointer.
1543 * @right: an arbitrary expression that evaluates to a pointer.
1545 * Sets an assertion that the values that @left and @right evaluate to are not
1546 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1547 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1549 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
1550 KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1552 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
1553 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1560 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
1561 * @test: The test context object.
1562 * @left: an arbitrary expression that evaluates to a primitive C type.
1563 * @right: an arbitrary expression that evaluates to a primitive C type.
1565 * Sets an assertion that the value that @left evaluates to is less than the
1566 * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
1567 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1570 #define KUNIT_ASSERT_LT(test, left, right) \
1571 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1573 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
1574 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1581 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
1582 * @test: The test context object.
1583 * @left: an arbitrary expression that evaluates to a primitive C type.
1584 * @right: an arbitrary expression that evaluates to a primitive C type.
1586 * Sets an assertion that the value that @left evaluates to is less than or
1587 * equal to the value that @right evaluates to. This is the same as
1588 * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
1589 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1591 #define KUNIT_ASSERT_LE(test, left, right) \
1592 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1594 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
1595 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1603 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
1604 * @test: The test context object.
1605 * @left: an arbitrary expression that evaluates to a primitive C type.
1606 * @right: an arbitrary expression that evaluates to a primitive C type.
1608 * Sets an assertion that the value that @left evaluates to is greater than the
1609 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
1610 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1613 #define KUNIT_ASSERT_GT(test, left, right) \
1614 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1616 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
1617 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1625 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
1626 * @test: The test context object.
1627 * @left: an arbitrary expression that evaluates to a primitive C type.
1628 * @right: an arbitrary expression that evaluates to a primitive C type.
1630 * Sets an assertion that the value that @left evaluates to is greater than the
1631 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
1632 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1635 #define KUNIT_ASSERT_GE(test, left, right) \
1636 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1638 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
1639 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1647 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
1648 * @test: The test context object.
1649 * @left: an arbitrary expression that evaluates to a null terminated string.
1650 * @right: an arbitrary expression that evaluates to a null terminated string.
1652 * Sets an assertion that the values that @left and @right evaluate to are
1653 * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
1654 * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1656 #define KUNIT_ASSERT_STREQ(test, left, right) \
1657 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1659 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
1660 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1668 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
1669 * @test: The test context object.
1670 * @left: an arbitrary expression that evaluates to a null terminated string.
1671 * @right: an arbitrary expression that evaluates to a null terminated string.
1673 * Sets an expectation that the values that @left and @right evaluate to are
1674 * not equal. This is semantically equivalent to
1675 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1676 * for more information.
1678 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
1679 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1681 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
1682 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1690 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
1691 * @test: The test context object.
1692 * @ptr: an arbitrary pointer.
1694 * Sets an assertion that the value that @ptr evaluates to is not null and not
1695 * an errno stored in a pointer. This is the same as
1696 * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
1697 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1699 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
1700 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
1702 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1703 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1709 #endif /* _KUNIT_TEST_H */