diff options
author | Raul E Rangel <rrangel@chromium.org> | 2022-08-22 12:29:27 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-08-22 21:47:11 +0000 |
commit | 92fe38eb22c90c5041dbc77ff85421a84a957e72 (patch) | |
tree | 865d5ffb40a1389dcb0f3b0dd6bb8c5dc342a5fc /test | |
parent | 462ec6f541f3b076c9cc6c99292209f0ba0f4e5d (diff) | |
download | chrome-ec-92fe38eb22c90c5041dbc77ff85421a84a957e72.tar.gz |
8042: Add tests that verify keyboard inhibit behavior
Now that we have control over the output buffer, we can build more
complex tests. These tests verify the keyboard inhibit functionality of
the 8042 controller. This exposed two bugs in the 8042/keyboard
implementation.
BUG=b:242886255
BRANCH=none
TEST=run unit tests
Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Change-Id: Ib8e84be88f4298d2c257c14989efa2571be86c70
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3846285
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/kb_8042.c | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/test/kb_8042.c b/test/kb_8042.c index 967f6bf345..36970564b2 100644 --- a/test/kb_8042.c +++ b/test/kb_8042.c @@ -424,6 +424,122 @@ static int test_8042_keyboard_key_pressed_while_inhibited(void) return EC_SUCCESS; } +static int test_8042_keyboard_key_pressed_before_inhibit_using_cmd_byte(void) +{ + ENABLE_KEYSTROKE(1); + /* Simulate a keypress on the keyboard */ + press_key(1, 1, 1); + press_key(1, 1, 0); + + /* + * We should have a press scan code in the output buffer, and a + * release scan code queued up in the keyboard queue. + */ + WAIT_FOR_DATA(30); + + /* Inhibit the keyboard device from sending data. */ + keyboard_host_write(I8042_WRITE_CMD_BYTE, 1); + keyboard_host_write(I8042_XLATE | I8042_KBD_DIS, 0); + /* Wait for controller to processes the command */ + msleep(10); + + /* Stop inhibiting the keyboard */ + keyboard_host_write(I8042_WRITE_CMD_BYTE, 1); + keyboard_host_write(I8042_XLATE, 0); + /* Wait for controller to processes the command */ + msleep(10); + + /* Verify the scan codes from above */ + VERIFY_LPC_CHAR("\x01"); + VERIFY_LPC_CHAR("\x81"); + + return EC_SUCCESS; +} + +static int +test_8042_keyboard_key_pressed_before_inhibit_using_cmd_byte_with_read(void) +{ + uint8_t cmd; + + ENABLE_KEYSTROKE(1); + /* Simulate a keypress on the keyboard */ + press_key(1, 1, 1); + press_key(1, 1, 0); + + /* + * We should have a press scan code in the output buffer, and a + * release scan code queued up in the keyboard queue. + */ + WAIT_FOR_DATA(30); + + /* Inhibit the keyboard device from sending data. */ + keyboard_host_write(I8042_WRITE_CMD_BYTE, 1); + keyboard_host_write(I8042_XLATE | I8042_KBD_DIS, 0); + /* Wait for controller to processes the command */ + msleep(10); + + /* Read the key press scan code from the output buffer. */ + VERIFY_LPC_CHAR("\x01"); + + /* + * With the keyboard output suppressed, we should be able to read from + * the 8042 controller. + */ + cmd = READ_CMD_BYTE(); + + /* Verify we got the cmd byte we set above */ + TEST_EQ(cmd, I8042_XLATE | I8042_KBD_DIS, "%d"); + + /* Stop inhibiting the keyboard */ + keyboard_host_write(I8042_WRITE_CMD_BYTE, 1); + keyboard_host_write(I8042_XLATE, 0); + /* Wait for controller to processes the command */ + msleep(10); + + /* Verify the key release scan code from above */ + /* + * FIXME: This is wrong. We should receive the key release scan code + * 0x81. Instead the `I8042_READ_CMD_BYTE` above cleared the keyboard's + * output queue. It did this because the 8042 and keyboard output queues + * are implemented as the same thing. + */ + VERIFY_NO_CHAR(); + + return EC_SUCCESS; +} + +static int test_8042_keyboard_key_pressed_before_inhibit_using_cmd(void) +{ + ENABLE_KEYSTROKE(1); + /* Simulate a keypress on the keyboard */ + press_key(1, 1, 1); + press_key(1, 1, 0); + + /* + * We should have a press scan code in the output buffer, and a + * release scan code queued up in the keyboard queue. + */ + WAIT_FOR_DATA(30); + + /* Inhibit the keyboard device from sending data. */ + keyboard_host_write(I8042_DIS_KB, 1); + + /* Stop inhibiting the keyboard */ + keyboard_host_write(I8042_ENA_KB, 1); + + /* Verify the scan codes from above */ + VERIFY_LPC_CHAR("\x01"); + /* + * FIXME: This is wrong. When the keyboard CLK is inhibited the keyboard + * will queue up events/scan codes in it's internal buffer. Once the + * inhibit is released, the keyboard will start clocking out the data. + * So in this test we should be receiving 0x81, but the keyboard buffer + * was cleared by the I8042_DIS_KB above. + */ + VERIFY_NO_CHAR(); + return EC_SUCCESS; +} + static int test_single_key_press(void) { ENABLE_KEYSTROKE(1); @@ -643,6 +759,12 @@ void run_test(int argc, char **argv) RUN_TEST(test_8042_aux_test_command); RUN_TEST(test_8042_keyboard_controller_commands); RUN_TEST(test_8042_keyboard_key_pressed_while_inhibited); + RUN_TEST( + test_8042_keyboard_key_pressed_before_inhibit_using_cmd_byte); + RUN_TEST( + test_8042_keyboard_key_pressed_before_inhibit_using_cmd_byte_with_read); + RUN_TEST( + test_8042_keyboard_key_pressed_before_inhibit_using_cmd); RUN_TEST(test_single_key_press); RUN_TEST(test_disable_keystroke); RUN_TEST(test_typematic); |