diff options
author | Tristan Honscheid <honscheid@google.com> | 2022-09-02 16:16:25 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-09 17:59:11 +0000 |
commit | 3d2a1c9fb1ebb38a0e5ca291e237d569da3bb904 (patch) | |
tree | 38b55d5844d1c1b565371eff6110cafac68b1b85 | |
parent | 3e456353c4f4f1c1c26c42ed6ac0298d04294971 (diff) | |
download | chrome-ec-3d2a1c9fb1ebb38a0e5ca291e237d569da3bb904.tar.gz |
zephyr: tests: Test handling of special key combos in `keyboard_scan.c`
Test that VOL_UP + ALT + {R|H} cause AP reboot and hibernate,
respectively.
BRANCH=None
BUG=b:244606945
TEST=./twister
Signed-off-by: Tristan Honscheid <honscheid@google.com>
Change-Id: Ic5d927fe830acbd9f6f33a0e436d6ed7c4301fce
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3872728
Reviewed-by: Yuval Peress <peress@google.com>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r-- | common/system.c | 3 | ||||
-rw-r--r-- | power/qcom.c | 2 | ||||
-rw-r--r-- | zephyr/test/drivers/keyboard_scan/src/keyboard_scan.c | 62 |
3 files changed, 64 insertions, 3 deletions
diff --git a/common/system.c b/common/system.c index acb31c3774..b47cd62cb3 100644 --- a/common/system.c +++ b/common/system.c @@ -1042,7 +1042,8 @@ static int handle_pending_reboot(enum ec_reboot_cmd cmd) } } -void system_enter_hibernate(uint32_t seconds, uint32_t microseconds) +test_mockable void system_enter_hibernate(uint32_t seconds, + uint32_t microseconds) { if (!IS_ENABLED(CONFIG_HIBERNATE)) return; diff --git a/power/qcom.c b/power/qcom.c index 6a98350814..f144468970 100644 --- a/power/qcom.c +++ b/power/qcom.c @@ -887,7 +887,7 @@ static void check_for_warm_reset_event(void) } } -void chipset_reset(enum chipset_shutdown_reason reason) +test_mockable void chipset_reset(enum chipset_shutdown_reason reason) { CPRINTS("%s(%d)", __func__, reason); report_ap_reset(reason); diff --git a/zephyr/test/drivers/keyboard_scan/src/keyboard_scan.c b/zephyr/test/drivers/keyboard_scan/src/keyboard_scan.c index f18c0e0e3c..fe049490c0 100644 --- a/zephyr/test/drivers/keyboard_scan/src/keyboard_scan.c +++ b/zephyr/test/drivers/keyboard_scan/src/keyboard_scan.c @@ -339,6 +339,64 @@ ZTEST(keyboard_scan, host_command_simulate__key_press) zassert_false(key_state_changed_fake.arg2_history[1], NULL); } +FAKE_VOID_FUNC(system_enter_hibernate, uint32_t, uint32_t); +FAKE_VOID_FUNC(chipset_reset, int); + +ZTEST(keyboard_scan, special_key_combos) +{ + system_is_locked_fake.return_val = 0; + zassume_false(system_is_locked(), "Expecting unlocked system."); + + /* Set the volume up key coordinates to something arbitrary */ + int vol_up_col = 1; + int vol_up_row = 2; + + set_vol_up_key(vol_up_row, vol_up_col); + + /* Vol up and the alt keys must be in different columns */ + zassume_false(vol_up_col == KEYBOARD_COL_LEFT_ALT, NULL); + + /* Hold down volume up, left alt (either alt key works), and R */ + zassert_ok(send_keypress_host_command(vol_up_col, vol_up_row, 1), NULL); + zassert_ok(send_keypress_host_command(KEYBOARD_COL_LEFT_ALT, + KEYBOARD_ROW_LEFT_ALT, 1), + NULL); + zassert_ok(send_keypress_host_command(KEYBOARD_COL_KEY_R, + KEYBOARD_ROW_KEY_R, 1), + NULL); + + k_sleep(K_MSEC(100)); + + /* Release R and the press H */ + zassert_ok(send_keypress_host_command(KEYBOARD_COL_KEY_R, + KEYBOARD_ROW_KEY_R, 0), + NULL); + zassert_ok(send_keypress_host_command(KEYBOARD_COL_KEY_H, + KEYBOARD_ROW_KEY_H, 1), + NULL); + + k_sleep(K_MSEC(100)); + + /* Release all */ + zassert_ok(send_keypress_host_command(vol_up_col, vol_up_row, 0), NULL); + zassert_ok(send_keypress_host_command(KEYBOARD_COL_LEFT_ALT, + KEYBOARD_ROW_LEFT_ALT, 0), + NULL); + zassert_ok(send_keypress_host_command(KEYBOARD_COL_KEY_H, + KEYBOARD_ROW_KEY_H, 0), + NULL); + + /* Check that a reboot was requested (VOLUP + ALT + R) */ + zassert_equal(1, chipset_reset_fake.call_count, + "Did not try to reboot"); + zassert_equal(CHIPSET_RESET_KB_WARM_REBOOT, + chipset_reset_fake.arg0_history[0], NULL); + + /* Check that we called system_enter_hibernate (VOLUP + ALT + H) */ + zassert_equal(1, system_enter_hibernate_fake.call_count, + "Did not enter hibernate"); +} + static void reset_keyboard(void *data) { ARG_UNUSED(data); @@ -351,9 +409,11 @@ static void reset_keyboard(void *data) /* Turn off key state change printing */ keyboard_scan_set_print_state_changes(0); - /* Reset the key state callback and system locked mocks */ + /* Reset all mocks. */ RESET_FAKE(key_state_changed); RESET_FAKE(system_is_locked); + RESET_FAKE(system_enter_hibernate); + RESET_FAKE(chipset_reset); /* Be locked by default */ system_is_locked_fake.return_val = 1; |