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 | |
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
-rw-r--r-- | common/test_util.c | 45 | ||||
-rw-r--r-- | include/test_util.h | 46 | ||||
-rw-r--r-- | test/flash.c | 73 | ||||
-rw-r--r-- | test/flash.tasklist | 2 |
4 files changed, 115 insertions, 51 deletions
diff --git a/common/test_util.c b/common/test_util.c index d944cca4b6..f613c62813 100644 --- a/common/test_util.c +++ b/common/test_util.c @@ -10,6 +10,8 @@ #include "console.h" #include "host_command.h" +#include "system.h" +#include "task.h" #include "test_util.h" #include "util.h" @@ -74,6 +76,49 @@ int test_get_error_count(void) return __test_error_count; } +uint32_t test_get_state(void) +{ + return system_get_scratchpad(); +} + +test_mockable void test_clean_up(void) +{ +} + +void test_reboot_to_next_step(enum test_state_t step) +{ + ccprintf("Rebooting to next test step...\n"); + cflush(); + system_set_scratchpad(TEST_STATE_MASK(step)); + system_reset(SYSTEM_RESET_HARD); +} + +test_mockable void test_run_step(uint32_t state) +{ +} + +void test_run_multistep(void) +{ + uint32_t state = test_get_state(); + + if (state & TEST_STATE_MASK(TEST_STATE_PASSED)) { + test_clean_up(); + system_set_scratchpad(0); + test_pass(); + } else if (state & TEST_STATE_MASK(TEST_STATE_FAILED)) { + test_clean_up(); + system_set_scratchpad(0); + test_fail(); + } + + if (state & TEST_STATE_STEP_1 || state == 0) { + task_wait_event(-1); /* Wait for run_test() */ + test_run_step(TEST_STATE_MASK(TEST_STATE_STEP_1)); + } else { + test_run_step(state); + } +} + #ifdef HAS_TASK_HOSTCMD int test_send_host_command(int command, int version, const void *params, int params_size, void *resp, int resp_size) diff --git a/include/test_util.h b/include/test_util.h index fb333deb16..367a602ae1 100644 --- a/include/test_util.h +++ b/include/test_util.h @@ -62,6 +62,22 @@ return EC_ERROR_UNKNOWN; \ } while (0) +/* Mutlistep test states */ +enum test_state_t { + TEST_STATE_STEP_1 = 0, + TEST_STATE_STEP_2, + TEST_STATE_STEP_3, + TEST_STATE_STEP_4, + TEST_STATE_STEP_5, + TEST_STATE_STEP_6, + TEST_STATE_STEP_7, + TEST_STATE_STEP_8, + TEST_STATE_STEP_9, + TEST_STATE_PASSED, + TEST_STATE_FAILED, +}; +#define TEST_STATE_MASK(x) (1 << (x)) + /* Hooks gcov_flush() for test coverage report generation */ void register_test_end_hook(void); @@ -113,4 +129,34 @@ const char *test_get_captured_console(void); */ void emulator_flush(void); +/* + * Entry point of multi-step test. + * + * Depending on current test state, this function runs the corresponding + * test step. This function should be called in a dedicated task on every + * reboot. Also, run_test() is responsible for starting the test by kicking + * that task. + */ +void test_run_multistep(void); + +/* + * A function that runs the test step specified in 'state'. This function + * should be defined by all multi-step tests. + * + * @param state TEST_STATE_MASK(x) indicating the step to run. + */ +void test_run_step(uint32_t state); + +/* Get the current test state */ +uint32_t test_get_state(void); + +/* + * Multistep test clean up. If a multi-step test has this function defined, + * it will be called on test end. (i.e. when test passes or fails.) + */ +void test_clean_up(void); + +/* Set the next step and reboot */ +void test_reboot_to_next_step(enum test_state_t step); + #endif /* __CROS_EC_TEST_UTIL_H */ 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) |