dm: usb: Avoid time delays in sandbox tests
authorSimon Glass <sjg@chromium.org>
Mon, 9 Nov 2015 06:47:44 +0000 (23:47 -0700)
committerSimon Glass <sjg@chromium.org>
Fri, 20 Nov 2015 03:27:50 +0000 (20:27 -0700)
Currently the USB tests take around two seconds to run. Remove these
unnecessary time delays so that the tests run quickly.

Signed-off-by: Simon Glass <sjg@chromium.org>
common/usb_hub.c
test/dm/test-main.c
test/dm/usb.c

index a92c9fb..e1de813 100644 (file)
@@ -31,6 +31,9 @@
 #include <asm/unaligned.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
+#ifdef CONFIG_SANDBOX
+#include <asm/state.h>
+#endif
 #include <asm/unaligned.h>
 #include <dm/root.h>
 
@@ -466,7 +469,12 @@ static int usb_hub_configure(struct usb_device *dev)
                unsigned short portstatus, portchange;
                int ret;
                ulong start = get_timer(0);
+               uint delay = CONFIG_SYS_HZ;
 
+#ifdef CONFIG_SANDBOX
+               if (state_get_skip_delays())
+                       delay = 0;
+#endif
 #ifdef CONFIG_DM_USB
                debug("\n\nScanning '%s' port %d\n", dev->dev->name, i + 1);
 #else
@@ -498,7 +506,7 @@ static int usb_hub_configure(struct usb_device *dev)
                        if (portstatus & USB_PORT_STAT_CONNECTION)
                                break;
 
-               } while (get_timer(start) < CONFIG_SYS_HZ * 1);
+               } while (get_timer(start) < delay);
 
                if (ret < 0)
                        continue;
index 0e43ab9..a36a9c0 100644 (file)
@@ -9,6 +9,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
+#include <asm/state.h>
 #include <dm/test.h>
 #include <dm/root.h>
 #include <dm/uclass-internal.h>
@@ -113,6 +114,7 @@ static int dm_test_main(const char *test_name)
                        ut_assertok(dm_scan_fdt(gd->fdt_blob, false));
 
                test->func(uts);
+               state_set_skip_delays(false);
 
                ut_assertok(dm_test_destroy(uts));
        }
index 9939d83..4300bbd 100644 (file)
@@ -8,6 +8,8 @@
 #include <dm.h>
 #include <usb.h>
 #include <asm/io.h>
+#include <asm/state.h>
+#include <dm/device-internal.h>
 #include <dm/test.h>
 #include <test/ut.h>
 
@@ -35,6 +37,7 @@ static int dm_test_usb_flash(struct unit_test_state *uts)
        block_dev_desc_t *dev_desc;
        char cmp[1024];
 
+       state_set_skip_delays(true);
        ut_assertok(usb_init());
        ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev));
        ut_assertok(get_device("usb", "0", &dev_desc));