blob: 235d728bfbe62ea9af8cc3f6e946a248ce9791cd [file] [log] [blame]
Simon Glassb2c1cac2014-02-26 15:59:21 -07001/*
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 */
18struct 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 */
32struct test_ops {
Heiko Schocherb74fcb42014-05-22 12:43:05 +020033 int (*ping)(struct udevice *dev, int pingval, int *pingret);
Simon Glassb2c1cac2014-02-26 15:59:21 -070034};
35
36/* Operations that our test driver supports */
37enum {
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 */
55enum {
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 */
66struct 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 */
74struct dm_test_uclass_perdev_priv {
75 int base_add;
76};
77
78/**
79 * struct dm_test_uclass_priv - private data for test uclass
80 */
81struct dm_test_uclass_priv {
82 int total_add;
83};
84
Simon Glass60d971b2014-07-23 06:55:20 -060085/**
86 * struct dm_test_parent_data - parent's information on each child
87 *
88 * @sum: Test value used to check parent data works correctly
Simon Glassd45560d2014-07-23 06:55:21 -060089 * @flag: Used to track calling of parent operations
Simon Glass60d971b2014-07-23 06:55:20 -060090 */
91struct dm_test_parent_data {
92 int sum;
Simon Glassd45560d2014-07-23 06:55:21 -060093 int flag;
Simon Glass60d971b2014-07-23 06:55:20 -060094};
95
Simon Glassb2c1cac2014-02-26 15:59:21 -070096/*
97 * Operation counts for the test driver, used to check that each method is
98 * called correctly
99 */
100extern int dm_testdrv_op_count[DM_TEST_OP_COUNT];
101
102extern 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
Simon Glassd45560d2014-07-23 06:55:21 -0600114 * @removed: Used to keep track of a device that was removed
Simon Glassb2c1cac2014-02-26 15:59:21 -0700115 */
116struct dm_test_state {
Heiko Schocherb74fcb42014-05-22 12:43:05 +0200117 struct udevice *root;
118 struct udevice *testdev;
Simon Glassb2c1cac2014-02-26 15:59:21 -0700119 int fail_count;
120 int force_fail_alloc;
121 int skip_post_probe;
Simon Glassd45560d2014-07-23 06:55:21 -0600122 struct udevice *removed;
Simon Glassb2c1cac2014-02-26 15:59:21 -0700123};
124
125/* Test flags for each test */
126enum {
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 */
139struct 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 */
Heiko Schocherb74fcb42014-05-22 12:43:05 +0200154int test_ping(struct udevice *dev, int pingval, int *pingret);
155int testfdt_ping(struct udevice *dev, int pingval, int *pingret);
Simon Glassb2c1cac2014-02-26 15:59:21 -0700156
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 */
Heiko Schocherb74fcb42014-05-22 12:43:05 +0200168int dm_check_operations(struct dm_test_state *dms, struct udevice *dev,
Simon Glassb2c1cac2014-02-26 15:59:21 -0700169 uint32_t base, struct dm_test_priv *priv);
170
171/**
Simon Glass40717422014-07-23 06:55:18 -0600172 * 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 */
178int dm_check_devices(struct dm_test_state *dms, int num_devices);
179
180/**
Simon Glassb2c1cac2014-02-26 15:59:21 -0700181 * 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 */
187int dm_test_main(void);
188
189#endif