From b96e04d2eba142d293d57958edbcc8ed89cecf08 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Tue, 26 Jun 2012 13:45:01 +0800 Subject: [PATCH] Add a test of keyboard typematic This test checks when holding down a key for different length, typematic works correctly. BUG=chrome-os-partner:10287 TEST=Test passed. Change-Id: I401db73098a98dc3367cedde31f8ec1c5d5f047b Reviewed-on: https://gerrit.chromium.org/gerrit/26086 Commit-Ready: Vic Yang Reviewed-by: Vic Yang Tested-by: Vic Yang --- test/build.mk | 6 +++- test/typematic.py | 67 +++++++++++++++++++++++++++++++++++++++++ test/typematic.tasklist | 25 +++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 test/typematic.py create mode 100644 test/typematic.tasklist diff --git a/test/build.mk b/test/build.mk index f5a5548133..8a8f7f1e1b 100644 --- a/test/build.mk +++ b/test/build.mk @@ -7,7 +7,7 @@ # test-list=hello pingpong timer_calib timer_dos timer_jump mutex thermal -test-list+=power_button kb_deghost scancode +test-list+=power_button kb_deghost scancode typematic #disable: powerdemo pingpong-y=pingpong.o @@ -35,3 +35,7 @@ common-mock-kb_deghost-i8042.o=mock_i8042.o # Mock modules for 'scancode' chip-mock-scancode-keyboard_scan_stub.o=mock_keyboard_scan_stub.o common-mock-scancode-i8042.o=mock_i8042.o + +# Mock modules for 'typematic' +chip-mock-typematic-keyboard_scan_stub.o=mock_keyboard_scan_stub.o +common-mock-typematic-i8042.o=mock_i8042.o diff --git a/test/typematic.py b/test/typematic.py new file mode 100644 index 0000000000..97aa8e90ca --- /dev/null +++ b/test/typematic.py @@ -0,0 +1,67 @@ +# Copyright (c) 2012 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# Keyboard typematic test +# + +import time + +KEY_PRESS_MSG = "i8042 SEND" + +def check_no_output(helper, reg_ex): + success = False + try: + helper.wait_output(reg_ex, use_re=True, timeout=1) + except: + success = True + return success + +def expect_keypress(helper, cnt): + for i in xrange(cnt + 1): # Plus 1 break code + helper.wait_output(KEY_PRESS_MSG) + if not check_no_output(helper, KEY_PRESS_MSG): + return False + return True + +def test(helper): + # Wait for EC initialized + helper.wait_output("--- UART initialized") + + # Enable keyboard scanning + helper.ec_command("kbd enable") + + # Set typematic rate to 1000ms/500ms and hold down a key for 500ms + # Expect 1 keypress. + helper.ec_command("typematic 1000 500") + helper.ec_command("mockmatrix 1 1 1") + time.sleep(0.5) + helper.ec_command("mockmatrix 1 1 0") + if not expect_keypress(helper, 1): + return False + + # Hold down a key for 1200ms. Expect 2 keypress. + helper.ec_command("mockmatrix 1 1 1") + time.sleep(1.2) + helper.ec_command("mockmatrix 1 1 0") + if not expect_keypress(helper, 2): + return False + + # Hold down a key for 1700ms. Expect 3 keypress. + helper.ec_command("mockmatrix 1 1 1") + time.sleep(1.7) + helper.ec_command("mockmatrix 1 1 0") + if not expect_keypress(helper, 3): + return False + + # Hold down a key for 5400ms. Expect 10 keypress. + # Here we choose 5400ms to allow short delay when each keypress is sent. + # If we choose time length too close to 5000ms, we might end up getting + # only 9 keypress. + helper.ec_command("mockmatrix 1 1 1") + time.sleep(5.4) + helper.ec_command("mockmatrix 1 1 0") + if not expect_keypress(helper, 10): + return False + + return True # PASS ! diff --git a/test/typematic.tasklist b/test/typematic.tasklist new file mode 100644 index 0000000000..996cceeacb --- /dev/null +++ b/test/typematic.tasklist @@ -0,0 +1,25 @@ +/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/** + * List of enabled tasks in the priority order + * + * The first one has the lowest priority. + * + * For each task, use the macro TASK(n, r, d) where : + * 'n' in the name of the task + * 'r' in the main routine of the task + * 'd' in an opaque parameter passed to the routine at startup + */ +#define CONFIG_TASK_LIST \ + TASK(WATCHDOG, watchdog_task, NULL) \ + TASK(VBOOTHASH, vboot_hash_task, NULL) \ + TASK(PWM, pwm_task, NULL) \ + TASK(TYPEMATIC, keyboard_typematic_task, NULL) \ + TASK(X86POWER, x86_power_task, NULL) \ + TASK(I8042CMD, i8042_command_task, NULL) \ + TASK(KEYSCAN, keyboard_scan_task, NULL) \ + TASK(POWERBTN, power_button_task, NULL) \ + TASK(CONSOLE, console_task, NULL)