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>
This commit is contained in:
Vic Yang
2012-06-22 16:00:04 +08:00
committed by Gerrit
parent b96e04d2eb
commit 0909a66d90
3 changed files with 132 additions and 1 deletions

View File

@@ -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

103
test/kb_debounce.py Normal file
View File

@@ -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!

24
test/kb_debounce.tasklist Normal file
View File

@@ -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)