summaryrefslogtreecommitdiff
path: root/test/dm/usb.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2015-11-08 23:48:08 -0700
committerSimon Glass <sjg@chromium.org>2015-11-19 20:27:52 -0700
commitbff1a71ede3557cd5502afdb74aabe9599d6f96b (patch)
tree537f0058c11f489beba99ab5b807b74e62923b8a /test/dm/usb.c
parent460a7172852033a1b897a61e954d1e3f1c32285f (diff)
downloadu-boot-bff1a71ede3557cd5502afdb74aabe9599d6f96b.tar.gz
dm: test: usb: sandbox: Add keyboard tests for sandbox
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>
Diffstat (limited to 'test/dm/usb.c')
-rw-r--r--test/dm/usb.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/dm/usb.c b/test/dm/usb.c
index fb193e80c2..7d6b644a51 100644
--- a/test/dm/usb.c
+++ b/test/dm/usb.c
@@ -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);