dm: usb: Add tests for the USB uclass
authorSimon Glass <sjg@chromium.org>
Wed, 25 Mar 2015 18:23:05 +0000 (12:23 -0600)
committerSimon Glass <sjg@chromium.org>
Sat, 18 Apr 2015 17:11:30 +0000 (11:11 -0600)
This adds a simple test for probing and a functional test using the flash
stick emulator, which tests a large chunk of the USB stack.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
test/dm/Makefile
test/dm/test-dm.sh
test/dm/test.dts
test/dm/usb.c [new file with mode: 0644]

index a2e2d2328e3c27136b6858ea58a7f5d9dfa3c42a..fd9e29f201c468b58da41648219f2b31287739ac 100644 (file)
@@ -23,4 +23,5 @@ obj-$(CONFIG_DM_I2C) += i2c.o
 obj-$(CONFIG_DM_PCI) += pci.o
 obj-$(CONFIG_DM_SPI_FLASH) += sf.o
 obj-$(CONFIG_DM_SPI) += spi.o
+obj-$(CONFIG_DM_USB) += usb.o
 endif
index 8ebc39297cb53ec315c828a4d0429e8c7ae46dc7..6158f6833f9bf5f3c5cd5e1dbddd22b88ff7c18e 100755 (executable)
@@ -10,5 +10,8 @@ dtc -I dts -O dtb test/dm/test.dts -o test/dm/test.dtb
 make O=sandbox sandbox_config || die "Cannot configure U-Boot"
 make O=sandbox -s -j${NUM_CPUS} || die "Cannot build U-Boot"
 dd if=/dev/zero of=spi.bin bs=1M count=2
+echo -n "this is a test" > testflash.bin
+dd if=/dev/zero bs=1M count=4 >>testflash.bin
 ./sandbox/u-boot -d test/dm/test.dtb -c "dm test"
 rm spi.bin
+rm testflash.bin
index 0ab0916858aaeab5a8c9af7ce1dee6c3ba8d2b2d..d0c40be6b0ad69cc641ba3d56477db5eb3eaa09c 100644 (file)
@@ -20,6 +20,9 @@
                testfdt8 = "/a-test";
                eth0 = "/eth@10002000";
                eth5 = &eth_5;
+               usb0 = &usb_0;
+               usb1 = &usb_1;
+               usb2 = &usb_2;
        };
 
        uart0: serial {
                fake-host-hwaddr = <0x00 0x00 0x66 0x44 0x22 0x22>;
        };
 
+       usb_0: usb@0 {
+               compatible = "sandbox,usb";
+               status = "disabled";
+               hub {
+                       compatible = "sandbox,usb-hub";
+                       #address-cells = <1>;
+                       #size-cells = <0>;
+                       flash-stick {
+                               reg = <0>;
+                               compatible = "sandbox,usb-flash";
+                       };
+               };
+       };
+
+       usb_1: usb@1 {
+               compatible = "sandbox,usb";
+               hub {
+                       compatible = "usb-hub";
+                       usb,device-class = <9>;
+                       hub-emul {
+                               compatible = "sandbox,usb-hub";
+                               #address-cells = <1>;
+                               #size-cells = <0>;
+                               flash-stick {
+                                       reg = <0>;
+                                       compatible = "sandbox,usb-flash";
+                                       sandbox,filepath = "testflash.bin";
+                               };
+
+                       };
+               };
+       };
+
+       usb_2: usb@2 {
+               compatible = "sandbox,usb";
+               status = "disabled";
+       };
+
 };
diff --git a/test/dm/usb.c b/test/dm/usb.c
new file mode 100644 (file)
index 0000000..6ea86d7
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <usb.h>
+#include <asm/io.h>
+#include <dm/test.h>
+#include <dm/ut.h>
+
+/* Test that sandbox USB works correctly */
+static int dm_test_usb_base(struct dm_test_state *dms)
+{
+       struct udevice *bus;
+
+       ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_USB, 0, &bus));
+       ut_assertok(uclass_get_device(UCLASS_USB, 0, &bus));
+       ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_USB, 2, &bus));
+
+       return 0;
+}
+DM_TEST(dm_test_usb_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/*
+ * Test that we can use the flash stick. This is more of a functional test. It
+ * covers scanning the bug, setting up a hub and a flash stick and reading
+ * data from the flash stick.
+ */
+static int dm_test_usb_flash(struct dm_test_state *dms)
+{
+       struct udevice *dev;
+       block_dev_desc_t *dev_desc;
+       char cmp[1024];
+
+       ut_assertok(usb_init());
+       ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev));
+       ut_assertok(get_device("usb", "0", &dev_desc));
+
+       /* Read a few blocks and look for the string we expect */
+       ut_asserteq(512, dev_desc->blksz);
+       memset(cmp, '\0', sizeof(cmp));
+       ut_asserteq(2, dev_desc->block_read(dev_desc->dev, 0, 2, cmp));
+       ut_assertok(strcmp(cmp, "this is a test"));
+
+       return 0;
+}
+DM_TEST(dm_test_usb_flash, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);