Update to Zstandard 1.4.4
[freebsd.git] / sys / contrib / zstd / tests / fuzz / fuzz_helpers.h
1 /*
2  * Copyright (c) 2016-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under both the BSD-style license (found in the
6  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7  * in the COPYING file in the root directory of this source tree).
8  */
9
10 /**
11  * Helper functions for fuzzing.
12  */
13
14 #ifndef FUZZ_HELPERS_H
15 #define FUZZ_HELPERS_H
16
17 #include "debug.h"
18 #include "fuzz.h"
19 #include "xxhash.h"
20 #include "zstd.h"
21 #include <stdint.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #define MIN(a, b) ((a) < (b) ? (a) : (b))
30 #define MAX(a, b) ((a) > (b) ? (a) : (b))
31
32 #define FUZZ_QUOTE_IMPL(str) #str
33 #define FUZZ_QUOTE(str) FUZZ_QUOTE_IMPL(str)
34
35 /**
36  * Asserts for fuzzing that are always enabled.
37  */
38 #define FUZZ_ASSERT_MSG(cond, msg)                                             \
39   ((cond) ? (void)0                                                            \
40           : (fprintf(stderr, "%s: %u: Assertion: `%s' failed. %s\n", __FILE__, \
41                      __LINE__, FUZZ_QUOTE(cond), (msg)),                       \
42              abort()))
43 #define FUZZ_ASSERT(cond) FUZZ_ASSERT_MSG((cond), "");
44 #define FUZZ_ZASSERT(code)                                                     \
45   FUZZ_ASSERT_MSG(!ZSTD_isError(code), ZSTD_getErrorName(code))
46
47 #if defined(__GNUC__)
48 #define FUZZ_STATIC static __inline __attribute__((unused))
49 #elif defined(__cplusplus) ||                                                  \
50     (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
51 #define FUZZ_STATIC static inline
52 #elif defined(_MSC_VER)
53 #define FUZZ_STATIC static __inline
54 #else
55 #define FUZZ_STATIC static
56 #endif
57
58 #ifdef __cplusplus
59 }
60 #endif
61
62 #endif