Andrew Scull | e184c5b | 2022-05-30 10:00:09 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright (c) 2022 Google, Inc. |
| 4 | * Written by Andrew Scull <ascull@google.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef __TEST_FUZZ_H |
| 8 | #define __TEST_FUZZ_H |
| 9 | |
| 10 | #include <linker_lists.h> |
| 11 | #include <linux/types.h> |
| 12 | |
| 13 | /** |
| 14 | * struct fuzz_test - Information about a fuzz test |
| 15 | * |
| 16 | * @name: Name of fuzz test |
| 17 | * @func: Function to call to perform fuzz test on an input |
| 18 | * @flags: Flags indicate pre-conditions for fuzz test |
| 19 | */ |
| 20 | struct fuzz_test { |
| 21 | const char *name; |
| 22 | int (*func)(const uint8_t * data, size_t size); |
| 23 | int flags; |
| 24 | }; |
| 25 | |
| 26 | /** |
| 27 | * FUZZ_TEST() - register a fuzz test |
| 28 | * |
| 29 | * The fuzz test function must return 0 as other values are reserved for future |
| 30 | * use. |
| 31 | * |
| 32 | * @_name: the name of the fuzz test function |
| 33 | * @_flags: an integer field that can be evaluated by the fuzzer |
| 34 | * implementation |
| 35 | */ |
| 36 | #define FUZZ_TEST(_name, _flags) \ |
| 37 | ll_entry_declare(struct fuzz_test, _name, fuzz_tests) = { \ |
| 38 | .name = #_name, \ |
| 39 | .func = _name, \ |
| 40 | .flags = _flags, \ |
| 41 | } |
| 42 | |
| 43 | /** Get the start of the list of fuzz tests */ |
| 44 | #define FUZZ_TEST_START() \ |
| 45 | ll_entry_start(struct fuzz_test, fuzz_tests) |
| 46 | |
| 47 | /** Get the number of elements in the list of fuzz tests */ |
| 48 | #define FUZZ_TEST_COUNT() \ |
| 49 | ll_entry_count(struct fuzz_test, fuzz_tests) |
| 50 | |
| 51 | #endif /* __TEST_FUZZ_H */ |