Add flash host read command test

This checks the correctness of data returned by flash read host command.

BUG=chrome-os-partner:19236
TEST=Pass all tests.
BRANCH=None

Change-Id: I3b97addb9b14922e9f33a71b865000ae9a8d40a8
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/60963
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Vic Yang
2013-06-19 00:29:08 +08:00
committed by ChromeBot
parent b3f1d0d059
commit 62f2a33ff2
2 changed files with 39 additions and 1 deletions

View File

@@ -70,6 +70,7 @@ int test_send_host_command(int command, int version, const void *params,
int params_size, void *resp, int resp_size)
{
struct host_cmd_handler_args args;
int rv;
args.version = version;
args.command = command;
@@ -79,7 +80,12 @@ int test_send_host_command(int command, int version, const void *params,
args.response_max = resp_size;
args.response_size = 0;
return host_command_process(&args);
rv = host_command_process(&args);
if (args.response != resp)
memcpy(resp, args.response, args.response_size);
return rv;
}
#endif /* TASK_HAS_HOSTCMD */

View File

@@ -177,6 +177,17 @@ static int verify_write(int offset, int size, const char *data)
TEST_ASSERT(size == (s)); \
} while (0)
int host_command_read(int offset, int size, char *out)
{
struct ec_params_flash_read params;
params.offset = offset;
params.size = size;
return test_send_host_command(EC_CMD_FLASH_READ, 0, &params,
sizeof(params), out, size);
}
int host_command_write(int offset, int size, const char *data)
{
uint8_t buf[256];
@@ -248,6 +259,26 @@ int host_command_region_info(enum ec_flash_region reg, uint32_t *offset,
/*****************************************************************************/
/* Tests */
static int test_read(void)
{
char buf[16];
#ifdef EMU_BUILD
int i;
/* Fill in some numbers so they are not all 0xff */
for (i = 0; i < sizeof(buf); ++i)
__host_flash[i] = i * i + i;
#endif
/* The first few bytes in the flash should always contain some code */
TEST_ASSERT(!flash_is_erased(0, sizeof(buf)));
TEST_ASSERT(host_command_read(0, sizeof(buf), buf) == EC_RES_SUCCESS);
TEST_ASSERT_ARRAY_EQ(buf, (char *)CONFIG_FLASH_BASE, sizeof(buf));
return EC_SUCCESS;
}
static int test_overwrite_current(void)
{
uint32_t offset, size;
@@ -420,6 +451,7 @@ static void run_test_step1(void)
test_reset();
mock_wp = 0;
RUN_TEST(test_read);
RUN_TEST(test_overwrite_current);
RUN_TEST(test_overwrite_other);
RUN_TEST(test_op_failure);