Add boot key test

This checks boot key combination like Power-F3-ESC and Power-F3-Down can
be properly detected.

BUG=chrome-os-partner:19236
TEST=Pass kb_scan test
BRANCH=None

Change-Id: I180918977299219a8421798dac2ab9fed84ef9a2
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167802
This commit is contained in:
Vic Yang
2013-09-02 13:55:02 +08:00
committed by chrome-internal-fetch
parent 6c3be20539
commit b448746bac
6 changed files with 100 additions and 5 deletions

View File

@@ -20,6 +20,9 @@ int __test_error_count;
/* Weak reference function as an entry point for unit test */
test_mockable void run_test(void) { }
/* Default dummy test init */
test_mockable void test_init(void) { }
#ifdef TEST_COVERAGE
extern void __gcov_flush(void);

View File

@@ -8,6 +8,7 @@
#include "console.h"
#include "flash.h"
#include "hooks.h"
#include "keyboard_scan.h"
#include "system.h"
#include "task.h"
#include "test_util.h"
@@ -35,7 +36,12 @@ int main(int argc, char **argv)
system_pre_init();
system_common_pre_init();
test_init();
timer_init();
#ifdef HAS_TASK_KEYSCAN
keyboard_scan_init();
#endif
hook_init();
uart_init();

View File

@@ -81,6 +81,12 @@ enum test_state_t {
/* Hooks gcov_flush() for test coverage report generation */
void register_test_end_hook(void);
/*
* Test initialization. This is called after all _pre_init() calls and before
* all _init() calls.
*/
void test_init(void);
/* Test entry point */
void run_test(void);

View File

@@ -61,7 +61,7 @@ static void non_deferred_func(void)
deferred_call_count++;
}
static int test_init(void)
static int test_init_hook(void)
{
TEST_ASSERT(init_hook_count == 1);
return EC_SUCCESS;
@@ -133,7 +133,7 @@ void run_test(void)
{
test_reset();
RUN_TEST(test_init);
RUN_TEST(test_init_hook);
RUN_TEST(test_ticks);
RUN_TEST(test_priority);
RUN_TEST(test_deferred);

View File

@@ -13,6 +13,7 @@
#include "keyboard_raw.h"
#include "keyboard_scan.h"
#include "lid_switch.h"
#include "system.h"
#include "task.h"
#include "test_util.h"
#include "timer.h"
@@ -340,7 +341,34 @@ static int lid_test(void)
}
#endif
void run_test(void)
static int test_check_boot_esc(void)
{
TEST_CHECK(keyboard_scan_get_boot_key() == BOOT_KEY_ESC);
}
static int test_check_boot_down(void)
{
TEST_CHECK(keyboard_scan_get_boot_key() == BOOT_KEY_DOWN_ARROW);
}
void test_init(void)
{
uint32_t state = system_get_scratchpad();
if (state & TEST_STATE_MASK(TEST_STATE_STEP_2)) {
/* Power-F3-ESC */
system_set_reset_flags(system_get_reset_flags() |
RESET_FLAG_RESET_PIN);
mock_key(1, 1, 1);
} else if (state & TEST_STATE_MASK(TEST_STATE_STEP_3)) {
/* Power-F3-Down */
system_set_reset_flags(system_get_reset_flags() |
RESET_FLAG_RESET_PIN);
mock_key(6, 11, 1);
}
}
static void run_test_step1(void)
{
lid_open = 1;
test_reset();
@@ -355,5 +383,56 @@ void run_test(void)
RUN_TEST(lid_test);
#endif
test_print_result();
if (test_get_error_count())
test_reboot_to_next_step(TEST_STATE_FAILED);
else
test_reboot_to_next_step(TEST_STATE_STEP_2);
}
static void run_test_step2(void)
{
lid_open = 1;
test_reset();
RUN_TEST(test_check_boot_esc);
if (test_get_error_count())
test_reboot_to_next_step(TEST_STATE_FAILED);
else
test_reboot_to_next_step(TEST_STATE_STEP_3);
}
static void run_test_step3(void)
{
lid_open = 1;
test_reset();
RUN_TEST(test_check_boot_down);
if (test_get_error_count())
test_reboot_to_next_step(TEST_STATE_FAILED);
else
test_reboot_to_next_step(TEST_STATE_PASSED);
}
void test_run_step(uint32_t state)
{
if (state & TEST_STATE_MASK(TEST_STATE_STEP_1))
run_test_step1();
else if (state & TEST_STATE_MASK(TEST_STATE_STEP_2))
run_test_step2();
else if (state & TEST_STATE_MASK(TEST_STATE_STEP_3))
run_test_step3();
}
int test_task(void *data)
{
test_run_multistep();
return EC_SUCCESS;
}
void run_test(void)
{
msleep(30); /* Wait for TASK_ID_TEST to initialize */
task_wake(TASK_ID_TEST);
}

View File

@@ -16,4 +16,5 @@
*/
#define CONFIG_TEST_TASK_LIST \
TASK_TEST(KEYSCAN, keyboard_scan_task, NULL, 256) \
TASK_TEST(CHIPSET, chipset_task, NULL, TASK_STACK_SIZE)
TASK_TEST(CHIPSET, chipset_task, NULL, TASK_STACK_SIZE) \
TASK_TEST(TEST, test_task, NULL, TASK_STACK_SIZE)