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 * @name: optional name
29 * @free: a user supplied function to free the resource. Populated by
30 * kunit_resource_alloc().
32 * Represents a *test managed resource*, a resource which will automatically be
33 * cleaned up at the end of a test case.
35 * Resources are reference counted so if a resource is retrieved via
36 * kunit_alloc_and_get_resource() or kunit_find_resource(), we need
37 * to call kunit_put_resource() to reduce the resource reference count
38 * when finished with it. Note that kunit_alloc_resource() does not require a
39 * kunit_resource_put() because it does not retrieve the resource itself.
45 * struct kunit_kmalloc_params {
50 * static int kunit_kmalloc_init(struct kunit_resource *res, void *context)
52 * struct kunit_kmalloc_params *params = context;
53 * res->data = kmalloc(params->size, params->gfp);
61 * static void kunit_kmalloc_free(struct kunit_resource *res)
66 * void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp)
68 * struct kunit_kmalloc_params params;
73 * return kunit_alloc_resource(test, kunit_kmalloc_init,
74 * kunit_kmalloc_free, ¶ms);
77 * Resources can also be named, with lookup/removal done on a name
78 * basis also. kunit_add_named_resource(), kunit_find_named_resource()
79 * and kunit_destroy_named_resource(). Resource names must be
80 * unique within the test instance.
82 struct kunit_resource {
85 kunit_resource_free_t free;
87 /* private: internal use only. */
89 struct list_head node;
94 /* Size of log associated with test. */
95 #define KUNIT_LOG_SIZE 512
98 * TAP specifies subtest stream indentation of 4 spaces, 8 spaces for a
99 * sub-subtest. See the "Subtests" section in
100 * https://node-tap.org/tap-protocol/
102 #define KUNIT_SUBTEST_INDENT " "
103 #define KUNIT_SUBSUBTEST_INDENT " "
106 * struct kunit_case - represents an individual test case.
108 * @run_case: the function representing the actual test case.
109 * @name: the name of the test case.
111 * A test case is a function with the signature,
112 * ``void (*)(struct kunit *)``
113 * that makes expectations and assertions (see KUNIT_EXPECT_TRUE() and
114 * KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated
115 * with a &struct kunit_suite and will be run after the suite's init
116 * function and followed by the suite's exit function.
118 * A test case should be static and should only be created with the
119 * KUNIT_CASE() macro; additionally, every array of test cases should be
120 * terminated with an empty test case.
126 * void add_test_basic(struct kunit *test)
128 * KUNIT_EXPECT_EQ(test, 1, add(1, 0));
129 * KUNIT_EXPECT_EQ(test, 2, add(1, 1));
130 * KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
131 * KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
132 * KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
135 * static struct kunit_case example_test_cases[] = {
136 * KUNIT_CASE(add_test_basic),
142 void (*run_case)(struct kunit *test);
145 /* private: internal use only. */
150 static inline char *kunit_status_to_string(bool status)
152 return status ? "ok" : "not ok";
156 * KUNIT_CASE - A helper for creating a &struct kunit_case
158 * @test_name: a reference to a test case function.
160 * Takes a symbol for a function representing a test case and creates a
161 * &struct kunit_case object from it. See the documentation for
162 * &struct kunit_case for an example on how to use it.
164 #define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }
167 * struct kunit_suite - describes a related collection of &struct kunit_case
169 * @name: the name of the test. Purely informational.
170 * @init: called before every test case.
171 * @exit: called after every test case.
172 * @test_cases: a null terminated array of test cases.
174 * A kunit_suite is a collection of related &struct kunit_case s, such that
175 * @init is called before every test case and @exit is called after every
176 * test case, similar to the notion of a *test fixture* or a *test class*
177 * in other unit testing frameworks like JUnit or Googletest.
179 * Every &struct kunit_case must be associated with a kunit_suite for KUnit
183 const char name[256];
184 int (*init)(struct kunit *test);
185 void (*exit)(struct kunit *test);
186 struct kunit_case *test_cases;
188 /* private: internal use only */
189 struct dentry *debugfs;
194 * struct kunit - represents a running instance of a test.
196 * @priv: for user to store arbitrary data. Commonly used to pass data
197 * created in the init function (see &struct kunit_suite).
199 * Used to store information about the current context under which the test
200 * is running. Most of this data is private and should only be accessed
201 * indirectly via public functions; the one exception is @priv which can be
202 * used by the test writer to store arbitrary data.
207 /* private: internal use only. */
208 const char *name; /* Read only after initialization! */
209 char *log; /* Points at case log after initialization */
210 struct kunit_try_catch try_catch;
212 * success starts as true, and may only be set to false during a
213 * test case; thus, it is safe to update this across multiple
214 * threads using WRITE_ONCE; however, as a consequence, it may only
215 * be read after the test case finishes once all threads associated
216 * with the test case have terminated.
218 bool success; /* Read only after test_case finishes! */
219 spinlock_t lock; /* Guards all mutable test state. */
221 * Because resources is a list that may be updated multiple times (with
222 * new resources) from any thread associated with a test case, we must
223 * protect it with some type of lock.
225 struct list_head resources; /* Protected by lock. */
228 static inline void kunit_set_failure(struct kunit *test)
230 WRITE_ONCE(test->success, false);
233 void kunit_init_test(struct kunit *test, const char *name, char *log);
235 int kunit_run_tests(struct kunit_suite *suite);
237 size_t kunit_suite_num_test_cases(struct kunit_suite *suite);
239 unsigned int kunit_test_case_num(struct kunit_suite *suite,
240 struct kunit_case *test_case);
242 int __kunit_test_suites_init(struct kunit_suite **suites);
244 void __kunit_test_suites_exit(struct kunit_suite **suites);
247 * kunit_test_suites() - used to register one or more &struct kunit_suite
250 * @suites_list...: a statically allocated list of &struct kunit_suite.
252 * Registers @suites_list with the test framework. See &struct kunit_suite for
255 * When builtin, KUnit tests are all run as late_initcalls; this means
256 * that they cannot test anything where tests must run at a different init
257 * phase. One significant restriction resulting from this is that KUnit
258 * cannot reliably test anything that is initialize in the late_init phase;
259 * another is that KUnit is useless to test things that need to be run in
260 * an earlier init phase.
262 * An alternative is to build the tests as a module. Because modules
263 * do not support multiple late_initcall()s, we need to initialize an
264 * array of suites for a module.
266 * TODO(brendanhiggins@google.com): Don't run all KUnit tests as
267 * late_initcalls. I have some future work planned to dispatch all KUnit
268 * tests from the same place, and at the very least to do so after
269 * everything else is definitely initialized.
271 #define kunit_test_suites(suites_list...) \
272 static struct kunit_suite *suites[] = {suites_list, NULL}; \
273 static int kunit_test_suites_init(void) \
275 return __kunit_test_suites_init(suites); \
277 late_initcall(kunit_test_suites_init); \
278 static void __exit kunit_test_suites_exit(void) \
280 return __kunit_test_suites_exit(suites); \
282 module_exit(kunit_test_suites_exit)
284 #define kunit_test_suite(suite) kunit_test_suites(&suite)
286 #define kunit_suite_for_each_test_case(suite, test_case) \
287 for (test_case = suite->test_cases; test_case->run_case; test_case++)
289 bool kunit_suite_has_succeeded(struct kunit_suite *suite);
292 * Like kunit_alloc_resource() below, but returns the struct kunit_resource
293 * object that contains the allocation. This is mostly for testing purposes.
295 struct kunit_resource *kunit_alloc_and_get_resource(struct kunit *test,
296 kunit_resource_init_t init,
297 kunit_resource_free_t free,
302 * kunit_get_resource() - Hold resource for use. Should not need to be used
303 * by most users as we automatically get resources
304 * retrieved by kunit_find_resource*().
307 static inline void kunit_get_resource(struct kunit_resource *res)
309 kref_get(&res->refcount);
313 * Called when refcount reaches zero via kunit_put_resources();
314 * should not be called directly.
316 static inline void kunit_release_resource(struct kref *kref)
318 struct kunit_resource *res = container_of(kref, struct kunit_resource,
321 /* If free function is defined, resource was dynamically allocated. */
329 * kunit_put_resource() - When caller is done with retrieved resource,
330 * kunit_put_resource() should be called to drop
331 * reference count. The resource list maintains
332 * a reference count on resources, so if no users
333 * are utilizing a resource and it is removed from
334 * the resource list, it will be freed via the
335 * associated free function (if any). Only
336 * needs to be used if we alloc_and_get() or
340 static inline void kunit_put_resource(struct kunit_resource *res)
342 kref_put(&res->refcount, kunit_release_resource);
346 * kunit_add_resource() - Add a *test managed resource*.
347 * @test: The test context object.
348 * @init: a user-supplied function to initialize the result (if needed). If
349 * none is supplied, the resource data value is simply set to @data.
350 * If an init function is supplied, @data is passed to it instead.
351 * @free: a user-supplied function to free the resource (if needed).
352 * @res: The resource.
353 * @data: value to pass to init function or set in resource data field.
355 int kunit_add_resource(struct kunit *test,
356 kunit_resource_init_t init,
357 kunit_resource_free_t free,
358 struct kunit_resource *res,
362 * kunit_add_named_resource() - Add a named *test managed resource*.
363 * @test: The test context object.
364 * @init: a user-supplied function to initialize the resource data, if needed.
365 * @free: a user-supplied function to free the resource data, if needed.
366 * @res: The resource.
367 * @name: name to be set for resource.
368 * @data: value to pass to init function or set in resource data field.
370 int kunit_add_named_resource(struct kunit *test,
371 kunit_resource_init_t init,
372 kunit_resource_free_t free,
373 struct kunit_resource *res,
378 * kunit_alloc_resource() - Allocates a *test managed resource*.
379 * @test: The test context object.
380 * @init: a user supplied function to initialize the resource.
381 * @free: a user supplied function to free the resource.
382 * @internal_gfp: gfp to use for internal allocations, if unsure, use GFP_KERNEL
383 * @context: for the user to pass in arbitrary data to the init function.
385 * Allocates a *test managed resource*, a resource which will automatically be
386 * cleaned up at the end of a test case. See &struct kunit_resource for an
389 * Note: KUnit needs to allocate memory for a kunit_resource object. You must
390 * specify an @internal_gfp that is compatible with the use context of your
393 static inline void *kunit_alloc_resource(struct kunit *test,
394 kunit_resource_init_t init,
395 kunit_resource_free_t free,
399 struct kunit_resource *res;
401 res = kzalloc(sizeof(*res), internal_gfp);
405 if (!kunit_add_resource(test, init, free, res, context))
411 typedef bool (*kunit_resource_match_t)(struct kunit *test,
412 struct kunit_resource *res,
416 * kunit_resource_instance_match() - Match a resource with the same instance.
417 * @test: Test case to which the resource belongs.
418 * @res: The resource.
419 * @match_data: The resource pointer to match against.
421 * An instance of kunit_resource_match_t that matches a resource whose
422 * allocation matches @match_data.
424 static inline bool kunit_resource_instance_match(struct kunit *test,
425 struct kunit_resource *res,
428 return res->data == match_data;
432 * kunit_resource_name_match() - Match a resource with the same name.
433 * @test: Test case to which the resource belongs.
434 * @res: The resource.
435 * @match_name: The name to match against.
437 static inline bool kunit_resource_name_match(struct kunit *test,
438 struct kunit_resource *res,
441 return res->name && strcmp(res->name, match_name) == 0;
445 * kunit_find_resource() - Find a resource using match function/data.
446 * @test: Test case to which the resource belongs.
447 * @match: match function to be applied to resources/match data.
448 * @match_data: data to be used in matching.
450 static inline struct kunit_resource *
451 kunit_find_resource(struct kunit *test,
452 kunit_resource_match_t match,
455 struct kunit_resource *res, *found = NULL;
457 spin_lock(&test->lock);
459 list_for_each_entry_reverse(res, &test->resources, node) {
460 if (match(test, res, (void *)match_data)) {
462 kunit_get_resource(found);
467 spin_unlock(&test->lock);
473 * kunit_find_named_resource() - Find a resource using match name.
474 * @test: Test case to which the resource belongs.
477 static inline struct kunit_resource *
478 kunit_find_named_resource(struct kunit *test,
481 return kunit_find_resource(test, kunit_resource_name_match,
486 * kunit_destroy_resource() - Find a kunit_resource and destroy it.
487 * @test: Test case to which the resource belongs.
488 * @match: Match function. Returns whether a given resource matches @match_data.
489 * @match_data: Data passed into @match.
492 * 0 if kunit_resource is found and freed, -ENOENT if not found.
494 int kunit_destroy_resource(struct kunit *test,
495 kunit_resource_match_t match,
498 static inline int kunit_destroy_named_resource(struct kunit *test,
501 return kunit_destroy_resource(test, kunit_resource_name_match,
506 * kunit_remove_resource() - remove resource from resource list associated with
508 * @test: The test context object.
509 * @res: The resource to be removed.
511 * Note that the resource will not be immediately freed since it is likely
512 * the caller has a reference to it via alloc_and_get() or find();
513 * in this case a final call to kunit_put_resource() is required.
515 void kunit_remove_resource(struct kunit *test, struct kunit_resource *res);
518 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
519 * @test: The test context object.
520 * @size: The size in bytes of the desired memory.
521 * @gfp: flags passed to underlying kmalloc().
523 * Just like `kmalloc(...)`, except the allocation is managed by the test case
524 * and is automatically cleaned up after the test case concludes. See &struct
525 * kunit_resource for more information.
527 void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp);
530 * kunit_kfree() - Like kfree except for allocations managed by KUnit.
531 * @test: The test case to which the resource belongs.
532 * @ptr: The memory allocation to free.
534 void kunit_kfree(struct kunit *test, const void *ptr);
537 * kunit_kzalloc() - Just like kunit_kmalloc(), but zeroes the allocation.
538 * @test: The test context object.
539 * @size: The size in bytes of the desired memory.
540 * @gfp: flags passed to underlying kmalloc().
542 * See kzalloc() and kunit_kmalloc() for more information.
544 static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp)
546 return kunit_kmalloc(test, size, gfp | __GFP_ZERO);
549 void kunit_cleanup(struct kunit *test);
551 void kunit_log_append(char *log, const char *fmt, ...);
554 * printk and log to per-test or per-suite log buffer. Logging only done
555 * if CONFIG_KUNIT_DEBUGFS is 'y'; if it is 'n', no log is allocated/used.
557 #define kunit_log(lvl, test_or_suite, fmt, ...) \
559 printk(lvl fmt, ##__VA_ARGS__); \
560 kunit_log_append((test_or_suite)->log, fmt "\n", \
564 #define kunit_printk(lvl, test, fmt, ...) \
565 kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \
566 (test)->name, ##__VA_ARGS__)
569 * kunit_info() - Prints an INFO level message associated with @test.
571 * @test: The test context object.
572 * @fmt: A printk() style format string.
574 * Prints an info level message associated with the test suite being run.
575 * Takes a variable number of format parameters just like printk().
577 #define kunit_info(test, fmt, ...) \
578 kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
581 * kunit_warn() - Prints a WARN level message associated with @test.
583 * @test: The test context object.
584 * @fmt: A printk() style format string.
586 * Prints a warning level message.
588 #define kunit_warn(test, fmt, ...) \
589 kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
592 * kunit_err() - Prints an ERROR level message associated with @test.
594 * @test: The test context object.
595 * @fmt: A printk() style format string.
597 * Prints an error level message.
599 #define kunit_err(test, fmt, ...) \
600 kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
603 * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
604 * @test: The test context object.
606 * The opposite of KUNIT_FAIL(), it is an expectation that cannot fail. In other
607 * words, it does nothing and only exists for code clarity. See
608 * KUNIT_EXPECT_TRUE() for more information.
610 #define KUNIT_SUCCEED(test) do {} while (0)
612 void kunit_do_assertion(struct kunit *test,
613 struct kunit_assert *assert,
615 const char *fmt, ...);
617 #define KUNIT_ASSERTION(test, pass, assert_class, INITIALIZER, fmt, ...) do { \
618 struct assert_class __assertion = INITIALIZER; \
619 kunit_do_assertion(test, \
620 &__assertion.assert, \
627 #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \
628 KUNIT_ASSERTION(test, \
631 KUNIT_INIT_FAIL_ASSERT_STRUCT(test, assert_type), \
636 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
637 * @test: The test context object.
638 * @fmt: an informational message to be printed when the assertion is made.
639 * @...: string format arguments.
641 * The opposite of KUNIT_SUCCEED(), it is an expectation that always fails. In
642 * other words, it always results in a failed expectation, and consequently
643 * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
644 * for more information.
646 #define KUNIT_FAIL(test, fmt, ...) \
647 KUNIT_FAIL_ASSERTION(test, \
652 #define KUNIT_UNARY_ASSERTION(test, \
658 KUNIT_ASSERTION(test, \
659 !!(condition) == !!expected_true, \
660 kunit_unary_assert, \
661 KUNIT_INIT_UNARY_ASSERT_STRUCT(test, \
668 #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
669 KUNIT_UNARY_ASSERTION(test, \
676 #define KUNIT_TRUE_ASSERTION(test, assert_type, condition) \
677 KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, NULL)
679 #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
680 KUNIT_UNARY_ASSERTION(test, \
687 #define KUNIT_FALSE_ASSERTION(test, assert_type, condition) \
688 KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, NULL)
691 * A factory macro for defining the assertions and expectations for the basic
692 * comparisons defined for the built in types.
694 * Unfortunately, there is no common type that all types can be promoted to for
695 * which all the binary operators behave the same way as for the actual types
696 * (for example, there is no type that long long and unsigned long long can
697 * both be cast to where the comparison result is preserved for all values). So
698 * the best we can do is do the comparison in the original types and then coerce
699 * everything to long long for printing; this way, the comparison behaves
700 * correctly and the printed out value usually makes sense without
701 * interpretation, but can always be interpreted to figure out the actual
704 #define KUNIT_BASE_BINARY_ASSERTION(test, \
714 typeof(left) __left = (left); \
715 typeof(right) __right = (right); \
716 ((void)__typecheck(__left, __right)); \
718 KUNIT_ASSERTION(test, \
721 ASSERT_CLASS_INIT(test, \
732 #define KUNIT_BASE_EQ_MSG_ASSERTION(test, \
740 KUNIT_BASE_BINARY_ASSERTION(test, \
748 #define KUNIT_BASE_NE_MSG_ASSERTION(test, \
756 KUNIT_BASE_BINARY_ASSERTION(test, \
764 #define KUNIT_BASE_LT_MSG_ASSERTION(test, \
772 KUNIT_BASE_BINARY_ASSERTION(test, \
780 #define KUNIT_BASE_LE_MSG_ASSERTION(test, \
788 KUNIT_BASE_BINARY_ASSERTION(test, \
796 #define KUNIT_BASE_GT_MSG_ASSERTION(test, \
804 KUNIT_BASE_BINARY_ASSERTION(test, \
812 #define KUNIT_BASE_GE_MSG_ASSERTION(test, \
820 KUNIT_BASE_BINARY_ASSERTION(test, \
828 #define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
829 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
830 kunit_binary_assert, \
831 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
838 #define KUNIT_BINARY_EQ_ASSERTION(test, assert_type, left, right) \
839 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
845 #define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
851 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
852 kunit_binary_ptr_assert, \
853 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
860 #define KUNIT_BINARY_PTR_EQ_ASSERTION(test, assert_type, left, right) \
861 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
867 #define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
868 KUNIT_BASE_NE_MSG_ASSERTION(test, \
869 kunit_binary_assert, \
870 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
877 #define KUNIT_BINARY_NE_ASSERTION(test, assert_type, left, right) \
878 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
884 #define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
890 KUNIT_BASE_NE_MSG_ASSERTION(test, \
891 kunit_binary_ptr_assert, \
892 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
899 #define KUNIT_BINARY_PTR_NE_ASSERTION(test, assert_type, left, right) \
900 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
906 #define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
907 KUNIT_BASE_LT_MSG_ASSERTION(test, \
908 kunit_binary_assert, \
909 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
916 #define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right) \
917 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
923 #define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
929 KUNIT_BASE_LT_MSG_ASSERTION(test, \
930 kunit_binary_ptr_assert, \
931 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
938 #define KUNIT_BINARY_PTR_LT_ASSERTION(test, assert_type, left, right) \
939 KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
945 #define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
946 KUNIT_BASE_LE_MSG_ASSERTION(test, \
947 kunit_binary_assert, \
948 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
955 #define KUNIT_BINARY_LE_ASSERTION(test, assert_type, left, right) \
956 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
962 #define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
968 KUNIT_BASE_LE_MSG_ASSERTION(test, \
969 kunit_binary_ptr_assert, \
970 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
977 #define KUNIT_BINARY_PTR_LE_ASSERTION(test, assert_type, left, right) \
978 KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
984 #define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
985 KUNIT_BASE_GT_MSG_ASSERTION(test, \
986 kunit_binary_assert, \
987 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
994 #define KUNIT_BINARY_GT_ASSERTION(test, assert_type, left, right) \
995 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1001 #define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
1007 KUNIT_BASE_GT_MSG_ASSERTION(test, \
1008 kunit_binary_ptr_assert, \
1009 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
1016 #define KUNIT_BINARY_PTR_GT_ASSERTION(test, assert_type, left, right) \
1017 KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
1023 #define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
1024 KUNIT_BASE_GE_MSG_ASSERTION(test, \
1025 kunit_binary_assert, \
1026 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
1033 #define KUNIT_BINARY_GE_ASSERTION(test, assert_type, left, right) \
1034 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1040 #define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
1046 KUNIT_BASE_GE_MSG_ASSERTION(test, \
1047 kunit_binary_ptr_assert, \
1048 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
1055 #define KUNIT_BINARY_PTR_GE_ASSERTION(test, assert_type, left, right) \
1056 KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
1062 #define KUNIT_BINARY_STR_ASSERTION(test, \
1070 typeof(left) __left = (left); \
1071 typeof(right) __right = (right); \
1073 KUNIT_ASSERTION(test, \
1074 strcmp(__left, __right) op 0, \
1075 kunit_binary_str_assert, \
1076 KUNIT_INIT_BINARY_ASSERT_STRUCT(test, \
1087 #define KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1093 KUNIT_BINARY_STR_ASSERTION(test, \
1099 #define KUNIT_BINARY_STR_EQ_ASSERTION(test, assert_type, left, right) \
1100 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1106 #define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1112 KUNIT_BINARY_STR_ASSERTION(test, \
1118 #define KUNIT_BINARY_STR_NE_ASSERTION(test, assert_type, left, right) \
1119 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1125 #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1131 typeof(ptr) __ptr = (ptr); \
1133 KUNIT_ASSERTION(test, \
1134 !IS_ERR_OR_NULL(__ptr), \
1135 kunit_ptr_not_err_assert, \
1136 KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, \
1144 #define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \
1145 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1151 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
1152 * @test: The test context object.
1153 * @condition: an arbitrary boolean expression. The test fails when this does
1154 * not evaluate to true.
1156 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
1157 * to fail when the specified condition is not met; however, it will not prevent
1158 * the test case from continuing to run; this is otherwise known as an
1159 * *expectation failure*.
1161 #define KUNIT_EXPECT_TRUE(test, condition) \
1162 KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1164 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
1165 KUNIT_TRUE_MSG_ASSERTION(test, \
1166 KUNIT_EXPECTATION, \
1172 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
1173 * @test: The test context object.
1174 * @condition: an arbitrary boolean expression. The test fails when this does
1175 * not evaluate to false.
1177 * Sets an expectation that @condition evaluates to false. See
1178 * KUNIT_EXPECT_TRUE() for more information.
1180 #define KUNIT_EXPECT_FALSE(test, condition) \
1181 KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1183 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
1184 KUNIT_FALSE_MSG_ASSERTION(test, \
1185 KUNIT_EXPECTATION, \
1191 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
1192 * @test: The test context object.
1193 * @left: an arbitrary expression that evaluates to a primitive C type.
1194 * @right: an arbitrary expression that evaluates to a primitive C type.
1196 * Sets an expectation that the values that @left and @right evaluate to are
1197 * equal. This is semantically equivalent to
1198 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1201 #define KUNIT_EXPECT_EQ(test, left, right) \
1202 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1204 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
1205 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1206 KUNIT_EXPECTATION, \
1213 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
1214 * @test: The test context object.
1215 * @left: an arbitrary expression that evaluates to a pointer.
1216 * @right: an arbitrary expression that evaluates to a pointer.
1218 * Sets an expectation that the values that @left and @right evaluate to are
1219 * equal. This is semantically equivalent to
1220 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1223 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
1224 KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
1225 KUNIT_EXPECTATION, \
1229 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1230 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1231 KUNIT_EXPECTATION, \
1238 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
1239 * @test: The test context object.
1240 * @left: an arbitrary expression that evaluates to a primitive C type.
1241 * @right: an arbitrary expression that evaluates to a primitive C type.
1243 * Sets an expectation that the values that @left and @right evaluate to are not
1244 * equal. This is semantically equivalent to
1245 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1248 #define KUNIT_EXPECT_NE(test, left, right) \
1249 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1251 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
1252 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1253 KUNIT_EXPECTATION, \
1260 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
1261 * @test: The test context object.
1262 * @left: an arbitrary expression that evaluates to a pointer.
1263 * @right: an arbitrary expression that evaluates to a pointer.
1265 * Sets an expectation that the values that @left and @right evaluate to are not
1266 * equal. This is semantically equivalent to
1267 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1270 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
1271 KUNIT_BINARY_PTR_NE_ASSERTION(test, \
1272 KUNIT_EXPECTATION, \
1276 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
1277 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1278 KUNIT_EXPECTATION, \
1285 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
1286 * @test: The test context object.
1287 * @left: an arbitrary expression that evaluates to a primitive C type.
1288 * @right: an arbitrary expression that evaluates to a primitive C type.
1290 * Sets an expectation that the value that @left evaluates to is less than the
1291 * value that @right evaluates to. This is semantically equivalent to
1292 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
1295 #define KUNIT_EXPECT_LT(test, left, right) \
1296 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1298 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
1299 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1300 KUNIT_EXPECTATION, \
1307 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
1308 * @test: The test context object.
1309 * @left: an arbitrary expression that evaluates to a primitive C type.
1310 * @right: an arbitrary expression that evaluates to a primitive C type.
1312 * Sets an expectation that the value that @left evaluates to is less than or
1313 * equal to the value that @right evaluates to. Semantically this is equivalent
1314 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
1317 #define KUNIT_EXPECT_LE(test, left, right) \
1318 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1320 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
1321 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1322 KUNIT_EXPECTATION, \
1329 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
1330 * @test: The test context object.
1331 * @left: an arbitrary expression that evaluates to a primitive C type.
1332 * @right: an arbitrary expression that evaluates to a primitive C type.
1334 * Sets an expectation that the value that @left evaluates to is greater than
1335 * the value that @right evaluates to. This is semantically equivalent to
1336 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
1339 #define KUNIT_EXPECT_GT(test, left, right) \
1340 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1342 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
1343 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1344 KUNIT_EXPECTATION, \
1351 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
1352 * @test: The test context object.
1353 * @left: an arbitrary expression that evaluates to a primitive C type.
1354 * @right: an arbitrary expression that evaluates to a primitive C type.
1356 * Sets an expectation that the value that @left evaluates to is greater than
1357 * the value that @right evaluates to. This is semantically equivalent to
1358 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
1361 #define KUNIT_EXPECT_GE(test, left, right) \
1362 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1364 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
1365 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1366 KUNIT_EXPECTATION, \
1373 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
1374 * @test: The test context object.
1375 * @left: an arbitrary expression that evaluates to a null terminated string.
1376 * @right: an arbitrary expression that evaluates to a null terminated string.
1378 * Sets an expectation that the values that @left and @right evaluate to are
1379 * equal. This is semantically equivalent to
1380 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1381 * for more information.
1383 #define KUNIT_EXPECT_STREQ(test, left, right) \
1384 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1386 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
1387 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1388 KUNIT_EXPECTATION, \
1395 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
1396 * @test: The test context object.
1397 * @left: an arbitrary expression that evaluates to a null terminated string.
1398 * @right: an arbitrary expression that evaluates to a null terminated string.
1400 * Sets an expectation that the values that @left and @right evaluate to are
1401 * not equal. This is semantically equivalent to
1402 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1403 * for more information.
1405 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
1406 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1408 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
1409 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1410 KUNIT_EXPECTATION, \
1417 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
1418 * @test: The test context object.
1419 * @ptr: an arbitrary pointer.
1421 * Sets an expectation that the value that @ptr evaluates to is not null and not
1422 * an errno stored in a pointer. This is semantically equivalent to
1423 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
1426 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
1427 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
1429 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1430 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1431 KUNIT_EXPECTATION, \
1436 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
1437 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
1440 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
1441 * @test: The test context object.
1442 * @condition: an arbitrary boolean expression. The test fails and aborts when
1443 * this does not evaluate to true.
1445 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1446 * fail *and immediately abort* when the specified condition is not met. Unlike
1447 * an expectation failure, it will prevent the test case from continuing to run;
1448 * this is otherwise known as an *assertion failure*.
1450 #define KUNIT_ASSERT_TRUE(test, condition) \
1451 KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
1453 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
1454 KUNIT_TRUE_MSG_ASSERTION(test, \
1461 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
1462 * @test: The test context object.
1463 * @condition: an arbitrary boolean expression.
1465 * Sets an assertion that the value that @condition evaluates to is false. This
1466 * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
1467 * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1469 #define KUNIT_ASSERT_FALSE(test, condition) \
1470 KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
1472 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
1473 KUNIT_FALSE_MSG_ASSERTION(test, \
1480 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
1481 * @test: The test context object.
1482 * @left: an arbitrary expression that evaluates to a primitive C type.
1483 * @right: an arbitrary expression that evaluates to a primitive C type.
1485 * Sets an assertion that the values that @left and @right evaluate to are
1486 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1487 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1489 #define KUNIT_ASSERT_EQ(test, left, right) \
1490 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1492 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
1493 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1501 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1502 * @test: The test context object.
1503 * @left: an arbitrary expression that evaluates to a pointer.
1504 * @right: an arbitrary expression that evaluates to a pointer.
1506 * Sets an assertion that the values that @left and @right evaluate to are
1507 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1508 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1510 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
1511 KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1513 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1514 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1522 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
1523 * @test: The test context object.
1524 * @left: an arbitrary expression that evaluates to a primitive C type.
1525 * @right: an arbitrary expression that evaluates to a primitive C type.
1527 * Sets an assertion that the values that @left and @right evaluate to are not
1528 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1529 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1531 #define KUNIT_ASSERT_NE(test, left, right) \
1532 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1534 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
1535 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1543 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
1544 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1545 * @test: The test context object.
1546 * @left: an arbitrary expression that evaluates to a pointer.
1547 * @right: an arbitrary expression that evaluates to a pointer.
1549 * Sets an assertion that the values that @left and @right evaluate to are not
1550 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1551 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1553 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
1554 KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1556 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
1557 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1564 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
1565 * @test: The test context object.
1566 * @left: an arbitrary expression that evaluates to a primitive C type.
1567 * @right: an arbitrary expression that evaluates to a primitive C type.
1569 * Sets an assertion that the value that @left evaluates to is less than the
1570 * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
1571 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1574 #define KUNIT_ASSERT_LT(test, left, right) \
1575 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1577 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
1578 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1585 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
1586 * @test: The test context object.
1587 * @left: an arbitrary expression that evaluates to a primitive C type.
1588 * @right: an arbitrary expression that evaluates to a primitive C type.
1590 * Sets an assertion that the value that @left evaluates to is less than or
1591 * equal to the value that @right evaluates to. This is the same as
1592 * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
1593 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1595 #define KUNIT_ASSERT_LE(test, left, right) \
1596 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1598 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
1599 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1607 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
1608 * @test: The test context object.
1609 * @left: an arbitrary expression that evaluates to a primitive C type.
1610 * @right: an arbitrary expression that evaluates to a primitive C type.
1612 * Sets an assertion that the value that @left evaluates to is greater than the
1613 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
1614 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1617 #define KUNIT_ASSERT_GT(test, left, right) \
1618 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1620 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
1621 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1629 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
1630 * @test: The test context object.
1631 * @left: an arbitrary expression that evaluates to a primitive C type.
1632 * @right: an arbitrary expression that evaluates to a primitive C type.
1634 * Sets an assertion that the value that @left evaluates to is greater than the
1635 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
1636 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1639 #define KUNIT_ASSERT_GE(test, left, right) \
1640 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1642 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
1643 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1651 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
1652 * @test: The test context object.
1653 * @left: an arbitrary expression that evaluates to a null terminated string.
1654 * @right: an arbitrary expression that evaluates to a null terminated string.
1656 * Sets an assertion that the values that @left and @right evaluate to are
1657 * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
1658 * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1660 #define KUNIT_ASSERT_STREQ(test, left, right) \
1661 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1663 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
1664 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1672 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
1673 * @test: The test context object.
1674 * @left: an arbitrary expression that evaluates to a null terminated string.
1675 * @right: an arbitrary expression that evaluates to a null terminated string.
1677 * Sets an expectation that the values that @left and @right evaluate to are
1678 * not equal. This is semantically equivalent to
1679 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1680 * for more information.
1682 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
1683 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1685 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
1686 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1694 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
1695 * @test: The test context object.
1696 * @ptr: an arbitrary pointer.
1698 * Sets an assertion that the value that @ptr evaluates to is not null and not
1699 * an errno stored in a pointer. This is the same as
1700 * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
1701 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1703 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
1704 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
1706 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1707 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1713 #endif /* _KUNIT_TEST_H */