summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2012-06-22 16:00:04 +0800
committerGerrit <chrome-bot@google.com>2012-06-27 02:51:42 -0700
commit0909a66d90f1397c69c47fb74bcdb83606e9f273 (patch)
treee9eb707b18e87e17206876daad38549827def2bb /test
parentb96e04d2eba142d293d57958edbcc8ed89cecf08 (diff)
downloadchrome-ec-0909a66d90f1397c69c47fb74bcdb83606e9f273.tar.gz
Add a test of keyboard debouncing
This test checks keyboard debouncing works correctly. BUG=chrome-os-partner:10284 TEST=Test passed Change-Id: I0c984ecc9444b149da580ff0775cc81245b21a1e Reviewed-on: https://gerrit.chromium.org/gerrit/26021 Commit-Ready: Vic Yang <victoryang@chromium.org> Reviewed-by: Vic Yang <victoryang@chromium.org> Tested-by: Vic Yang <victoryang@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/build.mk6
-rw-r--r--test/kb_debounce.py103
-rw-r--r--test/kb_debounce.tasklist24
3 files changed, 132 insertions, 1 deletions
diff --git a/test/build.mk b/test/build.mk
index 8a8f7f1e1b..b950372ec7 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 typematic
+test-list+=power_button kb_deghost kb_debounce scancode typematic
#disable: powerdemo
pingpong-y=pingpong.o
@@ -39,3 +39,7 @@ 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
+
+# Mock modules for 'kb_debounce'
+chip-mock-kb_debounce-keyboard_scan_stub.o=mock_keyboard_scan_stub.o
+common-mock-kb_debounce-i8042.o=mock_i8042.o
diff --git a/test/kb_debounce.py b/test/kb_debounce.py
new file mode 100644
index 0000000000..4ca8b616c3
--- /dev/null
+++ b/test/kb_debounce.py
@@ -0,0 +1,103 @@
+# 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 debounce test
+#
+
+import time
+
+SHORTER_THAN_DEBOUNCE_TIME = 0.005 # 5ms
+LONGER_THAN_DEBOUNCE_TIME = 0.020 # 20ms
+KEYPRESS_REGEX = "\[KB raw state: (?P<km>[0-9\s-]*)\]"
+
+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 consume_output(helper, reg_ex):
+ done = False
+ while not done:
+ try:
+ helper.wait_output(reg_ex, use_re=True, timeout=1)
+ except:
+ done = True
+
+def get_key_count(s):
+ key_count_map = {'1': 1, '2': 1, '3': 2, '4': 1, '5': 2, '6': 2, '7': 3,
+ '8': 1, '9': 2, 'a': 2, 'b': 3, 'c': 2, 'd': 3, 'e': 3,
+ 'e': 4, '-': 0, ' ': 0, '0': 0}
+ return reduce(lambda x, y: x + key_count_map[y], s, 0)
+
+def expect_key_count(helper, cnt):
+ s = helper.wait_output(KEYPRESS_REGEX, use_re=True, timeout=1)["km"]
+ act_cnt = get_key_count(s)
+ if act_cnt != cnt:
+ helper.trace("Expecting %d key press, got %d." % (cnt, act_cnt))
+ return False
+ else:
+ return True
+
+def test(helper):
+ # Wait for EC initialized
+ helper.wait_output("--- UART initialized")
+
+ # Enable keyboard scanning and disable typematic
+ helper.ec_command("kbd enable")
+ helper.ec_command("typematic 1000000 1000000")
+
+ # Press for a short period and check this is ignored
+ consume_output(helper, KEYPRESS_REGEX)
+ helper.ec_command("mockmatrix 1 1 1")
+ time.sleep(SHORTER_THAN_DEBOUNCE_TIME)
+ helper.ec_command("mockmatrix 1 1 0")
+ if not check_no_output(helper, KEYPRESS_REGEX):
+ return False
+
+ # Press for a longer period and check keypress is accepted
+ consume_output(helper, KEYPRESS_REGEX)
+ helper.ec_command("mockmatrix 1 1 1")
+ time.sleep(LONGER_THAN_DEBOUNCE_TIME)
+ helper.ec_command("mockmatrix 1 1 0")
+ if not expect_key_count(helper, 1): # Press
+ return False
+ if not expect_key_count(helper, 0): # Release
+ return False
+
+ # Press and release for a short period, and then press for a longer
+ # period and check exactly one keypress is accepted
+ consume_output(helper, KEYPRESS_REGEX)
+ helper.ec_command("mockmatrix 1 1 1")
+ time.sleep(SHORTER_THAN_DEBOUNCE_TIME)
+ helper.ec_command("mockmatrix 1 1 0")
+ time.sleep(SHORTER_THAN_DEBOUNCE_TIME)
+ helper.ec_command("mockmatrix 1 1 1")
+ time.sleep(LONGER_THAN_DEBOUNCE_TIME)
+ helper.ec_command("mockmatrix 1 1 0")
+ if not expect_key_count(helper, 1): # Press
+ return False
+ if not expect_key_count(helper, 0): # Release
+ return False
+ if not check_no_output(helper, KEYPRESS_REGEX):
+ return False
+
+ # Hold down a key and press another key for a short period. Expect
+ # this event is ignored
+ consume_output(helper, KEYPRESS_REGEX)
+ helper.ec_command("mockmatrix 1 1 1")
+ if not expect_key_count(helper, 1):
+ return False
+ helper.ec_command("mockmatrix 2 2 1")
+ time.sleep(SHORTER_THAN_DEBOUNCE_TIME)
+ helper.ec_command("mockmatrix 2 2 0")
+ if not check_no_output(helper, KEYPRESS_REGEX):
+ return False
+ helper.ec_command("mockmatrix 1 1 0")
+ if not expect_key_count(helper, 0):
+ return False
+
+ return True # Pass!
diff --git a/test/kb_debounce.tasklist b/test/kb_debounce.tasklist
new file mode 100644
index 0000000000..5c97164904
--- /dev/null
+++ b/test/kb_debounce.tasklist
@@ -0,0 +1,24 @@
+/* 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(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)