1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013 Google, Inc
16 #include <linux/list.h>
17 #include <test/test.h>
20 static struct unit_test_state *uts = &global_dm_test_state;
22 int test_ping(struct udevice *dev, int pingval, int *pingret)
24 const struct test_ops *ops = device_get_ops(dev);
29 return ops->ping(dev, pingval, pingret);
32 static int test_post_bind(struct udevice *dev)
34 struct dm_test_perdev_uc_pdata *uc_pdata;
36 dm_testdrv_op_count[DM_TEST_OP_POST_BIND]++;
37 ut_assert(!device_active(dev));
39 uc_pdata = dev_get_uclass_platdata(dev);
42 uc_pdata->intval1 = TEST_UC_PDATA_INTVAL1;
43 uc_pdata->intval2 = TEST_UC_PDATA_INTVAL2;
44 uc_pdata->intval3 = TEST_UC_PDATA_INTVAL3;
49 static int test_pre_unbind(struct udevice *dev)
51 dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]++;
56 static int test_pre_probe(struct udevice *dev)
58 struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
60 dm_testdrv_op_count[DM_TEST_OP_PRE_PROBE]++;
62 ut_assert(device_active(dev));
67 static int test_post_probe(struct udevice *dev)
69 struct udevice *prev = list_entry(dev->uclass_node.prev,
70 struct udevice, uclass_node);
72 struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
73 struct uclass *uc = dev->uclass;
74 struct dm_test_state *dms = uts->priv;
76 dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]++;
78 ut_assert(device_active(dev));
80 if (dms->skip_post_probe)
82 if (&prev->uclass_node != &uc->dev_head) {
83 struct dm_test_uclass_perdev_priv *prev_uc_priv
84 = dev_get_uclass_priv(prev);
85 struct dm_test_pdata *pdata = prev->platdata;
88 ut_assert(prev_uc_priv);
89 priv->base_add = prev_uc_priv->base_add + pdata->ping_add;
95 static int test_pre_remove(struct udevice *dev)
97 dm_testdrv_op_count[DM_TEST_OP_PRE_REMOVE]++;
102 static int test_init(struct uclass *uc)
104 dm_testdrv_op_count[DM_TEST_OP_INIT]++;
110 static int test_destroy(struct uclass *uc)
112 dm_testdrv_op_count[DM_TEST_OP_DESTROY]++;
117 UCLASS_DRIVER(test) = {
120 .post_bind = test_post_bind,
121 .pre_unbind = test_pre_unbind,
122 .pre_probe = test_pre_probe,
123 .post_probe = test_post_probe,
124 .pre_remove = test_pre_remove,
126 .destroy = test_destroy,
127 .priv_auto_alloc_size = sizeof(struct dm_test_uclass_priv),
128 .per_device_auto_alloc_size = sizeof(struct dm_test_uclass_perdev_priv),
129 .per_device_platdata_auto_alloc_size =
130 sizeof(struct dm_test_perdev_uc_pdata),