Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 Google, Inc. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #ifndef __TEST_TEST_H |
| 8 | #define __TEST_TEST_H |
| 9 | |
| 10 | #include <malloc.h> |
| 11 | |
| 12 | /* |
| 13 | * struct unit_test_state - Entire state of test system |
| 14 | * |
| 15 | * @fail_count: Number of tests that failed |
| 16 | * @start: Store the starting mallinfo when doing leak test |
| 17 | * @priv: A pointer to some other info some suites want to track |
Simon Glass | 017886b | 2017-05-18 20:09:17 -0600 | [diff] [blame] | 18 | * @of_root: Record of the livetree root node (used for setting up tests) |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 19 | */ |
| 20 | struct unit_test_state { |
| 21 | int fail_count; |
| 22 | struct mallinfo start; |
| 23 | void *priv; |
Simon Glass | 017886b | 2017-05-18 20:09:17 -0600 | [diff] [blame] | 24 | struct device_node *of_root; |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | /** |
| 28 | * struct unit_test - Information about a unit test |
| 29 | * |
| 30 | * @name: Name of test |
| 31 | * @func: Function to call to perform test |
| 32 | * @flags: Flags indicated pre-conditions for test |
| 33 | */ |
| 34 | struct unit_test { |
Simon Glass | be408ee | 2017-05-18 20:09:15 -0600 | [diff] [blame] | 35 | const char *file; |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 36 | const char *name; |
| 37 | int (*func)(struct unit_test_state *state); |
| 38 | int flags; |
| 39 | }; |
| 40 | |
| 41 | /* Declare a new unit test */ |
| 42 | #define UNIT_TEST(_name, _flags, _suite) \ |
| 43 | ll_entry_declare(struct unit_test, _name, _suite) = { \ |
Simon Glass | be408ee | 2017-05-18 20:09:15 -0600 | [diff] [blame] | 44 | .file = __FILE__, \ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 45 | .name = #_name, \ |
| 46 | .flags = _flags, \ |
| 47 | .func = _name, \ |
| 48 | } |
| 49 | |
| 50 | |
| 51 | #endif /* __TEST_TEST_H */ |