summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-04-12 15:07:56 +0800
committerChromeBot <chrome-bot@google.com>2013-04-13 03:12:21 -0700
commit2b3c02bf9f3b2ddda2ece73ca8291acf2000dd08 (patch)
tree9c5143239fbb54ffe33a7a67267fbc7b7e2bfbe7
parent25fb06ce516e15b9701eeb62664bc64f58f9a68e (diff)
downloadchrome-ec-2b3c02bf9f3b2ddda2ece73ca8291acf2000dd08.tar.gz
Add debounce test to kb_deghost and change name to kb_scan
To minimize the number of test binaries, we should put as many tests in a single binary as possible. This CL merges kb_debouncing and kb_deghosting and renames them to kb_scan. BUG=chrome-os-partner:18598 TEST=Run on Spring BRANCH=None Change-Id: I876363ba68c692a7af10badfa474a2ea9a9d002c Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/47980
-rw-r--r--test/build.mk14
-rw-r--r--test/kb_debounce.py95
-rw-r--r--test/kb_debounce.tasklist17
-rw-r--r--test/kb_deghost.c143
-rw-r--r--test/kb_deghost.py55
-rw-r--r--test/kb_scan.c246
-rw-r--r--test/kb_scan.tasklist (renamed from test/kb_deghost.tasklist)0
7 files changed, 251 insertions, 319 deletions
diff --git a/test/build.mk b/test/build.mk
index 542178c600..2fcdd3414d 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -7,18 +7,18 @@
#
test-list=hello pingpong timer_calib timer_dos timer_jump mutex thermal
-test-list+=power_button kb_deghost kb_debounce scancode typematic charging
+test-list+=power_button kb_scan scancode typematic charging
test-list+=flash_overwrite flash_rw_erase utils
#disable: powerdemo
-kb_deghost-y=kb_deghost.o
+flash_overwrite-y=flash.o
+flash_rw_erase-y=flash.o
+kb_scan-y=kb_scan.o
+mutex-y=mutex.o
pingpong-y=pingpong.o
powerdemo-y=powerdemo.o
timer_calib-y=timer_calib.o
timer_dos-y=timer_dos.o
-mutex-y=mutex.o
-flash_overwrite-y=flash.o
-flash_rw_erase-y=flash.o
utils-y=utils.o
# Mock modules for 'thermal'
@@ -41,10 +41,6 @@ common-mock-scancode-i8042.o=mock_i8042.o
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
-
# Mock modules for 'charging'
chip-mock-charging-gpio.o=mock_gpio.o
common-mock-charging-x86_power.o=mock_x86_power.o
diff --git a/test/kb_debounce.py b/test/kb_debounce.py
deleted file mode 100644
index 72d093afc4..0000000000
--- a/test/kb_debounce.py
+++ /dev/null
@@ -1,95 +0,0 @@
-# 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 state: (?P<km>[0-9\s-]*)\]"
-
-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 helper.check_no_output(KEYPRESS_REGEX, use_re=True):
- 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 helper.check_no_output(KEYPRESS_REGEX, use_re=True):
- 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 helper.check_no_output(KEYPRESS_REGEX, use_re=True):
- 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
deleted file mode 100644
index 26cfc53453..0000000000
--- a/test/kb_debounce.tasklist
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Copyright (c) 2013 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_TEST(n, r, d, s) 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
- * 's' is the stack size in bytes; must be a multiple of 8
- */
-#define CONFIG_TEST_TASK_LIST /* No test task */
diff --git a/test/kb_deghost.c b/test/kb_deghost.c
deleted file mode 100644
index 3a4384bed4..0000000000
--- a/test/kb_deghost.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/* Copyright (c) 2013 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.
- * Copyright 2013 Google Inc.
- *
- * Tasks for keyboard scan deghosting.
- */
-
-#include "common.h"
-#include "console.h"
-#include "keyboard_raw.h"
-#include "keyboard_scan.h"
-#include "task.h"
-#include "timer.h"
-#include "util.h"
-
-#define KEYDOWN_DELAY_MS 10
-#define KEYDOWN_RETRY 10
-#define NO_KEYDOWN_DELAY_MS 200
-
-#define TEST(n) \
- do { \
- if (!n()) { \
- ccprintf("%s failed.\n", #n); \
- return EC_ERROR_UNKNOWN; \
- } \
- } while (0)
-
-uint8_t mock_state[KEYBOARD_COLS];
-int column_driven;
-int fifo_add_count;
-
-void keyboard_raw_drive_column(int out)
-{
- column_driven = out;
-}
-
-int keyboard_raw_read_rows(void)
-{
- int i;
- int r = 0;
-
- if (column_driven == KEYBOARD_COLUMN_NONE) {
- return 0;
- } else if (column_driven == KEYBOARD_COLUMN_ALL) {
- for (i = 0; i < KEYBOARD_COLS; ++i)
- r |= mock_state[i];
- return r;
- } else {
- return mock_state[column_driven];
- }
-}
-
-int keyboard_fifo_add(const uint8_t *buffp)
-{
- fifo_add_count++;
- return EC_SUCCESS;
-}
-
-void mock_key(int r, int c, int keydown)
-{
- ccprintf("%s (%d, %d)\n", keydown ? "Pressing" : "Releasing", r, c);
- if (keydown)
- mock_state[c] |= (1 << r);
- else
- mock_state[c] &= ~(1 << r);
-}
-
-int expect_keychange(void)
-{
- int old_count = fifo_add_count;
- int retry = KEYDOWN_RETRY;
- task_wake(TASK_ID_KEYSCAN);
- while (retry--) {
- msleep(KEYDOWN_DELAY_MS);
- if (fifo_add_count > old_count)
- return 1;
- }
- return 0;
-}
-
-int expect_no_keychange(void)
-{
- int old_count = fifo_add_count;
- task_wake(TASK_ID_KEYSCAN);
- msleep(NO_KEYDOWN_DELAY_MS);
- return fifo_add_count == old_count;
-}
-
-int deghost_test(void)
-{
- /* Test we can detect a keypress */
- mock_key(1, 1, 1);
- TEST(expect_keychange);
- mock_key(1, 1, 0);
- TEST(expect_keychange);
-
- /* (1, 1) (1, 2) (2, 1) (2, 2) form ghosting keys */
- mock_key(1, 1, 1);
- TEST(expect_keychange);
- mock_key(2, 2, 1);
- TEST(expect_keychange);
- mock_key(1, 2, 1);
- mock_key(2, 1, 1);
- TEST(expect_no_keychange);
- mock_key(2, 1, 0);
- mock_key(1, 2, 0);
- TEST(expect_no_keychange);
- mock_key(2, 2, 0);
- TEST(expect_keychange);
- mock_key(1, 1, 0);
- TEST(expect_keychange);
-
- /* (1, 1) (2, 0) (2, 1) don't form ghosting keys */
- mock_key(1, 1, 1);
- TEST(expect_keychange);
- mock_key(2, 0, 1);
- TEST(expect_keychange);
- mock_key(1, 0, 1);
- mock_key(2, 1, 1);
- TEST(expect_keychange);
- mock_key(1, 0, 0);
- mock_key(2, 1, 0);
- TEST(expect_keychange);
- mock_key(2, 0, 0);
- TEST(expect_keychange);
- mock_key(1, 1, 0);
- TEST(expect_keychange);
-
- return EC_SUCCESS;
-}
-
-static int command_run_test(int argc, char **argv)
-{
- int r = deghost_test();
- if (r == EC_SUCCESS)
- ccprintf("Pass!\n");
- else
- ccprintf("Fail!\n");
- return r;
-}
-DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
- NULL, NULL, NULL);
diff --git a/test/kb_deghost.py b/test/kb_deghost.py
deleted file mode 100644
index b7ad9973c7..0000000000
--- a/test/kb_deghost.py
+++ /dev/null
@@ -1,55 +0,0 @@
-# Copyright (c) 2011 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 deghost test
-#
-
-import time
-
-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 (1, 1) and (2, 2)
- helper.ec_command("mockmatrix 1 1 1")
- helper.wait_output("KB raw")
- helper.ec_command("mockmatrix 2 2 1")
- helper.wait_output("KB raw")
-
- # Now press (1, 2) which should cause (2, 1) to be pressed also
- # Expect this is ignored
- helper.ec_command("mockmatrix 2 1 1")
- helper.ec_command("mockmatrix 1 2 1")
- if not helper.check_no_output("KB raw"):
- return False
- # Now release (1, 2) which should cause (2, 1) to be released also
- # Expect this is ignored
- helper.ec_command("mockmatrix 2 1 0")
- helper.ec_command("mockmatrix 1 2 0")
- if not helper.check_no_output("KB raw"):
- return False
-
- # Done testing with (1, 1) and (2, 2). Release them.
- helper.ec_command("mockmatrix 1 1 0")
- helper.wait_output("KB raw")
- helper.ec_command("mockmatrix 2 2 0")
- helper.wait_output("KB raw")
-
- # Press (0, 2) and (1, 1)
- helper.ec_command("mockmatrix 0 2 1")
- helper.wait_output("KB raw")
- helper.ec_command("mockmatrix 1 1 1")
- helper.wait_output("KB raw")
-
- # (0, 1) maps to no key. Pressing (1, 2) and (0, 1) should not be
- # deghosted.
- helper.ec_command("mockmatrix 1 2 1")
- helper.ec_command("mockmatrix 0 1 1")
- helper.wait_output("KB raw")
-
- return True # PASS !
diff --git a/test/kb_scan.c b/test/kb_scan.c
new file mode 100644
index 0000000000..3458d96724
--- /dev/null
+++ b/test/kb_scan.c
@@ -0,0 +1,246 @@
+/* Copyright (c) 2013 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.
+ * Copyright 2013 Google Inc.
+ *
+ * Tests for keyboard scan deghosting and debouncing.
+ */
+
+#include "common.h"
+#include "console.h"
+#include "keyboard_raw.h"
+#include "keyboard_scan.h"
+#include "task.h"
+#include "timer.h"
+#include "util.h"
+
+#define KEYDOWN_DELAY_MS 10
+#define KEYDOWN_RETRY 10
+#define NO_KEYDOWN_DELAY_MS 200
+
+#define TEST_ASSERT(n) \
+ do { \
+ if (n() != EC_SUCCESS) { \
+ ccprintf("%s failed.\n", #n); \
+ return EC_ERROR_UNKNOWN; \
+ } \
+ } while (0)
+
+#define RUN_TEST(n) \
+ do { \
+ ccprintf("Running %s...", #n); \
+ cflush(); \
+ if (n() == EC_SUCCESS) { \
+ ccputs("OK\n"); \
+ } else { \
+ ccputs("Fail\n"); \
+ error_count++; \
+ } \
+ } while (0)
+
+#define CHECK_KEY_COUNT(old, expected) \
+ do { \
+ if (verify_key_presses(old, expected) != EC_SUCCESS) \
+ return EC_ERROR_UNKNOWN; \
+ old = fifo_add_count; \
+ } while (0)
+
+static uint8_t mock_state[KEYBOARD_COLS];
+static int column_driven;
+static int fifo_add_count;
+static int error_count;
+
+void keyboard_raw_drive_column(int out)
+{
+ column_driven = out;
+}
+
+int keyboard_raw_read_rows(void)
+{
+ int i;
+ int r = 0;
+
+ if (column_driven == KEYBOARD_COLUMN_NONE) {
+ return 0;
+ } else if (column_driven == KEYBOARD_COLUMN_ALL) {
+ for (i = 0; i < KEYBOARD_COLS; ++i)
+ r |= mock_state[i];
+ return r;
+ } else {
+ return mock_state[column_driven];
+ }
+}
+
+int keyboard_fifo_add(const uint8_t *buffp)
+{
+ fifo_add_count++;
+ return EC_SUCCESS;
+}
+
+void mock_key(int r, int c, int keydown)
+{
+ ccprintf("%s (%d, %d)\n", keydown ? "Pressing" : "Releasing", r, c);
+ if (keydown)
+ mock_state[c] |= (1 << r);
+ else
+ mock_state[c] &= ~(1 << r);
+}
+
+int expect_keychange(void)
+{
+ int old_count = fifo_add_count;
+ int retry = KEYDOWN_RETRY;
+ task_wake(TASK_ID_KEYSCAN);
+ while (retry--) {
+ msleep(KEYDOWN_DELAY_MS);
+ if (fifo_add_count > old_count)
+ return EC_SUCCESS;
+ }
+ return EC_ERROR_UNKNOWN;
+}
+
+int expect_no_keychange(void)
+{
+ int old_count = fifo_add_count;
+ task_wake(TASK_ID_KEYSCAN);
+ msleep(NO_KEYDOWN_DELAY_MS);
+ return (fifo_add_count == old_count) ? EC_SUCCESS : EC_ERROR_UNKNOWN;
+}
+
+int verify_key_presses(int old, int expected)
+{
+ int retry = KEYDOWN_RETRY;
+
+ if (expected == 0) {
+ msleep(NO_KEYDOWN_DELAY_MS);
+ return (fifo_add_count == old) ? EC_SUCCESS : EC_ERROR_UNKNOWN;
+ } else {
+ while (retry--) {
+ msleep(KEYDOWN_DELAY_MS);
+ if (fifo_add_count == old + expected)
+ return EC_SUCCESS;
+ }
+ return EC_ERROR_UNKNOWN;
+ }
+}
+
+int deghost_test(void)
+{
+ /* Test we can detect a keypress */
+ mock_key(1, 1, 1);
+ TEST_ASSERT(expect_keychange);
+ mock_key(1, 1, 0);
+ TEST_ASSERT(expect_keychange);
+
+ /* (1, 1) (1, 2) (2, 1) (2, 2) form ghosting keys */
+ mock_key(1, 1, 1);
+ TEST_ASSERT(expect_keychange);
+ mock_key(2, 2, 1);
+ TEST_ASSERT(expect_keychange);
+ mock_key(1, 2, 1);
+ mock_key(2, 1, 1);
+ TEST_ASSERT(expect_no_keychange);
+ mock_key(2, 1, 0);
+ mock_key(1, 2, 0);
+ TEST_ASSERT(expect_no_keychange);
+ mock_key(2, 2, 0);
+ TEST_ASSERT(expect_keychange);
+ mock_key(1, 1, 0);
+ TEST_ASSERT(expect_keychange);
+
+ /* (1, 1) (2, 0) (2, 1) don't form ghosting keys */
+ mock_key(1, 1, 1);
+ TEST_ASSERT(expect_keychange);
+ mock_key(2, 0, 1);
+ TEST_ASSERT(expect_keychange);
+ mock_key(1, 0, 1);
+ mock_key(2, 1, 1);
+ TEST_ASSERT(expect_keychange);
+ mock_key(1, 0, 0);
+ mock_key(2, 1, 0);
+ TEST_ASSERT(expect_keychange);
+ mock_key(2, 0, 0);
+ TEST_ASSERT(expect_keychange);
+ mock_key(1, 1, 0);
+ TEST_ASSERT(expect_keychange);
+
+ return EC_SUCCESS;
+}
+
+int debounce_test(void)
+{
+ int old_count = fifo_add_count;
+ mock_key(1, 1, 1);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(1, 1, 0);
+ task_wake(TASK_ID_KEYSCAN);
+ CHECK_KEY_COUNT(old_count, 0);
+
+ mock_key(1, 1, 1);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(1, 1, 0);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(1, 1, 1);
+ task_wake(TASK_ID_KEYSCAN);
+ CHECK_KEY_COUNT(old_count, 1);
+
+ mock_key(1, 1, 0);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(1, 1, 1);
+ task_wake(TASK_ID_KEYSCAN);
+ CHECK_KEY_COUNT(old_count, 0);
+
+ mock_key(2, 2, 1);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(2, 2, 0);
+ task_wake(TASK_ID_KEYSCAN);
+ CHECK_KEY_COUNT(old_count, 0);
+
+ mock_key(2, 2, 1);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(2, 2, 0);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(2, 2, 1);
+ task_wake(TASK_ID_KEYSCAN);
+ CHECK_KEY_COUNT(old_count, 1);
+
+ mock_key(1, 1, 0);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(1, 1, 1);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(1, 1, 0);
+ task_wake(TASK_ID_KEYSCAN);
+ CHECK_KEY_COUNT(old_count, 1);
+
+ mock_key(2, 2, 0);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(2, 2, 1);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(2, 2, 0);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(2, 2, 1);
+ task_wake(TASK_ID_KEYSCAN);
+ mock_key(2, 2, 0);
+ task_wake(TASK_ID_KEYSCAN);
+ CHECK_KEY_COUNT(old_count, 1);
+
+ return EC_SUCCESS;
+}
+
+static int command_run_test(int argc, char **argv)
+{
+ error_count = 0;
+
+ RUN_TEST(deghost_test);
+ RUN_TEST(debounce_test);
+
+ if (error_count == 0) {
+ ccprintf("Pass!\n");
+ return EC_SUCCESS;
+ } else {
+ ccprintf("Fail!\n");
+ return EC_ERROR_UNKNOWN;
+ }
+}
+DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
+ NULL, NULL, NULL);
diff --git a/test/kb_deghost.tasklist b/test/kb_scan.tasklist
index 2368d7bc52..2368d7bc52 100644
--- a/test/kb_deghost.tasklist
+++ b/test/kb_scan.tasklist