diff --git a/common/test_util.c b/common/test_util.c index c133ac9d24..10e718399f 100644 --- a/common/test_util.c +++ b/common/test_util.c @@ -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 */ diff --git a/test/flash.c b/test/flash.c index ae1d6432df..73c4a95683 100644 --- a/test/flash.c +++ b/test/flash.c @@ -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, ¶ms, + 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);