xref: /openbmc/u-boot/include/dm/test.h (revision bf7716d6)
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 device *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  * Operation counts for the test driver, used to check that each method is
87  * called correctly
88  */
89 extern int dm_testdrv_op_count[DM_TEST_OP_COUNT];
90 
91 extern struct dm_test_state global_test_state;
92 
93 /*
94  * struct dm_test_state - Entire state of dm test system
95  *
96  * This is often abreviated to dms.
97  *
98  * @root: Root device
99  * @testdev: Test device
100  * @fail_count: Number of tests that failed
101  * @force_fail_alloc: Force all memory allocs to fail
102  * @skip_post_probe: Skip uclass post-probe processing
103  */
104 struct dm_test_state {
105 	struct device *root;
106 	struct device *testdev;
107 	int fail_count;
108 	int force_fail_alloc;
109 	int skip_post_probe;
110 };
111 
112 /* Test flags for each test */
113 enum {
114 	DM_TESTF_SCAN_PDATA	= 1 << 0,	/* test needs platform data */
115 	DM_TESTF_PROBE_TEST	= 1 << 1,	/* probe test uclass */
116 	DM_TESTF_SCAN_FDT	= 1 << 2,	/* scan device tree */
117 };
118 
119 /**
120  * struct dm_test - Information about a driver model test
121  *
122  * @name: Name of test
123  * @func: Function to call to perform test
124  * @flags: Flags indicated pre-conditions for test
125  */
126 struct dm_test {
127 	const char *name;
128 	int (*func)(struct dm_test_state *dms);
129 	int flags;
130 };
131 
132 /* Declare a new driver model test */
133 #define DM_TEST(_name, _flags)						\
134 	ll_entry_declare(struct dm_test, _name, dm_test) = {		\
135 		.name = #_name,						\
136 		.flags = _flags,					\
137 		.func = _name,						\
138 	}
139 
140 /* Declare ping methods for the drivers */
141 int test_ping(struct device *dev, int pingval, int *pingret);
142 int testfdt_ping(struct device *dev, int pingval, int *pingret);
143 
144 /**
145  * dm_check_operations() - Check that we can perform ping operations
146  *
147  * This checks that the ping operations work as expected for a device
148  *
149  * @dms: Overall test state
150  * @dev: Device to test
151  * @base: Base address, used to check ping return value
152  * @priv: Pointer to private test information
153  * @return 0 if OK, -ve on error
154  */
155 int dm_check_operations(struct dm_test_state *dms, struct device *dev,
156 			uint32_t base, struct dm_test_priv *priv);
157 
158 /**
159  * dm_test_main() - Run all the tests
160  *
161  * This runs all available driver model tests
162  *
163  * @return 0 if OK, -ve on error
164  */
165 int dm_test_main(void);
166 
167 #endif
168