summaryrefslogtreecommitdiff
path: root/test/flash.c
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-05-26 18:46:55 +0800
committerChromeBot <chrome-bot@google.com>2013-06-03 14:34:10 -0700
commit80105a95569c36b7a4d372c7e74f086ad27f5492 (patch)
tree368706c3d44566cb696ebf98018d1dfb7bcd7f80 /test/flash.c
parent1806f521955623770405778a742d0398cae028a2 (diff)
downloadchrome-ec-80105a95569c36b7a4d372c7e74f086ad27f5492.tar.gz
Enable flash unit test on emulator
BUG=chrome-os-partner:19236 TEST=Pass all tests BRANCH=None Change-Id: I09276292499b94b2d4810830de51e4c63a9b7342 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/56704 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'test/flash.c')
-rw-r--r--test/flash.c52
1 files changed, 36 insertions, 16 deletions
diff --git a/test/flash.c b/test/flash.c
index cf6ee659fd..33f47543bd 100644
--- a/test/flash.c
+++ b/test/flash.c
@@ -17,8 +17,6 @@
#include "timer.h"
#include "util.h"
-static int error_count;
-
static int last_write_offset;
static int last_write_size;
static char last_write_data[64];
@@ -33,9 +31,21 @@ static int mock_wp = -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 0
+#define CLEAN_UP_FLAG_FAILED TEST_STATE_FAILED
+
+/*****************************************************************************/
+/* Emulator-only mock functions */
+#ifdef EMU_BUILD
+static int mock_is_running_img;
+
+int system_unsafe_to_overwrite(uint32_t offset, uint32_t size)
+{
+ return mock_is_running_img;
+}
+#endif
/*****************************************************************************/
/* Mock functions */
@@ -240,6 +250,10 @@ static int test_overwrite_current(void)
size = CONFIG_FW_RW_SIZE;
}
+#ifdef EMU_BUILD
+ mock_is_running_img = 1;
+#endif
+
VERIFY_NO_ERASE(offset, sizeof(d));
VERIFY_NO_ERASE(offset + size - sizeof(d), sizeof(d));
VERIFY_NO_WRITE(offset, sizeof(d), d);
@@ -262,6 +276,10 @@ static int test_overwrite_other(void)
size = CONFIG_FW_RW_SIZE;
}
+#ifdef EMU_BUILD
+ mock_is_running_img = 0;
+#endif
+
VERIFY_ERASE(offset, sizeof(d));
VERIFY_ERASE(offset + size - sizeof(d), sizeof(d));
VERIFY_WRITE(offset, sizeof(d), d);
@@ -344,43 +362,37 @@ static void reboot_to_next_step(uint32_t step)
static void run_test_step1(void)
{
- error_count = 0;
+ test_reset();
mock_wp = 0;
RUN_TEST(test_overwrite_current);
RUN_TEST(test_overwrite_other);
RUN_TEST(test_write_protect);
- if (error_count) {
- ccprintf("Failed %d tests!\n", error_count);
+ if (test_get_error_count())
reboot_to_clean_up(CLEAN_UP_FLAG_FAILED);
- } else {
+ else
reboot_to_next_step(TEST_STATE_STEP_2 | TEST_STATE_BOOT_WP_ON);
- }
}
static void run_test_step2(void)
{
RUN_TEST(test_boot_write_protect);
- if (error_count) {
- ccprintf("Failed %d tests!\n", error_count);
+ if (test_get_error_count())
reboot_to_clean_up(CLEAN_UP_FLAG_FAILED);
- } else {
+ else
reboot_to_next_step(TEST_STATE_STEP_3);
- }
}
static void run_test_step3(void)
{
RUN_TEST(test_boot_no_write_protect);
- if (error_count) {
- ccprintf("Failed %d tests!\n", error_count);
+ if (test_get_error_count())
reboot_to_clean_up(CLEAN_UP_FLAG_FAILED);
- } else {
+ else
reboot_to_clean_up(CLEAN_UP_FLAG_PASSED);
- }
}
int TaskTest(void *data)
@@ -389,6 +401,8 @@ int TaskTest(void *data)
if (state & TEST_STATE_PASSED)
ccprintf("Pass!\n");
+ else if (state & TEST_STATE_FAILED)
+ ccprintf("Fail!\n");
if (state & TEST_STATE_STEP_2)
run_test_step2();
@@ -396,11 +410,17 @@ int TaskTest(void *data)
run_test_step3();
else if (state & TEST_STATE_CLEAN_UP)
clean_up();
+#ifdef EMU_BUILD
+ else
+ run_test_step1();
+#endif
return EC_SUCCESS;
}
+#ifndef EMU_BUILD
void run_test(void)
{
run_test_step1();
}
+#endif