1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Base unit test (KUnit) API.
5 * Copyright (C) 2019, Google LLC.
6 * Author: Brendan Higgins <brendanhiggins@google.com>
12 #include <kunit/assert.h>
13 #include <kunit/try-catch.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/types.h>
18 #include <linux/kref.h>
20 struct kunit_resource;
22 typedef int (*kunit_resource_init_t)(struct kunit_resource *, void *);
23 typedef void (*kunit_resource_free_t)(struct kunit_resource *);
26 * struct kunit_resource - represents a *test managed resource*
27 * @data: for the user to store arbitrary data.
28 * @free: a user supplied function to free the resource. Populated by
29 * kunit_resource_alloc().
31 * Represents a *test managed resource*, a resource which will automatically be
32 * cleaned up at the end of a test case.
34 * Resources are reference counted so if a resource is retrieved via
35 * kunit_alloc_and_get_resource() or kunit_find_resource(), we need
36 * to call kunit_put_resource() to reduce the resource reference count
37 * when finished with it. Note that kunit_alloc_resource() does not require a
38 * kunit_resource_put() because it does not retrieve the resource itself.
44 * struct kunit_kmalloc_params {
49 * static int kunit_kmalloc_init(struct kunit_resource *res, void *context)
51 * struct kunit_kmalloc_params *params = context;
52 * res->data = kmalloc(params->size, params->gfp);
60 * static void kunit_kmalloc_free(struct kunit_resource *res)
65 * void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp)
67 * struct kunit_kmalloc_params params;
72 * return kunit_alloc_resource(test, kunit_kmalloc_init,
73 * kunit_kmalloc_free, ¶ms);
76 * Resources can also be named, with lookup/removal done on a name
77 * basis also. kunit_add_named_resource(), kunit_find_named_resource()
78 * and kunit_destroy_named_resource(). Resource names must be
79 * unique within the test instance.
81 struct kunit_resource {
83 const char *name; /* optional name */
85 /* private: internal use only. */
86 kunit_resource_free_t free;
88 struct list_head node;
93 /* Size of log associated with test. */
94 #define KUNIT_LOG_SIZE 512
97 * TAP specifies subtest stream indentation of 4 spaces, 8 spaces for a
98 * sub-subtest. See the "Subtests" section in
99 * https://node-tap.org/tap-protocol/
101 #define KUNIT_SUBTEST_INDENT " "
102 #define KUNIT_SUBSUBTEST_INDENT " "
105 * struct kunit_case - represents an individual test case.
107 * @run_case: the function representing the actual test case.
108 * @name: the name of the test case.
110 * A test case is a function with the signature,
111 * ``void (*)(struct kunit *)``
112 * that makes expectations and assertions (see KUNIT_EXPECT_TRUE() and
113 * KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated
114 * with a &struct kunit_suite and will be run after the suite's init
115 * function and followed by the suite's exit function.
117 * A test case should be static and should only be created with the
118 * KUNIT_CASE() macro; additionally, every array of test cases should be
119 * terminated with an empty test case.
125 * void add_test_basic(struct kunit *test)
127 * KUNIT_EXPECT_EQ(test, 1, add(1, 0));
128 * KUNIT_EXPECT_EQ(test, 2, add(1, 1));
129 * KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
130 * KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
131 * KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
134 * static struct kunit_case example_test_cases[] = {
135 * KUNIT_CASE(add_test_basic),
141 void (*run_case)(struct kunit *test);
144 /* private: internal use only. */
149 static inline char *kunit_status_to_string(bool status)
151 return status ? "ok" : "not ok";
155 * KUNIT_CASE - A helper for creating a &struct kunit_case
157 * @test_name: a reference to a test case function.
159 * Takes a symbol for a function representing a test case and creates a
160 * &struct kunit_case object from it. See the documentation for
161 * &struct kunit_case for an example on how to use it.
163 #define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }
166 * struct kunit_suite - describes a related collection of &struct kunit_case
168 * @name: the name of the test. Purely informational.
169 * @init: called before every test case.
170 * @exit: called after every test case.
171 * @test_cases: a null terminated array of test cases.
173 * A kunit_suite is a collection of related &struct kunit_case s, such that
174 * @init is called before every test case and @exit is called after every
175 * test case, similar to the notion of a *test fixture* or a *test class*
176 * in other unit testing frameworks like JUnit or Googletest.
178 * Every &struct kunit_case must be associated with a kunit_suite for KUnit
182 const char name[256];
183 int (*init)(struct kunit *test);
184 void (*exit)(struct kunit *test);
185 struct kunit_case *test_cases;
187 /* private: internal use only */
188 struct dentry *debugfs;
193 * struct kunit - represents a running instance of a test.
195 * @priv: for user to store arbitrary data. Commonly used to pass data
196 * created in the init function (see &struct kunit_suite).
198 * Used to store information about the current context under which the test
199 * is running. Most of this data is private and should only be accessed
200 * indirectly via public functions; the one exception is @priv which can be
201 * used by the test writer to store arbitrary data.
206 /* private: internal use only. */
207 const char *name; /* Read only after initialization! */
208 char *log; /* Points at case log after initialization */
209 struct kunit_try_catch try_catch;
211 * success starts as true, and may only be set to false during a
212 * test case; thus, it is safe to update this across multiple
213 * threads using WRITE_ONCE; however, as a consequence, it may only
214 * be read after the test case finishes once all threads associated
215 * with the test case have terminated.
217 bool success; /* Read only after test_case finishes! */
218 spinlock_t lock; /* Guards all mutable test state. */
220 * Because resources is a list that may be updated multiple times (with
221 * new resources) from any thread associated with a test case, we must
222 * protect it with some type of lock.
224 struct list_head resources; /* Protected by lock. */
227 void kunit_init_test(struct kunit *test, const char *name, char *log);
229 int kunit_run_tests(struct kunit_suite *suite);
231 size_t kunit_suite_num_test_cases(struct kunit_suite *suite);
233 unsigned int kunit_test_case_num(struct kunit_suite *suite,
234 struct kunit_case *test_case);
236 int __kunit_test_suites_init(struct kunit_suite * const * const suites);
238 void __kunit_test_suites_exit(struct kunit_suite **suites);
241 * kunit_test_suites() - used to register one or more &struct kunit_suite
244 * @suites_list...: a statically allocated list of &struct kunit_suite.
246 * Registers @suites_list with the test framework. See &struct kunit_suite for
249 * If a test suite is built-in, module_init() gets translated into
250 * an initcall which we don't want as the idea is that for builtins
251 * the executor will manage execution. So ensure we do not define
252 * module_{init|exit} functions for the builtin case when registering
253 * suites via kunit_test_suites() below.
256 #define kunit_test_suites_for_module(__suites) \
257 static int __init kunit_test_suites_init(void) \
259 return __kunit_test_suites_init(__suites); \
261 module_init(kunit_test_suites_init); \
263 static void __exit kunit_test_suites_exit(void) \
265 return __kunit_test_suites_exit(__suites); \
267 module_exit(kunit_test_suites_exit)
269 #define kunit_test_suites_for_module(__suites)
272 #define __kunit_test_suites(unique_array, unique_suites, ...) \
273 static struct kunit_suite *unique_array[] = { __VA_ARGS__, NULL }; \
274 kunit_test_suites_for_module(unique_array); \
275 static struct kunit_suite **unique_suites \
276 __used __section(.kunit_test_suites) = unique_array
279 * kunit_test_suites() - used to register one or more &struct kunit_suite
282 * @suites: a statically allocated list of &struct kunit_suite.
284 * Registers @suites with the test framework. See &struct kunit_suite for
287 * When builtin, KUnit tests are all run via executor; this is done
288 * by placing the array of struct kunit_suite * in the .kunit_test_suites
291 * An alternative is to build the tests as a module. Because modules do not
292 * support multiple initcall()s, we need to initialize an array of suites for a
296 #define kunit_test_suites(...) \
297 __kunit_test_suites(__UNIQUE_ID(array), \
298 __UNIQUE_ID(suites), \
301 #define kunit_test_suite(suite) kunit_test_suites(&suite)
303 #define kunit_suite_for_each_test_case(suite, test_case) \
304 for (test_case = suite->test_cases; test_case->run_case; test_case++)
306 bool kunit_suite_has_succeeded(struct kunit_suite *suite);
309 * Like kunit_alloc_resource() below, but returns the struct kunit_resource
310 * object that contains the allocation. This is mostly for testing purposes.
312 struct kunit_resource *kunit_alloc_and_get_resource(struct kunit *test,
313 kunit_resource_init_t init,
314 kunit_resource_free_t free,
319 * kunit_get_resource() - Hold resource for use. Should not need to be used
320 * by most users as we automatically get resources
321 * retrieved by kunit_find_resource*().
324 static inline void kunit_get_resource(struct kunit_resource *res)
326 kref_get(&res->refcount);
330 * Called when refcount reaches zero via kunit_put_resources();
331 * should not be called directly.
333 static inline void kunit_release_resource(struct kref *kref)
335 struct kunit_resource *res = container_of(kref, struct kunit_resource,
338 /* If free function is defined, resource was dynamically allocated. */
346 * kunit_put_resource() - When caller is done with retrieved resource,
347 * kunit_put_resource() should be called to drop
348 * reference count. The resource list maintains
349 * a reference count on resources, so if no users
350 * are utilizing a resource and it is removed from
351 * the resource list, it will be freed via the
352 * associated free function (if any). Only
353 * needs to be used if we alloc_and_get() or
357 static inline void kunit_put_resource(struct kunit_resource *res)
359 kref_put(&res->refcount, kunit_release_resource);
363 * kunit_add_resource() - Add a *test managed resource*.
364 * @test: The test context object.
365 * @init: a user-supplied function to initialize the result (if needed). If
366 * none is supplied, the resource data value is simply set to @data.
367 * If an init function is supplied, @data is passed to it instead.
368 * @free: a user-supplied function to free the resource (if needed).
369 * @data: value to pass to init function or set in resource data field.
371 int kunit_add_resource(struct kunit *test,
372 kunit_resource_init_t init,
373 kunit_resource_free_t free,
374 struct kunit_resource *res,
378 * kunit_add_named_resource() - Add a named *test managed resource*.
379 * @test: The test context object.
380 * @init: a user-supplied function to initialize the resource data, if needed.
381 * @free: a user-supplied function to free the resource data, if needed.
382 * @name_data: name and data to be set for resource.
384 int kunit_add_named_resource(struct kunit *test,
385 kunit_resource_init_t init,
386 kunit_resource_free_t free,
387 struct kunit_resource *res,
392 * kunit_alloc_resource() - Allocates a *test managed resource*.
393 * @test: The test context object.
394 * @init: a user supplied function to initialize the resource.
395 * @free: a user supplied function to free the resource.
396 * @internal_gfp: gfp to use for internal allocations, if unsure, use GFP_KERNEL
397 * @context: for the user to pass in arbitrary data to the init function.
399 * Allocates a *test managed resource*, a resource which will automatically be
400 * cleaned up at the end of a test case. See &struct kunit_resource for an
403 * Note: KUnit needs to allocate memory for a kunit_resource object. You must
404 * specify an @internal_gfp that is compatible with the use context of your
407 static inline void *kunit_alloc_resource(struct kunit *test,
408 kunit_resource_init_t init,
409 kunit_resource_free_t free,
413 struct kunit_resource *res;
415 res = kzalloc(sizeof(*res), internal_gfp);
419 if (!kunit_add_resource(test, init, free, res, context))
425 typedef bool (*kunit_resource_match_t)(struct kunit *test,
426 struct kunit_resource *res,
430 * kunit_resource_instance_match() - Match a resource with the same instance.
431 * @test: Test case to which the resource belongs.
432 * @res: The resource.
433 * @match_data: The resource pointer to match against.
435 * An instance of kunit_resource_match_t that matches a resource whose
436 * allocation matches @match_data.
438 static inline bool kunit_resource_instance_match(struct kunit *test,
439 struct kunit_resource *res,
442 return res->data == match_data;
446 * kunit_resource_name_match() - Match a resource with the same name.
447 * @test: Test case to which the resource belongs.
448 * @res: The resource.
449 * @match_name: The name to match against.
451 static inline bool kunit_resource_name_match(struct kunit *test,
452 struct kunit_resource *res,
455 return res->name && strcmp(res->name, match_name) == 0;
459 * kunit_find_resource() - Find a resource using match function/data.
460 * @test: Test case to which the resource belongs.
461 * @match: match function to be applied to resources/match data.
462 * @match_data: data to be used in matching.
464 static inline struct kunit_resource *
465 kunit_find_resource(struct kunit *test,
466 kunit_resource_match_t match,
469 struct kunit_resource *res, *found = NULL;
471 spin_lock(&test->lock);
473 list_for_each_entry_reverse(res, &test->resources, node) {
474 if (match(test, res, (void *)match_data)) {
476 kunit_get_resource(found);
481 spin_unlock(&test->lock);
487 * kunit_find_named_resource() - Find a resource using match name.
488 * @test: Test case to which the resource belongs.
491 static inline struct kunit_resource *
492 kunit_find_named_resource(struct kunit *test,
495 return kunit_find_resource(test, kunit_resource_name_match,
500 * kunit_destroy_resource() - Find a kunit_resource and destroy it.
501 * @test: Test case to which the resource belongs.
502 * @match: Match function. Returns whether a given resource matches @match_data.
503 * @match_data: Data passed into @match.
506 * 0 if kunit_resource is found and freed, -ENOENT if not found.
508 int kunit_destroy_resource(struct kunit *test,
509 kunit_resource_match_t match,
512 static inline int kunit_destroy_named_resource(struct kunit *test,
515 return kunit_destroy_resource(test, kunit_resource_name_match,
520 * kunit_remove_resource: remove resource from resource list associated with
522 * @test: The test context object.
523 * @res: The resource to be removed.
525 * Note that the resource will not be immediately freed since it is likely
526 * the caller has a reference to it via alloc_and_get() or find();
527 * in this case a final call to kunit_put_resource() is required.
529 void kunit_remove_resource(struct kunit *test, struct kunit_resource *res);
532 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
533 * @test: The test context object.
534 * @size: The size in bytes of the desired memory.
535 * @gfp: flags passed to underlying kmalloc().
537 * Just like `kmalloc(...)`, except the allocation is managed by the test case
538 * and is automatically cleaned up after the test case concludes. See &struct
539 * kunit_resource for more information.
541 void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp);
544 * kunit_kfree() - Like kfree except for allocations managed by KUnit.
545 * @test: The test case to which the resource belongs.
546 * @ptr: The memory allocation to free.
548 void kunit_kfree(struct kunit *test, const void *ptr);
551 * kunit_kzalloc() - Just like kunit_kmalloc(), but zeroes the allocation.
552 * @test: The test context object.
553 * @size: The size in bytes of the desired memory.
554 * @gfp: flags passed to underlying kmalloc().
556 * See kzalloc() and kunit_kmalloc() for more information.
558 static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp)
560 return kunit_kmalloc(test, size, gfp | __GFP_ZERO);
563 void kunit_cleanup(struct kunit *test);
565 void kunit_log_append(char *log, const char *fmt, ...);
568 * printk and log to per-test or per-suite log buffer. Logging only done
569 * if CONFIG_KUNIT_DEBUGFS is 'y'; if it is 'n', no log is allocated/used.
571 #define kunit_log(lvl, test_or_suite, fmt, ...) \
573 printk(lvl fmt, ##__VA_ARGS__); \
574 kunit_log_append((test_or_suite)->log, fmt "\n", \
578 #define kunit_printk(lvl, test, fmt, ...) \
579 kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \
580 (test)->name, ##__VA_ARGS__)
583 * kunit_info() - Prints an INFO level message associated with @test.
585 * @test: The test context object.
586 * @fmt: A printk() style format string.
588 * Prints an info level message associated with the test suite being run.
589 * Takes a variable number of format parameters just like printk().
591 #define kunit_info(test, fmt, ...) \
592 kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
595 * kunit_warn() - Prints a WARN level message associated with @test.
597 * @test: The test context object.
598 * @fmt: A printk() style format string.
600 * Prints a warning level message.
602 #define kunit_warn(test, fmt, ...) \
603 kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
606 * kunit_err() - Prints an ERROR level message associated with @test.
608 * @test: The test context object.
609 * @fmt: A printk() style format string.
611 * Prints an error level message.
613 #define kunit_err(test, fmt, ...) \
614 kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
617 * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
618 * @test: The test context object.
620 * The opposite of KUNIT_FAIL(), it is an expectation that cannot fail. In other
621 * words, it does nothing and only exists for code clarity. See
622 * KUNIT_EXPECT_TRUE() for more information.
624 #define KUNIT_SUCCEED(test) do {} while (0)
626 void kunit_do_assertion(struct kunit *test,
627 struct kunit_assert *assert,
629 const char *fmt, ...);
631 #define KUNIT_ASSERTION(test, pass, assert_class, INITIALIZER, fmt, ...) do { \
632 struct assert_class __assertion = INITIALIZER; \
633 kunit_do_assertion(test, \
634 &__assertion.assert, \
641 #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \
642 KUNIT_ASSERTION(test, \
645 KUNIT_INIT_FAIL_ASSERT_STRUCT(test, assert_type), \
650 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
651 * @test: The test context object.
652 * @fmt: an informational message to be printed when the assertion is made.
653 * @...: string format arguments.
655 * The opposite of KUNIT_SUCCEED(), it is an expectation that always fails. In
656 * other words, it always results in a failed expectation, and consequently
657 * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
658 * for more information.
660 #define KUNIT_FAIL(test, fmt, ...) \
661 KUNIT_FAIL_ASSERTION(test, \
666 #define KUNIT_UNARY_ASSERTION(test, \
672 KUNIT_ASSERTION(test, \
673 !!(condition) == !!expected_true, \
674 kunit_unary_assert, \
675 KUNIT_INIT_UNARY_ASSERT_STRUCT(test, \
682 #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
683 KUNIT_UNARY_ASSERTION(test, \
690 #define KUNIT_TRUE_ASSERTION(test, assert_type, condition) \
691 KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, NULL)
693 #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
694 KUNIT_UNARY_ASSERTION(test, \
701 #define KUNIT_FALSE_ASSERTION(test, assert_type, condition) \
702 KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, NULL)
705 * A factory macro for defining the assertions and expectations for the basic
706 * comparisons defined for the built in types.
708 * Unfortunately, there is no common type that all types can be promoted to for
709 * which all the binary operators behave the same way as for the actual types
710 * (for example, there is no type that long long and unsigned long long can
711 * both be cast to where the comparison result is preserved for all values). So
712 * the best we can do is do the comparison in the original types and then coerce
713 * everything to long long for printing; this way, the comparison behaves
714 * correctly and the printed out value usually makes sense without
715 * interpretation, but can always be interpreted to figure out the actual
718 #define KUNIT_BASE_BINARY_ASSERTION(test, \
728 typeof(left) __left = (left); \
729 typeof(right) __right = (right); \
730 ((void)__typecheck(__left, __right)); \
732 KUNIT_ASSERTION(test, \
735 ASSERT_CLASS_INIT(test, \
746 #define KUNIT_BASE_EQ_MSG_ASSERTION(test, \
754 KUNIT_BASE_BINARY_ASSERTION(test, \
762 #define KUNIT_BASE_NE_MSG_ASSERTION(test, \
770 KUNIT_BASE_BINARY_ASSERTION(test, \
778 #define KUNIT_BASE_LT_MSG_ASSERTION(test, \
786 KUNIT_BASE_BINARY_ASSERTION(test, \
794 #define KUNIT_BASE_LE_MSG_ASSERTION(test, \
802 KUNIT_BASE_BINARY_ASSERTION(test, \
810 #define KUNIT_BASE_GT_MSG_ASSERTION(test, \
818 KUNIT_BASE_BINARY_ASSERTION(test, \
826 #define KUNIT_BASE_GE_MSG_ASSERTION(test, \
834 KUNIT_BASE_BINARY_ASSERTION(test, \
842 #define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
843 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
844 kunit_binary_assert, \
845 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
852 #define KUNIT_BINARY_EQ_ASSERTION(test, assert_type, left, right) \
853 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
859 #define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
865 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
866 kunit_binary_ptr_assert, \
867 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
874 #define KUNIT_BINARY_PTR_EQ_ASSERTION(test, assert_type, left, right) \
875 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
881 #define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
882 KUNIT_BASE_NE_MSG_ASSERTION(test, \
883 kunit_binary_assert, \
884 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
891 #define KUNIT_BINARY_NE_ASSERTION(test, assert_type, left, right) \
892 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
898 #define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
904 KUNIT_BASE_NE_MSG_ASSERTION(test, \
905 kunit_binary_ptr_assert, \
906 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
913 #define KUNIT_BINARY_PTR_NE_ASSERTION(test, assert_type, left, right) \
914 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
920 #define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
921 KUNIT_BASE_LT_MSG_ASSERTION(test, \
922 kunit_binary_assert, \
923 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
930 #define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right) \
931 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
937 #define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
943 KUNIT_BASE_LT_MSG_ASSERTION(test, \
944 kunit_binary_ptr_assert, \
945 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
952 #define KUNIT_BINARY_PTR_LT_ASSERTION(test, assert_type, left, right) \
953 KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
959 #define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
960 KUNIT_BASE_LE_MSG_ASSERTION(test, \
961 kunit_binary_assert, \
962 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
969 #define KUNIT_BINARY_LE_ASSERTION(test, assert_type, left, right) \
970 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
976 #define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
982 KUNIT_BASE_LE_MSG_ASSERTION(test, \
983 kunit_binary_ptr_assert, \
984 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
991 #define KUNIT_BINARY_PTR_LE_ASSERTION(test, assert_type, left, right) \
992 KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
998 #define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
999 KUNIT_BASE_GT_MSG_ASSERTION(test, \
1000 kunit_binary_assert, \
1001 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
1008 #define KUNIT_BINARY_GT_ASSERTION(test, assert_type, left, right) \
1009 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1015 #define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
1021 KUNIT_BASE_GT_MSG_ASSERTION(test, \
1022 kunit_binary_ptr_assert, \
1023 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
1030 #define KUNIT_BINARY_PTR_GT_ASSERTION(test, assert_type, left, right) \
1031 KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
1037 #define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
1038 KUNIT_BASE_GE_MSG_ASSERTION(test, \
1039 kunit_binary_assert, \
1040 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
1047 #define KUNIT_BINARY_GE_ASSERTION(test, assert_type, left, right) \
1048 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1054 #define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
1060 KUNIT_BASE_GE_MSG_ASSERTION(test, \
1061 kunit_binary_ptr_assert, \
1062 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
1069 #define KUNIT_BINARY_PTR_GE_ASSERTION(test, assert_type, left, right) \
1070 KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
1076 #define KUNIT_BINARY_STR_ASSERTION(test, \
1084 typeof(left) __left = (left); \
1085 typeof(right) __right = (right); \
1087 KUNIT_ASSERTION(test, \
1088 strcmp(__left, __right) op 0, \
1089 kunit_binary_str_assert, \
1090 KUNIT_INIT_BINARY_ASSERT_STRUCT(test, \
1101 #define KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1107 KUNIT_BINARY_STR_ASSERTION(test, \
1113 #define KUNIT_BINARY_STR_EQ_ASSERTION(test, assert_type, left, right) \
1114 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1120 #define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1126 KUNIT_BINARY_STR_ASSERTION(test, \
1132 #define KUNIT_BINARY_STR_NE_ASSERTION(test, assert_type, left, right) \
1133 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1139 #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1145 typeof(ptr) __ptr = (ptr); \
1147 KUNIT_ASSERTION(test, \
1148 !IS_ERR_OR_NULL(__ptr), \
1149 kunit_ptr_not_err_assert, \
1150 KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, \
1158 #define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \
1159 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1165 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
1166 * @test: The test context object.
1167 * @condition: an arbitrary boolean expression. The test fails when this does
1168 * not evaluate to true.
1170 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
1171 * to fail when the specified condition is not met; however, it will not prevent
1172 * the test case from continuing to run; this is otherwise known as an
1173 * *expectation failure*.
1175 #define KUNIT_EXPECT_TRUE(test, condition) \
1176 KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1178 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
1179 KUNIT_TRUE_MSG_ASSERTION(test, \
1180 KUNIT_EXPECTATION, \
1186 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
1187 * @test: The test context object.
1188 * @condition: an arbitrary boolean expression. The test fails when this does
1189 * not evaluate to false.
1191 * Sets an expectation that @condition evaluates to false. See
1192 * KUNIT_EXPECT_TRUE() for more information.
1194 #define KUNIT_EXPECT_FALSE(test, condition) \
1195 KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
1197 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
1198 KUNIT_FALSE_MSG_ASSERTION(test, \
1199 KUNIT_EXPECTATION, \
1205 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
1206 * @test: The test context object.
1207 * @left: an arbitrary expression that evaluates to a primitive C type.
1208 * @right: an arbitrary expression that evaluates to a primitive C type.
1210 * Sets an expectation that the values that @left and @right evaluate to are
1211 * equal. This is semantically equivalent to
1212 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1215 #define KUNIT_EXPECT_EQ(test, left, right) \
1216 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1218 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
1219 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1220 KUNIT_EXPECTATION, \
1227 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
1228 * @test: The test context object.
1229 * @left: an arbitrary expression that evaluates to a pointer.
1230 * @right: an arbitrary expression that evaluates to a pointer.
1232 * Sets an expectation that the values that @left and @right evaluate to are
1233 * equal. This is semantically equivalent to
1234 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1237 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
1238 KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
1239 KUNIT_EXPECTATION, \
1243 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1244 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1245 KUNIT_EXPECTATION, \
1252 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
1253 * @test: The test context object.
1254 * @left: an arbitrary expression that evaluates to a primitive C type.
1255 * @right: an arbitrary expression that evaluates to a primitive C type.
1257 * Sets an expectation that the values that @left and @right evaluate to are not
1258 * equal. This is semantically equivalent to
1259 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1262 #define KUNIT_EXPECT_NE(test, left, right) \
1263 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1265 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
1266 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1267 KUNIT_EXPECTATION, \
1274 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
1275 * @test: The test context object.
1276 * @left: an arbitrary expression that evaluates to a pointer.
1277 * @right: an arbitrary expression that evaluates to a pointer.
1279 * Sets an expectation that the values that @left and @right evaluate to are not
1280 * equal. This is semantically equivalent to
1281 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1284 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
1285 KUNIT_BINARY_PTR_NE_ASSERTION(test, \
1286 KUNIT_EXPECTATION, \
1290 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
1291 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1292 KUNIT_EXPECTATION, \
1299 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
1300 * @test: The test context object.
1301 * @left: an arbitrary expression that evaluates to a primitive C type.
1302 * @right: an arbitrary expression that evaluates to a primitive C type.
1304 * Sets an expectation that the value that @left evaluates to is less than the
1305 * value that @right evaluates to. This is semantically equivalent to
1306 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
1309 #define KUNIT_EXPECT_LT(test, left, right) \
1310 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1312 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
1313 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1314 KUNIT_EXPECTATION, \
1321 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
1322 * @test: The test context object.
1323 * @left: an arbitrary expression that evaluates to a primitive C type.
1324 * @right: an arbitrary expression that evaluates to a primitive C type.
1326 * Sets an expectation that the value that @left evaluates to is less than or
1327 * equal to the value that @right evaluates to. Semantically this is equivalent
1328 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
1331 #define KUNIT_EXPECT_LE(test, left, right) \
1332 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1334 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
1335 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1336 KUNIT_EXPECTATION, \
1343 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
1344 * @test: The test context object.
1345 * @left: an arbitrary expression that evaluates to a primitive C type.
1346 * @right: an arbitrary expression that evaluates to a primitive C type.
1348 * Sets an expectation that the value that @left evaluates to is greater than
1349 * the value that @right evaluates to. This is semantically equivalent to
1350 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
1353 #define KUNIT_EXPECT_GT(test, left, right) \
1354 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1356 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
1357 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1358 KUNIT_EXPECTATION, \
1365 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
1366 * @test: The test context object.
1367 * @left: an arbitrary expression that evaluates to a primitive C type.
1368 * @right: an arbitrary expression that evaluates to a primitive C type.
1370 * Sets an expectation that the value that @left evaluates to is greater than
1371 * the value that @right evaluates to. This is semantically equivalent to
1372 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
1375 #define KUNIT_EXPECT_GE(test, left, right) \
1376 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1378 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
1379 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1380 KUNIT_EXPECTATION, \
1387 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
1388 * @test: The test context object.
1389 * @left: an arbitrary expression that evaluates to a null terminated string.
1390 * @right: an arbitrary expression that evaluates to a null terminated string.
1392 * Sets an expectation that the values that @left and @right evaluate to are
1393 * equal. This is semantically equivalent to
1394 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1395 * for more information.
1397 #define KUNIT_EXPECT_STREQ(test, left, right) \
1398 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1400 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
1401 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1402 KUNIT_EXPECTATION, \
1409 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
1410 * @test: The test context object.
1411 * @left: an arbitrary expression that evaluates to a null terminated string.
1412 * @right: an arbitrary expression that evaluates to a null terminated string.
1414 * Sets an expectation that the values that @left and @right evaluate to are
1415 * not equal. This is semantically equivalent to
1416 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1417 * for more information.
1419 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
1420 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1422 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
1423 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1424 KUNIT_EXPECTATION, \
1431 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
1432 * @test: The test context object.
1433 * @ptr: an arbitrary pointer.
1435 * Sets an expectation that the value that @ptr evaluates to is not null and not
1436 * an errno stored in a pointer. This is semantically equivalent to
1437 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
1440 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
1441 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
1443 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1444 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1445 KUNIT_EXPECTATION, \
1450 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
1451 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
1454 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
1455 * @test: The test context object.
1456 * @condition: an arbitrary boolean expression. The test fails and aborts when
1457 * this does not evaluate to true.
1459 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1460 * fail *and immediately abort* when the specified condition is not met. Unlike
1461 * an expectation failure, it will prevent the test case from continuing to run;
1462 * this is otherwise known as an *assertion failure*.
1464 #define KUNIT_ASSERT_TRUE(test, condition) \
1465 KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
1467 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
1468 KUNIT_TRUE_MSG_ASSERTION(test, \
1475 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
1476 * @test: The test context object.
1477 * @condition: an arbitrary boolean expression.
1479 * Sets an assertion that the value that @condition evaluates to is false. This
1480 * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
1481 * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1483 #define KUNIT_ASSERT_FALSE(test, condition) \
1484 KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
1486 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
1487 KUNIT_FALSE_MSG_ASSERTION(test, \
1494 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
1495 * @test: The test context object.
1496 * @left: an arbitrary expression that evaluates to a primitive C type.
1497 * @right: an arbitrary expression that evaluates to a primitive C type.
1499 * Sets an assertion that the values that @left and @right evaluate to are
1500 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1501 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1503 #define KUNIT_ASSERT_EQ(test, left, right) \
1504 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1506 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
1507 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1515 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1516 * @test: The test context object.
1517 * @left: an arbitrary expression that evaluates to a pointer.
1518 * @right: an arbitrary expression that evaluates to a pointer.
1520 * Sets an assertion that the values that @left and @right evaluate to are
1521 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1522 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1524 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
1525 KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1527 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1528 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1536 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
1537 * @test: The test context object.
1538 * @left: an arbitrary expression that evaluates to a primitive C type.
1539 * @right: an arbitrary expression that evaluates to a primitive C type.
1541 * Sets an assertion that the values that @left and @right evaluate to are not
1542 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1543 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1545 #define KUNIT_ASSERT_NE(test, left, right) \
1546 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1548 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
1549 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1557 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
1558 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1559 * @test: The test context object.
1560 * @left: an arbitrary expression that evaluates to a pointer.
1561 * @right: an arbitrary expression that evaluates to a pointer.
1563 * Sets an assertion that the values that @left and @right evaluate to are not
1564 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1565 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1567 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
1568 KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1570 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
1571 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1578 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
1579 * @test: The test context object.
1580 * @left: an arbitrary expression that evaluates to a primitive C type.
1581 * @right: an arbitrary expression that evaluates to a primitive C type.
1583 * Sets an assertion that the value that @left evaluates to is less than the
1584 * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
1585 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1588 #define KUNIT_ASSERT_LT(test, left, right) \
1589 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1591 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
1592 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1599 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
1600 * @test: The test context object.
1601 * @left: an arbitrary expression that evaluates to a primitive C type.
1602 * @right: an arbitrary expression that evaluates to a primitive C type.
1604 * Sets an assertion that the value that @left evaluates to is less than or
1605 * equal to the value that @right evaluates to. This is the same as
1606 * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
1607 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1609 #define KUNIT_ASSERT_LE(test, left, right) \
1610 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1612 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
1613 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1621 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
1622 * @test: The test context object.
1623 * @left: an arbitrary expression that evaluates to a primitive C type.
1624 * @right: an arbitrary expression that evaluates to a primitive C type.
1626 * Sets an assertion that the value that @left evaluates to is greater than the
1627 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
1628 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1631 #define KUNIT_ASSERT_GT(test, left, right) \
1632 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1634 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
1635 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1643 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
1644 * @test: The test context object.
1645 * @left: an arbitrary expression that evaluates to a primitive C type.
1646 * @right: an arbitrary expression that evaluates to a primitive C type.
1648 * Sets an assertion that the value that @left evaluates to is greater than the
1649 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
1650 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1653 #define KUNIT_ASSERT_GE(test, left, right) \
1654 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1656 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
1657 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1665 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
1666 * @test: The test context object.
1667 * @left: an arbitrary expression that evaluates to a null terminated string.
1668 * @right: an arbitrary expression that evaluates to a null terminated string.
1670 * Sets an assertion that the values that @left and @right evaluate to are
1671 * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
1672 * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1674 #define KUNIT_ASSERT_STREQ(test, left, right) \
1675 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1677 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
1678 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1686 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
1687 * @test: The test context object.
1688 * @left: an arbitrary expression that evaluates to a null terminated string.
1689 * @right: an arbitrary expression that evaluates to a null terminated string.
1691 * Sets an expectation that the values that @left and @right evaluate to are
1692 * not equal. This is semantically equivalent to
1693 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1694 * for more information.
1696 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
1697 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1699 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
1700 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1708 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
1709 * @test: The test context object.
1710 * @ptr: an arbitrary pointer.
1712 * Sets an assertion that the value that @ptr evaluates to is not null and not
1713 * an errno stored in a pointer. This is the same as
1714 * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
1715 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1717 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
1718 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
1720 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1721 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1727 #endif /* _KUNIT_TEST_H */