diff options
-rw-r--r-- | common/test_util.c | 3 | ||||
-rw-r--r-- | core/host/main.c | 6 | ||||
-rw-r--r-- | include/test_util.h | 6 | ||||
-rw-r--r-- | test/hooks.c | 4 | ||||
-rw-r--r-- | test/kb_scan.c | 83 | ||||
-rw-r--r-- | test/kb_scan.tasklist | 3 |
6 files changed, 100 insertions, 5 deletions
diff --git a/common/test_util.c b/common/test_util.c index f613c62813..58a6e5e05c 100644 --- a/common/test_util.c +++ b/common/test_util.c @@ -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); diff --git a/core/host/main.c b/core/host/main.c index ed8985670b..2e01267626 100644 --- a/core/host/main.c +++ b/core/host/main.c @@ -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(); diff --git a/include/test_util.h b/include/test_util.h index 367a602ae1..f2b68c5981 100644 --- a/include/test_util.h +++ b/include/test_util.h @@ -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); diff --git a/test/hooks.c b/test/hooks.c index 679cf584d3..e688e610c2 100644 --- a/test/hooks.c +++ b/test/hooks.c @@ -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); diff --git a/test/kb_scan.c b/test/kb_scan.c index 79dcd79576..a273a20466 100644 --- a/test/kb_scan.c +++ b/test/kb_scan.c @@ -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); } diff --git a/test/kb_scan.tasklist b/test/kb_scan.tasklist index 2368d7bc52..85aee504fa 100644 --- a/test/kb_scan.tasklist +++ b/test/kb_scan.tasklist @@ -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) |