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