Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc. |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __TEST_TEST_H |
| 7 | #define __TEST_TEST_H |
| 8 | |
| 9 | #include <malloc.h> |
| 10 | |
| 11 | /* |
| 12 | * struct unit_test_state - Entire state of test system |
| 13 | * |
| 14 | * @fail_count: Number of tests that failed |
| 15 | * @start: Store the starting mallinfo when doing leak test |
| 16 | * @priv: A pointer to some other info some suites want to track |
Simon Glass | 017886b | 2017-05-18 20:09:17 -0600 | [diff] [blame] | 17 | * @of_root: Record of the livetree root node (used for setting up tests) |
Simon Glass | d856e91 | 2020-01-27 08:49:56 -0700 | [diff] [blame] | 18 | * @expect_str: Temporary string used to hold expected string value |
| 19 | * @actual_str: Temporary string used to hold actual string value |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 20 | */ |
| 21 | struct unit_test_state { |
| 22 | int fail_count; |
| 23 | struct mallinfo start; |
| 24 | void *priv; |
Simon Glass | 017886b | 2017-05-18 20:09:17 -0600 | [diff] [blame] | 25 | struct device_node *of_root; |
Simon Glass | d856e91 | 2020-01-27 08:49:56 -0700 | [diff] [blame] | 26 | char expect_str[256]; |
| 27 | char actual_str[256]; |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | /** |
| 31 | * struct unit_test - Information about a unit test |
| 32 | * |
| 33 | * @name: Name of test |
| 34 | * @func: Function to call to perform test |
| 35 | * @flags: Flags indicated pre-conditions for test |
| 36 | */ |
| 37 | struct unit_test { |
Simon Glass | be408ee | 2017-05-18 20:09:15 -0600 | [diff] [blame] | 38 | const char *file; |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 39 | const char *name; |
| 40 | int (*func)(struct unit_test_state *state); |
| 41 | int flags; |
| 42 | }; |
| 43 | |
Heinrich Schuchardt | df6c36c | 2020-05-06 18:26:07 +0200 | [diff] [blame] | 44 | /** |
| 45 | * UNIT_TEST() - create linker generated list entry for unit a unit test |
| 46 | * |
| 47 | * The macro UNIT_TEST() is used to create a linker generated list entry. These |
| 48 | * list entries are enumerate tests that can be execute using the ut command. |
| 49 | * The list entries are used both by the implementation of the ut command as |
| 50 | * well as in a related Python test. |
| 51 | * |
| 52 | * For Python testing the subtests are collected in Python function |
| 53 | * generate_ut_subtest() by applying a regular expression to the lines of file |
| 54 | * u-boot.sym. The list entries have to follow strict naming conventions to be |
| 55 | * matched by the expression. |
| 56 | * |
| 57 | * Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in test suite |
| 58 | * foo that can be executed via command 'ut foo bar' and is implemented in |
| 59 | * function foo_test_bar(). |
| 60 | * |
| 61 | * @_name: concatenation of name of the test suite, "_test_", and the name |
| 62 | * of the test |
| 63 | * @_flags: an integer field that can be evaluated by the test suite |
| 64 | * implementation |
| 65 | * @_suite: name of the test suite concatenated with "_test" |
| 66 | */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 67 | #define UNIT_TEST(_name, _flags, _suite) \ |
| 68 | ll_entry_declare(struct unit_test, _name, _suite) = { \ |
Simon Glass | be408ee | 2017-05-18 20:09:15 -0600 | [diff] [blame] | 69 | .file = __FILE__, \ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 70 | .name = #_name, \ |
| 71 | .flags = _flags, \ |
| 72 | .func = _name, \ |
| 73 | } |
| 74 | |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 75 | /* Sizes for devres tests */ |
| 76 | enum { |
| 77 | TEST_DEVRES_SIZE = 100, |
| 78 | TEST_DEVRES_COUNT = 10, |
| 79 | TEST_DEVRES_TOTAL = TEST_DEVRES_SIZE * TEST_DEVRES_COUNT, |
| 80 | |
Simon Glass | 0fe1537 | 2019-12-29 21:19:28 -0700 | [diff] [blame] | 81 | /* A few different sizes */ |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 82 | TEST_DEVRES_SIZE2 = 15, |
Simon Glass | 0fe1537 | 2019-12-29 21:19:28 -0700 | [diff] [blame] | 83 | TEST_DEVRES_SIZE3 = 37, |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 84 | }; |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 85 | |
| 86 | #endif /* __TEST_TEST_H */ |