Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 7 | #include <console.h> |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | e6f6f9e | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 9 | #include <part.h> |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 10 | #include <usb.h> |
| 11 | #include <asm/io.h> |
Simon Glass | 3884c98 | 2015-11-08 23:47:44 -0700 | [diff] [blame] | 12 | #include <asm/state.h> |
Simon Glass | bff1a71 | 2015-11-08 23:48:08 -0700 | [diff] [blame] | 13 | #include <asm/test.h> |
Simon Glass | 3884c98 | 2015-11-08 23:47:44 -0700 | [diff] [blame] | 14 | #include <dm/device-internal.h> |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 15 | #include <dm/test.h> |
Simon Glass | 431cbd6 | 2015-11-08 23:48:01 -0700 | [diff] [blame] | 16 | #include <dm/uclass-internal.h> |
Simon Glass | 0e1fad4 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 17 | #include <test/test.h> |
Joe Hershberger | e721b88 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 18 | #include <test/ut.h> |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 19 | |
Heinrich Schuchardt | 12f1e79 | 2019-11-23 18:15:23 +0100 | [diff] [blame] | 20 | struct keyboard_test_data { |
| 21 | const char modifiers; |
| 22 | const char scancode; |
| 23 | const char result[6]; |
| 24 | }; |
| 25 | |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 26 | /* Test that sandbox USB works correctly */ |
Joe Hershberger | e721b88 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 27 | static int dm_test_usb_base(struct unit_test_state *uts) |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 28 | { |
| 29 | struct udevice *bus; |
| 30 | |
| 31 | ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_USB, 0, &bus)); |
| 32 | ut_assertok(uclass_get_device(UCLASS_USB, 0, &bus)); |
| 33 | ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_USB, 2, &bus)); |
| 34 | |
| 35 | return 0; |
| 36 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 37 | DM_TEST(dm_test_usb_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * Test that we can use the flash stick. This is more of a functional test. It |
| 41 | * covers scanning the bug, setting up a hub and a flash stick and reading |
| 42 | * data from the flash stick. |
| 43 | */ |
Joe Hershberger | e721b88 | 2015-05-20 14:27:27 -0500 | [diff] [blame] | 44 | static int dm_test_usb_flash(struct unit_test_state *uts) |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 45 | { |
| 46 | struct udevice *dev; |
Simon Glass | 4101f68 | 2016-02-29 15:25:34 -0700 | [diff] [blame] | 47 | struct blk_desc *dev_desc; |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 48 | char cmp[1024]; |
| 49 | |
Simon Glass | 3884c98 | 2015-11-08 23:47:44 -0700 | [diff] [blame] | 50 | state_set_skip_delays(true); |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 51 | ut_assertok(usb_init()); |
| 52 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev)); |
Simon Glass | ebac37c | 2016-02-29 15:25:43 -0700 | [diff] [blame] | 53 | ut_assertok(blk_get_device_by_str("usb", "0", &dev_desc)); |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 54 | |
| 55 | /* Read a few blocks and look for the string we expect */ |
| 56 | ut_asserteq(512, dev_desc->blksz); |
| 57 | memset(cmp, '\0', sizeof(cmp)); |
Simon Glass | 2a981dc | 2016-02-29 15:25:52 -0700 | [diff] [blame] | 58 | ut_asserteq(2, blk_dread(dev_desc, 0, 2, cmp)); |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 59 | ut_assertok(strcmp(cmp, "this is a test")); |
Simon Glass | 61ccd88 | 2016-02-29 15:26:02 -0700 | [diff] [blame] | 60 | ut_assertok(usb_stop()); |
Simon Glass | e00cb22 | 2015-03-25 12:23:05 -0600 | [diff] [blame] | 61 | |
| 62 | return 0; |
| 63 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 64 | DM_TEST(dm_test_usb_flash, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 431cbd6 | 2015-11-08 23:48:01 -0700 | [diff] [blame] | 65 | |
| 66 | /* test that we can handle multiple storage devices */ |
| 67 | static int dm_test_usb_multi(struct unit_test_state *uts) |
| 68 | { |
| 69 | struct udevice *dev; |
| 70 | |
| 71 | state_set_skip_delays(true); |
| 72 | ut_assertok(usb_init()); |
| 73 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev)); |
| 74 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 1, &dev)); |
| 75 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 2, &dev)); |
Simon Glass | 61ccd88 | 2016-02-29 15:26:02 -0700 | [diff] [blame] | 76 | ut_assertok(usb_stop()); |
Simon Glass | 431cbd6 | 2015-11-08 23:48:01 -0700 | [diff] [blame] | 77 | |
| 78 | return 0; |
| 79 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 80 | DM_TEST(dm_test_usb_multi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 431cbd6 | 2015-11-08 23:48:01 -0700 | [diff] [blame] | 81 | |
Michael Walle | c03b761 | 2020-06-02 01:47:07 +0200 | [diff] [blame] | 82 | /* test that we have an associated ofnode with the usb device */ |
| 83 | static int dm_test_usb_fdt_node(struct unit_test_state *uts) |
| 84 | { |
| 85 | struct udevice *dev; |
| 86 | ofnode node; |
| 87 | |
| 88 | state_set_skip_delays(true); |
| 89 | ut_assertok(usb_init()); |
| 90 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev)); |
| 91 | node = ofnode_path("/usb@1/hub/usbstor@1"); |
| 92 | ut_asserteq(1, ofnode_equal(node, dev_ofnode(dev))); |
| 93 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 1, &dev)); |
| 94 | ut_asserteq(1, ofnode_equal(ofnode_null(), dev_ofnode(dev))); |
| 95 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 2, &dev)); |
| 96 | node = ofnode_path("/usb@1/hub/usbstor@3"); |
| 97 | ut_asserteq(1, ofnode_equal(node, dev_ofnode(dev))); |
| 98 | ut_assertok(usb_stop()); |
| 99 | |
| 100 | return 0; |
| 101 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 102 | DM_TEST(dm_test_usb_fdt_node, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Michael Walle | c03b761 | 2020-06-02 01:47:07 +0200 | [diff] [blame] | 103 | |
Simon Glass | 431cbd6 | 2015-11-08 23:48:01 -0700 | [diff] [blame] | 104 | static int count_usb_devices(void) |
| 105 | { |
| 106 | struct udevice *hub; |
| 107 | struct uclass *uc; |
| 108 | int count = 0; |
| 109 | int ret; |
| 110 | |
| 111 | ret = uclass_get(UCLASS_USB_HUB, &uc); |
| 112 | if (ret) |
| 113 | return ret; |
| 114 | |
| 115 | uclass_foreach_dev(hub, uc) { |
| 116 | struct udevice *dev; |
| 117 | |
| 118 | count++; |
| 119 | for (device_find_first_child(hub, &dev); |
| 120 | dev; |
| 121 | device_find_next_child(&dev)) { |
| 122 | count++; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | return count; |
| 127 | } |
| 128 | |
Bin Meng | f4d4f7d | 2017-10-01 06:19:45 -0700 | [diff] [blame] | 129 | /* test that no USB devices are found after we stop the stack */ |
| 130 | static int dm_test_usb_stop(struct unit_test_state *uts) |
Simon Glass | 431cbd6 | 2015-11-08 23:48:01 -0700 | [diff] [blame] | 131 | { |
Bin Meng | f4d4f7d | 2017-10-01 06:19:45 -0700 | [diff] [blame] | 132 | struct udevice *dev; |
Simon Glass | 431cbd6 | 2015-11-08 23:48:01 -0700 | [diff] [blame] | 133 | |
| 134 | /* Scan and check that all devices are present */ |
| 135 | state_set_skip_delays(true); |
| 136 | ut_assertok(usb_init()); |
| 137 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 0, &dev)); |
| 138 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 1, &dev)); |
| 139 | ut_assertok(uclass_get_device(UCLASS_MASS_STORAGE, 2, &dev)); |
Simon Glass | a57a817 | 2016-01-07 10:23:42 -0700 | [diff] [blame] | 140 | ut_asserteq(6, count_usb_devices()); |
Simon Glass | 431cbd6 | 2015-11-08 23:48:01 -0700 | [diff] [blame] | 141 | ut_assertok(usb_stop()); |
Bin Meng | f4d4f7d | 2017-10-01 06:19:45 -0700 | [diff] [blame] | 142 | ut_asserteq(0, count_usb_devices()); |
Simon Glass | 431cbd6 | 2015-11-08 23:48:01 -0700 | [diff] [blame] | 143 | |
| 144 | return 0; |
| 145 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 146 | DM_TEST(dm_test_usb_stop, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | bff1a71 | 2015-11-08 23:48:08 -0700 | [diff] [blame] | 147 | |
Heinrich Schuchardt | 12f1e79 | 2019-11-23 18:15:23 +0100 | [diff] [blame] | 148 | /** |
| 149 | * dm_test_usb_keyb() - test USB keyboard driver |
| 150 | * |
| 151 | * This test copies USB keyboard scan codes into the key buffer of the USB |
| 152 | * keyboard emulation driver. These are picked up during emulated interrupts |
| 153 | * by the USB keyboard driver and converted to characters and escape sequences. |
| 154 | * The test then reads and verifies these characters and escape sequences from |
| 155 | * the standard input. |
| 156 | * |
| 157 | * TODO: The following features are not yet tested: |
| 158 | * |
| 159 | * * LED status |
| 160 | * * caps-lock |
| 161 | * * num-lock |
| 162 | * * numerical pad keys |
| 163 | * |
| 164 | * TODO: The following features are not yet implemented by the USB keyboard |
| 165 | * driver and therefore not tested: |
| 166 | * |
| 167 | * * modifiers for non-alpha-numeric keys, e.g. <SHIFT><TAB> and <ALT><F4> |
| 168 | * * some special keys, e.g. <PRINT> |
| 169 | * * some modifiers, e.g. <ALT> and <META> |
| 170 | * * alternative keyboard layouts |
| 171 | * |
| 172 | * @uts: unit test state |
| 173 | * Return: 0 on success |
| 174 | */ |
Simon Glass | bff1a71 | 2015-11-08 23:48:08 -0700 | [diff] [blame] | 175 | static int dm_test_usb_keyb(struct unit_test_state *uts) |
| 176 | { |
| 177 | struct udevice *dev; |
Heinrich Schuchardt | 12f1e79 | 2019-11-23 18:15:23 +0100 | [diff] [blame] | 178 | const struct keyboard_test_data *pos; |
| 179 | const struct keyboard_test_data kbd_test_data[] = { |
| 180 | /* <A> */ |
| 181 | {0x00, 0x04, "a"}, |
| 182 | /* <B> */ |
| 183 | {0x00, 0x05, "b"}, |
| 184 | /* <C> */ |
| 185 | {0x00, 0x06, "c"}, |
| 186 | /* <D> */ |
| 187 | {0x00, 0x07, "d"}, |
| 188 | /* <E> */ |
| 189 | {0x00, 0x08, "e"}, |
| 190 | /* <F> */ |
| 191 | {0x00, 0x09, "f"}, |
| 192 | /* <G> */ |
| 193 | {0x00, 0x0a, "g"}, |
| 194 | /* <H> */ |
| 195 | {0x00, 0x0b, "h"}, |
| 196 | /* <I> */ |
| 197 | {0x00, 0x0c, "i"}, |
| 198 | /* <J> */ |
| 199 | {0x00, 0x0d, "j"}, |
| 200 | /* <K> */ |
| 201 | {0x00, 0x0e, "k"}, |
| 202 | /* <L> */ |
| 203 | {0x00, 0x0f, "l"}, |
| 204 | /* <M> */ |
| 205 | {0x00, 0x10, "m"}, |
| 206 | /* <N> */ |
| 207 | {0x00, 0x11, "n"}, |
| 208 | /* <O> */ |
| 209 | {0x00, 0x12, "o"}, |
| 210 | /* <P> */ |
| 211 | {0x00, 0x13, "p"}, |
| 212 | /* <Q> */ |
| 213 | {0x00, 0x14, "q"}, |
| 214 | /* <R> */ |
| 215 | {0x00, 0x15, "r"}, |
| 216 | /* <S> */ |
| 217 | {0x00, 0x16, "s"}, |
| 218 | /* <T> */ |
| 219 | {0x00, 0x17, "t"}, |
| 220 | /* <U> */ |
| 221 | {0x00, 0x18, "u"}, |
| 222 | /* <V> */ |
| 223 | {0x00, 0x19, "v"}, |
| 224 | /* <W> */ |
| 225 | {0x00, 0x1a, "w"}, |
| 226 | /* <X> */ |
| 227 | {0x00, 0x1b, "x"}, |
| 228 | /* <Y> */ |
| 229 | {0x00, 0x1c, "y"}, |
| 230 | /* <Z> */ |
| 231 | {0x00, 0x1d, "z"}, |
| 232 | |
| 233 | /* <LEFT-SHIFT><A> */ |
| 234 | {0x02, 0x04, "A"}, |
| 235 | /* <RIGHT-SHIFT><Z> */ |
| 236 | {0x20, 0x1d, "Z"}, |
| 237 | |
| 238 | /* <LEFT-CONTROL><A> */ |
| 239 | {0x01, 0x04, "\x01"}, |
| 240 | /* <RIGHT-CONTROL><Z> */ |
| 241 | {0x10, 0x1d, "\x1a"}, |
| 242 | |
| 243 | /* <1> */ |
| 244 | {0x00, 0x1e, "1"}, |
| 245 | /* <2> */ |
| 246 | {0x00, 0x1f, "2"}, |
| 247 | /* <3> */ |
| 248 | {0x00, 0x20, "3"}, |
| 249 | /* <4> */ |
| 250 | {0x00, 0x21, "4"}, |
| 251 | /* <5> */ |
| 252 | {0x00, 0x22, "5"}, |
| 253 | /* <6> */ |
| 254 | {0x00, 0x23, "6"}, |
| 255 | /* <7> */ |
| 256 | {0x00, 0x24, "7"}, |
| 257 | /* <8> */ |
| 258 | {0x00, 0x25, "8"}, |
| 259 | /* <9> */ |
| 260 | {0x00, 0x26, "9"}, |
| 261 | /* <0> */ |
| 262 | {0x00, 0x27, "0"}, |
| 263 | |
| 264 | /* <LEFT-SHIFT><1> */ |
| 265 | {0x02, 0x1e, "!"}, |
| 266 | /* <RIGHT-SHIFT><2> */ |
| 267 | {0x20, 0x1f, "@"}, |
| 268 | /* <LEFT-SHIFT><3> */ |
| 269 | {0x02, 0x20, "#"}, |
| 270 | /* <RIGHT-SHIFT><4> */ |
| 271 | {0x20, 0x21, "$"}, |
| 272 | /* <LEFT-SHIFT><5> */ |
| 273 | {0x02, 0x22, "%"}, |
| 274 | /* <RIGHT-SHIFT><6> */ |
| 275 | {0x20, 0x23, "^"}, |
| 276 | /* <LEFT-SHIFT><7> */ |
| 277 | {0x02, 0x24, "&"}, |
| 278 | /* <RIGHT-SHIFT><8> */ |
| 279 | {0x20, 0x25, "*"}, |
| 280 | /* <LEFT-SHIFT><9> */ |
| 281 | {0x02, 0x26, "("}, |
| 282 | /* <RIGHT-SHIFT><0> */ |
| 283 | {0x20, 0x27, ")"}, |
| 284 | |
| 285 | /* <ENTER> */ |
| 286 | {0x00, 0x28, "\r"}, |
| 287 | /* <ESCAPE> */ |
| 288 | {0x00, 0x29, "\x1b"}, |
| 289 | /* <BACKSPACE> */ |
| 290 | {0x00, 0x2a, "\x08"}, |
| 291 | /* <TAB> */ |
| 292 | {0x00, 0x2b, "\x09"}, |
| 293 | /* <SPACE> */ |
| 294 | {0x00, 0x2c, " "}, |
| 295 | /* <MINUS> */ |
| 296 | {0x00, 0x2d, "-"}, |
| 297 | /* <EQUAL> */ |
| 298 | {0x00, 0x2e, "="}, |
| 299 | /* <LEFT BRACE> */ |
| 300 | {0x00, 0x2f, "["}, |
| 301 | /* <RIGHT BRACE> */ |
| 302 | {0x00, 0x30, "]"}, |
| 303 | /* <BACKSLASH> */ |
| 304 | {0x00, 0x31, "\\"}, |
| 305 | /* <HASH-TILDE> */ |
| 306 | {0x00, 0x32, "#"}, |
| 307 | /* <SEMICOLON> */ |
| 308 | {0x00, 0x33, ";"}, |
| 309 | /* <APOSTROPHE> */ |
| 310 | {0x00, 0x34, "'"}, |
| 311 | /* <GRAVE> */ |
| 312 | {0x00, 0x35, "`"}, |
| 313 | /* <COMMA> */ |
| 314 | {0x00, 0x36, ","}, |
| 315 | /* <DOT> */ |
| 316 | {0x00, 0x37, "."}, |
| 317 | /* <SLASH> */ |
| 318 | {0x00, 0x38, "/"}, |
| 319 | |
| 320 | /* <LEFT-SHIFT><ENTER> */ |
| 321 | {0x02, 0x28, "\r"}, |
| 322 | /* <RIGHT-SHIFT><ESCAPE> */ |
| 323 | {0x20, 0x29, "\x1b"}, |
| 324 | /* <LEFT-SHIFT><BACKSPACE> */ |
| 325 | {0x02, 0x2a, "\x08"}, |
| 326 | /* <RIGHT-SHIFT><TAB> */ |
| 327 | {0x20, 0x2b, "\x09"}, |
| 328 | /* <LEFT-SHIFT><SPACE> */ |
| 329 | {0x02, 0x2c, " "}, |
| 330 | /* <MINUS> */ |
| 331 | {0x20, 0x2d, "_"}, |
| 332 | /* <LEFT-SHIFT><EQUAL> */ |
| 333 | {0x02, 0x2e, "+"}, |
| 334 | /* <RIGHT-SHIFT><LEFT BRACE> */ |
| 335 | {0x20, 0x2f, "{"}, |
| 336 | /* <LEFT-SHIFT><RIGHT BRACE> */ |
| 337 | {0x02, 0x30, "}"}, |
| 338 | /* <RIGHT-SHIFT><BACKSLASH> */ |
| 339 | {0x20, 0x31, "|"}, |
| 340 | /* <LEFT-SHIFT><HASH-TILDE> */ |
| 341 | {0x02, 0x32, "~"}, |
| 342 | /* <RIGHT-SHIFT><SEMICOLON> */ |
| 343 | {0x20, 0x33, ":"}, |
| 344 | /* <LEFT-SHIFT><APOSTROPHE> */ |
| 345 | {0x02, 0x34, "\""}, |
| 346 | /* <RIGHT-SHIFT><GRAVE> */ |
| 347 | {0x20, 0x35, "~"}, |
| 348 | /* <LEFT-SHIFT><COMMA> */ |
| 349 | {0x02, 0x36, "<"}, |
| 350 | /* <RIGHT-SHIFT><DOT> */ |
| 351 | {0x20, 0x37, ">"}, |
| 352 | /* <LEFT-SHIFT><SLASH> */ |
| 353 | {0x02, 0x38, "?"}, |
| 354 | #ifdef CONFIG_USB_KEYBOARD_FN_KEYS |
| 355 | /* <F1> */ |
| 356 | {0x00, 0x3a, "\x1bOP"}, |
| 357 | /* <F2> */ |
| 358 | {0x00, 0x3b, "\x1bOQ"}, |
| 359 | /* <F3> */ |
| 360 | {0x00, 0x3c, "\x1bOR"}, |
| 361 | /* <F4> */ |
| 362 | {0x00, 0x3d, "\x1bOS"}, |
| 363 | /* <F5> */ |
| 364 | {0x00, 0x3e, "\x1b[15~"}, |
| 365 | /* <F6> */ |
| 366 | {0x00, 0x3f, "\x1b[17~"}, |
| 367 | /* <F7> */ |
| 368 | {0x00, 0x40, "\x1b[18~"}, |
| 369 | /* <F8> */ |
| 370 | {0x00, 0x41, "\x1b[19~"}, |
| 371 | /* <F9> */ |
| 372 | {0x00, 0x42, "\x1b[20~"}, |
| 373 | /* <F10> */ |
| 374 | {0x00, 0x43, "\x1b[21~"}, |
| 375 | /* <F11> */ |
| 376 | {0x00, 0x44, "\x1b[23~"}, |
| 377 | /* <F12> */ |
| 378 | {0x00, 0x45, "\x1b[24~"}, |
| 379 | /* <INSERT> */ |
| 380 | {0x00, 0x49, "\x1b[2~"}, |
| 381 | /* <HOME> */ |
| 382 | {0x00, 0x4a, "\x1b[H"}, |
| 383 | /* <PAGE UP> */ |
| 384 | {0x00, 0x4b, "\x1b[5~"}, |
| 385 | /* <DELETE> */ |
| 386 | {0x00, 0x4c, "\x1b[3~"}, |
| 387 | /* <END> */ |
| 388 | {0x00, 0x4d, "\x1b[F"}, |
| 389 | /* <PAGE DOWN> */ |
| 390 | {0x00, 0x4e, "\x1b[6~"}, |
| 391 | /* <RIGHT> */ |
| 392 | {0x00, 0x4f, "\x1b[C"}, |
| 393 | /* <LEFT> */ |
| 394 | {0x00, 0x50, "\x1b[D"}, |
| 395 | /* <DOWN> */ |
| 396 | {0x00, 0x51, "\x1b[B"}, |
| 397 | /* <UP> */ |
| 398 | {0x00, 0x52, "\x1b[A"}, |
| 399 | #endif /* CONFIG_USB_KEYBOARD_FN_KEYS */ |
| 400 | |
| 401 | /* End of list */ |
| 402 | {0x00, 0x00, "\0"} |
| 403 | }; |
| 404 | |
Simon Glass | bff1a71 | 2015-11-08 23:48:08 -0700 | [diff] [blame] | 405 | |
| 406 | state_set_skip_delays(true); |
| 407 | ut_assertok(usb_init()); |
| 408 | |
| 409 | /* Initially there should be no characters */ |
| 410 | ut_asserteq(0, tstc()); |
| 411 | |
Peng Fan | 819ac50 | 2019-05-22 07:08:12 +0000 | [diff] [blame] | 412 | ut_assertok(uclass_get_device_by_name(UCLASS_USB_EMUL, "keyb@3", |
Simon Glass | bff1a71 | 2015-11-08 23:48:08 -0700 | [diff] [blame] | 413 | &dev)); |
| 414 | |
| 415 | /* |
Heinrich Schuchardt | 12f1e79 | 2019-11-23 18:15:23 +0100 | [diff] [blame] | 416 | * Add scan codes to the USB keyboard buffer. They should appear as |
| 417 | * corresponding characters and escape sequences in stdin. |
Simon Glass | bff1a71 | 2015-11-08 23:48:08 -0700 | [diff] [blame] | 418 | */ |
Heinrich Schuchardt | 12f1e79 | 2019-11-23 18:15:23 +0100 | [diff] [blame] | 419 | for (pos = kbd_test_data; pos->scancode; ++pos) { |
| 420 | const char *c; |
| 421 | char scancodes[USB_KBD_BOOT_REPORT_SIZE] = {0}; |
Simon Glass | bff1a71 | 2015-11-08 23:48:08 -0700 | [diff] [blame] | 422 | |
Heinrich Schuchardt | 12f1e79 | 2019-11-23 18:15:23 +0100 | [diff] [blame] | 423 | scancodes[0] = pos->modifiers; |
| 424 | scancodes[2] = pos->scancode; |
| 425 | |
| 426 | ut_assertok(sandbox_usb_keyb_add_string(dev, scancodes)); |
| 427 | |
| 428 | for (c = pos->result; *c; ++c) { |
| 429 | ut_asserteq(1, tstc()); |
Heinrich Schuchardt | c670aee | 2020-10-07 18:11:48 +0200 | [diff] [blame] | 430 | ut_asserteq(*c, getchar()); |
Heinrich Schuchardt | 12f1e79 | 2019-11-23 18:15:23 +0100 | [diff] [blame] | 431 | } |
| 432 | ut_asserteq(0, tstc()); |
| 433 | } |
Simon Glass | bff1a71 | 2015-11-08 23:48:08 -0700 | [diff] [blame] | 434 | ut_assertok(usb_stop()); |
| 435 | |
| 436 | return 0; |
| 437 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 438 | DM_TEST(dm_test_usb_keyb, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |