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,
48 DM_TEST_OP_POST_PROBE,
49 DM_TEST_OP_PRE_REMOVE,
56 /* Test driver types */
58 DM_TEST_TYPE_FIRST = 0,
62 /* The number added to the ping total on each probe */
63 #define DM_TEST_START_TOTAL 5
66 * struct dm_test_priv - private data for the test devices
70 int op_count[DM_TEST_OP_COUNT];
76 * struct dm_test_perdev_class_priv - private per-device data for test uclass
78 struct dm_test_uclass_perdev_priv {
83 * struct dm_test_uclass_priv - private data for test uclass
85 struct dm_test_uclass_priv {
90 * struct dm_test_parent_data - parent's information on each child
92 * @sum: Test value used to check parent data works correctly
93 * @flag: Used to track calling of parent operations
94 * @uclass_flag: Used to track calling of parent operations by uclass
96 struct dm_test_parent_data {
102 * Operation counts for the test driver, used to check that each method is
105 extern int dm_testdrv_op_count[DM_TEST_OP_COUNT];
107 extern struct dm_test_state global_test_state;
110 * struct dm_test_state - Entire state of dm test system
112 * This is often abreviated to dms.
115 * @testdev: Test device
116 * @fail_count: Number of tests that failed
117 * @force_fail_alloc: Force all memory allocs to fail
118 * @skip_post_probe: Skip uclass post-probe processing
119 * @removed: Used to keep track of a device that was removed
121 struct dm_test_state {
122 struct udevice *root;
123 struct udevice *testdev;
125 int force_fail_alloc;
127 struct udevice *removed;
128 struct mallinfo start;
131 /* Test flags for each test */
133 DM_TESTF_SCAN_PDATA = 1 << 0, /* test needs platform data */
134 DM_TESTF_PROBE_TEST = 1 << 1, /* probe test uclass */
135 DM_TESTF_SCAN_FDT = 1 << 2, /* scan device tree */
139 * struct dm_test - Information about a driver model test
141 * @name: Name of test
142 * @func: Function to call to perform test
143 * @flags: Flags indicated pre-conditions for test
147 int (*func)(struct dm_test_state *dms);
151 /* Declare a new driver model test */
152 #define DM_TEST(_name, _flags) \
153 ll_entry_declare(struct dm_test, _name, dm_test) = { \
159 /* Declare ping methods for the drivers */
160 int test_ping(struct udevice *dev, int pingval, int *pingret);
161 int testfdt_ping(struct udevice *dev, int pingval, int *pingret);
164 * dm_check_operations() - Check that we can perform ping operations
166 * This checks that the ping operations work as expected for a device
168 * @dms: Overall test state
169 * @dev: Device to test
170 * @base: Base address, used to check ping return value
171 * @priv: Pointer to private test information
172 * @return 0 if OK, -ve on error
174 int dm_check_operations(struct dm_test_state *dms, struct udevice *dev,
175 uint32_t base, struct dm_test_priv *priv);
178 * dm_check_devices() - check the devices respond to operations correctly
180 * @dms: Overall test state
181 * @num_devices: Number of test devices to check
182 * @return 0 if OK, -ve on error
184 int dm_check_devices(struct dm_test_state *dms, int num_devices);
187 * dm_leak_check_start() - Prepare to check for a memory leak
189 * Call this before allocating memory to record the amount of memory being
192 * @dms: Overall test state
194 void dm_leak_check_start(struct dm_test_state *dms);
197 * dm_leak_check_end() - Check that no memory has leaked
199 * Call this after dm_leak_check_start() and after you have hopefuilly freed
200 * all the memory that was allocated. This function will print an error if
201 * it sees a different amount of total memory allocated than before.
203 * @dms: Overall test state
204 */int dm_leak_check_end(struct dm_test_state *dms);
208 * dm_test_main() - Run all the tests
210 * This runs all available driver model tests
212 * @return 0 if OK, -ve on error
214 int dm_test_main(void);