1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2013 Google, Inc.
10 #include <linux/bitops.h>
13 * struct unit_test_state - Entire state of test system
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
18 * @of_live: true to use livetree if available, false to use flattree
19 * @of_root: Record of the livetree root node (used for setting up tests)
20 * @expect_str: Temporary string used to hold expected string value
21 * @actual_str: Temporary string used to hold actual string value
23 struct unit_test_state {
25 struct mallinfo start;
27 struct device_node *of_root;
33 /* Test flags for each test */
35 UT_TESTF_SCAN_PDATA = BIT(0), /* test needs platform data */
36 UT_TESTF_PROBE_TEST = BIT(1), /* probe test uclass */
37 UT_TESTF_SCAN_FDT = BIT(2), /* scan device tree */
38 UT_TESTF_FLAT_TREE = BIT(3), /* test needs flat DT */
39 UT_TESTF_LIVE_TREE = BIT(4), /* needs live device tree */
40 UT_TESTF_CONSOLE_REC = BIT(5), /* needs console recording */
41 /* do extra driver model init and uninit */
46 * struct unit_test - Information about a unit test
49 * @func: Function to call to perform test
50 * @flags: Flags indicated pre-conditions for test
55 int (*func)(struct unit_test_state *state);
60 * UNIT_TEST() - create linker generated list entry for unit a unit test
62 * The macro UNIT_TEST() is used to create a linker generated list entry. These
63 * list entries are enumerate tests that can be execute using the ut command.
64 * The list entries are used both by the implementation of the ut command as
65 * well as in a related Python test.
67 * For Python testing the subtests are collected in Python function
68 * generate_ut_subtest() by applying a regular expression to the lines of file
69 * u-boot.sym. The list entries have to follow strict naming conventions to be
70 * matched by the expression.
72 * Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in test suite
73 * foo that can be executed via command 'ut foo bar' and is implemented in
74 * function foo_test_bar().
76 * @_name: concatenation of name of the test suite, "_test_", and the name
78 * @_flags: an integer field that can be evaluated by the test suite
80 * @_suite: name of the test suite concatenated with "_test"
82 #define UNIT_TEST(_name, _flags, _suite) \
83 ll_entry_declare(struct unit_test, _name, _suite) = { \
90 /* Sizes for devres tests */
92 TEST_DEVRES_SIZE = 100,
93 TEST_DEVRES_COUNT = 10,
94 TEST_DEVRES_TOTAL = TEST_DEVRES_SIZE * TEST_DEVRES_COUNT,
96 /* A few different sizes */
97 TEST_DEVRES_SIZE2 = 15,
98 TEST_DEVRES_SIZE3 = 37,
102 * testbus_get_clear_removed() - Test function to obtain removed device
104 * This is used in testbus to find out which device was removed. Calling this
105 * function returns a pointer to the device and then clears it back to NULL, so
106 * that a future test can check it.
108 struct udevice *testbus_get_clear_removed(void);
111 * dm_test_run() - Run driver model tests
113 * Run all the available driver model tests, or a selection
115 * @test_name: Name of single test to run (e.g. "dm_test_fdt_pre_reloc" or just
116 * "fdt_pre_reloc"), or NULL to run all
117 * @return 0 if all tests passed, 1 if not
119 int dm_test_run(const char *test_name);
121 #endif /* __TEST_TEST_H */