aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBin Meng2018-10-15 04:21:26 -0500
committerSimon Glass2018-11-14 11:16:28 -0600
commit4f89d4947c9ecb2e859f70a6aed2e0c18d63fb54 (patch)
treeca46eea8d5603ccef536cf296eb861f6d41226c4
parent640aae0fb1f8b5741e62782cf06fc0f1beb0f612 (diff)
downloadu-boot-4f89d4947c9ecb2e859f70a6aed2e0c18d63fb54.tar.gz
u-boot-4f89d4947c9ecb2e859f70a6aed2e0c18d63fb54.tar.xz
u-boot-4f89d4947c9ecb2e859f70a6aed2e0c18d63fb54.zip
test: dm: virtio: Add test cases for virtio uclass
Now that we have a sandbox virtio transport driver, add some test cases to test virtio uclass driver. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--arch/Kconfig5
-rw-r--r--arch/sandbox/dts/test.dts8
-rw-r--r--configs/sandbox_noblk_defconfig1
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/virtio.c122
5 files changed, 137 insertions, 0 deletions
diff --git a/arch/Kconfig b/arch/Kconfig
index e822a0b27e..9fdd2f7e66 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -110,6 +110,11 @@ config SANDBOX
110 imply LIBAVB 110 imply LIBAVB
111 imply CMD_AVB 111 imply CMD_AVB
112 imply UDP_FUNCTION_FASTBOOT 112 imply UDP_FUNCTION_FASTBOOT
113 imply VIRTIO_MMIO
114 imply VIRTIO_PCI
115 imply VIRTIO_SANDBOX
116 imply VIRTIO_BLK
117 imply VIRTIO_NET
113 118
114config SH 119config SH
115 bool "SuperH architecture" 120 bool "SuperH architecture"
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 71d1b39022..6b54115f9b 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -716,6 +716,14 @@
716 sandbox_tee { 716 sandbox_tee {
717 compatible = "sandbox,tee"; 717 compatible = "sandbox,tee";
718 }; 718 };
719
720 sandbox_virtio1 {
721 compatible = "sandbox,virtio1";
722 };
723
724 sandbox_virtio2 {
725 compatible = "sandbox,virtio2";
726 };
719}; 727};
720 728
721#include "sandbox_pmic.dtsi" 729#include "sandbox_pmic.dtsi"
diff --git a/configs/sandbox_noblk_defconfig b/configs/sandbox_noblk_defconfig
index 93b2240185..e71e2d3860 100644
--- a/configs/sandbox_noblk_defconfig
+++ b/configs/sandbox_noblk_defconfig
@@ -171,6 +171,7 @@ CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
171CONFIG_VIDEO_SANDBOX_SDL=y 171CONFIG_VIDEO_SANDBOX_SDL=y
172CONFIG_OSD=y 172CONFIG_OSD=y
173CONFIG_SANDBOX_OSD=y 173CONFIG_SANDBOX_OSD=y
174# CONFIG_VIRTIO_BLK is not set
174CONFIG_FS_CBFS=y 175CONFIG_FS_CBFS=y
175CONFIG_FS_CRAMFS=y 176CONFIG_FS_CRAMFS=y
176CONFIG_CMD_DHRYSTONE=y 177CONFIG_CMD_DHRYSTONE=y
diff --git a/test/dm/Makefile b/test/dm/Makefile
index b490cf2862..213e0fda94 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -53,4 +53,5 @@ obj-$(CONFIG_MISC) += misc.o
53obj-$(CONFIG_DM_SERIAL) += serial.o 53obj-$(CONFIG_DM_SERIAL) += serial.o
54obj-$(CONFIG_CPU) += cpu.o 54obj-$(CONFIG_CPU) += cpu.o
55obj-$(CONFIG_TEE) += tee.o 55obj-$(CONFIG_TEE) += tee.o
56obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
56endif 57endif
diff --git a/test/dm/virtio.c b/test/dm/virtio.c
new file mode 100644
index 0000000000..4b317d2ec3
--- /dev/null
+++ b/test/dm/virtio.c
@@ -0,0 +1,122 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
4 */
5
6#include <common.h>
7#include <dm.h>
8#include <virtio_types.h>
9#include <virtio.h>
10#include <virtio_ring.h>
11#include <dm/device-internal.h>
12#include <dm/uclass-internal.h>
13#include <dm/root.h>
14#include <dm/test.h>
15#include <test/ut.h>
16
17/* Basic test of the virtio uclass */
18static int dm_test_virtio_base(struct unit_test_state *uts)
19{
20 struct udevice *bus, *dev;
21 u8 status;
22
23 /* check probe success */
24 ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
25
26 /* check the child virtio-blk device is bound */
27 ut_assertok(device_find_first_child(bus, &dev));
28 ut_assertok(strcmp(dev->name, "virtio-blk#0"));
29
30 /* check driver status */
31 ut_assertok(virtio_get_status(dev, &status));
32 ut_asserteq(VIRTIO_CONFIG_S_ACKNOWLEDGE, status);
33
34 return 0;
35}
36DM_TEST(dm_test_virtio_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
37
38/* Test all of the virtio uclass ops */
39static int dm_test_virtio_all_ops(struct unit_test_state *uts)
40{
41 struct udevice *bus, *dev;
42 struct virtio_dev_priv *uc_priv;
43 uint offset = 0, len = 0, nvqs = 1;
44 void *buffer = NULL;
45 u8 status;
46 u32 counter;
47 u64 features;
48 struct virtqueue *vqs[2];
49
50 /* check probe success */
51 ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
52
53 /* check the child virtio-blk device is bound */
54 ut_assertok(device_find_first_child(bus, &dev));
55
56 /*
57 * fake the virtio device probe by filling in uc_priv->vdev
58 * which is used by virtio_find_vqs/virtio_del_vqs.
59 */
60 uc_priv = dev_get_uclass_priv(bus);
61 uc_priv->vdev = dev;
62
63 /* test virtio_xxx APIs */
64 ut_assertok(virtio_get_config(dev, offset, buffer, len));
65 ut_assertok(virtio_set_config(dev, offset, buffer, len));
66 ut_asserteq(-ENOSYS, virtio_generation(dev, &counter));
67 ut_assertok(virtio_set_status(dev, VIRTIO_CONFIG_S_DRIVER_OK));
68 ut_assertok(virtio_get_status(dev, &status));
69 ut_asserteq(VIRTIO_CONFIG_S_DRIVER_OK, status);
70 ut_assertok(virtio_reset(dev));
71 ut_assertok(virtio_get_status(dev, &status));
72 ut_asserteq(0, status);
73 ut_assertok(virtio_get_features(dev, &features));
74 ut_asserteq(VIRTIO_F_VERSION_1, features);
75 ut_assertok(virtio_set_features(dev));
76 ut_assertok(virtio_find_vqs(dev, nvqs, vqs));
77 ut_assertok(virtio_del_vqs(dev));
78 ut_assertok(virtio_notify(dev, vqs[0]));
79
80 return 0;
81}
82DM_TEST(dm_test_virtio_all_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
83
84/* Test of the virtio driver that does not have required driver ops */
85static int dm_test_virtio_missing_ops(struct unit_test_state *uts)
86{
87 struct udevice *bus;
88
89 /* find the virtio device */
90 ut_assertok(uclass_find_device(UCLASS_VIRTIO, 1, &bus));
91
92 /*
93 * Probe the device should fail with error -ENOENT.
94 * See ops check in virtio_uclass_pre_probe().
95 */
96 ut_asserteq(-ENOENT, device_probe(bus));
97
98 return 0;
99}
100DM_TEST(dm_test_virtio_missing_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
101
102/* Test removal of virtio device driver */
103static int dm_test_virtio_remove(struct unit_test_state *uts)
104{
105 struct udevice *bus, *dev;
106
107 /* check probe success */
108 ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
109
110 /* check the child virtio-blk device is bound */
111 ut_assertok(device_find_first_child(bus, &dev));
112
113 /* set driver status to VIRTIO_CONFIG_S_DRIVER_OK */
114 ut_assertok(virtio_set_status(dev, VIRTIO_CONFIG_S_DRIVER_OK));
115
116 /* check the device can be successfully removed */
117 dev->flags |= DM_FLAG_ACTIVATED;
118 ut_assertok(device_remove(bus, DM_REMOVE_ACTIVE_ALL));
119
120 return 0;
121}
122DM_TEST(dm_test_virtio_remove, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);