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
* const * const suites
);
244 void __kunit_test_suites_exit(struct kunit_suite
**suites
);
246 #if IS_BUILTIN(CONFIG_KUNIT)
247 int kunit_run_all_tests(void);
249 static inline int kunit_run_all_tests(void)
253 #endif /* IS_BUILTIN(CONFIG_KUNIT) */
257 * kunit_test_suites_for_module() - used to register one or more
258 * &struct kunit_suite with KUnit.
260 * @__suites: a statically allocated list of &struct kunit_suite.
262 * Registers @__suites with the test framework. See &struct kunit_suite for
265 * If a test suite is built-in, module_init() gets translated into
266 * an initcall which we don't want as the idea is that for builtins
267 * the executor will manage execution. So ensure we do not define
268 * module_{init|exit} functions for the builtin case when registering
269 * suites via kunit_test_suites() below.
271 #define kunit_test_suites_for_module(__suites) \
272 static int __init kunit_test_suites_init(void) \
274 return __kunit_test_suites_init(__suites); \
276 module_init(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_suites_for_module(__suites)
287 #define __kunit_test_suites(unique_array, unique_suites, ...) \
288 static struct kunit_suite *unique_array[] = { __VA_ARGS__, NULL }; \
289 kunit_test_suites_for_module(unique_array); \
290 static struct kunit_suite **unique_suites \
291 __used __section(".kunit_test_suites") = unique_array
294 * kunit_test_suites() - used to register one or more &struct kunit_suite
297 * @__suites: a statically allocated list of &struct kunit_suite.
299 * Registers @suites with the test framework. See &struct kunit_suite for
302 * When builtin, KUnit tests are all run via executor; this is done
303 * by placing the array of struct kunit_suite * in the .kunit_test_suites
306 * An alternative is to build the tests as a module. Because modules do not
307 * support multiple initcall()s, we need to initialize an array of suites for a
311 #define kunit_test_suites(__suites...) \
312 __kunit_test_suites(__UNIQUE_ID(array), \
313 __UNIQUE_ID(suites), \
316 #define kunit_test_suite(suite) kunit_test_suites(&suite)
318 #define kunit_suite_for_each_test_case(suite, test_case) \
319 for (test_case = suite->test_cases; test_case->run_case; test_case++)
321 bool kunit_suite_has_succeeded(struct kunit_suite
*suite
);
324 * Like kunit_alloc_resource() below, but returns the struct kunit_resource
325 * object that contains the allocation. This is mostly for testing purposes.
327 struct kunit_resource
*kunit_alloc_and_get_resource(struct kunit
*test
,
328 kunit_resource_init_t init
,
329 kunit_resource_free_t free
,
334 * kunit_get_resource() - Hold resource for use. Should not need to be used
335 * by most users as we automatically get resources
336 * retrieved by kunit_find_resource*().
339 static inline void kunit_get_resource(struct kunit_resource
*res
)
341 kref_get(&res
->refcount
);
345 * Called when refcount reaches zero via kunit_put_resources();
346 * should not be called directly.
348 static inline void kunit_release_resource(struct kref
*kref
)
350 struct kunit_resource
*res
= container_of(kref
, struct kunit_resource
,
353 /* If free function is defined, resource was dynamically allocated. */
361 * kunit_put_resource() - When caller is done with retrieved resource,
362 * kunit_put_resource() should be called to drop
363 * reference count. The resource list maintains
364 * a reference count on resources, so if no users
365 * are utilizing a resource and it is removed from
366 * the resource list, it will be freed via the
367 * associated free function (if any). Only
368 * needs to be used if we alloc_and_get() or
372 static inline void kunit_put_resource(struct kunit_resource
*res
)
374 kref_put(&res
->refcount
, kunit_release_resource
);
378 * kunit_add_resource() - Add a *test managed resource*.
379 * @test: The test context object.
380 * @init: a user-supplied function to initialize the result (if needed). If
381 * none is supplied, the resource data value is simply set to @data.
382 * If an init function is supplied, @data is passed to it instead.
383 * @free: a user-supplied function to free the resource (if needed).
384 * @res: The resource.
385 * @data: value to pass to init function or set in resource data field.
387 int kunit_add_resource(struct kunit
*test
,
388 kunit_resource_init_t init
,
389 kunit_resource_free_t free
,
390 struct kunit_resource
*res
,
394 * kunit_add_named_resource() - Add a named *test managed resource*.
395 * @test: The test context object.
396 * @init: a user-supplied function to initialize the resource data, if needed.
397 * @free: a user-supplied function to free the resource data, if needed.
398 * @res: The resource.
399 * @name: name to be set for resource.
400 * @data: value to pass to init function or set in resource data field.
402 int kunit_add_named_resource(struct kunit
*test
,
403 kunit_resource_init_t init
,
404 kunit_resource_free_t free
,
405 struct kunit_resource
*res
,
410 * kunit_alloc_resource() - Allocates a *test managed resource*.
411 * @test: The test context object.
412 * @init: a user supplied function to initialize the resource.
413 * @free: a user supplied function to free the resource.
414 * @internal_gfp: gfp to use for internal allocations, if unsure, use GFP_KERNEL
415 * @context: for the user to pass in arbitrary data to the init function.
417 * Allocates a *test managed resource*, a resource which will automatically be
418 * cleaned up at the end of a test case. See &struct kunit_resource for an
421 * Note: KUnit needs to allocate memory for a kunit_resource object. You must
422 * specify an @internal_gfp that is compatible with the use context of your
425 static inline void *kunit_alloc_resource(struct kunit
*test
,
426 kunit_resource_init_t init
,
427 kunit_resource_free_t free
,
431 struct kunit_resource
*res
;
433 res
= kzalloc(sizeof(*res
), internal_gfp
);
437 if (!kunit_add_resource(test
, init
, free
, res
, context
))
443 typedef bool (*kunit_resource_match_t
)(struct kunit
*test
,
444 struct kunit_resource
*res
,
448 * kunit_resource_instance_match() - Match a resource with the same instance.
449 * @test: Test case to which the resource belongs.
450 * @res: The resource.
451 * @match_data: The resource pointer to match against.
453 * An instance of kunit_resource_match_t that matches a resource whose
454 * allocation matches @match_data.
456 static inline bool kunit_resource_instance_match(struct kunit
*test
,
457 struct kunit_resource
*res
,
460 return res
->data
== match_data
;
464 * kunit_resource_name_match() - Match a resource with the same name.
465 * @test: Test case to which the resource belongs.
466 * @res: The resource.
467 * @match_name: The name to match against.
469 static inline bool kunit_resource_name_match(struct kunit
*test
,
470 struct kunit_resource
*res
,
473 return res
->name
&& strcmp(res
->name
, match_name
) == 0;
477 * kunit_find_resource() - Find a resource using match function/data.
478 * @test: Test case to which the resource belongs.
479 * @match: match function to be applied to resources/match data.
480 * @match_data: data to be used in matching.
482 static inline struct kunit_resource
*
483 kunit_find_resource(struct kunit
*test
,
484 kunit_resource_match_t match
,
487 struct kunit_resource
*res
, *found
= NULL
;
489 spin_lock(&test
->lock
);
491 list_for_each_entry_reverse(res
, &test
->resources
, node
) {
492 if (match(test
, res
, (void *)match_data
)) {
494 kunit_get_resource(found
);
499 spin_unlock(&test
->lock
);
505 * kunit_find_named_resource() - Find a resource using match name.
506 * @test: Test case to which the resource belongs.
509 static inline struct kunit_resource
*
510 kunit_find_named_resource(struct kunit
*test
,
513 return kunit_find_resource(test
, kunit_resource_name_match
,
518 * kunit_destroy_resource() - Find a kunit_resource and destroy it.
519 * @test: Test case to which the resource belongs.
520 * @match: Match function. Returns whether a given resource matches @match_data.
521 * @match_data: Data passed into @match.
524 * 0 if kunit_resource is found and freed, -ENOENT if not found.
526 int kunit_destroy_resource(struct kunit
*test
,
527 kunit_resource_match_t match
,
530 static inline int kunit_destroy_named_resource(struct kunit
*test
,
533 return kunit_destroy_resource(test
, kunit_resource_name_match
,
538 * kunit_remove_resource() - remove resource from resource list associated with
540 * @test: The test context object.
541 * @res: The resource to be removed.
543 * Note that the resource will not be immediately freed since it is likely
544 * the caller has a reference to it via alloc_and_get() or find();
545 * in this case a final call to kunit_put_resource() is required.
547 void kunit_remove_resource(struct kunit
*test
, struct kunit_resource
*res
);
550 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
551 * @test: The test context object.
552 * @size: The size in bytes of the desired memory.
553 * @gfp: flags passed to underlying kmalloc().
555 * Just like `kmalloc(...)`, except the allocation is managed by the test case
556 * and is automatically cleaned up after the test case concludes. See &struct
557 * kunit_resource for more information.
559 void *kunit_kmalloc(struct kunit
*test
, size_t size
, gfp_t gfp
);
562 * kunit_kfree() - Like kfree except for allocations managed by KUnit.
563 * @test: The test case to which the resource belongs.
564 * @ptr: The memory allocation to free.
566 void kunit_kfree(struct kunit
*test
, const void *ptr
);
569 * kunit_kzalloc() - Just like kunit_kmalloc(), but zeroes the allocation.
570 * @test: The test context object.
571 * @size: The size in bytes of the desired memory.
572 * @gfp: flags passed to underlying kmalloc().
574 * See kzalloc() and kunit_kmalloc() for more information.
576 static inline void *kunit_kzalloc(struct kunit
*test
, size_t size
, gfp_t gfp
)
578 return kunit_kmalloc(test
, size
, gfp
| __GFP_ZERO
);
581 void kunit_cleanup(struct kunit
*test
);
583 void kunit_log_append(char *log
, const char *fmt
, ...);
586 * printk and log to per-test or per-suite log buffer. Logging only done
587 * if CONFIG_KUNIT_DEBUGFS is 'y'; if it is 'n', no log is allocated/used.
589 #define kunit_log(lvl, test_or_suite, fmt, ...) \
591 printk(lvl fmt, ##__VA_ARGS__); \
592 kunit_log_append((test_or_suite)->log, fmt "\n", \
596 #define kunit_printk(lvl, test, fmt, ...) \
597 kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \
598 (test)->name, ##__VA_ARGS__)
601 * kunit_info() - Prints an INFO level message associated with @test.
603 * @test: The test context object.
604 * @fmt: A printk() style format string.
606 * Prints an info level message associated with the test suite being run.
607 * Takes a variable number of format parameters just like printk().
609 #define kunit_info(test, fmt, ...) \
610 kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
613 * kunit_warn() - Prints a WARN level message associated with @test.
615 * @test: The test context object.
616 * @fmt: A printk() style format string.
618 * Prints a warning level message.
620 #define kunit_warn(test, fmt, ...) \
621 kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
624 * kunit_err() - Prints an ERROR level message associated with @test.
626 * @test: The test context object.
627 * @fmt: A printk() style format string.
629 * Prints an error level message.
631 #define kunit_err(test, fmt, ...) \
632 kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
635 * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
636 * @test: The test context object.
638 * The opposite of KUNIT_FAIL(), it is an expectation that cannot fail. In other
639 * words, it does nothing and only exists for code clarity. See
640 * KUNIT_EXPECT_TRUE() for more information.
642 #define KUNIT_SUCCEED(test) do {} while (0)
644 void kunit_do_assertion(struct kunit
*test
,
645 struct kunit_assert
*assert,
647 const char *fmt
, ...);
649 #define KUNIT_ASSERTION(test, pass, assert_class, INITIALIZER, fmt, ...) do { \
650 struct assert_class __assertion = INITIALIZER; \
651 kunit_do_assertion(test, \
652 &__assertion.assert, \
659 #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \
660 KUNIT_ASSERTION(test, \
663 KUNIT_INIT_FAIL_ASSERT_STRUCT(test, assert_type), \
668 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
669 * @test: The test context object.
670 * @fmt: an informational message to be printed when the assertion is made.
671 * @...: string format arguments.
673 * The opposite of KUNIT_SUCCEED(), it is an expectation that always fails. In
674 * other words, it always results in a failed expectation, and consequently
675 * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
676 * for more information.
678 #define KUNIT_FAIL(test, fmt, ...) \
679 KUNIT_FAIL_ASSERTION(test, \
684 #define KUNIT_UNARY_ASSERTION(test, \
690 KUNIT_ASSERTION(test, \
691 !!(condition) == !!expected_true, \
692 kunit_unary_assert, \
693 KUNIT_INIT_UNARY_ASSERT_STRUCT(test, \
700 #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
701 KUNIT_UNARY_ASSERTION(test, \
708 #define KUNIT_TRUE_ASSERTION(test, assert_type, condition) \
709 KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, NULL)
711 #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
712 KUNIT_UNARY_ASSERTION(test, \
719 #define KUNIT_FALSE_ASSERTION(test, assert_type, condition) \
720 KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, NULL)
723 * A factory macro for defining the assertions and expectations for the basic
724 * comparisons defined for the built in types.
726 * Unfortunately, there is no common type that all types can be promoted to for
727 * which all the binary operators behave the same way as for the actual types
728 * (for example, there is no type that long long and unsigned long long can
729 * both be cast to where the comparison result is preserved for all values). So
730 * the best we can do is do the comparison in the original types and then coerce
731 * everything to long long for printing; this way, the comparison behaves
732 * correctly and the printed out value usually makes sense without
733 * interpretation, but can always be interpreted to figure out the actual
736 #define KUNIT_BASE_BINARY_ASSERTION(test, \
746 typeof(left) __left = (left); \
747 typeof(right) __right = (right); \
748 ((void)__typecheck(__left, __right)); \
750 KUNIT_ASSERTION(test, \
753 ASSERT_CLASS_INIT(test, \
764 #define KUNIT_BASE_EQ_MSG_ASSERTION(test, \
772 KUNIT_BASE_BINARY_ASSERTION(test, \
780 #define KUNIT_BASE_NE_MSG_ASSERTION(test, \
788 KUNIT_BASE_BINARY_ASSERTION(test, \
796 #define KUNIT_BASE_LT_MSG_ASSERTION(test, \
804 KUNIT_BASE_BINARY_ASSERTION(test, \
812 #define KUNIT_BASE_LE_MSG_ASSERTION(test, \
820 KUNIT_BASE_BINARY_ASSERTION(test, \
828 #define KUNIT_BASE_GT_MSG_ASSERTION(test, \
836 KUNIT_BASE_BINARY_ASSERTION(test, \
844 #define KUNIT_BASE_GE_MSG_ASSERTION(test, \
852 KUNIT_BASE_BINARY_ASSERTION(test, \
860 #define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
861 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
862 kunit_binary_assert, \
863 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
870 #define KUNIT_BINARY_EQ_ASSERTION(test, assert_type, left, right) \
871 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
877 #define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
883 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
884 kunit_binary_ptr_assert, \
885 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
892 #define KUNIT_BINARY_PTR_EQ_ASSERTION(test, assert_type, left, right) \
893 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
899 #define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
900 KUNIT_BASE_NE_MSG_ASSERTION(test, \
901 kunit_binary_assert, \
902 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
909 #define KUNIT_BINARY_NE_ASSERTION(test, assert_type, left, right) \
910 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
916 #define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
922 KUNIT_BASE_NE_MSG_ASSERTION(test, \
923 kunit_binary_ptr_assert, \
924 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
931 #define KUNIT_BINARY_PTR_NE_ASSERTION(test, assert_type, left, right) \
932 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
938 #define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
939 KUNIT_BASE_LT_MSG_ASSERTION(test, \
940 kunit_binary_assert, \
941 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
948 #define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right) \
949 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
955 #define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
961 KUNIT_BASE_LT_MSG_ASSERTION(test, \
962 kunit_binary_ptr_assert, \
963 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
970 #define KUNIT_BINARY_PTR_LT_ASSERTION(test, assert_type, left, right) \
971 KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
977 #define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
978 KUNIT_BASE_LE_MSG_ASSERTION(test, \
979 kunit_binary_assert, \
980 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
987 #define KUNIT_BINARY_LE_ASSERTION(test, assert_type, left, right) \
988 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
994 #define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
1000 KUNIT_BASE_LE_MSG_ASSERTION(test, \
1001 kunit_binary_ptr_assert, \
1002 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
1009 #define KUNIT_BINARY_PTR_LE_ASSERTION(test, assert_type, left, right) \
1010 KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
1016 #define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
1017 KUNIT_BASE_GT_MSG_ASSERTION(test, \
1018 kunit_binary_assert, \
1019 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
1026 #define KUNIT_BINARY_GT_ASSERTION(test, assert_type, left, right) \
1027 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1033 #define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
1039 KUNIT_BASE_GT_MSG_ASSERTION(test, \
1040 kunit_binary_ptr_assert, \
1041 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
1048 #define KUNIT_BINARY_PTR_GT_ASSERTION(test, assert_type, left, right) \
1049 KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
1055 #define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
1056 KUNIT_BASE_GE_MSG_ASSERTION(test, \
1057 kunit_binary_assert, \
1058 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
1065 #define KUNIT_BINARY_GE_ASSERTION(test, assert_type, left, right) \
1066 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1072 #define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
1078 KUNIT_BASE_GE_MSG_ASSERTION(test, \
1079 kunit_binary_ptr_assert, \
1080 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
1087 #define KUNIT_BINARY_PTR_GE_ASSERTION(test, assert_type, left, right) \
1088 KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
1094 #define KUNIT_BINARY_STR_ASSERTION(test, \
1102 typeof(left) __left = (left); \
1103 typeof(right) __right = (right); \
1105 KUNIT_ASSERTION(test, \
1106 strcmp(__left, __right) op 0, \
1107 kunit_binary_str_assert, \
1108 KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(test, \
1119 #define KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1125 KUNIT_BINARY_STR_ASSERTION(test, \
1131 #define KUNIT_BINARY_STR_EQ_ASSERTION(test, assert_type, left, right) \
1132 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1138 #define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1144 KUNIT_BINARY_STR_ASSERTION(test, \
1150 #define KUNIT_BINARY_STR_NE_ASSERTION(test, assert_type, left, right) \
1151 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1157 #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1163 typeof(ptr) __ptr = (ptr); \
1165 KUNIT_ASSERTION(test, \
1166 !IS_ERR_OR_NULL(__ptr), \
1167 kunit_ptr_not_err_assert, \
1168 KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, \
1176 #define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \
1177 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1183 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
1184 * @test: The test context object.
1185 * @condition: an arbitrary boolean expression. The test fails when this does
1186 * not evaluate to true.
1188 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
1189 * to fail when the specified condition is not met; however, it will not prevent
1190 * the test case from continuing to run; this is otherwise known as an
1191 * *expectation failure*.
1193 #define KUNIT_EXPECT_TRUE(test, condition) \
1194 KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1196 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
1197 KUNIT_TRUE_MSG_ASSERTION(test, \
1198 KUNIT_EXPECTATION, \
1204 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
1205 * @test: The test context object.
1206 * @condition: an arbitrary boolean expression. The test fails when this does
1207 * not evaluate to false.
1209 * Sets an expectation that @condition evaluates to false. See
1210 * KUNIT_EXPECT_TRUE() for more information.
1212 #define KUNIT_EXPECT_FALSE(test, condition) \
1213 KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1215 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
1216 KUNIT_FALSE_MSG_ASSERTION(test, \
1217 KUNIT_EXPECTATION, \
1223 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
1224 * @test: The test context object.
1225 * @left: an arbitrary expression that evaluates to a primitive C type.
1226 * @right: an arbitrary expression that evaluates to a primitive C type.
1228 * Sets an expectation that the values that @left and @right evaluate to are
1229 * equal. This is semantically equivalent to
1230 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1233 #define KUNIT_EXPECT_EQ(test, left, right) \
1234 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1236 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
1237 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1238 KUNIT_EXPECTATION, \
1245 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
1246 * @test: The test context object.
1247 * @left: an arbitrary expression that evaluates to a pointer.
1248 * @right: an arbitrary expression that evaluates to a pointer.
1250 * Sets an expectation that the values that @left and @right evaluate to are
1251 * equal. This is semantically equivalent to
1252 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1255 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
1256 KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
1257 KUNIT_EXPECTATION, \
1261 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1262 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1263 KUNIT_EXPECTATION, \
1270 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
1271 * @test: The test context object.
1272 * @left: an arbitrary expression that evaluates to a primitive C type.
1273 * @right: an arbitrary expression that evaluates to a primitive C type.
1275 * Sets an expectation that the values that @left and @right evaluate to are not
1276 * equal. This is semantically equivalent to
1277 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1280 #define KUNIT_EXPECT_NE(test, left, right) \
1281 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1283 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
1284 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1285 KUNIT_EXPECTATION, \
1292 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
1293 * @test: The test context object.
1294 * @left: an arbitrary expression that evaluates to a pointer.
1295 * @right: an arbitrary expression that evaluates to a pointer.
1297 * Sets an expectation that the values that @left and @right evaluate to are not
1298 * equal. This is semantically equivalent to
1299 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1302 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
1303 KUNIT_BINARY_PTR_NE_ASSERTION(test, \
1304 KUNIT_EXPECTATION, \
1308 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
1309 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1310 KUNIT_EXPECTATION, \
1317 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
1318 * @test: The test context object.
1319 * @left: an arbitrary expression that evaluates to a primitive C type.
1320 * @right: an arbitrary expression that evaluates to a primitive C type.
1322 * Sets an expectation that the value that @left evaluates to is less than the
1323 * value that @right evaluates to. This is semantically equivalent to
1324 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
1327 #define KUNIT_EXPECT_LT(test, left, right) \
1328 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1330 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
1331 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1332 KUNIT_EXPECTATION, \
1339 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
1340 * @test: The test context object.
1341 * @left: an arbitrary expression that evaluates to a primitive C type.
1342 * @right: an arbitrary expression that evaluates to a primitive C type.
1344 * Sets an expectation that the value that @left evaluates to is less than or
1345 * equal to the value that @right evaluates to. Semantically this is equivalent
1346 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
1349 #define KUNIT_EXPECT_LE(test, left, right) \
1350 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1352 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
1353 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1354 KUNIT_EXPECTATION, \
1361 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
1362 * @test: The test context object.
1363 * @left: an arbitrary expression that evaluates to a primitive C type.
1364 * @right: an arbitrary expression that evaluates to a primitive C type.
1366 * Sets an expectation that the value that @left evaluates to is greater than
1367 * the value that @right evaluates to. This is semantically equivalent to
1368 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
1371 #define KUNIT_EXPECT_GT(test, left, right) \
1372 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1374 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
1375 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1376 KUNIT_EXPECTATION, \
1383 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
1384 * @test: The test context object.
1385 * @left: an arbitrary expression that evaluates to a primitive C type.
1386 * @right: an arbitrary expression that evaluates to a primitive C type.
1388 * Sets an expectation that the value that @left evaluates to is greater than
1389 * the value that @right evaluates to. This is semantically equivalent to
1390 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
1393 #define KUNIT_EXPECT_GE(test, left, right) \
1394 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1396 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
1397 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1398 KUNIT_EXPECTATION, \
1405 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
1406 * @test: The test context object.
1407 * @left: an arbitrary expression that evaluates to a null terminated string.
1408 * @right: an arbitrary expression that evaluates to a null terminated string.
1410 * Sets an expectation that the values that @left and @right evaluate to are
1411 * equal. This is semantically equivalent to
1412 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1413 * for more information.
1415 #define KUNIT_EXPECT_STREQ(test, left, right) \
1416 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1418 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
1419 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1420 KUNIT_EXPECTATION, \
1427 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
1428 * @test: The test context object.
1429 * @left: an arbitrary expression that evaluates to a null terminated string.
1430 * @right: an arbitrary expression that evaluates to a null terminated string.
1432 * Sets an expectation that the values that @left and @right evaluate to are
1433 * not equal. This is semantically equivalent to
1434 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1435 * for more information.
1437 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
1438 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1440 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
1441 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1442 KUNIT_EXPECTATION, \
1449 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
1450 * @test: The test context object.
1451 * @ptr: an arbitrary pointer.
1453 * Sets an expectation that the value that @ptr evaluates to is not null and not
1454 * an errno stored in a pointer. This is semantically equivalent to
1455 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
1458 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
1459 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
1461 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1462 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1463 KUNIT_EXPECTATION, \
1468 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
1469 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
1472 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
1473 * @test: The test context object.
1474 * @condition: an arbitrary boolean expression. The test fails and aborts when
1475 * this does not evaluate to true.
1477 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1478 * fail *and immediately abort* when the specified condition is not met. Unlike
1479 * an expectation failure, it will prevent the test case from continuing to run;
1480 * this is otherwise known as an *assertion failure*.
1482 #define KUNIT_ASSERT_TRUE(test, condition) \
1483 KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
1485 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
1486 KUNIT_TRUE_MSG_ASSERTION(test, \
1493 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
1494 * @test: The test context object.
1495 * @condition: an arbitrary boolean expression.
1497 * Sets an assertion that the value that @condition evaluates to is false. This
1498 * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
1499 * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1501 #define KUNIT_ASSERT_FALSE(test, condition) \
1502 KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
1504 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
1505 KUNIT_FALSE_MSG_ASSERTION(test, \
1512 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
1513 * @test: The test context object.
1514 * @left: an arbitrary expression that evaluates to a primitive C type.
1515 * @right: an arbitrary expression that evaluates to a primitive C type.
1517 * Sets an assertion that the values that @left and @right evaluate to are
1518 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1519 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1521 #define KUNIT_ASSERT_EQ(test, left, right) \
1522 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1524 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
1525 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1533 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1534 * @test: The test context object.
1535 * @left: an arbitrary expression that evaluates to a pointer.
1536 * @right: an arbitrary expression that evaluates to a pointer.
1538 * Sets an assertion that the values that @left and @right evaluate to are
1539 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1540 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1542 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
1543 KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1545 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1546 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1554 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
1555 * @test: The test context object.
1556 * @left: an arbitrary expression that evaluates to a primitive C type.
1557 * @right: an arbitrary expression that evaluates to a primitive C type.
1559 * Sets an assertion that the values that @left and @right evaluate to are not
1560 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1561 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1563 #define KUNIT_ASSERT_NE(test, left, right) \
1564 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1566 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
1567 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1575 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
1576 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1577 * @test: The test context object.
1578 * @left: an arbitrary expression that evaluates to a pointer.
1579 * @right: an arbitrary expression that evaluates to a pointer.
1581 * Sets an assertion that the values that @left and @right evaluate to are not
1582 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1583 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1585 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
1586 KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1588 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
1589 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1596 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
1597 * @test: The test context object.
1598 * @left: an arbitrary expression that evaluates to a primitive C type.
1599 * @right: an arbitrary expression that evaluates to a primitive C type.
1601 * Sets an assertion that the value that @left evaluates to is less than the
1602 * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
1603 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1606 #define KUNIT_ASSERT_LT(test, left, right) \
1607 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1609 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
1610 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1617 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
1618 * @test: The test context object.
1619 * @left: an arbitrary expression that evaluates to a primitive C type.
1620 * @right: an arbitrary expression that evaluates to a primitive C type.
1622 * Sets an assertion that the value that @left evaluates to is less than or
1623 * equal to the value that @right evaluates to. This is the same as
1624 * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
1625 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1627 #define KUNIT_ASSERT_LE(test, left, right) \
1628 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1630 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
1631 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1639 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
1640 * @test: The test context object.
1641 * @left: an arbitrary expression that evaluates to a primitive C type.
1642 * @right: an arbitrary expression that evaluates to a primitive C type.
1644 * Sets an assertion that the value that @left evaluates to is greater than the
1645 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
1646 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1649 #define KUNIT_ASSERT_GT(test, left, right) \
1650 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1652 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
1653 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1661 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
1662 * @test: The test context object.
1663 * @left: an arbitrary expression that evaluates to a primitive C type.
1664 * @right: an arbitrary expression that evaluates to a primitive C type.
1666 * Sets an assertion that the value that @left evaluates to is greater than the
1667 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
1668 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1671 #define KUNIT_ASSERT_GE(test, left, right) \
1672 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1674 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
1675 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1683 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
1684 * @test: The test context object.
1685 * @left: an arbitrary expression that evaluates to a null terminated string.
1686 * @right: an arbitrary expression that evaluates to a null terminated string.
1688 * Sets an assertion that the values that @left and @right evaluate to are
1689 * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
1690 * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1692 #define KUNIT_ASSERT_STREQ(test, left, right) \
1693 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1695 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
1696 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1704 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
1705 * @test: The test context object.
1706 * @left: an arbitrary expression that evaluates to a null terminated string.
1707 * @right: an arbitrary expression that evaluates to a null terminated string.
1709 * Sets an expectation that the values that @left and @right evaluate to are
1710 * not equal. This is semantically equivalent to
1711 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1712 * for more information.
1714 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
1715 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1717 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
1718 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1726 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
1727 * @test: The test context object.
1728 * @ptr: an arbitrary pointer.
1730 * Sets an assertion that the value that @ptr evaluates to is not null and not
1731 * an errno stored in a pointer. This is the same as
1732 * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
1733 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1735 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
1736 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
1738 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1739 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1745 #endif /* _KUNIT_TEST_H */