xref: /freebsd/sys/contrib/openzfs/tests/unit/munit.h (revision d9497217456002b0ddad3cd319570d0b098daa29)
1 // SPDX-License-Identifier: MIT
2 /* µnit Testing Framework
3  * Copyright (c) 2013-2017 Evan Nemerson <evan@nemerson.com>
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #ifndef MUNIT_H
27 #define MUNIT_H
28 
29 #include <stdarg.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <stddef.h>
33 
34 #define MUNIT_VERSION(major, minor, revision)                                  \
35   (((major) << 16) | ((minor) << 8) | (revision))
36 
37 #define MUNIT_CURRENT_VERSION MUNIT_VERSION(0, 4, 1)
38 
39 #if defined(_MSC_VER) && (_MSC_VER < 1600)
40 #  define munit_int8_t __int8
41 #  define munit_uint8_t unsigned __int8
42 #  define munit_int16_t __int16
43 #  define munit_uint16_t unsigned __int16
44 #  define munit_int32_t __int32
45 #  define munit_uint32_t unsigned __int32
46 #  define munit_int64_t __int64
47 #  define munit_uint64_t unsigned __int64
48 #else
49 #  include <stdint.h>
50 #  define munit_int8_t int8_t
51 #  define munit_uint8_t uint8_t
52 #  define munit_int16_t int16_t
53 #  define munit_uint16_t uint16_t
54 #  define munit_int32_t int32_t
55 #  define munit_uint32_t uint32_t
56 #  define munit_int64_t int64_t
57 #  define munit_uint64_t uint64_t
58 #endif
59 
60 #if defined(_MSC_VER) && (_MSC_VER < 1800)
61 #  if !defined(PRIi8)
62 #    define PRIi8 "i"
63 #  endif
64 #  if !defined(PRIi16)
65 #    define PRIi16 "i"
66 #  endif
67 #  if !defined(PRIi32)
68 #    define PRIi32 "i"
69 #  endif
70 #  if !defined(PRIi64)
71 #    define PRIi64 "I64i"
72 #  endif
73 #  if !defined(PRId8)
74 #    define PRId8 "d"
75 #  endif
76 #  if !defined(PRId16)
77 #    define PRId16 "d"
78 #  endif
79 #  if !defined(PRId32)
80 #    define PRId32 "d"
81 #  endif
82 #  if !defined(PRId64)
83 #    define PRId64 "I64d"
84 #  endif
85 #  if !defined(PRIx8)
86 #    define PRIx8 "x"
87 #  endif
88 #  if !defined(PRIx16)
89 #    define PRIx16 "x"
90 #  endif
91 #  if !defined(PRIx32)
92 #    define PRIx32 "x"
93 #  endif
94 #  if !defined(PRIx64)
95 #    define PRIx64 "I64x"
96 #  endif
97 #  if !defined(PRIu8)
98 #    define PRIu8 "u"
99 #  endif
100 #  if !defined(PRIu16)
101 #    define PRIu16 "u"
102 #  endif
103 #  if !defined(PRIu32)
104 #    define PRIu32 "u"
105 #  endif
106 #  if !defined(PRIu64)
107 #    define PRIu64 "I64u"
108 #  endif
109 #else
110 #  include <inttypes.h>
111 #endif
112 
113 #if !defined(munit_bool)
114 #  if defined(bool)
115 #    define munit_bool bool
116 #  elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
117 #    define munit_bool _Bool
118 #  else
119 #    define munit_bool int
120 #  endif
121 #endif
122 
123 #if defined(__cplusplus)
124 extern "C" {
125 #endif
126 
127 #if defined(__GNUC__)
128 #  define MUNIT_LIKELY(expr) (__builtin_expect((expr), 1))
129 #  define MUNIT_UNLIKELY(expr) (__builtin_expect((expr), 0))
130 #  define MUNIT_UNUSED __attribute__((__unused__))
131 #else
132 #  define MUNIT_LIKELY(expr) (expr)
133 #  define MUNIT_UNLIKELY(expr) (expr)
134 #  define MUNIT_UNUSED
135 #endif
136 
137 #if !defined(_WIN32)
138 #  define MUNIT_SIZE_MODIFIER "z"
139 #  define MUNIT_CHAR_MODIFIER "hh"
140 #  define MUNIT_SHORT_MODIFIER "h"
141 #else
142 #  if defined(_M_X64) || defined(__amd64__)
143 #    define MUNIT_SIZE_MODIFIER "I64"
144 #  else
145 #    define MUNIT_SIZE_MODIFIER ""
146 #  endif
147 #  define MUNIT_CHAR_MODIFIER ""
148 #  define MUNIT_SHORT_MODIFIER ""
149 #endif
150 
151 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
152 #  define MUNIT_NO_RETURN _Noreturn
153 #elif defined(__GNUC__)
154 #  define MUNIT_NO_RETURN __attribute__((__noreturn__))
155 #elif defined(_MSC_VER)
156 #  define MUNIT_NO_RETURN __declspec(noreturn)
157 #else
158 #  define MUNIT_NO_RETURN
159 #endif
160 
161 #if defined(_MSC_VER) && (_MSC_VER >= 1500)
162 #  define MUNIT_PUSH_DISABLE_MSVC_C4127_                                       \
163     __pragma(warning(push)) __pragma(warning(disable : 4127))
164 #  define MUNIT_POP_DISABLE_MSVC_C4127_ __pragma(warning(pop))
165 #else
166 #  define MUNIT_PUSH_DISABLE_MSVC_C4127_
167 #  define MUNIT_POP_DISABLE_MSVC_C4127_
168 #endif
169 
170 typedef enum {
171   MUNIT_LOG_DEBUG,
172   MUNIT_LOG_INFO,
173   MUNIT_LOG_WARNING,
174   MUNIT_LOG_ERROR
175 } MunitLogLevel;
176 
177 #if defined(__GNUC__) && !defined(__MINGW32__)
178 #  define MUNIT_PRINTF(string_index, first_to_check)                           \
179     __attribute__((format(printf, string_index, first_to_check)))
180 #else
181 #  define MUNIT_PRINTF(string_index, first_to_check)
182 #endif
183 
184 MUNIT_PRINTF(4, 5)
185 void munit_logf_ex(MunitLogLevel level, const char *filename, int line,
186                    const char *format, ...);
187 
188 #define munit_logf(level, format, ...)                                         \
189   munit_logf_ex(level, __FILE__, __LINE__, format, __VA_ARGS__)
190 
191 #define munit_log(level, msg) munit_logf(level, "%s", msg)
192 
193 MUNIT_NO_RETURN
194 MUNIT_PRINTF(3, 4)
195 void munit_errorf_ex(const char *filename, int line, const char *format, ...);
196 
197 #define munit_errorf(format, ...)                                              \
198   munit_errorf_ex(__FILE__, __LINE__, format, __VA_ARGS__)
199 
200 #define munit_error(msg) munit_errorf("%s", msg)
201 
202 #define munit_assert(expr)                                                     \
203   do {                                                                         \
204     if (!MUNIT_LIKELY(expr)) {                                                 \
205       munit_error("assertion failed: " #expr);                                 \
206     }                                                                          \
207     MUNIT_PUSH_DISABLE_MSVC_C4127_                                             \
208   } while (0) MUNIT_POP_DISABLE_MSVC_C4127_
209 
210 #define munit_assert_true(expr)                                                \
211   do {                                                                         \
212     if (!MUNIT_LIKELY(expr)) {                                                 \
213       munit_error("assertion failed: " #expr " is not true");                  \
214     }                                                                          \
215     MUNIT_PUSH_DISABLE_MSVC_C4127_                                             \
216   } while (0) MUNIT_POP_DISABLE_MSVC_C4127_
217 
218 #define munit_assert_false(expr)                                               \
219   do {                                                                         \
220     if (!MUNIT_LIKELY(!(expr))) {                                              \
221       munit_error("assertion failed: " #expr " is not false");                 \
222     }                                                                          \
223     MUNIT_PUSH_DISABLE_MSVC_C4127_                                             \
224   } while (0) MUNIT_POP_DISABLE_MSVC_C4127_
225 
226 #define munit_assert_type_full(prefix, suffix, T, fmt, a, op, b)               \
227   do {                                                                         \
228     T munit_tmp_a_ = (a);                                                      \
229     T munit_tmp_b_ = (b);                                                      \
230     if (!(munit_tmp_a_ op munit_tmp_b_)) {                                     \
231       munit_errorf("assertion failed: %s %s %s (" prefix "%" fmt suffix        \
232                    " %s " prefix "%" fmt suffix ")",                           \
233                    #a, #op, #b, munit_tmp_a_, #op, munit_tmp_b_);              \
234     }                                                                          \
235     MUNIT_PUSH_DISABLE_MSVC_C4127_                                             \
236   } while (0) MUNIT_POP_DISABLE_MSVC_C4127_
237 
238 #define munit_assert_type(T, fmt, a, op, b)                                    \
239   munit_assert_type_full("", "", T, fmt, a, op, b)
240 
241 #define munit_assert_char(a, op, b)                                            \
242   munit_assert_type_full("'\\x", "'", char, "02" MUNIT_CHAR_MODIFIER "x", a,   \
243                          op, b)
244 #define munit_assert_uchar(a, op, b)                                           \
245   munit_assert_type_full("'\\x", "'", unsigned char,                           \
246                          "02" MUNIT_CHAR_MODIFIER "x", a, op, b)
247 #define munit_assert_short(a, op, b)                                           \
248   munit_assert_type(short, MUNIT_SHORT_MODIFIER "d", a, op, b)
249 #define munit_assert_ushort(a, op, b)                                          \
250   munit_assert_type(unsigned short, MUNIT_SHORT_MODIFIER "u", a, op, b)
251 #define munit_assert_int(a, op, b) munit_assert_type(int, "d", a, op, b)
252 #define munit_assert_uint(a, op, b)                                            \
253   munit_assert_type(unsigned int, "u", a, op, b)
254 #define munit_assert_long(a, op, b) munit_assert_type(long int, "ld", a, op, b)
255 #define munit_assert_ulong(a, op, b)                                           \
256   munit_assert_type(unsigned long int, "lu", a, op, b)
257 #define munit_assert_llong(a, op, b)                                           \
258   munit_assert_type(long long int, "lld", a, op, b)
259 #define munit_assert_ullong(a, op, b)                                          \
260   munit_assert_type(unsigned long long int, "llu", a, op, b)
261 
262 #define munit_assert_size(a, op, b)                                            \
263   munit_assert_type(size_t, MUNIT_SIZE_MODIFIER "u", a, op, b)
264 #define munit_assert_ssize(a, op, b)                                           \
265   munit_assert_type(ssize_t, MUNIT_SIZE_MODIFIER "d", a, op, b)
266 
267 #define munit_assert_float(a, op, b) munit_assert_type(float, "f", a, op, b)
268 #define munit_assert_double(a, op, b) munit_assert_type(double, "g", a, op, b)
269 #define munit_assert_ptr(a, op, b)                                             \
270   munit_assert_type(const void *, "p", a, op, b)
271 
272 #define munit_assert_int8(a, op, b)                                            \
273   munit_assert_type(munit_int8_t, PRIi8, a, op, b)
274 #define munit_assert_uint8(a, op, b)                                           \
275   munit_assert_type(munit_uint8_t, PRIu8, a, op, b)
276 #define munit_assert_int16(a, op, b)                                           \
277   munit_assert_type(munit_int16_t, PRIi16, a, op, b)
278 #define munit_assert_uint16(a, op, b)                                          \
279   munit_assert_type(munit_uint16_t, PRIu16, a, op, b)
280 #define munit_assert_int32(a, op, b)                                           \
281   munit_assert_type(munit_int32_t, PRIi32, a, op, b)
282 #define munit_assert_uint32(a, op, b)                                          \
283   munit_assert_type(munit_uint32_t, PRIu32, a, op, b)
284 #define munit_assert_int64(a, op, b)                                           \
285   munit_assert_type(munit_int64_t, PRIi64, a, op, b)
286 #define munit_assert_uint64(a, op, b)                                          \
287   munit_assert_type(munit_uint64_t, PRIu64, a, op, b)
288 
289 #define munit_assert_ptrdiff(a, op, b)                                         \
290   munit_assert_type(ptrdiff_t, "td", a, op, b)
291 
292 #define munit_assert_enum(T, a, op, b) munit_assert_type(T, "d", a, op, b)
293 
294 #define munit_assert_double_equal(a, b, precision)                             \
295   do {                                                                         \
296     const double munit_tmp_a_ = (a);                                           \
297     const double munit_tmp_b_ = (b);                                           \
298     const double munit_tmp_diff_ = ((munit_tmp_a_ - munit_tmp_b_) < 0)         \
299                                      ? -(munit_tmp_a_ - munit_tmp_b_)          \
300                                      : (munit_tmp_a_ - munit_tmp_b_);          \
301     if (MUNIT_UNLIKELY(munit_tmp_diff_ > 1e-##precision)) {                    \
302       munit_errorf("assertion failed: %s == %s (%0." #precision                \
303                    "g == %0." #precision "g)",                                 \
304                    #a, #b, munit_tmp_a_, munit_tmp_b_);                        \
305     }                                                                          \
306     MUNIT_PUSH_DISABLE_MSVC_C4127_                                             \
307   } while (0) MUNIT_POP_DISABLE_MSVC_C4127_
308 
309 #include <string.h>
310 #define munit_assert_string_equal(a, b)                                        \
311   do {                                                                         \
312     const char *munit_tmp_a_ = (a);                                            \
313     const char *munit_tmp_b_ = (b);                                            \
314     if (MUNIT_UNLIKELY(strcmp(munit_tmp_a_, munit_tmp_b_) != 0)) {             \
315       munit_hexdump_diff(stderr, munit_tmp_a_, strlen(munit_tmp_a_),           \
316                          munit_tmp_b_, strlen(munit_tmp_b_));                  \
317       munit_errorf("assertion failed: string %s == %s (\"%s\" == \"%s\")", #a, \
318                    #b, munit_tmp_a_, munit_tmp_b_);                            \
319     }                                                                          \
320     MUNIT_PUSH_DISABLE_MSVC_C4127_                                             \
321   } while (0) MUNIT_POP_DISABLE_MSVC_C4127_
322 
323 #define munit_assert_string_not_equal(a, b)                                    \
324   do {                                                                         \
325     const char *munit_tmp_a_ = (a);                                            \
326     const char *munit_tmp_b_ = (b);                                            \
327     if (MUNIT_UNLIKELY(strcmp(munit_tmp_a_, munit_tmp_b_) == 0)) {             \
328       munit_errorf("assertion failed: string %s != %s (\"%s\" == \"%s\")", #a, \
329                    #b, munit_tmp_a_, munit_tmp_b_);                            \
330     }                                                                          \
331     MUNIT_PUSH_DISABLE_MSVC_C4127_                                             \
332   } while (0) MUNIT_POP_DISABLE_MSVC_C4127_
333 
334 #define munit_assert_memory_equal(size, a, b)                                  \
335   do {                                                                         \
336     const unsigned char *munit_tmp_a_ = (const unsigned char *)(a);            \
337     const unsigned char *munit_tmp_b_ = (const unsigned char *)(b);            \
338     const size_t munit_tmp_size_ = (size);                                     \
339     if (MUNIT_UNLIKELY(memcmp(munit_tmp_a_, munit_tmp_b_, munit_tmp_size_)) != \
340         0) {                                                                   \
341       size_t munit_tmp_pos_;                                                   \
342       for (munit_tmp_pos_ = 0; munit_tmp_pos_ < munit_tmp_size_;               \
343            munit_tmp_pos_++) {                                                 \
344         if (munit_tmp_a_[munit_tmp_pos_] != munit_tmp_b_[munit_tmp_pos_]) {    \
345           munit_hexdump_diff(stderr, munit_tmp_a_, size, munit_tmp_b_, size);  \
346           munit_errorf("assertion failed: memory %s == %s, at offset "         \
347                        "%" MUNIT_SIZE_MODIFIER "u",                            \
348                        #a, #b, munit_tmp_pos_);                                \
349           break;                                                               \
350         }                                                                      \
351       }                                                                        \
352     }                                                                          \
353     MUNIT_PUSH_DISABLE_MSVC_C4127_                                             \
354   } while (0) MUNIT_POP_DISABLE_MSVC_C4127_
355 
356 #define munit_assert_memn_equal(a, a_size, b, b_size)                          \
357   do {                                                                         \
358     const unsigned char *munit_tmp_a_ = (const unsigned char *)(a);            \
359     const unsigned char *munit_tmp_b_ = (const unsigned char *)(b);            \
360     const size_t munit_tmp_a_size_ = (a_size);                                 \
361     const size_t munit_tmp_b_size_ = (b_size);                                 \
362     if (MUNIT_UNLIKELY(munit_tmp_a_size_ != munit_tmp_b_size_) ||              \
363         MUNIT_UNLIKELY(munit_tmp_a_size_ && memcmp(munit_tmp_a_, munit_tmp_b_, \
364                                                    munit_tmp_a_size_)) != 0) { \
365       munit_hexdump_diff(stderr, munit_tmp_a_, munit_tmp_a_size_,              \
366                          munit_tmp_b_, munit_tmp_b_size_);                     \
367       munit_errorf("assertion failed: memory %s == %s", #a, #b);               \
368     }                                                                          \
369     MUNIT_PUSH_DISABLE_MSVC_C4127_                                             \
370   } while (0) MUNIT_POP_DISABLE_MSVC_C4127_
371 
372 #define munit_assert_memory_not_equal(size, a, b)                              \
373   do {                                                                         \
374     const unsigned char *munit_tmp_a_ = (const unsigned char *)(a);            \
375     const unsigned char *munit_tmp_b_ = (const unsigned char *)(b);            \
376     const size_t munit_tmp_size_ = (size);                                     \
377     if (MUNIT_UNLIKELY(memcmp(munit_tmp_a_, munit_tmp_b_, munit_tmp_size_)) == \
378         0) {                                                                   \
379       munit_errorf("assertion failed: memory %s != %s (%zu bytes)", #a, #b,    \
380                    munit_tmp_size_);                                           \
381     }                                                                          \
382     MUNIT_PUSH_DISABLE_MSVC_C4127_                                             \
383   } while (0) MUNIT_POP_DISABLE_MSVC_C4127_
384 
385 #define munit_assert_ptr_equal(a, b) munit_assert_ptr(a, ==, b)
386 #define munit_assert_ptr_not_equal(a, b) munit_assert_ptr(a, !=, b)
387 #define munit_assert_null(ptr) munit_assert_ptr(ptr, ==, NULL)
388 #define munit_assert_not_null(ptr) munit_assert_ptr(ptr, !=, NULL)
389 #define munit_assert_ptr_null(ptr) munit_assert_ptr(ptr, ==, NULL)
390 #define munit_assert_ptr_not_null(ptr) munit_assert_ptr(ptr, !=, NULL)
391 
392 /*** Memory allocation ***/
393 
394 void *munit_malloc_ex(const char *filename, int line, size_t size);
395 
396 #define munit_malloc(size) munit_malloc_ex(__FILE__, __LINE__, (size))
397 
398 #define munit_new(type) ((type *)munit_malloc(sizeof(type)))
399 
400 #define munit_calloc(nmemb, size) munit_malloc((nmemb) * (size))
401 
402 #define munit_newa(type, nmemb) ((type *)munit_calloc((nmemb), sizeof(type)))
403 
404 /*** Random number generation ***/
405 
406 void munit_rand_seed(munit_uint32_t seed);
407 munit_uint32_t munit_rand_uint32(void);
408 int munit_rand_int_range(int min, int max);
409 double munit_rand_double(void);
410 void munit_rand_memory(size_t size, munit_uint8_t *buffer);
411 
412 /*** Tests and Suites ***/
413 
414 typedef enum {
415   /* Test successful */
416   MUNIT_OK,
417   /* Test failed */
418   MUNIT_FAIL,
419   /* Test was skipped */
420   MUNIT_SKIP,
421   /* Test failed due to circumstances not intended to be tested
422    * (things like network errors, invalid parameter value, failure to
423    * allocate memory in the test harness, etc.). */
424   MUNIT_ERROR
425 } MunitResult;
426 
427 typedef struct {
428   char *name;
429   char **values;
430 } MunitParameterEnum;
431 
432 typedef struct {
433   char *name;
434   char *value;
435 } MunitParameter;
436 
437 const char *munit_parameters_get(const MunitParameter params[],
438                                  const char *key);
439 
440 typedef enum {
441   MUNIT_TEST_OPTION_NONE = 0,
442   MUNIT_TEST_OPTION_SINGLE_ITERATION = 1 << 0,
443   MUNIT_TEST_OPTION_TODO = 1 << 1
444 } MunitTestOptions;
445 
446 typedef MunitResult (*MunitTestFunc)(const MunitParameter params[],
447                                      void *user_data_or_fixture);
448 typedef void *(*MunitTestSetup)(const MunitParameter params[], void *user_data);
449 typedef void (*MunitTestTearDown)(void *fixture);
450 
451 typedef struct {
452   const char *name;
453   MunitTestFunc test;
454   MunitTestSetup setup;
455   MunitTestTearDown tear_down;
456   MunitTestOptions options;
457   MunitParameterEnum *parameters;
458 } MunitTest;
459 
460 typedef enum { MUNIT_SUITE_OPTION_NONE = 0 } MunitSuiteOptions;
461 
462 typedef struct MunitSuite_ MunitSuite;
463 
464 struct MunitSuite_ {
465   const char *prefix;
466   const MunitTest *tests;
467   const MunitSuite *suites;
468   unsigned int iterations;
469   MunitSuiteOptions options;
470 };
471 
472 int munit_suite_main(const MunitSuite *suite, void *user_data, int argc,
473                      char *const *argv);
474 
475 /* Note: I'm not very happy with this API; it's likely to change if I
476  * figure out something better.  Suggestions welcome. */
477 
478 typedef struct MunitArgument_ MunitArgument;
479 
480 struct MunitArgument_ {
481   char *name;
482   munit_bool (*parse_argument)(const MunitSuite *suite, void *user_data,
483                                int *arg, int argc, char *const *argv);
484   void (*write_help)(const MunitArgument *argument, void *user_data);
485 };
486 
487 int munit_suite_main_custom(const MunitSuite *suite, void *user_data, int argc,
488                             char *const *argv, const MunitArgument arguments[]);
489 
490 #if defined(MUNIT_ENABLE_ASSERT_ALIASES)
491 
492 #  define assert_true(expr) munit_assert_true(expr)
493 #  define assert_false(expr) munit_assert_false(expr)
494 #  define assert_char(a, op, b) munit_assert_char(a, op, b)
495 #  define assert_uchar(a, op, b) munit_assert_uchar(a, op, b)
496 #  define assert_short(a, op, b) munit_assert_short(a, op, b)
497 #  define assert_ushort(a, op, b) munit_assert_ushort(a, op, b)
498 #  define assert_int(a, op, b) munit_assert_int(a, op, b)
499 #  define assert_uint(a, op, b) munit_assert_uint(a, op, b)
500 #  define assert_long(a, op, b) munit_assert_long(a, op, b)
501 #  define assert_ulong(a, op, b) munit_assert_ulong(a, op, b)
502 #  define assert_llong(a, op, b) munit_assert_llong(a, op, b)
503 #  define assert_ullong(a, op, b) munit_assert_ullong(a, op, b)
504 #  define assert_size(a, op, b) munit_assert_size(a, op, b)
505 #  define assert_ssize(a, op, b) munit_assert_ssize(a, op, b)
506 #  define assert_float(a, op, b) munit_assert_float(a, op, b)
507 #  define assert_double(a, op, b) munit_assert_double(a, op, b)
508 #  define assert_ptr(a, op, b) munit_assert_ptr(a, op, b)
509 
510 #  define assert_int8(a, op, b) munit_assert_int8(a, op, b)
511 #  define assert_uint8(a, op, b) munit_assert_uint8(a, op, b)
512 #  define assert_int16(a, op, b) munit_assert_int16(a, op, b)
513 #  define assert_uint16(a, op, b) munit_assert_uint16(a, op, b)
514 #  define assert_int32(a, op, b) munit_assert_int32(a, op, b)
515 #  define assert_uint32(a, op, b) munit_assert_uint32(a, op, b)
516 #  define assert_int64(a, op, b) munit_assert_int64(a, op, b)
517 #  define assert_uint64(a, op, b) munit_assert_uint64(a, op, b)
518 
519 #  define assert_ptrdiff(a, op, b) munit_assert_ptrdiff(a, op, b)
520 
521 #  define assert_enum(T, a, op, b) munit_assert_enum(T, a, op, b)
522 
523 #  define assert_double_equal(a, b, precision)                                 \
524     munit_assert_double_equal(a, b, precision)
525 #  define assert_string_equal(a, b) munit_assert_string_equal(a, b)
526 #  define assert_string_not_equal(a, b) munit_assert_string_not_equal(a, b)
527 #  define assert_memory_equal(size, a, b) munit_assert_memory_equal(size, a, b)
528 #  define assert_memn_equal(a, a_size, b, b_size)                              \
529     munit_assert_memn_equal(a, a_size, b, b_size)
530 #  define assert_memory_not_equal(size, a, b)                                  \
531     munit_assert_memory_not_equal(size, a, b)
532 #  define assert_ptr_equal(a, b) munit_assert_ptr_equal(a, b)
533 #  define assert_ptr_not_equal(a, b) munit_assert_ptr_not_equal(a, b)
534 #  define assert_ptr_null(ptr) munit_assert_null_equal(ptr)
535 #  define assert_ptr_not_null(ptr) munit_assert_not_null(ptr)
536 
537 #  define assert_null(ptr) munit_assert_null(ptr)
538 #  define assert_not_null(ptr) munit_assert_not_null(ptr)
539 
540 #endif /* defined(MUNIT_ENABLE_ASSERT_ALIASES) */
541 
542 #define munit_void_test_decl(func)                                             \
543   void func(void);                                                             \
544                                                                                \
545   static inline MunitResult wrap_##func(const MunitParameter params[],         \
546                                         void *fixture) {                       \
547     (void)params;                                                              \
548     (void)fixture;                                                             \
549                                                                                \
550     func();                                                                    \
551     return MUNIT_OK;                                                           \
552   }
553 
554 #define munit_void_test(func)                                                  \
555   {"/" #func, wrap_##func, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}
556 
557 #define munit_test_end() {NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}
558 
559 int munit_hexdump(FILE *fp, const void *data, size_t datalen);
560 
561 int munit_hexdump_diff(FILE *fp, const void *a, size_t alen, const void *b,
562                        size_t blen);
563 
564 #if defined(__cplusplus)
565 }
566 #endif
567 
568 #endif /* !defined(MUNIT_H) */
569 
570 #if defined(MUNIT_ENABLE_ASSERT_ALIASES)
571 #if defined(assert)
572 #  undef assert
573 #endif
574 #define assert(expr) munit_assert(expr)
575 #endif
576