1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013 Google, Inc
16 #include <test/test.h>
19 int dm_testdrv_op_count[DM_TEST_OP_COUNT];
20 static struct unit_test_state *uts = &global_dm_test_state;
22 static int testdrv_ping(struct udevice *dev, int pingval, int *pingret)
24 const struct dm_test_pdata *pdata = dev_get_platdata(dev);
25 struct dm_test_priv *priv = dev_get_priv(dev);
27 *pingret = pingval + pdata->ping_add;
28 priv->ping_total += *pingret;
33 static const struct test_ops test_ops = {
37 static int test_bind(struct udevice *dev)
39 /* Private data should not be allocated */
40 ut_assert(!dev_get_priv(dev));
42 dm_testdrv_op_count[DM_TEST_OP_BIND]++;
46 static int test_probe(struct udevice *dev)
48 struct dm_test_priv *priv = dev_get_priv(dev);
50 /* Private data should be allocated */
53 dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
54 priv->ping_total += DM_TEST_START_TOTAL;
58 static int test_remove(struct udevice *dev)
60 /* Private data should still be allocated */
61 ut_assert(dev_get_priv(dev));
63 dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
67 static int test_unbind(struct udevice *dev)
69 /* Private data should not be allocated */
70 ut_assert(!dev->priv);
72 dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
76 U_BOOT_DRIVER(test_drv) = {
82 .remove = test_remove,
83 .unbind = test_unbind,
84 .priv_auto = sizeof(struct dm_test_priv),
87 U_BOOT_DRIVER(test2_drv) = {
93 .remove = test_remove,
94 .unbind = test_unbind,
95 .priv_auto = sizeof(struct dm_test_priv),
98 static int test_manual_drv_ping(struct udevice *dev, int pingval, int *pingret)
100 *pingret = pingval + 2;
105 static const struct test_ops test_manual_ops = {
106 .ping = test_manual_drv_ping,
109 static int test_manual_bind(struct udevice *dev)
111 dm_testdrv_op_count[DM_TEST_OP_BIND]++;
116 static int test_manual_probe(struct udevice *dev)
118 struct dm_test_state *dms = uts->priv;
120 dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
121 if (!dms->force_fail_alloc)
122 dev->priv = calloc(1, sizeof(struct dm_test_priv));
129 static int test_manual_remove(struct udevice *dev)
131 dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
135 static int test_manual_unbind(struct udevice *dev)
137 dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
141 U_BOOT_DRIVER(test_manual_drv) = {
142 .name = "test_manual_drv",
144 .ops = &test_manual_ops,
145 .bind = test_manual_bind,
146 .probe = test_manual_probe,
147 .remove = test_manual_remove,
148 .unbind = test_manual_unbind,
151 U_BOOT_DRIVER(test_pre_reloc_drv) = {
152 .name = "test_pre_reloc_drv",
154 .ops = &test_manual_ops,
155 .bind = test_manual_bind,
156 .probe = test_manual_probe,
157 .remove = test_manual_remove,
158 .unbind = test_manual_unbind,
159 .flags = DM_FLAG_PRE_RELOC,
162 U_BOOT_DRIVER(test_act_dma_drv) = {
163 .name = "test_act_dma_drv",
165 .ops = &test_manual_ops,
166 .bind = test_manual_bind,
167 .probe = test_manual_probe,
168 .remove = test_manual_remove,
169 .unbind = test_manual_unbind,
170 .flags = DM_FLAG_ACTIVE_DMA,