summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2022-09-15 16:02:51 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-28 19:10:20 +0000
commit4dee64a4c53dc954ca9695108c10ea1d0b578209 (patch)
tree2ba86e08d48d848ff6fec6c4f80dd4fe04c76fc3 /test
parentdd451d0aab9c78f0fc7cff91c39a7f5c50f2790d (diff)
downloadchrome-ec-4dee64a4c53dc954ca9695108c10ea1d0b578209.tar.gz
i8042: Send command response from priority queue
This patch also makes KEYPROTO task hold sending a scancode when it receives SETLEDS command until it returns ACK to the second byte (and leaves STATE_ATKBD_SETLEDS). This patch also removes and repositions some kblog_put calls because checking OBF and writing to DBBOUT must be done as atomically as possible to minimize the race condition. BUG=b:237981131,b:247795316 BRANCH=None TEST=Taniks. Press search+alt then 'k' 100 times. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I7ccfae99b3657ead5fa9e3c337db623aaffdb0bc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3901253 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Diffstat (limited to 'test')
-rw-r--r--test/kb_8042.c101
1 files changed, 53 insertions, 48 deletions
diff --git a/test/kb_8042.c b/test/kb_8042.c
index e7d7690cff..eb043d5f82 100644
--- a/test/kb_8042.c
+++ b/test/kb_8042.c
@@ -261,6 +261,7 @@ static int _read_cmd_byte(uint8_t *cmd)
void before_test(void)
{
/* Make sure all tests start with the controller in the same state */
+ keyboard_clear_buffer();
_write_cmd_byte(I8042_XLATE | I8042_AUX_DIS | I8042_KBD_DIS);
}
@@ -274,7 +275,7 @@ void after_test(void)
}
}
-static int test_8042_aux_loopback(void)
+test_static int test_8042_aux_loopback(void)
{
/* Disable all IRQs */
WRITE_CMD_BYTE(0);
@@ -293,7 +294,7 @@ static int test_8042_aux_loopback(void)
return EC_SUCCESS;
}
-static int test_8042_aux_two_way_communication(void)
+test_static int test_8042_aux_two_way_communication(void)
{
/* Enable AUX IRQ */
WRITE_CMD_BYTE(I8042_ENIRQ12);
@@ -311,7 +312,7 @@ static int test_8042_aux_two_way_communication(void)
return EC_SUCCESS;
}
-static int test_8042_aux_inhibit(void)
+test_static int test_8042_aux_inhibit(void)
{
/* Enable AUX IRQ, but inhibit the AUX device from sending data. */
WRITE_CMD_BYTE(I8042_ENIRQ12 | I8042_AUX_DIS);
@@ -339,7 +340,7 @@ static int test_8042_aux_inhibit(void)
return EC_SUCCESS;
}
-static int test_8042_aux_controller_commands(void)
+test_static int test_8042_aux_controller_commands(void)
{
uint8_t ctrl;
@@ -359,7 +360,7 @@ static int test_8042_aux_controller_commands(void)
return EC_SUCCESS;
}
-static int test_8042_aux_test_command(void)
+test_static int test_8042_aux_test_command(void)
{
i8042_write_cmd(I8042_TEST_MOUSE);
@@ -368,7 +369,7 @@ static int test_8042_aux_test_command(void)
return EC_SUCCESS;
}
-static int test_8042_self_test(void)
+test_static int test_8042_self_test(void)
{
i8042_write_cmd(I8042_RESET_SELF_TEST);
VERIFY_LPC_CHAR("\x55");
@@ -376,7 +377,7 @@ static int test_8042_self_test(void)
return EC_SUCCESS;
}
-static int test_8042_keyboard_test_command(void)
+test_static int test_8042_keyboard_test_command(void)
{
i8042_write_cmd(I8042_TEST_KB_PORT);
VERIFY_LPC_CHAR("\x00"); /* Data and Clock are not stuck */
@@ -384,7 +385,7 @@ static int test_8042_keyboard_test_command(void)
return EC_SUCCESS;
}
-static int test_8042_keyboard_controller_commands(void)
+test_static int test_8042_keyboard_controller_commands(void)
{
uint8_t ctrl;
@@ -404,7 +405,7 @@ static int test_8042_keyboard_controller_commands(void)
return EC_SUCCESS;
}
-static int test_8042_keyboard_key_pressed_while_inhibited(void)
+test_static int test_8042_keyboard_key_pressed_while_inhibited(void)
{
ENABLE_KEYSTROKE(1);
@@ -440,7 +441,8 @@ 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)
+test_static int
+test_8042_keyboard_key_pressed_before_inhibit_using_cmd_byte(void)
{
ENABLE_KEYSTROKE(1);
/* Simulate a keypress on the keyboard */
@@ -472,7 +474,7 @@ static int test_8042_keyboard_key_pressed_before_inhibit_using_cmd_byte(void)
return EC_SUCCESS;
}
-static int
+test_static int
test_8042_keyboard_key_pressed_before_inhibit_using_cmd_byte_with_read(void)
{
uint8_t cmd;
@@ -524,7 +526,7 @@ test_8042_keyboard_key_pressed_before_inhibit_using_cmd_byte_with_read(void)
return EC_SUCCESS;
}
-static int test_8042_keyboard_key_pressed_before_inhibit_using_cmd(void)
+test_static int test_8042_keyboard_key_pressed_before_inhibit_using_cmd(void)
{
ENABLE_KEYSTROKE(1);
/* Simulate a keypress on the keyboard */
@@ -556,7 +558,7 @@ static int test_8042_keyboard_key_pressed_before_inhibit_using_cmd(void)
return EC_SUCCESS;
}
-static int test_single_key_press(void)
+test_static int test_single_key_press(void)
{
ENABLE_KEYSTROKE(1);
press_key(1, 1, 1);
@@ -572,7 +574,7 @@ static int test_single_key_press(void)
return EC_SUCCESS;
}
-static int test_disable_keystroke(void)
+test_static int test_disable_keystroke(void)
{
ENABLE_KEYSTROKE(0);
press_key(1, 1, 1);
@@ -583,7 +585,7 @@ static int test_disable_keystroke(void)
return EC_SUCCESS;
}
-static int test_typematic(void)
+test_static int test_typematic(void)
{
ENABLE_KEYSTROKE(1);
@@ -610,7 +612,7 @@ static int test_typematic(void)
return EC_SUCCESS;
}
-static int test_atkbd_get_scancode(void)
+test_static int test_atkbd_get_scancode(void)
{
SET_SCANCODE(1);
@@ -635,7 +637,7 @@ static int test_atkbd_get_scancode(void)
return EC_SUCCESS;
}
-static int test_atkbd_set_scancode_with_keystroke_disabled(void)
+test_static int test_atkbd_set_scancode_with_keystroke_disabled(void)
{
ENABLE_KEYSTROKE(0);
@@ -647,7 +649,7 @@ static int test_atkbd_set_scancode_with_keystroke_disabled(void)
return EC_SUCCESS;
}
-static int test_atkbd_set_scancode_with_key_press_before_set(void)
+test_static int test_atkbd_set_scancode_with_key_press_before_set(void)
{
ENABLE_KEYSTROKE(0);
ENABLE_KEYSTROKE(1);
@@ -660,26 +662,17 @@ static int test_atkbd_set_scancode_with_key_press_before_set(void)
* ATKBD_CMD_SSCANSET should cause the keyboard to stop scanning, flush
* the keyboards output queue, and reset the typematic key.
*/
- keyboard_host_write(ATKBD_CMD_SSCANSET, 0);
- /* Read out the scan code that got pushed into the output buffer before
- * the command was sent.
- */
- VERIFY_LPC_CHAR("\x01");
+ i8042_write_data(ATKBD_CMD_SSCANSET);
+ VERIFY_ATKBD_ACK();
/*
* FIXME: This is wrong. The keyboard's output queue should have been
* flushed when it received the `ATKBD_CMD_SSCANSET` command.
*/
- VERIFY_LPC_CHAR("\x81");
-
- /* This is the ACK for `ATKBD_CMD_SSCANSET`. */
- VERIFY_ATKBD_ACK();
-
- /* The keyboard has flushed the buffer so no more keys. */
- VERIFY_NO_CHAR();
+ VERIFY_LPC_CHAR("\x01\x81");
/* Finish setting scan code 1 */
- keyboard_host_write(1, 0);
+ i8042_write_data(1);
VERIFY_ATKBD_ACK();
/* Key scanning should be restored. */
@@ -690,7 +683,7 @@ static int test_atkbd_set_scancode_with_key_press_before_set(void)
return EC_SUCCESS;
}
-static int test_atkbd_set_scancode_with_key_press_during_set(void)
+test_static int test_atkbd_set_scancode_with_key_press_during_set(void)
{
ENABLE_KEYSTROKE(1);
@@ -698,7 +691,7 @@ static int test_atkbd_set_scancode_with_key_press_during_set(void)
* ATKBD_CMD_SSCANSET should cause the keyboard to stop scanning, flush
* the keyboards output queue, and reset the typematic key.
*/
- keyboard_host_write(ATKBD_CMD_SSCANSET, 0);
+ i8042_write_data(ATKBD_CMD_SSCANSET);
VERIFY_ATKBD_ACK();
/* These keypresses should be dropped. */
@@ -711,7 +704,7 @@ static int test_atkbd_set_scancode_with_key_press_during_set(void)
VERIFY_LPC_CHAR("\x01\x81");
/* Finish setting scan code 1 */
- keyboard_host_write(1, 0);
+ i8042_write_data(1);
VERIFY_ATKBD_ACK();
/* Key scanning should be restored. */
@@ -722,7 +715,7 @@ static int test_atkbd_set_scancode_with_key_press_during_set(void)
return EC_SUCCESS;
}
-static int test_atkbd_echo(void)
+test_static int test_atkbd_echo(void)
{
i8042_write_data(ATKBD_CMD_DIAG_ECHO);
VERIFY_ATKBD_ACK();
@@ -732,7 +725,7 @@ static int test_atkbd_echo(void)
return EC_SUCCESS;
}
-static int test_atkbd_get_id(void)
+test_static int test_atkbd_get_id(void)
{
i8042_write_data(ATKBD_CMD_GETID);
VERIFY_ATKBD_ACK();
@@ -747,8 +740,10 @@ static int test_atkbd_get_id(void)
return EC_SUCCESS;
}
-static int test_atkbd_set_leds_keypress_during(void)
+test_static int test_atkbd_set_leds_keypress_during(void)
{
+ ENABLE_KEYSTROKE(1);
+
/* This should pause scanning. */
i8042_write_data(ATKBD_CMD_SETLEDS);
VERIFY_ATKBD_ACK();
@@ -756,16 +751,20 @@ static int test_atkbd_set_leds_keypress_during(void)
/* Simulate keypress while keyboard is waiting for option byte */
press_key(1, 1, 1);
press_key(1, 1, 0);
- /* FIXME: This is wrong, we shouldn't have any key strokes */
- VERIFY_LPC_CHAR("\x01\x81");
+
+ /* Scancode is kept in queue during SETLEDS. */
+ VERIFY_NO_CHAR();
i8042_write_data(0x01);
VERIFY_ATKBD_ACK();
+ /* Scancode previously queued should be sent now. */
+ VERIFY_LPC_CHAR("\x01\x81");
+
return EC_SUCCESS;
}
-static int test_atkbd_set_leds_abort_set(void)
+test_static int test_atkbd_set_leds_abort_set(void)
{
i8042_write_data(ATKBD_CMD_SETLEDS);
VERIFY_ATKBD_ACK();
@@ -785,7 +784,7 @@ static int test_atkbd_set_leds_abort_set(void)
return EC_SUCCESS;
}
-static int test_atkbd_set_ex_leds(void)
+test_static int test_atkbd_set_ex_leds(void)
{
i8042_write_data(ATKBD_CMD_EX_SETLEDS);
VERIFY_ATKBD_ACK();
@@ -801,9 +800,10 @@ static int test_atkbd_set_ex_leds(void)
return EC_SUCCESS;
}
-static int test_scancode_set2(void)
+test_static int test_scancode_set2(void)
{
SET_SCANCODE(2);
+ ENABLE_KEYSTROKE(1);
WRITE_CMD_BYTE(READ_CMD_BYTE() | I8042_XLATE);
press_key(1, 1, 1);
@@ -820,7 +820,7 @@ static int test_scancode_set2(void)
return EC_SUCCESS;
}
-static int test_power_button(void)
+test_static int test_power_button(void)
{
ENABLE_KEYSTROKE(0);
@@ -857,7 +857,7 @@ static int test_power_button(void)
return EC_SUCCESS;
}
-static int test_sysjump(void)
+test_static int test_sysjump(void)
{
SET_SCANCODE(2);
ENABLE_KEYSTROKE(1);
@@ -868,15 +868,17 @@ static int test_sysjump(void)
return EC_ERROR_UNKNOWN;
}
-static int test_sysjump_cont(void)
+test_static int test_sysjump_cont(void)
{
WRITE_CMD_BYTE(READ_CMD_BYTE() | I8042_XLATE);
+
press_key(1, 1, 1);
VERIFY_LPC_CHAR("\x01");
press_key(1, 1, 0);
VERIFY_LPC_CHAR("\x81");
WRITE_CMD_BYTE(READ_CMD_BYTE() & ~I8042_XLATE);
+
press_key(1, 1, 1);
VERIFY_LPC_CHAR("\x76");
press_key(1, 1, 0);
@@ -885,7 +887,7 @@ static int test_sysjump_cont(void)
return EC_SUCCESS;
}
-static const struct ec_response_keybd_config keybd_config = {
+test_static const struct ec_response_keybd_config keybd_config = {
.num_top_row_keys = 13,
.action_keys = {
TK_BACK, /* T1 */
@@ -910,7 +912,7 @@ board_vivaldi_keybd_config(void)
return &keybd_config;
}
-static int test_ec_cmd_get_keybd_config(void)
+test_static int test_ec_cmd_get_keybd_config(void)
{
struct ec_response_keybd_config resp;
int rv;
@@ -931,22 +933,25 @@ static int test_ec_cmd_get_keybd_config(void)
return EC_SUCCESS;
}
-static int test_vivaldi_top_keys(void)
+test_static int test_vivaldi_top_keys(void)
{
SET_SCANCODE(2);
/* Test REFRESH key */
WRITE_CMD_BYTE(READ_CMD_BYTE() | I8042_XLATE);
+
press_key(2, 3, 1); /* Press T2 */
VERIFY_LPC_CHAR("\xe0\x67"); /* Check REFRESH scancode in set-1 */
/* Test SNAPSHOT key */
WRITE_CMD_BYTE(READ_CMD_BYTE() | I8042_XLATE);
+
press_key(4, 3, 1); /* Press T2 */
VERIFY_LPC_CHAR("\xe0\x13"); /* Check SNAPSHOT scancode in set-1 */
/* Test VOL_UP key */
WRITE_CMD_BYTE(READ_CMD_BYTE() | I8042_XLATE);
+
press_key(5, 3, 1); /* Press T2 */
VERIFY_LPC_CHAR("\xe0\x30"); /* Check VOL_UP scancode in set-1 */