kunit: test: add support for test abort
[linux-2.6-microblaze.git] / include / kunit / test.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Base unit test (KUnit) API.
4  *
5  * Copyright (C) 2019, Google LLC.
6  * Author: Brendan Higgins <brendanhiggins@google.com>
7  */
8
9 #ifndef _KUNIT_TEST_H
10 #define _KUNIT_TEST_H
11
12 #include <kunit/assert.h>
13 #include <kunit/try-catch.h>
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/types.h>
17
18 struct kunit_resource;
19
20 typedef int (*kunit_resource_init_t)(struct kunit_resource *, void *);
21 typedef void (*kunit_resource_free_t)(struct kunit_resource *);
22
23 /**
24  * struct kunit_resource - represents a *test managed resource*
25  * @allocation: for the user to store arbitrary data.
26  * @free: a user supplied function to free the resource. Populated by
27  * kunit_alloc_resource().
28  *
29  * Represents a *test managed resource*, a resource which will automatically be
30  * cleaned up at the end of a test case.
31  *
32  * Example:
33  *
34  * .. code-block:: c
35  *
36  *      struct kunit_kmalloc_params {
37  *              size_t size;
38  *              gfp_t gfp;
39  *      };
40  *
41  *      static int kunit_kmalloc_init(struct kunit_resource *res, void *context)
42  *      {
43  *              struct kunit_kmalloc_params *params = context;
44  *              res->allocation = kmalloc(params->size, params->gfp);
45  *
46  *              if (!res->allocation)
47  *                      return -ENOMEM;
48  *
49  *              return 0;
50  *      }
51  *
52  *      static void kunit_kmalloc_free(struct kunit_resource *res)
53  *      {
54  *              kfree(res->allocation);
55  *      }
56  *
57  *      void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp)
58  *      {
59  *              struct kunit_kmalloc_params params;
60  *              struct kunit_resource *res;
61  *
62  *              params.size = size;
63  *              params.gfp = gfp;
64  *
65  *              res = kunit_alloc_resource(test, kunit_kmalloc_init,
66  *                      kunit_kmalloc_free, &params);
67  *              if (res)
68  *                      return res->allocation;
69  *
70  *              return NULL;
71  *      }
72  */
73 struct kunit_resource {
74         void *allocation;
75         kunit_resource_free_t free;
76
77         /* private: internal use only. */
78         struct list_head node;
79 };
80
81 struct kunit;
82
83 /**
84  * struct kunit_case - represents an individual test case.
85  *
86  * @run_case: the function representing the actual test case.
87  * @name:     the name of the test case.
88  *
89  * A test case is a function with the signature,
90  * ``void (*)(struct kunit *)`` that makes expectations (see
91  * KUNIT_EXPECT_TRUE()) about code under test. Each test case is associated
92  * with a &struct kunit_suite and will be run after the suite's init
93  * function and followed by the suite's exit function.
94  *
95  * A test case should be static and should only be created with the
96  * KUNIT_CASE() macro; additionally, every array of test cases should be
97  * terminated with an empty test case.
98  *
99  * Example:
100  *
101  * .. code-block:: c
102  *
103  *      void add_test_basic(struct kunit *test)
104  *      {
105  *              KUNIT_EXPECT_EQ(test, 1, add(1, 0));
106  *              KUNIT_EXPECT_EQ(test, 2, add(1, 1));
107  *              KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
108  *              KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
109  *              KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
110  *      }
111  *
112  *      static struct kunit_case example_test_cases[] = {
113  *              KUNIT_CASE(add_test_basic),
114  *              {}
115  *      };
116  *
117  */
118 struct kunit_case {
119         void (*run_case)(struct kunit *test);
120         const char *name;
121
122         /* private: internal use only. */
123         bool success;
124 };
125
126 /**
127  * KUNIT_CASE - A helper for creating a &struct kunit_case
128  *
129  * @test_name: a reference to a test case function.
130  *
131  * Takes a symbol for a function representing a test case and creates a
132  * &struct kunit_case object from it. See the documentation for
133  * &struct kunit_case for an example on how to use it.
134  */
135 #define KUNIT_CASE(test_name) { .run_case = test_name, .name = #test_name }
136
137 /**
138  * struct kunit_suite - describes a related collection of &struct kunit_case
139  *
140  * @name:       the name of the test. Purely informational.
141  * @init:       called before every test case.
142  * @exit:       called after every test case.
143  * @test_cases: a null terminated array of test cases.
144  *
145  * A kunit_suite is a collection of related &struct kunit_case s, such that
146  * @init is called before every test case and @exit is called after every
147  * test case, similar to the notion of a *test fixture* or a *test class*
148  * in other unit testing frameworks like JUnit or Googletest.
149  *
150  * Every &struct kunit_case must be associated with a kunit_suite for KUnit
151  * to run it.
152  */
153 struct kunit_suite {
154         const char name[256];
155         int (*init)(struct kunit *test);
156         void (*exit)(struct kunit *test);
157         struct kunit_case *test_cases;
158 };
159
160 /**
161  * struct kunit - represents a running instance of a test.
162  *
163  * @priv: for user to store arbitrary data. Commonly used to pass data
164  *        created in the init function (see &struct kunit_suite).
165  *
166  * Used to store information about the current context under which the test
167  * is running. Most of this data is private and should only be accessed
168  * indirectly via public functions; the one exception is @priv which can be
169  * used by the test writer to store arbitrary data.
170  */
171 struct kunit {
172         void *priv;
173
174         /* private: internal use only. */
175         const char *name; /* Read only after initialization! */
176         struct kunit_try_catch try_catch;
177         /*
178          * success starts as true, and may only be set to false during a
179          * test case; thus, it is safe to update this across multiple
180          * threads using WRITE_ONCE; however, as a consequence, it may only
181          * be read after the test case finishes once all threads associated
182          * with the test case have terminated.
183          */
184         bool success; /* Read only after test_case finishes! */
185         spinlock_t lock; /* Guards all mutable test state. */
186         /*
187          * Because resources is a list that may be updated multiple times (with
188          * new resources) from any thread associated with a test case, we must
189          * protect it with some type of lock.
190          */
191         struct list_head resources; /* Protected by lock. */
192 };
193
194 void kunit_init_test(struct kunit *test, const char *name);
195
196 int kunit_run_tests(struct kunit_suite *suite);
197
198 /**
199  * kunit_test_suite() - used to register a &struct kunit_suite with KUnit.
200  *
201  * @suite: a statically allocated &struct kunit_suite.
202  *
203  * Registers @suite with the test framework. See &struct kunit_suite for
204  * more information.
205  *
206  * NOTE: Currently KUnit tests are all run as late_initcalls; this means
207  * that they cannot test anything where tests must run at a different init
208  * phase. One significant restriction resulting from this is that KUnit
209  * cannot reliably test anything that is initialize in the late_init phase;
210  * another is that KUnit is useless to test things that need to be run in
211  * an earlier init phase.
212  *
213  * TODO(brendanhiggins@google.com): Don't run all KUnit tests as
214  * late_initcalls.  I have some future work planned to dispatch all KUnit
215  * tests from the same place, and at the very least to do so after
216  * everything else is definitely initialized.
217  */
218 #define kunit_test_suite(suite)                                                \
219         static int kunit_suite_init##suite(void)                               \
220         {                                                                      \
221                 return kunit_run_tests(&suite);                                \
222         }                                                                      \
223         late_initcall(kunit_suite_init##suite)
224
225 /*
226  * Like kunit_alloc_resource() below, but returns the struct kunit_resource
227  * object that contains the allocation. This is mostly for testing purposes.
228  */
229 struct kunit_resource *kunit_alloc_and_get_resource(struct kunit *test,
230                                                     kunit_resource_init_t init,
231                                                     kunit_resource_free_t free,
232                                                     gfp_t internal_gfp,
233                                                     void *context);
234
235 /**
236  * kunit_alloc_resource() - Allocates a *test managed resource*.
237  * @test: The test context object.
238  * @init: a user supplied function to initialize the resource.
239  * @free: a user supplied function to free the resource.
240  * @internal_gfp: gfp to use for internal allocations, if unsure, use GFP_KERNEL
241  * @context: for the user to pass in arbitrary data to the init function.
242  *
243  * Allocates a *test managed resource*, a resource which will automatically be
244  * cleaned up at the end of a test case. See &struct kunit_resource for an
245  * example.
246  *
247  * NOTE: KUnit needs to allocate memory for each kunit_resource object. You must
248  * specify an @internal_gfp that is compatible with the use context of your
249  * resource.
250  */
251 static inline void *kunit_alloc_resource(struct kunit *test,
252                                          kunit_resource_init_t init,
253                                          kunit_resource_free_t free,
254                                          gfp_t internal_gfp,
255                                          void *context)
256 {
257         struct kunit_resource *res;
258
259         res = kunit_alloc_and_get_resource(test, init, free, internal_gfp,
260                                            context);
261
262         if (res)
263                 return res->allocation;
264
265         return NULL;
266 }
267
268 typedef bool (*kunit_resource_match_t)(struct kunit *test,
269                                        const void *res,
270                                        void *match_data);
271
272 /**
273  * kunit_resource_instance_match() - Match a resource with the same instance.
274  * @test: Test case to which the resource belongs.
275  * @res: The data stored in kunit_resource->allocation.
276  * @match_data: The resource pointer to match against.
277  *
278  * An instance of kunit_resource_match_t that matches a resource whose
279  * allocation matches @match_data.
280  */
281 static inline bool kunit_resource_instance_match(struct kunit *test,
282                                                  const void *res,
283                                                  void *match_data)
284 {
285         return res == match_data;
286 }
287
288 /**
289  * kunit_resource_destroy() - Find a kunit_resource and destroy it.
290  * @test: Test case to which the resource belongs.
291  * @match: Match function. Returns whether a given resource matches @match_data.
292  * @free: Must match free on the kunit_resource to free.
293  * @match_data: Data passed into @match.
294  *
295  * Free the latest kunit_resource of @test for which @free matches the
296  * kunit_resource_free_t associated with the resource and for which @match
297  * returns true.
298  *
299  * RETURNS:
300  * 0 if kunit_resource is found and freed, -ENOENT if not found.
301  */
302 int kunit_resource_destroy(struct kunit *test,
303                            kunit_resource_match_t match,
304                            kunit_resource_free_t free,
305                            void *match_data);
306
307 /**
308  * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*.
309  * @test: The test context object.
310  * @size: The size in bytes of the desired memory.
311  * @gfp: flags passed to underlying kmalloc().
312  *
313  * Just like `kmalloc(...)`, except the allocation is managed by the test case
314  * and is automatically cleaned up after the test case concludes. See &struct
315  * kunit_resource for more information.
316  */
317 void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp);
318
319 /**
320  * kunit_kfree() - Like kfree except for allocations managed by KUnit.
321  * @test: The test case to which the resource belongs.
322  * @ptr: The memory allocation to free.
323  */
324 void kunit_kfree(struct kunit *test, const void *ptr);
325
326 /**
327  * kunit_kzalloc() - Just like kunit_kmalloc(), but zeroes the allocation.
328  * @test: The test context object.
329  * @size: The size in bytes of the desired memory.
330  * @gfp: flags passed to underlying kmalloc().
331  *
332  * See kzalloc() and kunit_kmalloc() for more information.
333  */
334 static inline void *kunit_kzalloc(struct kunit *test, size_t size, gfp_t gfp)
335 {
336         return kunit_kmalloc(test, size, gfp | __GFP_ZERO);
337 }
338
339 void kunit_cleanup(struct kunit *test);
340
341 void __printf(3, 4) kunit_printk(const char *level,
342                                  const struct kunit *test,
343                                  const char *fmt, ...);
344
345 /**
346  * kunit_info() - Prints an INFO level message associated with @test.
347  *
348  * @test: The test context object.
349  * @fmt:  A printk() style format string.
350  *
351  * Prints an info level message associated with the test suite being run.
352  * Takes a variable number of format parameters just like printk().
353  */
354 #define kunit_info(test, fmt, ...) \
355         kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__)
356
357 /**
358  * kunit_warn() - Prints a WARN level message associated with @test.
359  *
360  * @test: The test context object.
361  * @fmt:  A printk() style format string.
362  *
363  * Prints a warning level message.
364  */
365 #define kunit_warn(test, fmt, ...) \
366         kunit_printk(KERN_WARNING, test, fmt, ##__VA_ARGS__)
367
368 /**
369  * kunit_err() - Prints an ERROR level message associated with @test.
370  *
371  * @test: The test context object.
372  * @fmt:  A printk() style format string.
373  *
374  * Prints an error level message.
375  */
376 #define kunit_err(test, fmt, ...) \
377         kunit_printk(KERN_ERR, test, fmt, ##__VA_ARGS__)
378
379 /**
380  * KUNIT_SUCCEED() - A no-op expectation. Only exists for code clarity.
381  * @test: The test context object.
382  *
383  * The opposite of KUNIT_FAIL(), it is an expectation that cannot fail. In other
384  * words, it does nothing and only exists for code clarity. See
385  * KUNIT_EXPECT_TRUE() for more information.
386  */
387 #define KUNIT_SUCCEED(test) do {} while (0)
388
389 void kunit_do_assertion(struct kunit *test,
390                         struct kunit_assert *assert,
391                         bool pass,
392                         const char *fmt, ...);
393
394 #define KUNIT_ASSERTION(test, pass, assert_class, INITIALIZER, fmt, ...) do {  \
395         struct assert_class __assertion = INITIALIZER;                         \
396         kunit_do_assertion(test,                                               \
397                            &__assertion.assert,                                \
398                            pass,                                               \
399                            fmt,                                                \
400                            ##__VA_ARGS__);                                     \
401 } while (0)
402
403
404 #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...)                      \
405         KUNIT_ASSERTION(test,                                                  \
406                         false,                                                 \
407                         kunit_fail_assert,                                     \
408                         KUNIT_INIT_FAIL_ASSERT_STRUCT(test, assert_type),      \
409                         fmt,                                                   \
410                         ##__VA_ARGS__)
411
412 /**
413  * KUNIT_FAIL() - Always causes a test to fail when evaluated.
414  * @test: The test context object.
415  * @fmt: an informational message to be printed when the assertion is made.
416  * @...: string format arguments.
417  *
418  * The opposite of KUNIT_SUCCEED(), it is an expectation that always fails. In
419  * other words, it always results in a failed expectation, and consequently
420  * always causes the test case to fail when evaluated. See KUNIT_EXPECT_TRUE()
421  * for more information.
422  */
423 #define KUNIT_FAIL(test, fmt, ...)                                             \
424         KUNIT_FAIL_ASSERTION(test,                                             \
425                              KUNIT_EXPECTATION,                                \
426                              fmt,                                              \
427                              ##__VA_ARGS__)
428
429 #define KUNIT_UNARY_ASSERTION(test,                                            \
430                               assert_type,                                     \
431                               condition,                                       \
432                               expected_true,                                   \
433                               fmt,                                             \
434                               ...)                                             \
435         KUNIT_ASSERTION(test,                                                  \
436                         !!(condition) == !!expected_true,                      \
437                         kunit_unary_assert,                                    \
438                         KUNIT_INIT_UNARY_ASSERT_STRUCT(test,                   \
439                                                        assert_type,            \
440                                                        #condition,             \
441                                                        expected_true),         \
442                         fmt,                                                   \
443                         ##__VA_ARGS__)
444
445 #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...)       \
446         KUNIT_UNARY_ASSERTION(test,                                            \
447                               assert_type,                                     \
448                               condition,                                       \
449                               true,                                            \
450                               fmt,                                             \
451                               ##__VA_ARGS__)
452
453 #define KUNIT_TRUE_ASSERTION(test, assert_type, condition) \
454         KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, NULL)
455
456 #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...)      \
457         KUNIT_UNARY_ASSERTION(test,                                            \
458                               assert_type,                                     \
459                               condition,                                       \
460                               false,                                           \
461                               fmt,                                             \
462                               ##__VA_ARGS__)
463
464 #define KUNIT_FALSE_ASSERTION(test, assert_type, condition) \
465         KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, NULL)
466
467 /*
468  * A factory macro for defining the assertions and expectations for the basic
469  * comparisons defined for the built in types.
470  *
471  * Unfortunately, there is no common type that all types can be promoted to for
472  * which all the binary operators behave the same way as for the actual types
473  * (for example, there is no type that long long and unsigned long long can
474  * both be cast to where the comparison result is preserved for all values). So
475  * the best we can do is do the comparison in the original types and then coerce
476  * everything to long long for printing; this way, the comparison behaves
477  * correctly and the printed out value usually makes sense without
478  * interpretation, but can always be interpreted to figure out the actual
479  * value.
480  */
481 #define KUNIT_BASE_BINARY_ASSERTION(test,                                      \
482                                     assert_class,                              \
483                                     ASSERT_CLASS_INIT,                         \
484                                     assert_type,                               \
485                                     left,                                      \
486                                     op,                                        \
487                                     right,                                     \
488                                     fmt,                                       \
489                                     ...)                                       \
490 do {                                                                           \
491         typeof(left) __left = (left);                                          \
492         typeof(right) __right = (right);                                       \
493         ((void)__typecheck(__left, __right));                                  \
494                                                                                \
495         KUNIT_ASSERTION(test,                                                  \
496                         __left op __right,                                     \
497                         assert_class,                                          \
498                         ASSERT_CLASS_INIT(test,                                \
499                                           assert_type,                         \
500                                           #op,                                 \
501                                           #left,                               \
502                                           __left,                              \
503                                           #right,                              \
504                                           __right),                            \
505                         fmt,                                                   \
506                         ##__VA_ARGS__);                                        \
507 } while (0)
508
509 #define KUNIT_BASE_EQ_MSG_ASSERTION(test,                                      \
510                                     assert_class,                              \
511                                     ASSERT_CLASS_INIT,                         \
512                                     assert_type,                               \
513                                     left,                                      \
514                                     right,                                     \
515                                     fmt,                                       \
516                                     ...)                                       \
517         KUNIT_BASE_BINARY_ASSERTION(test,                                      \
518                                     assert_class,                              \
519                                     ASSERT_CLASS_INIT,                         \
520                                     assert_type,                               \
521                                     left, ==, right,                           \
522                                     fmt,                                       \
523                                     ##__VA_ARGS__)
524
525 #define KUNIT_BASE_NE_MSG_ASSERTION(test,                                      \
526                                     assert_class,                              \
527                                     ASSERT_CLASS_INIT,                         \
528                                     assert_type,                               \
529                                     left,                                      \
530                                     right,                                     \
531                                     fmt,                                       \
532                                     ...)                                       \
533         KUNIT_BASE_BINARY_ASSERTION(test,                                      \
534                                     assert_class,                              \
535                                     ASSERT_CLASS_INIT,                         \
536                                     assert_type,                               \
537                                     left, !=, right,                           \
538                                     fmt,                                       \
539                                     ##__VA_ARGS__)
540
541 #define KUNIT_BASE_LT_MSG_ASSERTION(test,                                      \
542                                     assert_class,                              \
543                                     ASSERT_CLASS_INIT,                         \
544                                     assert_type,                               \
545                                     left,                                      \
546                                     right,                                     \
547                                     fmt,                                       \
548                                     ...)                                       \
549         KUNIT_BASE_BINARY_ASSERTION(test,                                      \
550                                     assert_class,                              \
551                                     ASSERT_CLASS_INIT,                         \
552                                     assert_type,                               \
553                                     left, <, right,                            \
554                                     fmt,                                       \
555                                     ##__VA_ARGS__)
556
557 #define KUNIT_BASE_LE_MSG_ASSERTION(test,                                      \
558                                     assert_class,                              \
559                                     ASSERT_CLASS_INIT,                         \
560                                     assert_type,                               \
561                                     left,                                      \
562                                     right,                                     \
563                                     fmt,                                       \
564                                     ...)                                       \
565         KUNIT_BASE_BINARY_ASSERTION(test,                                      \
566                                     assert_class,                              \
567                                     ASSERT_CLASS_INIT,                         \
568                                     assert_type,                               \
569                                     left, <=, right,                           \
570                                     fmt,                                       \
571                                     ##__VA_ARGS__)
572
573 #define KUNIT_BASE_GT_MSG_ASSERTION(test,                                      \
574                                     assert_class,                              \
575                                     ASSERT_CLASS_INIT,                         \
576                                     assert_type,                               \
577                                     left,                                      \
578                                     right,                                     \
579                                     fmt,                                       \
580                                     ...)                                       \
581         KUNIT_BASE_BINARY_ASSERTION(test,                                      \
582                                     assert_class,                              \
583                                     ASSERT_CLASS_INIT,                         \
584                                     assert_type,                               \
585                                     left, >, right,                            \
586                                     fmt,                                       \
587                                     ##__VA_ARGS__)
588
589 #define KUNIT_BASE_GE_MSG_ASSERTION(test,                                      \
590                                     assert_class,                              \
591                                     ASSERT_CLASS_INIT,                         \
592                                     assert_type,                               \
593                                     left,                                      \
594                                     right,                                     \
595                                     fmt,                                       \
596                                     ...)                                       \
597         KUNIT_BASE_BINARY_ASSERTION(test,                                      \
598                                     assert_class,                              \
599                                     ASSERT_CLASS_INIT,                         \
600                                     assert_type,                               \
601                                     left, >=, right,                           \
602                                     fmt,                                       \
603                                     ##__VA_ARGS__)
604
605 #define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
606         KUNIT_BASE_EQ_MSG_ASSERTION(test,                                      \
607                                     kunit_binary_assert,                       \
608                                     KUNIT_INIT_BINARY_ASSERT_STRUCT,           \
609                                     assert_type,                               \
610                                     left,                                      \
611                                     right,                                     \
612                                     fmt,                                       \
613                                     ##__VA_ARGS__)
614
615 #define KUNIT_BINARY_EQ_ASSERTION(test, assert_type, left, right)              \
616         KUNIT_BINARY_EQ_MSG_ASSERTION(test,                                    \
617                                       assert_type,                             \
618                                       left,                                    \
619                                       right,                                   \
620                                       NULL)
621
622 #define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test,                                \
623                                           assert_type,                         \
624                                           left,                                \
625                                           right,                               \
626                                           fmt,                                 \
627                                           ...)                                 \
628         KUNIT_BASE_EQ_MSG_ASSERTION(test,                                      \
629                                     kunit_binary_ptr_assert,                   \
630                                     KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
631                                     assert_type,                               \
632                                     left,                                      \
633                                     right,                                     \
634                                     fmt,                                       \
635                                     ##__VA_ARGS__)
636
637 #define KUNIT_BINARY_PTR_EQ_ASSERTION(test, assert_type, left, right)          \
638         KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test,                                \
639                                           assert_type,                         \
640                                           left,                                \
641                                           right,                               \
642                                           NULL)
643
644 #define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
645         KUNIT_BASE_NE_MSG_ASSERTION(test,                                      \
646                                     kunit_binary_assert,                       \
647                                     KUNIT_INIT_BINARY_ASSERT_STRUCT,           \
648                                     assert_type,                               \
649                                     left,                                      \
650                                     right,                                     \
651                                     fmt,                                       \
652                                     ##__VA_ARGS__)
653
654 #define KUNIT_BINARY_NE_ASSERTION(test, assert_type, left, right)              \
655         KUNIT_BINARY_NE_MSG_ASSERTION(test,                                    \
656                                       assert_type,                             \
657                                       left,                                    \
658                                       right,                                   \
659                                       NULL)
660
661 #define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test,                                \
662                                           assert_type,                         \
663                                           left,                                \
664                                           right,                               \
665                                           fmt,                                 \
666                                           ...)                                 \
667         KUNIT_BASE_NE_MSG_ASSERTION(test,                                      \
668                                     kunit_binary_ptr_assert,                   \
669                                     KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
670                                     assert_type,                               \
671                                     left,                                      \
672                                     right,                                     \
673                                     fmt,                                       \
674                                     ##__VA_ARGS__)
675
676 #define KUNIT_BINARY_PTR_NE_ASSERTION(test, assert_type, left, right)          \
677         KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test,                                \
678                                           assert_type,                         \
679                                           left,                                \
680                                           right,                               \
681                                           NULL)
682
683 #define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
684         KUNIT_BASE_LT_MSG_ASSERTION(test,                                      \
685                                     kunit_binary_assert,                       \
686                                     KUNIT_INIT_BINARY_ASSERT_STRUCT,           \
687                                     assert_type,                               \
688                                     left,                                      \
689                                     right,                                     \
690                                     fmt,                                       \
691                                     ##__VA_ARGS__)
692
693 #define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right)              \
694         KUNIT_BINARY_LT_MSG_ASSERTION(test,                                    \
695                                       assert_type,                             \
696                                       left,                                    \
697                                       right,                                   \
698                                       NULL)
699
700 #define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test,                                \
701                                           assert_type,                         \
702                                           left,                                \
703                                           right,                               \
704                                           fmt,                                 \
705                                           ...)                                 \
706         KUNIT_BASE_LT_MSG_ASSERTION(test,                                      \
707                                     kunit_binary_ptr_assert,                   \
708                                     KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
709                                     assert_type,                               \
710                                     left,                                      \
711                                     right,                                     \
712                                     fmt,                                       \
713                                     ##__VA_ARGS__)
714
715 #define KUNIT_BINARY_PTR_LT_ASSERTION(test, assert_type, left, right)          \
716         KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test,                                \
717                                           assert_type,                         \
718                                           left,                                \
719                                           right,                               \
720                                           NULL)
721
722 #define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
723         KUNIT_BASE_LE_MSG_ASSERTION(test,                                      \
724                                     kunit_binary_assert,                       \
725                                     KUNIT_INIT_BINARY_ASSERT_STRUCT,           \
726                                     assert_type,                               \
727                                     left,                                      \
728                                     right,                                     \
729                                     fmt,                                       \
730                                     ##__VA_ARGS__)
731
732 #define KUNIT_BINARY_LE_ASSERTION(test, assert_type, left, right)              \
733         KUNIT_BINARY_LE_MSG_ASSERTION(test,                                    \
734                                       assert_type,                             \
735                                       left,                                    \
736                                       right,                                   \
737                                       NULL)
738
739 #define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test,                                \
740                                           assert_type,                         \
741                                           left,                                \
742                                           right,                               \
743                                           fmt,                                 \
744                                           ...)                                 \
745         KUNIT_BASE_LE_MSG_ASSERTION(test,                                      \
746                                     kunit_binary_ptr_assert,                   \
747                                     KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
748                                     assert_type,                               \
749                                     left,                                      \
750                                     right,                                     \
751                                     fmt,                                       \
752                                     ##__VA_ARGS__)
753
754 #define KUNIT_BINARY_PTR_LE_ASSERTION(test, assert_type, left, right)          \
755         KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test,                                \
756                                           assert_type,                         \
757                                           left,                                \
758                                           right,                               \
759                                           NULL)
760
761 #define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
762         KUNIT_BASE_GT_MSG_ASSERTION(test,                                      \
763                                     kunit_binary_assert,                       \
764                                     KUNIT_INIT_BINARY_ASSERT_STRUCT,           \
765                                     assert_type,                               \
766                                     left,                                      \
767                                     right,                                     \
768                                     fmt,                                       \
769                                     ##__VA_ARGS__)
770
771 #define KUNIT_BINARY_GT_ASSERTION(test, assert_type, left, right)              \
772         KUNIT_BINARY_GT_MSG_ASSERTION(test,                                    \
773                                       assert_type,                             \
774                                       left,                                    \
775                                       right,                                   \
776                                       NULL)
777
778 #define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test,                                \
779                                           assert_type,                         \
780                                           left,                                \
781                                           right,                               \
782                                           fmt,                                 \
783                                           ...)                                 \
784         KUNIT_BASE_GT_MSG_ASSERTION(test,                                      \
785                                     kunit_binary_ptr_assert,                   \
786                                     KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
787                                     assert_type,                               \
788                                     left,                                      \
789                                     right,                                     \
790                                     fmt,                                       \
791                                     ##__VA_ARGS__)
792
793 #define KUNIT_BINARY_PTR_GT_ASSERTION(test, assert_type, left, right)          \
794         KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test,                                \
795                                           assert_type,                         \
796                                           left,                                \
797                                           right,                               \
798                                           NULL)
799
800 #define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
801         KUNIT_BASE_GE_MSG_ASSERTION(test,                                      \
802                                     kunit_binary_assert,                       \
803                                     KUNIT_INIT_BINARY_ASSERT_STRUCT,           \
804                                     assert_type,                               \
805                                     left,                                      \
806                                     right,                                     \
807                                     fmt,                                       \
808                                     ##__VA_ARGS__)
809
810 #define KUNIT_BINARY_GE_ASSERTION(test, assert_type, left, right)              \
811         KUNIT_BINARY_GE_MSG_ASSERTION(test,                                    \
812                                       assert_type,                             \
813                                       left,                                    \
814                                       right,                                   \
815                                       NULL)
816
817 #define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test,                                \
818                                           assert_type,                         \
819                                           left,                                \
820                                           right,                               \
821                                           fmt,                                 \
822                                           ...)                                 \
823         KUNIT_BASE_GE_MSG_ASSERTION(test,                                      \
824                                     kunit_binary_ptr_assert,                   \
825                                     KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT,       \
826                                     assert_type,                               \
827                                     left,                                      \
828                                     right,                                     \
829                                     fmt,                                       \
830                                     ##__VA_ARGS__)
831
832 #define KUNIT_BINARY_PTR_GE_ASSERTION(test, assert_type, left, right)          \
833         KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test,                                \
834                                           assert_type,                         \
835                                           left,                                \
836                                           right,                               \
837                                           NULL)
838
839 #define KUNIT_BINARY_STR_ASSERTION(test,                                       \
840                                    assert_type,                                \
841                                    left,                                       \
842                                    op,                                         \
843                                    right,                                      \
844                                    fmt,                                        \
845                                    ...)                                        \
846 do {                                                                           \
847         typeof(left) __left = (left);                                          \
848         typeof(right) __right = (right);                                       \
849                                                                                \
850         KUNIT_ASSERTION(test,                                                  \
851                         strcmp(__left, __right) op 0,                          \
852                         kunit_binary_str_assert,                               \
853                         KUNIT_INIT_BINARY_ASSERT_STRUCT(test,                  \
854                                                         assert_type,           \
855                                                         #op,                   \
856                                                         #left,                 \
857                                                         __left,                \
858                                                         #right,                \
859                                                         __right),              \
860                         fmt,                                                   \
861                         ##__VA_ARGS__);                                        \
862 } while (0)
863
864 #define KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test,                                \
865                                           assert_type,                         \
866                                           left,                                \
867                                           right,                               \
868                                           fmt,                                 \
869                                           ...)                                 \
870         KUNIT_BINARY_STR_ASSERTION(test,                                       \
871                                    assert_type,                                \
872                                    left, ==, right,                            \
873                                    fmt,                                        \
874                                    ##__VA_ARGS__)
875
876 #define KUNIT_BINARY_STR_EQ_ASSERTION(test, assert_type, left, right)          \
877         KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test,                                \
878                                           assert_type,                         \
879                                           left,                                \
880                                           right,                               \
881                                           NULL)
882
883 #define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test,                                \
884                                           assert_type,                         \
885                                           left,                                \
886                                           right,                               \
887                                           fmt,                                 \
888                                           ...)                                 \
889         KUNIT_BINARY_STR_ASSERTION(test,                                       \
890                                    assert_type,                                \
891                                    left, !=, right,                            \
892                                    fmt,                                        \
893                                    ##__VA_ARGS__)
894
895 #define KUNIT_BINARY_STR_NE_ASSERTION(test, assert_type, left, right)          \
896         KUNIT_BINARY_STR_NE_MSG_ASSERTION(test,                                \
897                                           assert_type,                         \
898                                           left,                                \
899                                           right,                               \
900                                           NULL)
901
902 #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test,                          \
903                                                 assert_type,                   \
904                                                 ptr,                           \
905                                                 fmt,                           \
906                                                 ...)                           \
907 do {                                                                           \
908         typeof(ptr) __ptr = (ptr);                                             \
909                                                                                \
910         KUNIT_ASSERTION(test,                                                  \
911                         !IS_ERR_OR_NULL(__ptr),                                \
912                         kunit_ptr_not_err_assert,                              \
913                         KUNIT_INIT_PTR_NOT_ERR_STRUCT(test,                    \
914                                                       assert_type,             \
915                                                       #ptr,                    \
916                                                       __ptr),                  \
917                         fmt,                                                   \
918                         ##__VA_ARGS__);                                        \
919 } while (0)
920
921 #define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr)            \
922         KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test,                          \
923                                                 assert_type,                   \
924                                                 ptr,                           \
925                                                 NULL)
926
927 /**
928  * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
929  * @test: The test context object.
930  * @condition: an arbitrary boolean expression. The test fails when this does
931  * not evaluate to true.
932  *
933  * This and expectations of the form `KUNIT_EXPECT_*` will cause the test case
934  * to fail when the specified condition is not met; however, it will not prevent
935  * the test case from continuing to run; this is otherwise known as an
936  * *expectation failure*.
937  */
938 #define KUNIT_EXPECT_TRUE(test, condition) \
939         KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
940
941 #define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...)                       \
942         KUNIT_TRUE_MSG_ASSERTION(test,                                         \
943                                  KUNIT_EXPECTATION,                            \
944                                  condition,                                    \
945                                  fmt,                                          \
946                                  ##__VA_ARGS__)
947
948 /**
949  * KUNIT_EXPECT_FALSE() - Makes a test failure when the expression is not false.
950  * @test: The test context object.
951  * @condition: an arbitrary boolean expression. The test fails when this does
952  * not evaluate to false.
953  *
954  * Sets an expectation that @condition evaluates to false. See
955  * KUNIT_EXPECT_TRUE() for more information.
956  */
957 #define KUNIT_EXPECT_FALSE(test, condition) \
958         KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
959
960 #define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...)                      \
961         KUNIT_FALSE_MSG_ASSERTION(test,                                        \
962                                   KUNIT_EXPECTATION,                           \
963                                   condition,                                   \
964                                   fmt,                                         \
965                                   ##__VA_ARGS__)
966
967 /**
968  * KUNIT_EXPECT_EQ() - Sets an expectation that @left and @right are equal.
969  * @test: The test context object.
970  * @left: an arbitrary expression that evaluates to a primitive C type.
971  * @right: an arbitrary expression that evaluates to a primitive C type.
972  *
973  * Sets an expectation that the values that @left and @right evaluate to are
974  * equal. This is semantically equivalent to
975  * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
976  * more information.
977  */
978 #define KUNIT_EXPECT_EQ(test, left, right) \
979         KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
980
981 #define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...)                       \
982         KUNIT_BINARY_EQ_MSG_ASSERTION(test,                                    \
983                                       KUNIT_EXPECTATION,                       \
984                                       left,                                    \
985                                       right,                                   \
986                                       fmt,                                     \
987                                       ##__VA_ARGS__)
988
989 /**
990  * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
991  * @test: The test context object.
992  * @left: an arbitrary expression that evaluates to a pointer.
993  * @right: an arbitrary expression that evaluates to a pointer.
994  *
995  * Sets an expectation that the values that @left and @right evaluate to are
996  * equal. This is semantically equivalent to
997  * KUNIT_EXPECT_TRUE(@test, (@left) == (@right)). See KUNIT_EXPECT_TRUE() for
998  * more information.
999  */
1000 #define KUNIT_EXPECT_PTR_EQ(test, left, right)                                 \
1001         KUNIT_BINARY_PTR_EQ_ASSERTION(test,                                    \
1002                                       KUNIT_EXPECTATION,                       \
1003                                       left,                                    \
1004                                       right)
1005
1006 #define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...)                   \
1007         KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test,                                \
1008                                           KUNIT_EXPECTATION,                   \
1009                                           left,                                \
1010                                           right,                               \
1011                                           fmt,                                 \
1012                                           ##__VA_ARGS__)
1013
1014 /**
1015  * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
1016  * @test: The test context object.
1017  * @left: an arbitrary expression that evaluates to a primitive C type.
1018  * @right: an arbitrary expression that evaluates to a primitive C type.
1019  *
1020  * Sets an expectation that the values that @left and @right evaluate to are not
1021  * equal. This is semantically equivalent to
1022  * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1023  * more information.
1024  */
1025 #define KUNIT_EXPECT_NE(test, left, right) \
1026         KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1027
1028 #define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...)                       \
1029         KUNIT_BINARY_NE_MSG_ASSERTION(test,                                    \
1030                                       KUNIT_EXPECTATION,                       \
1031                                       left,                                    \
1032                                       right,                                   \
1033                                       fmt,                                     \
1034                                       ##__VA_ARGS__)
1035
1036 /**
1037  * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
1038  * @test: The test context object.
1039  * @left: an arbitrary expression that evaluates to a pointer.
1040  * @right: an arbitrary expression that evaluates to a pointer.
1041  *
1042  * Sets an expectation that the values that @left and @right evaluate to are not
1043  * equal. This is semantically equivalent to
1044  * KUNIT_EXPECT_TRUE(@test, (@left) != (@right)). See KUNIT_EXPECT_TRUE() for
1045  * more information.
1046  */
1047 #define KUNIT_EXPECT_PTR_NE(test, left, right)                                 \
1048         KUNIT_BINARY_PTR_NE_ASSERTION(test,                                    \
1049                                       KUNIT_EXPECTATION,                       \
1050                                       left,                                    \
1051                                       right)
1052
1053 #define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...)                   \
1054         KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test,                                \
1055                                           KUNIT_EXPECTATION,                   \
1056                                           left,                                \
1057                                           right,                               \
1058                                           fmt,                                 \
1059                                           ##__VA_ARGS__)
1060
1061 /**
1062  * KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
1063  * @test: The test context object.
1064  * @left: an arbitrary expression that evaluates to a primitive C type.
1065  * @right: an arbitrary expression that evaluates to a primitive C type.
1066  *
1067  * Sets an expectation that the value that @left evaluates to is less than the
1068  * value that @right evaluates to. This is semantically equivalent to
1069  * KUNIT_EXPECT_TRUE(@test, (@left) < (@right)). See KUNIT_EXPECT_TRUE() for
1070  * more information.
1071  */
1072 #define KUNIT_EXPECT_LT(test, left, right) \
1073         KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1074
1075 #define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...)                       \
1076         KUNIT_BINARY_LT_MSG_ASSERTION(test,                                    \
1077                                       KUNIT_EXPECTATION,                       \
1078                                       left,                                    \
1079                                       right,                                   \
1080                                       fmt,                                     \
1081                                       ##__VA_ARGS__)
1082
1083 /**
1084  * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
1085  * @test: The test context object.
1086  * @left: an arbitrary expression that evaluates to a primitive C type.
1087  * @right: an arbitrary expression that evaluates to a primitive C type.
1088  *
1089  * Sets an expectation that the value that @left evaluates to is less than or
1090  * equal to the value that @right evaluates to. Semantically this is equivalent
1091  * to KUNIT_EXPECT_TRUE(@test, (@left) <= (@right)). See KUNIT_EXPECT_TRUE() for
1092  * more information.
1093  */
1094 #define KUNIT_EXPECT_LE(test, left, right) \
1095         KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1096
1097 #define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...)                       \
1098         KUNIT_BINARY_LE_MSG_ASSERTION(test,                                    \
1099                                       KUNIT_EXPECTATION,                       \
1100                                       left,                                    \
1101                                       right,                                   \
1102                                       fmt,                                     \
1103                                       ##__VA_ARGS__)
1104
1105 /**
1106  * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
1107  * @test: The test context object.
1108  * @left: an arbitrary expression that evaluates to a primitive C type.
1109  * @right: an arbitrary expression that evaluates to a primitive C type.
1110  *
1111  * Sets an expectation that the value that @left evaluates to is greater than
1112  * the value that @right evaluates to. This is semantically equivalent to
1113  * KUNIT_EXPECT_TRUE(@test, (@left) > (@right)). See KUNIT_EXPECT_TRUE() for
1114  * more information.
1115  */
1116 #define KUNIT_EXPECT_GT(test, left, right) \
1117         KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1118
1119 #define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...)                       \
1120         KUNIT_BINARY_GT_MSG_ASSERTION(test,                                    \
1121                                       KUNIT_EXPECTATION,                       \
1122                                       left,                                    \
1123                                       right,                                   \
1124                                       fmt,                                     \
1125                                       ##__VA_ARGS__)
1126
1127 /**
1128  * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
1129  * @test: The test context object.
1130  * @left: an arbitrary expression that evaluates to a primitive C type.
1131  * @right: an arbitrary expression that evaluates to a primitive C type.
1132  *
1133  * Sets an expectation that the value that @left evaluates to is greater than
1134  * the value that @right evaluates to. This is semantically equivalent to
1135  * KUNIT_EXPECT_TRUE(@test, (@left) >= (@right)). See KUNIT_EXPECT_TRUE() for
1136  * more information.
1137  */
1138 #define KUNIT_EXPECT_GE(test, left, right) \
1139         KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1140
1141 #define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...)                       \
1142         KUNIT_BINARY_GE_MSG_ASSERTION(test,                                    \
1143                                       KUNIT_EXPECTATION,                       \
1144                                       left,                                    \
1145                                       right,                                   \
1146                                       fmt,                                     \
1147                                       ##__VA_ARGS__)
1148
1149 /**
1150  * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
1151  * @test: The test context object.
1152  * @left: an arbitrary expression that evaluates to a null terminated string.
1153  * @right: an arbitrary expression that evaluates to a null terminated string.
1154  *
1155  * Sets an expectation that the values that @left and @right evaluate to are
1156  * equal. This is semantically equivalent to
1157  * KUNIT_EXPECT_TRUE(@test, !strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1158  * for more information.
1159  */
1160 #define KUNIT_EXPECT_STREQ(test, left, right) \
1161         KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1162
1163 #define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...)                    \
1164         KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test,                                \
1165                                           KUNIT_EXPECTATION,                   \
1166                                           left,                                \
1167                                           right,                               \
1168                                           fmt,                                 \
1169                                           ##__VA_ARGS__)
1170
1171 /**
1172  * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
1173  * @test: The test context object.
1174  * @left: an arbitrary expression that evaluates to a null terminated string.
1175  * @right: an arbitrary expression that evaluates to a null terminated string.
1176  *
1177  * Sets an expectation that the values that @left and @right evaluate to are
1178  * not equal. This is semantically equivalent to
1179  * KUNIT_EXPECT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_EXPECT_TRUE()
1180  * for more information.
1181  */
1182 #define KUNIT_EXPECT_STRNEQ(test, left, right) \
1183         KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
1184
1185 #define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...)                   \
1186         KUNIT_BINARY_STR_NE_MSG_ASSERTION(test,                                \
1187                                           KUNIT_EXPECTATION,                   \
1188                                           left,                                \
1189                                           right,                               \
1190                                           fmt,                                 \
1191                                           ##__VA_ARGS__)
1192
1193 /**
1194  * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
1195  * @test: The test context object.
1196  * @ptr: an arbitrary pointer.
1197  *
1198  * Sets an expectation that the value that @ptr evaluates to is not null and not
1199  * an errno stored in a pointer. This is semantically equivalent to
1200  * KUNIT_EXPECT_TRUE(@test, !IS_ERR_OR_NULL(@ptr)). See KUNIT_EXPECT_TRUE() for
1201  * more information.
1202  */
1203 #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
1204         KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
1205
1206 #define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...)                  \
1207         KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test,                          \
1208                                                 KUNIT_EXPECTATION,             \
1209                                                 ptr,                           \
1210                                                 fmt,                           \
1211                                                 ##__VA_ARGS__)
1212
1213 #endif /* _KUNIT_TEST_H */