]> git.sur5r.net Git - u-boot/commitdiff
dm: test: usb: sandbox: Add keyboard tests for sandbox
authorSimon Glass <sjg@chromium.org>
Mon, 9 Nov 2015 06:48:08 +0000 (23:48 -0700)
committerSimon Glass <sjg@chromium.org>
Fri, 20 Nov 2015 03:27:52 +0000 (20:27 -0700)
Add a test that verifies that USB keyboards work correctly on sandbox.
This verifies some additional parts of the USB stack.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/sandbox/dts/test.dts
test/dm/usb.c

index 52749c0705061fc0e37e4566f5ec19e2d24c504c..b6d9a15da4a78782da6c5ebf95d6d37e1041c065 100644 (file)
                                        sandbox,filepath = "testflash2.bin";
                                };
 
+                               keyb@3 {
+                                       reg = <3>;
+                                       compatible = "sandbox,usb-keyb";
+                               };
+
                        };
                };
        };
index fb193e80c263b6d142b86fa5e0c6e5ea743ef385..7d6b644a51b53c0a04bec769ab16d08341783bd6 100644 (file)
@@ -10,6 +10,7 @@
 #include <usb.h>
 #include <asm/io.h>
 #include <asm/state.h>
+#include <asm/test.h>
 #include <dm/device-internal.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
@@ -258,3 +259,33 @@ static int dm_test_usb_tree_reorder(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_usb_tree_reorder, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_usb_keyb(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+
+       state_set_skip_delays(true);
+       ut_assertok(usb_init());
+
+       /* Initially there should be no characters */
+       ut_asserteq(0, tstc());
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_USB_EMUL, "keyb",
+                                             &dev));
+
+       /*
+        * Add a string to the USB keyboard buffer - it should appear in
+        * stdin
+        */
+       ut_assertok(sandbox_usb_keyb_add_string(dev, "ab"));
+       ut_asserteq(1, tstc());
+       ut_asserteq('a', getc());
+       ut_asserteq(1, tstc());
+       ut_asserteq('b', getc());
+       ut_asserteq(0, tstc());
+
+       ut_assertok(usb_stop());
+
+       return 0;
+}
+DM_TEST(dm_test_usb_keyb, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);