diff options
author | Vic Yang <victoryang@chromium.org> | 2013-09-04 10:14:43 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-09-05 07:20:46 +0000 |
commit | 6c3be20539a3b336e2c1c83181ea6f9b0c1506d2 (patch) | |
tree | 9d4ba5f42126078e6244916017ad51624f1c474a /test | |
parent | 30136468c0352a2bcce1a948d9d5e9e4851b294d (diff) | |
download | chrome-ec-6c3be20539a3b336e2c1c83181ea6f9b0c1506d2.tar.gz |
Add multi-step test support
We already have a multi-step test. Let's move it to test_util.c so that
upcoming tests can also use it.
BUG=chrome-os-partner:19235
TEST=Pass all tests
BRANCH=None
Change-Id: I6b7a036297f3b4b2778687488d1dc5b5bb4fe255
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167950
Diffstat (limited to 'test')
-rw-r--r-- | test/flash.c | 73 | ||||
-rw-r--r-- | test/flash.tasklist | 2 |
2 files changed, 24 insertions, 51 deletions
diff --git a/test/flash.c b/test/flash.c index 9bc5ddca61..c5a9c4ebd1 100644 --- a/test/flash.c +++ b/test/flash.c @@ -12,6 +12,7 @@ #include "hooks.h" #include "host_command.h" #include "system.h" +#include "task.h" #include "test_util.h" #include "timer.h" #include "util.h" @@ -29,15 +30,7 @@ static int mock_flash_op_fail = EC_SUCCESS; const char *testdata = "TestData0000000"; /* 16 bytes */ -#define TEST_STATE_CLEAN_UP (1 << 0) -#define TEST_STATE_STEP_2 (1 << 1) -#define TEST_STATE_STEP_3 (1 << 2) -#define TEST_STATE_BOOT_WP_ON (1 << 3) -#define TEST_STATE_PASSED (1 << 4) -#define TEST_STATE_FAILED (1 << 5) - -#define CLEAN_UP_FLAG_PASSED TEST_STATE_PASSED -#define CLEAN_UP_FLAG_FAILED TEST_STATE_FAILED +#define BOOT_WP_MASK TEST_STATE_MASK(TEST_STATE_STEP_2) /*****************************************************************************/ /* Emulator-only mock functions */ @@ -81,7 +74,7 @@ int gpio_get_level(enum gpio_signal signal) const char *name = gpio_list[signal].name; if (mock_wp == -1) - mock_wp = !!(system_get_scratchpad() & TEST_STATE_BOOT_WP_ON); + mock_wp = !!(test_get_state() & BOOT_WP_MASK); if (strcasecmp(name, "WP_L") == 0) return !mock_wp; @@ -422,27 +415,15 @@ static int test_boot_no_write_protect(void) return EC_SUCCESS; } -static int clean_up(void) +int test_clean_up_(void) { - system_set_scratchpad(0); SET_WP_FLAGS(EC_FLASH_PROTECT_RO_AT_BOOT, 0); return EC_SUCCESS; } -static void reboot_to_clean_up(uint32_t flags) -{ - ccprintf("Rebooting to clear WP...\n"); - cflush(); - system_set_scratchpad(TEST_STATE_CLEAN_UP | flags); - system_reset(SYSTEM_RESET_HARD); -} - -static void reboot_to_next_step(uint32_t step) +void test_clean_up(void) { - ccprintf("Rebooting to next test step...\n"); - cflush(); - system_set_scratchpad(step); - system_reset(SYSTEM_RESET_HARD); + test_clean_up_(); /* Throw away return value */ } static void run_test_step1(void) @@ -459,9 +440,9 @@ static void run_test_step1(void) RUN_TEST(test_write_protect); if (test_get_error_count()) - reboot_to_clean_up(CLEAN_UP_FLAG_FAILED); + test_reboot_to_next_step(TEST_STATE_FAILED); else - reboot_to_next_step(TEST_STATE_STEP_2 | TEST_STATE_BOOT_WP_ON); + test_reboot_to_next_step(TEST_STATE_STEP_2); } static void run_test_step2(void) @@ -469,9 +450,9 @@ static void run_test_step2(void) RUN_TEST(test_boot_write_protect); if (test_get_error_count()) - reboot_to_clean_up(CLEAN_UP_FLAG_FAILED); + test_reboot_to_next_step(TEST_STATE_FAILED); else - reboot_to_next_step(TEST_STATE_STEP_3); + test_reboot_to_next_step(TEST_STATE_STEP_3); } static void run_test_step3(void) @@ -479,37 +460,29 @@ static void run_test_step3(void) RUN_TEST(test_boot_no_write_protect); if (test_get_error_count()) - reboot_to_clean_up(CLEAN_UP_FLAG_FAILED); + test_reboot_to_next_step(TEST_STATE_FAILED); else - reboot_to_clean_up(CLEAN_UP_FLAG_PASSED); + test_reboot_to_next_step(TEST_STATE_PASSED); } -int TaskTest(void *data) +void test_run_step(uint32_t state) { - uint32_t state = system_get_scratchpad(); - - if (state & TEST_STATE_PASSED) - ccprintf("Pass!\n"); - else if (state & TEST_STATE_FAILED) - ccprintf("Fail!\n"); - - if (state & TEST_STATE_STEP_2) + 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_STEP_3) + else if (state & TEST_STATE_MASK(TEST_STATE_STEP_3)) run_test_step3(); - else if (state & TEST_STATE_CLEAN_UP) - clean_up(); -#ifdef EMU_BUILD - else - run_test_step1(); -#endif +} +int task_test(void *data) +{ + test_run_multistep(); return EC_SUCCESS; } -#ifndef EMU_BUILD void run_test(void) { - run_test_step1(); + msleep(30); /* Wait for TASK_ID_TEST to initialize */ + task_wake(TASK_ID_TEST); } -#endif diff --git a/test/flash.tasklist b/test/flash.tasklist index 98ba7a6c83..ce012123d9 100644 --- a/test/flash.tasklist +++ b/test/flash.tasklist @@ -15,4 +15,4 @@ * 's' is the stack size in bytes; must be a multiple of 8 */ #define CONFIG_TEST_TASK_LIST \ - TASK_TEST(TEST, TaskTest, NULL, TASK_STACK_SIZE) + TASK_TEST(TEST, task_test, NULL, TASK_STACK_SIZE) |