drm/panfrost: Remove set but not used variable 'bo'
[linux/fpc-iii.git] / include / kunit / test.h
blob2dfb550c6723aab9f9cb4544851247b7b18ce668
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Base unit test (KUnit) API.
5 * Copyright (C) 2019, Google LLC.
6 * Author: Brendan Higgins <brendanhiggins@google.com>
7 */
9 #ifndef _KUNIT_TEST_H
10 #define _KUNIT_TEST_H
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>
19 struct kunit_resource;
21 typedef int (*kunit_resource_init_t)(struct kunit_resource *, void *);
22 typedef void (*kunit_resource_free_t)(struct kunit_resource *);
24 /**
25 * struct kunit_resource - represents a *test managed resource*
26 * @allocation: for the user to store arbitrary data.
27 * @free: a user supplied function to free the resource. Populated by
28 * kunit_alloc_resource().
30 * Represents a *test managed resource*, a resource which will automatically be
31 * cleaned up at the end of a test case.
33 * Example:
35 * .. code-block:: c
37 * struct kunit_kmalloc_params {
38 * size_t size;
39 * gfp_t gfp;
40 * };
42 * static int kunit_kmalloc_init(struct kunit_resource *res, void *context)
43 * {
44 * struct kunit_kmalloc_params *params = context;
45 * res->allocation = kmalloc(params->size, params->gfp);
47 * if (!res->allocation)
48 * return -ENOMEM;
50 * return 0;
51 * }
53 * static void kunit_kmalloc_free(struct kunit_resource *res)
54 * {
55 * kfree(res->allocation);
56 * }
58 * void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp)
59 * {
60 * struct kunit_kmalloc_params params;
61 * struct kunit_resource *res;
63 * params.size = size;
64 * params.gfp = gfp;
66 * res = kunit_alloc_resource(test, kunit_kmalloc_init,
67 * kunit_kmalloc_free, &params);
68 * if (res)
69 * return res->allocation;
71 * return NULL;
72 * }
74 struct kunit_resource {
75 void *allocation;
76 kunit_resource_free_t free;
78 /* private: internal use only. */
79 struct list_head node;
82 struct kunit;
84 /**
85 * struct kunit_case - represents an individual test case.
87 * @run_case: the function representing the actual test case.
88 * @name: the name of the test case.
90 * A test case is a function with the signature,
91 * ``void (*)(struct kunit *)``
92 * that makes expectations and assertions (see KUNIT_EXPECT_TRUE() and
93 * KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated
94 * with a &struct kunit_suite and will be run after the suite's init
95 * function and followed by the suite's exit function.
97 * A test case should be static and should only be created with the
98 * KUNIT_CASE() macro; additionally, every array of test cases should be
99 * terminated with an empty test case.
101 * Example:
103 * .. code-block:: c
105 * void add_test_basic(struct kunit *test)
107 * KUNIT_EXPECT_EQ(test, 1, add(1, 0));
108 * KUNIT_EXPECT_EQ(test, 2, add(1, 1));
109 * KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
110 * KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
111 * KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
114 * static struct kunit_case example_test_cases[] = {
115 * KUNIT_CASE(add_test_basic),
116 * {}
117 * };
120 struct kunit_case {
121 void (*run_case)(struct kunit *test);
122 const char *name;
124 /* private: internal use only. */
125 bool success;
129 * KUNIT_CASE - A helper for creating a &struct kunit_case
131 * @test_name: a reference to a test case function.
133 * Takes a symbol for a function representing a test case and creates a
134 * &struct kunit_case object from it. See the documentation for
135 * &struct kunit_case for an example on how to use it.
137 #define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }
140 * struct kunit_suite - describes a related collection of &struct kunit_case
142 * @name: the name of the test. Purely informational.
143 * @init: called before every test case.
144 * @exit: called after every test case.
145 * @test_cases: a null terminated array of test cases.
147 * A kunit_suite is a collection of related &struct kunit_case s, such that
148 * @init is called before every test case and @exit is called after every
149 * test case, similar to the notion of a *test fixture* or a *test class*
150 * in other unit testing frameworks like JUnit or Googletest.
152 * Every &struct kunit_case must be associated with a kunit_suite for KUnit
153 * to run it.
155 struct kunit_suite {
156 const char name[256];
157 int (*init)(struct kunit *test);
158 void (*exit)(struct kunit *test);
159 struct kunit_case *test_cases;
163 * struct kunit - represents a running instance of a test.
165 * @priv: for user to store arbitrary data. Commonly used to pass data
166 * created in the init function (see &struct kunit_suite).
168 * Used to store information about the current context under which the test
169 * is running. Most of this data is private and should only be accessed
170 * indirectly via public functions; the one exception is @priv which can be
171 * used by the test writer to store arbitrary data.
173 struct kunit {
174 void *priv;
176 /* private: internal use only. */
177 const char *name; /* Read only after initialization! */
178 struct kunit_try_catch try_catch;
180 * success starts as true, and may only be set to false during a
181 * test case; thus, it is safe to update this across multiple
182 * threads using WRITE_ONCE; however, as a consequence, it may only
183 * be read after the test case finishes once all threads associated
184 * with the test case have terminated.
186 bool success; /* Read only after test_case finishes! */
187 spinlock_t lock; /* Guards all mutable test state. */
189 * Because resources is a list that may be updated multiple times (with
190 * new resources) from any thread associated with a test case, we must
191 * protect it with some type of lock.
193 struct list_head resources; /* Protected by lock. */
196 void kunit_init_test(struct kunit *test, const char *name);
198 int kunit_run_tests(struct kunit_suite *suite);
201 * kunit_test_suites() - used to register one or more &struct kunit_suite
202 * with KUnit.
204 * @suites: a statically allocated list of &struct kunit_suite.
206 * Registers @suites with the test framework. See &struct kunit_suite for
207 * more information.
209 * When builtin, KUnit tests are all run as late_initcalls; this means
210 * that they cannot test anything where tests must run at a different init
211 * phase. One significant restriction resulting from this is that KUnit
212 * cannot reliably test anything that is initialize in the late_init phase;
213 * another is that KUnit is useless to test things that need to be run in
214 * an earlier init phase.
216 * An alternative is to build the tests as a module. Because modules
217 * do not support multiple late_initcall()s, we need to initialize an
218 * array of suites for a module.
220 * TODO(brendanhiggins@google.com): Don't run all KUnit tests as
221 * late_initcalls. I have some future work planned to dispatch all KUnit
222 * tests from the same place, and at the very least to do so after
223 * everything else is definitely initialized.
225 #define kunit_test_suites(...) \
226 static struct kunit_suite *suites[] = { __VA_ARGS__, NULL}; \
227 static int kunit_test_suites_init(void) \
229 unsigned int i; \
230 for (i = 0; suites[i] != NULL; i++) \
231 kunit_run_tests(suites[i]); \
232 return 0; \
234 late_initcall(kunit_test_suites_init); \
235 static void __exit kunit_test_suites_exit(void) \
237 return; \
239 module_exit(kunit_test_suites_exit)
241 #define kunit_test_suite(suite) kunit_test_suites(&suite)
244 * Like kunit_alloc_resource() below, but returns the struct kunit_resource
245 * object that contains the allocation. This is mostly for testing purposes.
247 struct kunit_resource *kunit_alloc_and_get_resource(struct kunit *test,
248 kunit_resource_init_t init,
249 kunit_resource_free_t free,
250 gfp_t internal_gfp,
251 void *context);
254 * kunit_alloc_resource() - Allocates a *test managed resource*.
255 * @test: The test context object.
256 * @init: a user supplied function to initialize the resource.
257 * @free: a user supplied function to free the resource.
258 * @internal_gfp: gfp to use for internal allocations, if unsure, use GFP_KERNEL
259 * @context: for the user to pass in arbitrary data to the init function.
261 * Allocates a *test managed resource*, a resource which will automatically be
262 * cleaned up at the end of a test case. See &struct kunit_resource for an
263 * example.
265 * NOTE: KUnit needs to allocate memory for each kunit_resource object. You must
266 * specify an @internal_gfp that is compatible with the use context of your
267 * resource.
269 static inline void *kunit_alloc_resource(struct kunit *test,
270 kunit_resource_init_t init,
271 kunit_resource_free_t free,
272 gfp_t internal_gfp,
273 void *context)
275 struct kunit_resource *res;
277 res = kunit_alloc_and_get_resource(test, init, free, internal_gfp,
278 context);
280 if (res)
281 return res->allocation;
283 return NULL;
286 typedef bool (*kunit_resource_match_t)(struct kunit *test,
287 const void *res,
288 void *match_data);
291 * kunit_resource_instance_match() - Match a resource with the same instance.
292 * @test: Test case to which the resource belongs.
293 * @res: The data stored in kunit_resource->allocation.
294 * @match_data: The resource pointer to match against.
296 * An instance of kunit_resource_match_t that matches a resource whose
297 * allocation matches @match_data.
299 static inline bool kunit_resource_instance_match(struct kunit *test,
300 const void *res,
301 void *match_data)
303 return res == match_data;
307 * kunit_resource_destroy() - Find a kunit_resource and destroy it.
308 * @test: Test case to which the resource belongs.
309 * @match: Match function. Returns whether a given resource matches @match_data.
310 * @free: Must match free on the kunit_resource to free.
311 * @match_data: Data passed into @match.
313 * Free the latest kunit_resource of @test for which @free matches the
314 * kunit_resource_free_t associated with the resource and for which @match
315 * returns true.
317 * RETURNS:
318 * 0 if kunit_resource is found and freed, -ENOENT if not found.
320 int kunit_resource_destroy(struct kunit *test,
321 kunit_resource_match_t match,
322 kunit_resource_free_t free,
323 void *match_data);
326 * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
327 * @test: The test context object.
328 * @size: The size in bytes of the desired memory.
329 * @gfp: flags passed to underlying kmalloc().
331 * Just like `kmalloc(...)`, except the allocation is managed by the test case
332 * and is automatically cleaned up after the test case concludes. See &struct
333 * kunit_resource for more information.
335 void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp);
338 * kunit_kfree() - Like kfree except for allocations managed by KUnit.
339 * @test: The test case to which the resource belongs.
340 * @ptr: The memory allocation to free.
342 void kunit_kfree(struct kunit *test, const void *ptr);
345 * kunit_kzalloc() - Just like kunit_kmalloc(), but zeroes the allocation.
346 * @test: The test context object.
347 * @size: The size in bytes of the desired memory.
348 * @gfp: flags passed to underlying kmalloc().
350 * See kzalloc() and kunit_kmalloc() for more information.
352 static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp)
354 return kunit_kmalloc(test, size, gfp | __GFP_ZERO);
357 void kunit_cleanup(struct kunit *test);
359 #define kunit_printk(lvl, test, fmt, ...) \
360 printk(lvl "\t# %s: " fmt, (test)->name, ##__VA_ARGS__)
363 * kunit_info() - Prints an INFO level message associated with @test.
365 * @test: The test context object.
366 * @fmt: A printk() style format string.
368 * Prints an info level message associated with the test suite being run.
369 * Takes a variable number of format parameters just like printk().
371 #define kunit_info(test, fmt, ...) \
372 kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
375 * kunit_warn() - Prints a WARN level message associated with @test.
377 * @test: The test context object.
378 * @fmt: A printk() style format string.
380 * Prints a warning level message.
382 #define kunit_warn(test, fmt, ...) \
383 kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
386 * kunit_err() - Prints an ERROR level message associated with @test.
388 * @test: The test context object.
389 * @fmt: A printk() style format string.
391 * Prints an error level message.
393 #define kunit_err(test, fmt, ...) \
394 kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
397 * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
398 * @test: The test context object.
400 * The opposite of KUNIT_FAIL(), it is an expectation that cannot fail. In other
401 * words, it does nothing and only exists for code clarity. See
402 * KUNIT_EXPECT_TRUE() for more information.
404 #define KUNIT_SUCCEED(test) do {} while (0)
406 void kunit_do_assertion(struct kunit *test,
407 struct kunit_assert *assert,
408 bool pass,
409 const char *fmt, ...);
411 #define KUNIT_ASSERTION(test, pass, assert_class, INITIALIZER, fmt, ...) do { \
412 struct assert_class __assertion = INITIALIZER; \
413 kunit_do_assertion(test, \
414 &__assertion.assert, \
415 pass, \
416 fmt, \
417 ##__VA_ARGS__); \
418 } while (0)
421 #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \
422 KUNIT_ASSERTION(test, \
423 false, \
424 kunit_fail_assert, \
425 KUNIT_INIT_FAIL_ASSERT_STRUCT(test, assert_type), \
426 fmt, \
427 ##__VA_ARGS__)
430 * KUNIT_FAIL() - Always causes a test to fail when evaluated.
431 * @test: The test context object.
432 * @fmt: an informational message to be printed when the assertion is made.
433 * @...: string format arguments.
435 * The opposite of KUNIT_SUCCEED(), it is an expectation that always fails. In
436 * other words, it always results in a failed expectation, and consequently
437 * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
438 * for more information.
440 #define KUNIT_FAIL(test, fmt, ...) \
441 KUNIT_FAIL_ASSERTION(test, \
442 KUNIT_EXPECTATION, \
443 fmt, \
444 ##__VA_ARGS__)
446 #define KUNIT_UNARY_ASSERTION(test, \
447 assert_type, \
448 condition, \
449 expected_true, \
450 fmt, \
451 ...) \
452 KUNIT_ASSERTION(test, \
453 !!(condition) == !!expected_true, \
454 kunit_unary_assert, \
455 KUNIT_INIT_UNARY_ASSERT_STRUCT(test, \
456 assert_type, \
457 #condition, \
458 expected_true), \
459 fmt, \
460 ##__VA_ARGS__)
462 #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
463 KUNIT_UNARY_ASSERTION(test, \
464 assert_type, \
465 condition, \
466 true, \
467 fmt, \
468 ##__VA_ARGS__)
470 #define KUNIT_TRUE_ASSERTION(test, assert_type, condition) \
471 KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, NULL)
473 #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
474 KUNIT_UNARY_ASSERTION(test, \
475 assert_type, \
476 condition, \
477 false, \
478 fmt, \
479 ##__VA_ARGS__)
481 #define KUNIT_FALSE_ASSERTION(test, assert_type, condition) \
482 KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, NULL)
485 * A factory macro for defining the assertions and expectations for the basic
486 * comparisons defined for the built in types.
488 * Unfortunately, there is no common type that all types can be promoted to for
489 * which all the binary operators behave the same way as for the actual types
490 * (for example, there is no type that long long and unsigned long long can
491 * both be cast to where the comparison result is preserved for all values). So
492 * the best we can do is do the comparison in the original types and then coerce
493 * everything to long long for printing; this way, the comparison behaves
494 * correctly and the printed out value usually makes sense without
495 * interpretation, but can always be interpreted to figure out the actual
496 * value.
498 #define KUNIT_BASE_BINARY_ASSERTION(test, \
499 assert_class, \
500 ASSERT_CLASS_INIT, \
501 assert_type, \
502 left, \
503 op, \
504 right, \
505 fmt, \
506 ...) \
507 do { \
508 typeof(left) __left = (left); \
509 typeof(right) __right = (right); \
510 ((void)__typecheck(__left, __right)); \
512 KUNIT_ASSERTION(test, \
513 __left op __right, \
514 assert_class, \
515 ASSERT_CLASS_INIT(test, \
516 assert_type, \
517 #op, \
518 #left, \
519 __left, \
520 #right, \
521 __right), \
522 fmt, \
523 ##__VA_ARGS__); \
524 } while (0)
526 #define KUNIT_BASE_EQ_MSG_ASSERTION(test, \
527 assert_class, \
528 ASSERT_CLASS_INIT, \
529 assert_type, \
530 left, \
531 right, \
532 fmt, \
533 ...) \
534 KUNIT_BASE_BINARY_ASSERTION(test, \
535 assert_class, \
536 ASSERT_CLASS_INIT, \
537 assert_type, \
538 left, ==, right, \
539 fmt, \
540 ##__VA_ARGS__)
542 #define KUNIT_BASE_NE_MSG_ASSERTION(test, \
543 assert_class, \
544 ASSERT_CLASS_INIT, \
545 assert_type, \
546 left, \
547 right, \
548 fmt, \
549 ...) \
550 KUNIT_BASE_BINARY_ASSERTION(test, \
551 assert_class, \
552 ASSERT_CLASS_INIT, \
553 assert_type, \
554 left, !=, right, \
555 fmt, \
556 ##__VA_ARGS__)
558 #define KUNIT_BASE_LT_MSG_ASSERTION(test, \
559 assert_class, \
560 ASSERT_CLASS_INIT, \
561 assert_type, \
562 left, \
563 right, \
564 fmt, \
565 ...) \
566 KUNIT_BASE_BINARY_ASSERTION(test, \
567 assert_class, \
568 ASSERT_CLASS_INIT, \
569 assert_type, \
570 left, <, right, \
571 fmt, \
572 ##__VA_ARGS__)
574 #define KUNIT_BASE_LE_MSG_ASSERTION(test, \
575 assert_class, \
576 ASSERT_CLASS_INIT, \
577 assert_type, \
578 left, \
579 right, \
580 fmt, \
581 ...) \
582 KUNIT_BASE_BINARY_ASSERTION(test, \
583 assert_class, \
584 ASSERT_CLASS_INIT, \
585 assert_type, \
586 left, <=, right, \
587 fmt, \
588 ##__VA_ARGS__)
590 #define KUNIT_BASE_GT_MSG_ASSERTION(test, \
591 assert_class, \
592 ASSERT_CLASS_INIT, \
593 assert_type, \
594 left, \
595 right, \
596 fmt, \
597 ...) \
598 KUNIT_BASE_BINARY_ASSERTION(test, \
599 assert_class, \
600 ASSERT_CLASS_INIT, \
601 assert_type, \
602 left, >, right, \
603 fmt, \
604 ##__VA_ARGS__)
606 #define KUNIT_BASE_GE_MSG_ASSERTION(test, \
607 assert_class, \
608 ASSERT_CLASS_INIT, \
609 assert_type, \
610 left, \
611 right, \
612 fmt, \
613 ...) \
614 KUNIT_BASE_BINARY_ASSERTION(test, \
615 assert_class, \
616 ASSERT_CLASS_INIT, \
617 assert_type, \
618 left, >=, right, \
619 fmt, \
620 ##__VA_ARGS__)
622 #define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
623 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
624 kunit_binary_assert, \
625 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
626 assert_type, \
627 left, \
628 right, \
629 fmt, \
630 ##__VA_ARGS__)
632 #define KUNIT_BINARY_EQ_ASSERTION(test, assert_type, left, right) \
633 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
634 assert_type, \
635 left, \
636 right, \
637 NULL)
639 #define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
640 assert_type, \
641 left, \
642 right, \
643 fmt, \
644 ...) \
645 KUNIT_BASE_EQ_MSG_ASSERTION(test, \
646 kunit_binary_ptr_assert, \
647 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
648 assert_type, \
649 left, \
650 right, \
651 fmt, \
652 ##__VA_ARGS__)
654 #define KUNIT_BINARY_PTR_EQ_ASSERTION(test, assert_type, left, right) \
655 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
656 assert_type, \
657 left, \
658 right, \
659 NULL)
661 #define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
662 KUNIT_BASE_NE_MSG_ASSERTION(test, \
663 kunit_binary_assert, \
664 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
665 assert_type, \
666 left, \
667 right, \
668 fmt, \
669 ##__VA_ARGS__)
671 #define KUNIT_BINARY_NE_ASSERTION(test, assert_type, left, right) \
672 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
673 assert_type, \
674 left, \
675 right, \
676 NULL)
678 #define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
679 assert_type, \
680 left, \
681 right, \
682 fmt, \
683 ...) \
684 KUNIT_BASE_NE_MSG_ASSERTION(test, \
685 kunit_binary_ptr_assert, \
686 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
687 assert_type, \
688 left, \
689 right, \
690 fmt, \
691 ##__VA_ARGS__)
693 #define KUNIT_BINARY_PTR_NE_ASSERTION(test, assert_type, left, right) \
694 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
695 assert_type, \
696 left, \
697 right, \
698 NULL)
700 #define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
701 KUNIT_BASE_LT_MSG_ASSERTION(test, \
702 kunit_binary_assert, \
703 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
704 assert_type, \
705 left, \
706 right, \
707 fmt, \
708 ##__VA_ARGS__)
710 #define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right) \
711 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
712 assert_type, \
713 left, \
714 right, \
715 NULL)
717 #define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
718 assert_type, \
719 left, \
720 right, \
721 fmt, \
722 ...) \
723 KUNIT_BASE_LT_MSG_ASSERTION(test, \
724 kunit_binary_ptr_assert, \
725 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
726 assert_type, \
727 left, \
728 right, \
729 fmt, \
730 ##__VA_ARGS__)
732 #define KUNIT_BINARY_PTR_LT_ASSERTION(test, assert_type, left, right) \
733 KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
734 assert_type, \
735 left, \
736 right, \
737 NULL)
739 #define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
740 KUNIT_BASE_LE_MSG_ASSERTION(test, \
741 kunit_binary_assert, \
742 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
743 assert_type, \
744 left, \
745 right, \
746 fmt, \
747 ##__VA_ARGS__)
749 #define KUNIT_BINARY_LE_ASSERTION(test, assert_type, left, right) \
750 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
751 assert_type, \
752 left, \
753 right, \
754 NULL)
756 #define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
757 assert_type, \
758 left, \
759 right, \
760 fmt, \
761 ...) \
762 KUNIT_BASE_LE_MSG_ASSERTION(test, \
763 kunit_binary_ptr_assert, \
764 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
765 assert_type, \
766 left, \
767 right, \
768 fmt, \
769 ##__VA_ARGS__)
771 #define KUNIT_BINARY_PTR_LE_ASSERTION(test, assert_type, left, right) \
772 KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
773 assert_type, \
774 left, \
775 right, \
776 NULL)
778 #define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
779 KUNIT_BASE_GT_MSG_ASSERTION(test, \
780 kunit_binary_assert, \
781 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
782 assert_type, \
783 left, \
784 right, \
785 fmt, \
786 ##__VA_ARGS__)
788 #define KUNIT_BINARY_GT_ASSERTION(test, assert_type, left, right) \
789 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
790 assert_type, \
791 left, \
792 right, \
793 NULL)
795 #define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
796 assert_type, \
797 left, \
798 right, \
799 fmt, \
800 ...) \
801 KUNIT_BASE_GT_MSG_ASSERTION(test, \
802 kunit_binary_ptr_assert, \
803 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
804 assert_type, \
805 left, \
806 right, \
807 fmt, \
808 ##__VA_ARGS__)
810 #define KUNIT_BINARY_PTR_GT_ASSERTION(test, assert_type, left, right) \
811 KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
812 assert_type, \
813 left, \
814 right, \
815 NULL)
817 #define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
818 KUNIT_BASE_GE_MSG_ASSERTION(test, \
819 kunit_binary_assert, \
820 KUNIT_INIT_BINARY_ASSERT_STRUCT, \
821 assert_type, \
822 left, \
823 right, \
824 fmt, \
825 ##__VA_ARGS__)
827 #define KUNIT_BINARY_GE_ASSERTION(test, assert_type, left, right) \
828 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
829 assert_type, \
830 left, \
831 right, \
832 NULL)
834 #define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
835 assert_type, \
836 left, \
837 right, \
838 fmt, \
839 ...) \
840 KUNIT_BASE_GE_MSG_ASSERTION(test, \
841 kunit_binary_ptr_assert, \
842 KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
843 assert_type, \
844 left, \
845 right, \
846 fmt, \
847 ##__VA_ARGS__)
849 #define KUNIT_BINARY_PTR_GE_ASSERTION(test, assert_type, left, right) \
850 KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
851 assert_type, \
852 left, \
853 right, \
854 NULL)
856 #define KUNIT_BINARY_STR_ASSERTION(test, \
857 assert_type, \
858 left, \
859 op, \
860 right, \
861 fmt, \
862 ...) \
863 do { \
864 typeof(left) __left = (left); \
865 typeof(right) __right = (right); \
867 KUNIT_ASSERTION(test, \
868 strcmp(__left, __right) op 0, \
869 kunit_binary_str_assert, \
870 KUNIT_INIT_BINARY_ASSERT_STRUCT(test, \
871 assert_type, \
872 #op, \
873 #left, \
874 __left, \
875 #right, \
876 __right), \
877 fmt, \
878 ##__VA_ARGS__); \
879 } while (0)
881 #define KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
882 assert_type, \
883 left, \
884 right, \
885 fmt, \
886 ...) \
887 KUNIT_BINARY_STR_ASSERTION(test, \
888 assert_type, \
889 left, ==, right, \
890 fmt, \
891 ##__VA_ARGS__)
893 #define KUNIT_BINARY_STR_EQ_ASSERTION(test, assert_type, left, right) \
894 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
895 assert_type, \
896 left, \
897 right, \
898 NULL)
900 #define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
901 assert_type, \
902 left, \
903 right, \
904 fmt, \
905 ...) \
906 KUNIT_BINARY_STR_ASSERTION(test, \
907 assert_type, \
908 left, !=, right, \
909 fmt, \
910 ##__VA_ARGS__)
912 #define KUNIT_BINARY_STR_NE_ASSERTION(test, assert_type, left, right) \
913 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
914 assert_type, \
915 left, \
916 right, \
917 NULL)
919 #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
920 assert_type, \
921 ptr, \
922 fmt, \
923 ...) \
924 do { \
925 typeof(ptr) __ptr = (ptr); \
927 KUNIT_ASSERTION(test, \
928 !IS_ERR_OR_NULL(__ptr), \
929 kunit_ptr_not_err_assert, \
930 KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, \
931 assert_type, \
932 #ptr, \
933 __ptr), \
934 fmt, \
935 ##__VA_ARGS__); \
936 } while (0)
938 #define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \
939 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
940 assert_type, \
941 ptr, \
942 NULL)
945 * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
946 * @test: The test context object.
947 * @condition: an arbitrary boolean expression. The test fails when this does
948 * not evaluate to true.
950 * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
951 * to fail when the specified condition is not met; however, it will not prevent
952 * the test case from continuing to run; this is otherwise known as an
953 * *expectation failure*.
955 #define KUNIT_EXPECT_TRUE(test, condition) \
956 KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
958 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \
959 KUNIT_TRUE_MSG_ASSERTION(test, \
960 KUNIT_EXPECTATION, \
961 condition, \
962 fmt, \
963 ##__VA_ARGS__)
966 * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
967 * @test: The test context object.
968 * @condition: an arbitrary boolean expression. The test fails when this does
969 * not evaluate to false.
971 * Sets an expectation that @condition evaluates to false. See
972 * KUNIT_EXPECT_TRUE() for more information.
974 #define KUNIT_EXPECT_FALSE(test, condition) \
975 KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
977 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \
978 KUNIT_FALSE_MSG_ASSERTION(test, \
979 KUNIT_EXPECTATION, \
980 condition, \
981 fmt, \
982 ##__VA_ARGS__)
985 * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
986 * @test: The test context object.
987 * @left: an arbitrary expression that evaluates to a primitive C type.
988 * @right: an arbitrary expression that evaluates to a primitive C type.
990 * Sets an expectation that the values that @left and @right evaluate to are
991 * equal. This is semantically equivalent to
992 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
993 * more information.
995 #define KUNIT_EXPECT_EQ(test, left, right) \
996 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
998 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
999 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1000 KUNIT_EXPECTATION, \
1001 left, \
1002 right, \
1003 fmt, \
1004 ##__VA_ARGS__)
1007 * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
1008 * @test: The test context object.
1009 * @left: an arbitrary expression that evaluates to a pointer.
1010 * @right: an arbitrary expression that evaluates to a pointer.
1012 * Sets an expectation that the values that @left and @right evaluate to are
1013 * equal. This is semantically equivalent to
1014 * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
1015 * more information.
1017 #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
1018 KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
1019 KUNIT_EXPECTATION, \
1020 left, \
1021 right)
1023 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1024 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1025 KUNIT_EXPECTATION, \
1026 left, \
1027 right, \
1028 fmt, \
1029 ##__VA_ARGS__)
1032 * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
1033 * @test: The test context object.
1034 * @left: an arbitrary expression that evaluates to a primitive C type.
1035 * @right: an arbitrary expression that evaluates to a primitive C type.
1037 * Sets an expectation that the values that @left and @right evaluate to are not
1038 * equal. This is semantically equivalent to
1039 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1040 * more information.
1042 #define KUNIT_EXPECT_NE(test, left, right) \
1043 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1045 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
1046 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1047 KUNIT_EXPECTATION, \
1048 left, \
1049 right, \
1050 fmt, \
1051 ##__VA_ARGS__)
1054 * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
1055 * @test: The test context object.
1056 * @left: an arbitrary expression that evaluates to a pointer.
1057 * @right: an arbitrary expression that evaluates to a pointer.
1059 * Sets an expectation that the values that @left and @right evaluate to are not
1060 * equal. This is semantically equivalent to
1061 * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1062 * more information.
1064 #define KUNIT_EXPECT_PTR_NE(test, left, right) \
1065 KUNIT_BINARY_PTR_NE_ASSERTION(test, \
1066 KUNIT_EXPECTATION, \
1067 left, \
1068 right)
1070 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
1071 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1072 KUNIT_EXPECTATION, \
1073 left, \
1074 right, \
1075 fmt, \
1076 ##__VA_ARGS__)
1079 * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
1080 * @test: The test context object.
1081 * @left: an arbitrary expression that evaluates to a primitive C type.
1082 * @right: an arbitrary expression that evaluates to a primitive C type.
1084 * Sets an expectation that the value that @left evaluates to is less than the
1085 * value that @right evaluates to. This is semantically equivalent to
1086 * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
1087 * more information.
1089 #define KUNIT_EXPECT_LT(test, left, right) \
1090 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1092 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
1093 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1094 KUNIT_EXPECTATION, \
1095 left, \
1096 right, \
1097 fmt, \
1098 ##__VA_ARGS__)
1101 * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
1102 * @test: The test context object.
1103 * @left: an arbitrary expression that evaluates to a primitive C type.
1104 * @right: an arbitrary expression that evaluates to a primitive C type.
1106 * Sets an expectation that the value that @left evaluates to is less than or
1107 * equal to the value that @right evaluates to. Semantically this is equivalent
1108 * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
1109 * more information.
1111 #define KUNIT_EXPECT_LE(test, left, right) \
1112 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1114 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
1115 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1116 KUNIT_EXPECTATION, \
1117 left, \
1118 right, \
1119 fmt, \
1120 ##__VA_ARGS__)
1123 * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
1124 * @test: The test context object.
1125 * @left: an arbitrary expression that evaluates to a primitive C type.
1126 * @right: an arbitrary expression that evaluates to a primitive C type.
1128 * Sets an expectation that the value that @left evaluates to is greater than
1129 * the value that @right evaluates to. This is semantically equivalent to
1130 * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
1131 * more information.
1133 #define KUNIT_EXPECT_GT(test, left, right) \
1134 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1136 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
1137 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1138 KUNIT_EXPECTATION, \
1139 left, \
1140 right, \
1141 fmt, \
1142 ##__VA_ARGS__)
1145 * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
1146 * @test: The test context object.
1147 * @left: an arbitrary expression that evaluates to a primitive C type.
1148 * @right: an arbitrary expression that evaluates to a primitive C type.
1150 * Sets an expectation that the value that @left evaluates to is greater than
1151 * the value that @right evaluates to. This is semantically equivalent to
1152 * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
1153 * more information.
1155 #define KUNIT_EXPECT_GE(test, left, right) \
1156 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1158 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
1159 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1160 KUNIT_EXPECTATION, \
1161 left, \
1162 right, \
1163 fmt, \
1164 ##__VA_ARGS__)
1167 * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
1168 * @test: The test context object.
1169 * @left: an arbitrary expression that evaluates to a null terminated string.
1170 * @right: an arbitrary expression that evaluates to a null terminated string.
1172 * Sets an expectation that the values that @left and @right evaluate to are
1173 * equal. This is semantically equivalent to
1174 * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1175 * for more information.
1177 #define KUNIT_EXPECT_STREQ(test, left, right) \
1178 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1180 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
1181 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1182 KUNIT_EXPECTATION, \
1183 left, \
1184 right, \
1185 fmt, \
1186 ##__VA_ARGS__)
1189 * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
1190 * @test: The test context object.
1191 * @left: an arbitrary expression that evaluates to a null terminated string.
1192 * @right: an arbitrary expression that evaluates to a null terminated string.
1194 * Sets an expectation that the values that @left and @right evaluate to are
1195 * not equal. This is semantically equivalent to
1196 * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1197 * for more information.
1199 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
1200 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1202 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
1203 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1204 KUNIT_EXPECTATION, \
1205 left, \
1206 right, \
1207 fmt, \
1208 ##__VA_ARGS__)
1211 * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
1212 * @test: The test context object.
1213 * @ptr: an arbitrary pointer.
1215 * Sets an expectation that the value that @ptr evaluates to is not null and not
1216 * an errno stored in a pointer. This is semantically equivalent to
1217 * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
1218 * more information.
1220 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
1221 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
1223 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1224 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1225 KUNIT_EXPECTATION, \
1226 ptr, \
1227 fmt, \
1228 ##__VA_ARGS__)
1230 #define KUNIT_ASSERT_FAILURE(test, fmt, ...) \
1231 KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__)
1234 * KUNIT_ASSERT_TRUE() - Sets an assertion that @condition is true.
1235 * @test: The test context object.
1236 * @condition: an arbitrary boolean expression. The test fails and aborts when
1237 * this does not evaluate to true.
1239 * This and assertions of the form `KUNIT_ASSERT_*` will cause the test case to
1240 * fail *and immediately abort* when the specified condition is not met. Unlike
1241 * an expectation failure, it will prevent the test case from continuing to run;
1242 * this is otherwise known as an *assertion failure*.
1244 #define KUNIT_ASSERT_TRUE(test, condition) \
1245 KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
1247 #define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \
1248 KUNIT_TRUE_MSG_ASSERTION(test, \
1249 KUNIT_ASSERTION, \
1250 condition, \
1251 fmt, \
1252 ##__VA_ARGS__)
1255 * KUNIT_ASSERT_FALSE() - Sets an assertion that @condition is false.
1256 * @test: The test context object.
1257 * @condition: an arbitrary boolean expression.
1259 * Sets an assertion that the value that @condition evaluates to is false. This
1260 * is the same as KUNIT_EXPECT_FALSE(), except it causes an assertion failure
1261 * (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1263 #define KUNIT_ASSERT_FALSE(test, condition) \
1264 KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
1266 #define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \
1267 KUNIT_FALSE_MSG_ASSERTION(test, \
1268 KUNIT_ASSERTION, \
1269 condition, \
1270 fmt, \
1271 ##__VA_ARGS__)
1274 * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal.
1275 * @test: The test context object.
1276 * @left: an arbitrary expression that evaluates to a primitive C type.
1277 * @right: an arbitrary expression that evaluates to a primitive C type.
1279 * Sets an assertion that the values that @left and @right evaluate to are
1280 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1281 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1283 #define KUNIT_ASSERT_EQ(test, left, right) \
1284 KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1286 #define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
1287 KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
1288 KUNIT_ASSERTION, \
1289 left, \
1290 right, \
1291 fmt, \
1292 ##__VA_ARGS__)
1295 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1296 * @test: The test context object.
1297 * @left: an arbitrary expression that evaluates to a pointer.
1298 * @right: an arbitrary expression that evaluates to a pointer.
1300 * Sets an assertion that the values that @left and @right evaluate to are
1301 * equal. This is the same as KUNIT_EXPECT_EQ(), except it causes an assertion
1302 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1304 #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
1305 KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1307 #define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
1308 KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
1309 KUNIT_ASSERTION, \
1310 left, \
1311 right, \
1312 fmt, \
1313 ##__VA_ARGS__)
1316 * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
1317 * @test: The test context object.
1318 * @left: an arbitrary expression that evaluates to a primitive C type.
1319 * @right: an arbitrary expression that evaluates to a primitive C type.
1321 * Sets an assertion that the values that @left and @right evaluate to are not
1322 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1323 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1325 #define KUNIT_ASSERT_NE(test, left, right) \
1326 KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1328 #define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
1329 KUNIT_BINARY_NE_MSG_ASSERTION(test, \
1330 KUNIT_ASSERTION, \
1331 left, \
1332 right, \
1333 fmt, \
1334 ##__VA_ARGS__)
1337 * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
1338 * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
1339 * @test: The test context object.
1340 * @left: an arbitrary expression that evaluates to a pointer.
1341 * @right: an arbitrary expression that evaluates to a pointer.
1343 * Sets an assertion that the values that @left and @right evaluate to are not
1344 * equal. This is the same as KUNIT_EXPECT_NE(), except it causes an assertion
1345 * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1347 #define KUNIT_ASSERT_PTR_NE(test, left, right) \
1348 KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1350 #define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
1351 KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
1352 KUNIT_ASSERTION, \
1353 left, \
1354 right, \
1355 fmt, \
1356 ##__VA_ARGS__)
1358 * KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
1359 * @test: The test context object.
1360 * @left: an arbitrary expression that evaluates to a primitive C type.
1361 * @right: an arbitrary expression that evaluates to a primitive C type.
1363 * Sets an assertion that the value that @left evaluates to is less than the
1364 * value that @right evaluates to. This is the same as KUNIT_EXPECT_LT(), except
1365 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1366 * is not met.
1368 #define KUNIT_ASSERT_LT(test, left, right) \
1369 KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1371 #define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
1372 KUNIT_BINARY_LT_MSG_ASSERTION(test, \
1373 KUNIT_ASSERTION, \
1374 left, \
1375 right, \
1376 fmt, \
1377 ##__VA_ARGS__)
1379 * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
1380 * @test: The test context object.
1381 * @left: an arbitrary expression that evaluates to a primitive C type.
1382 * @right: an arbitrary expression that evaluates to a primitive C type.
1384 * Sets an assertion that the value that @left evaluates to is less than or
1385 * equal to the value that @right evaluates to. This is the same as
1386 * KUNIT_EXPECT_LE(), except it causes an assertion failure (see
1387 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1389 #define KUNIT_ASSERT_LE(test, left, right) \
1390 KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1392 #define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
1393 KUNIT_BINARY_LE_MSG_ASSERTION(test, \
1394 KUNIT_ASSERTION, \
1395 left, \
1396 right, \
1397 fmt, \
1398 ##__VA_ARGS__)
1401 * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
1402 * @test: The test context object.
1403 * @left: an arbitrary expression that evaluates to a primitive C type.
1404 * @right: an arbitrary expression that evaluates to a primitive C type.
1406 * Sets an assertion that the value that @left evaluates to is greater than the
1407 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GT(), except
1408 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1409 * is not met.
1411 #define KUNIT_ASSERT_GT(test, left, right) \
1412 KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
1414 #define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
1415 KUNIT_BINARY_GT_MSG_ASSERTION(test, \
1416 KUNIT_ASSERTION, \
1417 left, \
1418 right, \
1419 fmt, \
1420 ##__VA_ARGS__)
1423 * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
1424 * @test: The test context object.
1425 * @left: an arbitrary expression that evaluates to a primitive C type.
1426 * @right: an arbitrary expression that evaluates to a primitive C type.
1428 * Sets an assertion that the value that @left evaluates to is greater than the
1429 * value that @right evaluates to. This is the same as KUNIT_EXPECT_GE(), except
1430 * it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion
1431 * is not met.
1433 #define KUNIT_ASSERT_GE(test, left, right) \
1434 KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1436 #define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
1437 KUNIT_BINARY_GE_MSG_ASSERTION(test, \
1438 KUNIT_ASSERTION, \
1439 left, \
1440 right, \
1441 fmt, \
1442 ##__VA_ARGS__)
1445 * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
1446 * @test: The test context object.
1447 * @left: an arbitrary expression that evaluates to a null terminated string.
1448 * @right: an arbitrary expression that evaluates to a null terminated string.
1450 * Sets an assertion that the values that @left and @right evaluate to are
1451 * equal. This is the same as KUNIT_EXPECT_STREQ(), except it causes an
1452 * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
1454 #define KUNIT_ASSERT_STREQ(test, left, right) \
1455 KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
1457 #define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
1458 KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
1459 KUNIT_ASSERTION, \
1460 left, \
1461 right, \
1462 fmt, \
1463 ##__VA_ARGS__)
1466 * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
1467 * @test: The test context object.
1468 * @left: an arbitrary expression that evaluates to a null terminated string.
1469 * @right: an arbitrary expression that evaluates to a null terminated string.
1471 * Sets an expectation that the values that @left and @right evaluate to are
1472 * not equal. This is semantically equivalent to
1473 * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE()
1474 * for more information.
1476 #define KUNIT_ASSERT_STRNEQ(test, left, right) \
1477 KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
1479 #define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
1480 KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
1481 KUNIT_ASSERTION, \
1482 left, \
1483 right, \
1484 fmt, \
1485 ##__VA_ARGS__)
1488 * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
1489 * @test: The test context object.
1490 * @ptr: an arbitrary pointer.
1492 * Sets an assertion that the value that @ptr evaluates to is not null and not
1493 * an errno stored in a pointer. This is the same as
1494 * KUNIT_EXPECT_NOT_ERR_OR_NULL(), except it causes an assertion failure (see
1495 * KUNIT_ASSERT_TRUE()) when the assertion is not met.
1497 #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
1498 KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
1500 #define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \
1501 KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
1502 KUNIT_ASSERTION, \
1503 ptr, \
1504 fmt, \
1505 ##__VA_ARGS__)
1507 #endif /* _KUNIT_TEST_H */