xref: /rk3399_rockchip-uboot/include/dm/test.h (revision e59f458de6999b8a786da857e653db6777f675ca)
1 /*
2  * Copyright (c) 2013 Google, Inc.
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #ifndef __DM_TEST_H
8 #define __DM_TEST_H
9 
10 #include <dm.h>
11 
12 /**
13  * struct dm_test_cdata - configuration data for test instance
14  *
15  * @ping_add: Amonut to add each time we get a ping
16  * @base: Base address of this device
17  */
18 struct dm_test_pdata {
19 	int ping_add;
20 	uint32_t base;
21 };
22 
23 /**
24  * struct test_ops - Operations supported by the test device
25  *
26  * @ping: Ping operation
27  *	@dev: Device to operate on
28  *	@pingval: Value to ping the device with
29  *	@pingret: Returns resulting value from driver
30  *	@return 0 if OK, -ve on error
31  */
32 struct test_ops {
33 	int (*ping)(struct udevice *dev, int pingval, int *pingret);
34 };
35 
36 /* Operations that our test driver supports */
37 enum {
38 	DM_TEST_OP_BIND = 0,
39 	DM_TEST_OP_UNBIND,
40 	DM_TEST_OP_PROBE,
41 	DM_TEST_OP_REMOVE,
42 
43 	/* For uclass */
44 	DM_TEST_OP_POST_BIND,
45 	DM_TEST_OP_PRE_UNBIND,
46 	DM_TEST_OP_POST_PROBE,
47 	DM_TEST_OP_PRE_REMOVE,
48 	DM_TEST_OP_INIT,
49 	DM_TEST_OP_DESTROY,
50 
51 	DM_TEST_OP_COUNT,
52 };
53 
54 /* Test driver types */
55 enum {
56 	DM_TEST_TYPE_FIRST = 0,
57 	DM_TEST_TYPE_SECOND,
58 };
59 
60 /* The number added to the ping total on each probe */
61 #define DM_TEST_START_TOTAL	5
62 
63 /**
64  * struct dm_test_priv - private data for the test devices
65  */
66 struct dm_test_priv {
67 	int ping_total;
68 	int op_count[DM_TEST_OP_COUNT];
69 };
70 
71 /**
72  * struct dm_test_perdev_class_priv - private per-device data for test uclass
73  */
74 struct dm_test_uclass_perdev_priv {
75 	int base_add;
76 };
77 
78 /**
79  * struct dm_test_uclass_priv - private data for test uclass
80  */
81 struct dm_test_uclass_priv {
82 	int total_add;
83 };
84 
85 /**
86  * struct dm_test_parent_data - parent's information on each child
87  *
88  * @sum: Test value used to check parent data works correctly
89  */
90 struct dm_test_parent_data {
91 	int sum;
92 };
93 
94 /*
95  * Operation counts for the test driver, used to check that each method is
96  * called correctly
97  */
98 extern int dm_testdrv_op_count[DM_TEST_OP_COUNT];
99 
100 extern struct dm_test_state global_test_state;
101 
102 /*
103  * struct dm_test_state - Entire state of dm test system
104  *
105  * This is often abreviated to dms.
106  *
107  * @root: Root device
108  * @testdev: Test device
109  * @fail_count: Number of tests that failed
110  * @force_fail_alloc: Force all memory allocs to fail
111  * @skip_post_probe: Skip uclass post-probe processing
112  */
113 struct dm_test_state {
114 	struct udevice *root;
115 	struct udevice *testdev;
116 	int fail_count;
117 	int force_fail_alloc;
118 	int skip_post_probe;
119 };
120 
121 /* Test flags for each test */
122 enum {
123 	DM_TESTF_SCAN_PDATA	= 1 << 0,	/* test needs platform data */
124 	DM_TESTF_PROBE_TEST	= 1 << 1,	/* probe test uclass */
125 	DM_TESTF_SCAN_FDT	= 1 << 2,	/* scan device tree */
126 };
127 
128 /**
129  * struct dm_test - Information about a driver model test
130  *
131  * @name: Name of test
132  * @func: Function to call to perform test
133  * @flags: Flags indicated pre-conditions for test
134  */
135 struct dm_test {
136 	const char *name;
137 	int (*func)(struct dm_test_state *dms);
138 	int flags;
139 };
140 
141 /* Declare a new driver model test */
142 #define DM_TEST(_name, _flags)						\
143 	ll_entry_declare(struct dm_test, _name, dm_test) = {		\
144 		.name = #_name,						\
145 		.flags = _flags,					\
146 		.func = _name,						\
147 	}
148 
149 /* Declare ping methods for the drivers */
150 int test_ping(struct udevice *dev, int pingval, int *pingret);
151 int testfdt_ping(struct udevice *dev, int pingval, int *pingret);
152 
153 /**
154  * dm_check_operations() - Check that we can perform ping operations
155  *
156  * This checks that the ping operations work as expected for a device
157  *
158  * @dms: Overall test state
159  * @dev: Device to test
160  * @base: Base address, used to check ping return value
161  * @priv: Pointer to private test information
162  * @return 0 if OK, -ve on error
163  */
164 int dm_check_operations(struct dm_test_state *dms, struct udevice *dev,
165 			uint32_t base, struct dm_test_priv *priv);
166 
167 /**
168  * dm_check_devices() - check the devices respond to operations correctly
169  *
170  * @dms: Overall test state
171  * @num_devices: Number of test devices to check
172  * @return 0 if OK, -ve on error
173  */
174 int dm_check_devices(struct dm_test_state *dms, int num_devices);
175 
176 /**
177  * dm_test_main() - Run all the tests
178  *
179  * This runs all available driver model tests
180  *
181  * @return 0 if OK, -ve on error
182  */
183 int dm_test_main(void);
184 
185 #endif
186