diff options
author | Vic Yang <victoryang@chromium.org> | 2013-04-11 16:11:45 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-04-11 11:29:32 -0700 |
commit | 4adcb45f2c067292b470a1c9506968e8cf7ac23a (patch) | |
tree | 1008c19830a703b529b2219ea7b206a84b6504e3 /test | |
parent | 5018f1d9d6adfd02d967fea32ab3d9e0ba11b443 (diff) | |
download | chrome-ec-4adcb45f2c067292b470a1c9506968e8cf7ac23a.tar.gz |
Fix kb_deghost test
BUG=chrome-os-partner:18598
TEST=Run test on Spring
BRANCH=none
Change-Id: Ia95ba6144dbdac0ffe77f6aef9c4ed948de181d8
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/47841
Diffstat (limited to 'test')
-rw-r--r-- | test/build.mk | 1 | ||||
-rw-r--r-- | test/kb_deghost.c | 143 | ||||
-rw-r--r-- | test/kb_deghost.tasklist | 4 |
3 files changed, 147 insertions, 1 deletions
diff --git a/test/build.mk b/test/build.mk index a38cce29e8..4a6fa6299a 100644 --- a/test/build.mk +++ b/test/build.mk @@ -11,6 +11,7 @@ test-list+=power_button kb_deghost kb_debounce scancode typematic charging test-list+=flash_overwrite flash_rw_erase #disable: powerdemo +kb_deghost-y=kb_deghost.o pingpong-y=pingpong.o powerdemo-y=powerdemo.o timer_calib-y=timer_calib.o diff --git a/test/kb_deghost.c b/test/kb_deghost.c new file mode 100644 index 0000000000..3a4384bed4 --- /dev/null +++ b/test/kb_deghost.c @@ -0,0 +1,143 @@ +/* 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.tasklist b/test/kb_deghost.tasklist index 26cfc53453..2368d7bc52 100644 --- a/test/kb_deghost.tasklist +++ b/test/kb_deghost.tasklist @@ -14,4 +14,6 @@ * '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 */ +#define CONFIG_TEST_TASK_LIST \ + TASK_TEST(KEYSCAN, keyboard_scan_task, NULL, 256) \ + TASK_TEST(CHIPSET, chipset_task, NULL, TASK_STACK_SIZE) |