summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-09-23 23:57:21 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-09-24 21:00:25 +0000
commit1e08d488bdf680adc20094aec4e58c065b208b82 (patch)
tree6667f5f14dc9199f037f8ff27b4e87eeb4d7daf7
parent03cc4b422d28459fca60d29d830078bd8d6f1db1 (diff)
downloadchrome-ec-1e08d488bdf680adc20094aec4e58c065b208b82.tar.gz
Mock flash erase/write function at physical layer
This moves the mock function from common layer down to physical layer to complete the test of common layer. Also disable flash test for hardware tests, as this is only testing common layer. BUG=chrome-os-partner:19236 TEST=util/make_all.sh BRANCH=None Change-Id: Idd1c2c44591952894486f84d428872cfbf2cfdad Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/170297 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--chip/host/config_chip.h2
-rw-r--r--chip/host/flash.c16
-rw-r--r--common/flash_common.c4
-rw-r--r--test/build.mk9
-rw-r--r--test/flash.c87
5 files changed, 59 insertions, 59 deletions
diff --git a/chip/host/config_chip.h b/chip/host/config_chip.h
index 0c9a350617..9aa51f6108 100644
--- a/chip/host/config_chip.h
+++ b/chip/host/config_chip.h
@@ -15,7 +15,7 @@ extern char __host_flash[CONFIG_FLASH_PHYSICAL_SIZE];
#define CONFIG_FLASH_BASE ((uintptr_t)__host_flash)
#define CONFIG_FLASH_BANK_SIZE 0x1000
-#define CONFIG_FLASH_ERASE_SIZE 0x0400 /* erase bank size */
+#define CONFIG_FLASH_ERASE_SIZE 0x0010 /* erase bank size */
#define CONFIG_FLASH_WRITE_SIZE 0x0002 /* minimum write size */
#define CONFIG_FLASH_WRITE_IDEAL_SIZE 0x0080 /* ideal write size */
#define CONFIG_RAM_BASE 0x0 /* Not supported */
diff --git a/chip/host/flash.c b/chip/host/flash.c
index fac8620b38..892e4067a9 100644
--- a/chip/host/flash.c
+++ b/chip/host/flash.c
@@ -15,14 +15,20 @@
char __host_flash[CONFIG_FLASH_PHYSICAL_SIZE];
uint8_t __host_flash_protect[PHYSICAL_BANKS];
+/* Override this function to make flash erase/write operation fail */
+test_mockable int flash_pre_op(void)
+{
+ return EC_SUCCESS;
+}
+
static int flash_check_protect(int offset, int size)
{
int first_bank = offset / CONFIG_FLASH_BANK_SIZE;
- int last_bank = DIV_ROUND_UP(offset + size + 1,
+ int last_bank = DIV_ROUND_UP(offset + size,
CONFIG_FLASH_BANK_SIZE);
int bank;
- for (bank = first_bank; bank <= last_bank; ++bank)
+ for (bank = first_bank; bank < last_bank; ++bank)
if (__host_flash_protect[bank])
return 1;
return 0;
@@ -61,6 +67,9 @@ int flash_physical_write(int offset, int size, const char *data)
{
ASSERT((size & (CONFIG_FLASH_WRITE_SIZE - 1)) == 0);
+ if (flash_pre_op() != EC_SUCCESS)
+ return EC_ERROR_UNKNOWN;
+
if (flash_check_protect(offset, size))
return EC_ERROR_ACCESS_DENIED;
@@ -74,6 +83,9 @@ int flash_physical_erase(int offset, int size)
{
ASSERT((size & (CONFIG_FLASH_ERASE_SIZE - 1)) == 0);
+ if (flash_pre_op() != EC_SUCCESS)
+ return EC_ERROR_UNKNOWN;
+
if (flash_check_protect(offset, size))
return EC_ERROR_ACCESS_DENIED;
diff --git a/common/flash_common.c b/common/flash_common.c
index f225aaaf53..c2773f6dd0 100644
--- a/common/flash_common.c
+++ b/common/flash_common.c
@@ -127,7 +127,7 @@ int flash_is_erased(uint32_t offset, int size)
return 1;
}
-test_mockable int flash_write(int offset, int size, const char *data)
+int flash_write(int offset, int size, const char *data)
{
if (flash_dataptr(offset, size, CONFIG_FLASH_WRITE_SIZE, NULL) < 0)
return EC_ERROR_INVAL; /* Invalid range */
@@ -139,7 +139,7 @@ test_mockable int flash_write(int offset, int size, const char *data)
return flash_physical_write(offset, size, data);
}
-test_mockable int flash_erase(int offset, int size)
+int flash_erase(int offset, int size)
{
if (flash_dataptr(offset, size, CONFIG_FLASH_ERASE_SIZE, NULL) < 0)
return EC_ERROR_INVAL; /* Invalid range */
diff --git a/test/build.mk b/test/build.mk
index e38e0ee11c..7dbb08336f 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -13,11 +13,10 @@ test-list-y=pingpong timer_calib timer_dos timer_jump mutex utils
# scancode typematic charging
test-list-$(BOARD_bds)+=
-test-list-$(BOARD_daisy)+=kb_scan flash stress
-test-list-$(BOARD_mccroskey)+=flash
-test-list-$(BOARD_pit)+=kb_scan flash stress
-test-list-$(BOARD_snow)+=kb_scan flash stress
-test-list-$(BOARD_spring)+=kb_scan flash stress
+test-list-$(BOARD_daisy)+=kb_scan stress
+test-list-$(BOARD_pit)+=kb_scan stress
+test-list-$(BOARD_snow)+=kb_scan stress
+test-list-$(BOARD_spring)+=kb_scan stress
# Disable x86 boards until they compiles
# TODO(victoryang): Fix them
diff --git a/test/flash.c b/test/flash.c
index c5a9c4ebd1..2bf6ee9925 100644
--- a/test/flash.c
+++ b/test/flash.c
@@ -17,18 +17,13 @@
#include "timer.h"
#include "util.h"
-static int last_write_offset;
-static int last_write_size;
-static char last_write_data[64];
-
-static int last_erase_offset;
-static int last_erase_size;
-
static int mock_wp = -1;
static int mock_flash_op_fail = EC_SUCCESS;
-const char *testdata = "TestData0000000"; /* 16 bytes */
+const char *testdata = "TestData00000000"; /* 16 bytes excluding NULL end */
+
+char flash_recorded_data[128];
#define BOOT_WP_MASK TEST_STATE_MASK(TEST_STATE_STEP_2)
@@ -50,23 +45,9 @@ void host_send_response(struct host_cmd_handler_args *args)
/* Do nothing */
}
-int flash_write(int offset, int size, const char *data)
+int flash_pre_op(void)
{
- if (mock_flash_op_fail != EC_SUCCESS)
- return mock_flash_op_fail;
- last_write_offset = offset;
- last_write_size = size;
- memcpy(last_write_data, data, size);
- return EC_SUCCESS;
-}
-
-int flash_erase(int offset, int size)
-{
- if (mock_flash_op_fail != EC_SUCCESS)
- return mock_flash_op_fail;
- last_erase_offset = offset;
- last_erase_size = size;
- return EC_SUCCESS;
+ return mock_flash_op_fail;
}
int gpio_get_level(enum gpio_signal signal)
@@ -88,23 +69,34 @@ int gpio_get_level(enum gpio_signal signal)
/*****************************************************************************/
/* Test utilities */
-static void begin_verify(void)
+static void record_flash(int offset, int size)
{
- last_write_offset = -1;
- last_write_size = -1;
- last_write_data[0] = '\0';
- last_erase_offset = -1;
- last_erase_size = -1;
+ memcpy(flash_recorded_data, __host_flash + offset, size);
+}
+
+static int verify_flash(int offset, int size)
+{
+ TEST_ASSERT_ARRAY_EQ(flash_recorded_data, __host_flash + offset, size);
+ return EC_SUCCESS;
}
static int verify_write(int offset, int size, const char *data)
{
int i;
- if (offset != last_write_offset || size != last_write_size)
- return EC_ERROR_UNKNOWN;
for (i = 0; i < size; ++i)
- if (data[i] != last_write_data[i])
+ if (__host_flash[offset + i] != data[i])
+ return EC_ERROR_UNKNOWN;
+
+ return EC_SUCCESS;
+}
+
+static int verify_erase(int offset, int size)
+{
+ int i;
+
+ for (i = 0; i < size; ++i)
+ if ((__host_flash[offset + i] & 0xff) != 0xff)
return EC_ERROR_UNKNOWN;
return EC_SUCCESS;
@@ -113,31 +105,28 @@ static int verify_write(int offset, int size, const char *data)
#define VERIFY_NO_WRITE(off, sz, d) \
do { \
- begin_verify(); \
+ record_flash(off, sz); \
TEST_ASSERT(host_command_write(off, sz, d) != EC_SUCCESS); \
- TEST_ASSERT(last_write_offset == -1 && last_write_size == -1); \
+ TEST_ASSERT(verify_flash(off, sz) == EC_SUCCESS); \
} while (0)
#define VERIFY_NO_ERASE(off, sz) \
do { \
- begin_verify(); \
+ record_flash(off, sz); \
TEST_ASSERT(host_command_erase(off, sz) != EC_SUCCESS); \
- TEST_ASSERT(last_erase_offset == -1 && last_erase_size == -1); \
+ TEST_ASSERT(verify_flash(off, sz) == EC_SUCCESS); \
} while (0)
#define VERIFY_WRITE(off, sz, d) \
do { \
- begin_verify(); \
TEST_ASSERT(host_command_write(off, sz, d) == EC_SUCCESS); \
TEST_ASSERT(verify_write(off, sz, d) == EC_SUCCESS); \
} while (0)
#define VERIFY_ERASE(off, sz) \
do { \
- begin_verify(); \
TEST_ASSERT(host_command_erase(off, sz) == EC_SUCCESS); \
- TEST_ASSERT(last_erase_offset == off && \
- last_erase_size == sz); \
+ TEST_ASSERT(verify_erase(off, sz) == EC_SUCCESS); \
} while (0)
#define SET_WP_FLAGS(m, f) \
@@ -288,10 +277,10 @@ static int test_overwrite_current(void)
mock_is_running_img = 1;
#endif
- VERIFY_NO_ERASE(offset, sizeof(testdata));
- VERIFY_NO_ERASE(offset + size - sizeof(testdata), sizeof(testdata));
- VERIFY_NO_WRITE(offset, sizeof(testdata), testdata);
- VERIFY_NO_WRITE(offset + size - sizeof(testdata), sizeof(testdata),
+ VERIFY_NO_ERASE(offset, strlen(testdata));
+ VERIFY_NO_ERASE(offset + size - strlen(testdata), strlen(testdata));
+ VERIFY_NO_WRITE(offset, strlen(testdata), testdata);
+ VERIFY_NO_WRITE(offset + size - strlen(testdata), strlen(testdata),
testdata);
return EC_SUCCESS;
@@ -314,10 +303,10 @@ static int test_overwrite_other(void)
mock_is_running_img = 0;
#endif
- VERIFY_ERASE(offset, sizeof(testdata));
- VERIFY_ERASE(offset + size - sizeof(testdata), sizeof(testdata));
- VERIFY_WRITE(offset, sizeof(testdata), testdata);
- VERIFY_WRITE(offset + size - sizeof(testdata), sizeof(testdata),
+ VERIFY_ERASE(offset, strlen(testdata));
+ VERIFY_ERASE(offset + size - strlen(testdata), strlen(testdata));
+ VERIFY_WRITE(offset, strlen(testdata), testdata);
+ VERIFY_WRITE(offset + size - strlen(testdata), strlen(testdata),
testdata);
return EC_SUCCESS;