summaryrefslogtreecommitdiff
path: root/common/test_util.c
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-09-04 10:14:43 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-09-05 07:20:46 +0000
commit6c3be20539a3b336e2c1c83181ea6f9b0c1506d2 (patch)
tree9d4ba5f42126078e6244916017ad51624f1c474a /common/test_util.c
parent30136468c0352a2bcce1a948d9d5e9e4851b294d (diff)
downloadchrome-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 'common/test_util.c')
-rw-r--r--common/test_util.c45
1 files changed, 45 insertions, 0 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)