2 * Copyright (c) 2013 Google, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
14 * struct dm_test_cdata - configuration data for test instance
16 * @ping_add: Amonut to add each time we get a ping
17 * @base: Base address of this device
19 struct dm_test_pdata {
25 * struct test_ops - Operations supported by the test device
27 * @ping: Ping operation
28 * @dev: Device to operate on
29 * @pingval: Value to ping the device with
30 * @pingret: Returns resulting value from driver
31 * @return 0 if OK, -ve on error
34 int (*ping)(struct udevice *dev, int pingval, int *pingret);
37 /* Operations that our test driver supports */
46 DM_TEST_OP_PRE_UNBIND,
47 DM_TEST_OP_POST_PROBE,
48 DM_TEST_OP_PRE_REMOVE,
55 /* Test driver types */
57 DM_TEST_TYPE_FIRST = 0,
61 /* The number added to the ping total on each probe */
62 #define DM_TEST_START_TOTAL 5
65 * struct dm_test_priv - private data for the test devices
69 int op_count[DM_TEST_OP_COUNT];
73 * struct dm_test_perdev_class_priv - private per-device data for test uclass
75 struct dm_test_uclass_perdev_priv {
80 * struct dm_test_uclass_priv - private data for test uclass
82 struct dm_test_uclass_priv {
87 * struct dm_test_parent_data - parent's information on each child
89 * @sum: Test value used to check parent data works correctly
90 * @flag: Used to track calling of parent operations
92 struct dm_test_parent_data {
98 * Operation counts for the test driver, used to check that each method is
101 extern int dm_testdrv_op_count[DM_TEST_OP_COUNT];
103 extern struct dm_test_state global_test_state;
106 * struct dm_test_state - Entire state of dm test system
108 * This is often abreviated to dms.
111 * @testdev: Test device
112 * @fail_count: Number of tests that failed
113 * @force_fail_alloc: Force all memory allocs to fail
114 * @skip_post_probe: Skip uclass post-probe processing
115 * @removed: Used to keep track of a device that was removed
117 struct dm_test_state {
118 struct udevice *root;
119 struct udevice *testdev;
121 int force_fail_alloc;
123 struct udevice *removed;
124 struct mallinfo start;
127 /* Test flags for each test */
129 DM_TESTF_SCAN_PDATA = 1 << 0, /* test needs platform data */
130 DM_TESTF_PROBE_TEST = 1 << 1, /* probe test uclass */
131 DM_TESTF_SCAN_FDT = 1 << 2, /* scan device tree */
135 * struct dm_test - Information about a driver model test
137 * @name: Name of test
138 * @func: Function to call to perform test
139 * @flags: Flags indicated pre-conditions for test
143 int (*func)(struct dm_test_state *dms);
147 /* Declare a new driver model test */
148 #define DM_TEST(_name, _flags) \
149 ll_entry_declare(struct dm_test, _name, dm_test) = { \
155 /* Declare ping methods for the drivers */
156 int test_ping(struct udevice *dev, int pingval, int *pingret);
157 int testfdt_ping(struct udevice *dev, int pingval, int *pingret);
160 * dm_check_operations() - Check that we can perform ping operations
162 * This checks that the ping operations work as expected for a device
164 * @dms: Overall test state
165 * @dev: Device to test
166 * @base: Base address, used to check ping return value
167 * @priv: Pointer to private test information
168 * @return 0 if OK, -ve on error
170 int dm_check_operations(struct dm_test_state *dms, struct udevice *dev,
171 uint32_t base, struct dm_test_priv *priv);
174 * dm_check_devices() - check the devices respond to operations correctly
176 * @dms: Overall test state
177 * @num_devices: Number of test devices to check
178 * @return 0 if OK, -ve on error
180 int dm_check_devices(struct dm_test_state *dms, int num_devices);
183 * dm_leak_check_start() - Prepare to check for a memory leak
185 * Call this before allocating memory to record the amount of memory being
188 * @dms: Overall test state
190 void dm_leak_check_start(struct dm_test_state *dms);
193 * dm_leak_check_end() - Check that no memory has leaked
195 * Call this after dm_leak_check_start() and after you have hopefuilly freed
196 * all the memory that was allocated. This function will print an error if
197 * it sees a different amount of total memory allocated than before.
199 * @dms: Overall test state
200 */int dm_leak_check_end(struct dm_test_state *dms);
204 * dm_test_main() - Run all the tests
206 * This runs all available driver model tests
208 * @return 0 if OK, -ve on error
210 int dm_test_main(void);