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> |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 10 | #include <linux/bitops.h> |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 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) |
Simon Glass | d856e91 | 2020-01-27 08:49:56 -0700 | [diff] [blame] | 19 | * @expect_str: Temporary string used to hold expected string value |
| 20 | * @actual_str: Temporary string used to hold actual string value |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 21 | */ |
| 22 | struct unit_test_state { |
| 23 | int fail_count; |
| 24 | struct mallinfo start; |
| 25 | void *priv; |
Simon Glass | 017886b | 2017-05-18 20:09:17 -0600 | [diff] [blame] | 26 | struct device_node *of_root; |
Simon Glass | d856e91 | 2020-01-27 08:49:56 -0700 | [diff] [blame] | 27 | char expect_str[256]; |
| 28 | char actual_str[256]; |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 29 | }; |
| 30 | |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 31 | /* Test flags for each test */ |
| 32 | enum { |
| 33 | UT_TESTF_SCAN_PDATA = BIT(0), /* test needs platform data */ |
| 34 | UT_TESTF_PROBE_TEST = BIT(1), /* probe test uclass */ |
| 35 | UT_TESTF_SCAN_FDT = BIT(2), /* scan device tree */ |
| 36 | UT_TESTF_FLAT_TREE = BIT(3), /* test needs flat DT */ |
| 37 | UT_TESTF_LIVE_TREE = BIT(4), /* needs live device tree */ |
Simon Glass | 6db8ea5 | 2020-07-28 19:41:13 -0600 | [diff] [blame] | 38 | UT_TESTF_CONSOLE_REC = BIT(5), /* needs console recording */ |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 39 | }; |
| 40 | |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 41 | /** |
| 42 | * struct unit_test - Information about a unit test |
| 43 | * |
| 44 | * @name: Name of test |
| 45 | * @func: Function to call to perform test |
| 46 | * @flags: Flags indicated pre-conditions for test |
| 47 | */ |
| 48 | struct unit_test { |
Simon Glass | be408ee | 2017-05-18 20:09:15 -0600 | [diff] [blame] | 49 | const char *file; |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 50 | const char *name; |
| 51 | int (*func)(struct unit_test_state *state); |
| 52 | int flags; |
| 53 | }; |
| 54 | |
Heinrich Schuchardt | df6c36c | 2020-05-06 18:26:07 +0200 | [diff] [blame] | 55 | /** |
| 56 | * UNIT_TEST() - create linker generated list entry for unit a unit test |
| 57 | * |
| 58 | * The macro UNIT_TEST() is used to create a linker generated list entry. These |
| 59 | * list entries are enumerate tests that can be execute using the ut command. |
| 60 | * The list entries are used both by the implementation of the ut command as |
| 61 | * well as in a related Python test. |
| 62 | * |
| 63 | * For Python testing the subtests are collected in Python function |
| 64 | * generate_ut_subtest() by applying a regular expression to the lines of file |
| 65 | * u-boot.sym. The list entries have to follow strict naming conventions to be |
| 66 | * matched by the expression. |
| 67 | * |
| 68 | * Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in test suite |
| 69 | * foo that can be executed via command 'ut foo bar' and is implemented in |
| 70 | * function foo_test_bar(). |
| 71 | * |
| 72 | * @_name: concatenation of name of the test suite, "_test_", and the name |
| 73 | * of the test |
| 74 | * @_flags: an integer field that can be evaluated by the test suite |
| 75 | * implementation |
| 76 | * @_suite: name of the test suite concatenated with "_test" |
| 77 | */ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 78 | #define UNIT_TEST(_name, _flags, _suite) \ |
| 79 | ll_entry_declare(struct unit_test, _name, _suite) = { \ |
Simon Glass | be408ee | 2017-05-18 20:09:15 -0600 | [diff] [blame] | 80 | .file = __FILE__, \ |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 81 | .name = #_name, \ |
| 82 | .flags = _flags, \ |
| 83 | .func = _name, \ |
| 84 | } |
| 85 | |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 86 | /* Sizes for devres tests */ |
| 87 | enum { |
| 88 | TEST_DEVRES_SIZE = 100, |
| 89 | TEST_DEVRES_COUNT = 10, |
| 90 | TEST_DEVRES_TOTAL = TEST_DEVRES_SIZE * TEST_DEVRES_COUNT, |
| 91 | |
Simon Glass | 0fe1537 | 2019-12-29 21:19:28 -0700 | [diff] [blame] | 92 | /* A few different sizes */ |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 93 | TEST_DEVRES_SIZE2 = 15, |
Simon Glass | 0fe1537 | 2019-12-29 21:19:28 -0700 | [diff] [blame] | 94 | TEST_DEVRES_SIZE3 = 37, |
Simon Glass | 204675c | 2019-12-29 21:19:25 -0700 | [diff] [blame] | 95 | }; |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 96 | |
Simon Glass | a4e289b | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 97 | /** |
Simon Glass | 4bf8972 | 2020-12-23 08:11:18 -0700 | [diff] [blame] | 98 | * testbus_get_clear_removed() - Test function to obtain removed device |
| 99 | * |
| 100 | * This is used in testbus to find out which device was removed. Calling this |
| 101 | * function returns a pointer to the device and then clears it back to NULL, so |
| 102 | * that a future test can check it. |
| 103 | */ |
| 104 | struct udevice *testbus_get_clear_removed(void); |
| 105 | |
| 106 | /** |
Simon Glass | a4e289b | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 107 | * dm_test_main() - Run driver model tests |
| 108 | * |
| 109 | * Run all the available driver model tests, or a selection |
| 110 | * |
| 111 | * @test_name: Name of single test to run (e.g. "dm_test_fdt_pre_reloc" or just |
| 112 | * "fdt_pre_reloc"), or NULL to run all |
| 113 | * @return 0 if all tests passed, 1 if not |
| 114 | */ |
| 115 | int dm_test_main(const char *test_name); |
| 116 | |
Joe Hershberger | 3a77be5 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 117 | #endif /* __TEST_TEST_H */ |