diff options
author | Wai-Hong Tam <waihong@google.com> | 2022-08-26 15:40:30 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-08-29 22:55:43 +0000 |
commit | 48340e3dc378e9b498e6f8085f6abb4477dd679e (patch) | |
tree | 10236000e8d392d903ec09eedbcec92e1e9c01a5 | |
parent | 534ff5c3a9bc007b45cea61ea2d53f0f0291488d (diff) | |
download | chrome-ec-48340e3dc378e9b498e6f8085f6abb4477dd679e.tar.gz |
zephyr: test: Add the flash region info host command tests
Add the tests for the flash region info host command.
BRANCH=None
BUG=b:236075788
TEST=./twister -s zephyr/test/drivers/drivers.default
Change-Id: I4b86d101a8e5af8e424fc188e1b2996968d43f3a
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3858038
Reviewed-by: Yuval Peress <peress@google.com>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r-- | zephyr/test/drivers/default/src/flash.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/zephyr/test/drivers/default/src/flash.c b/zephyr/test/drivers/default/src/flash.c index b0cf9df449..6bb9d89d99 100644 --- a/zephyr/test/drivers/default/src/flash.c +++ b/zephyr/test/drivers/default/src/flash.c @@ -13,6 +13,7 @@ #include "emul/emul_flash.h" #include "flash.h" #include "host_command.h" +#include "system.h" #include "test/drivers/test_state.h" #define WP_L_GPIO_PATH DT_PATH(named_gpios, wp_l) @@ -188,6 +189,68 @@ ZTEST_USER(flash, test_hostcmd_flash_write_and_erase) "readback data not expected: 0x%x", in_buf[0]); } +#define EC_FLASH_REGION_START \ + MIN(CONFIG_EC_PROTECTED_STORAGE_OFF, CONFIG_EC_WRITABLE_STORAGE_OFF) + +static void test_region_info(uint32_t region, uint32_t expected_offset, + uint32_t expected_size) +{ + struct ec_response_flash_region_info response; + struct ec_params_flash_region_info params = { + .region = region, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_FLASH_REGION_INFO, 1, response, params); + + zassert_ok(host_command_process(&args), NULL); + zassert_equal(response.offset, expected_offset, NULL); + zassert_equal(response.size, expected_size, NULL); +} + +ZTEST_USER(flash, test_hostcmd_flash_region_info_ro) +{ + test_region_info(EC_FLASH_REGION_RO, + CONFIG_EC_PROTECTED_STORAGE_OFF + + CONFIG_RO_STORAGE_OFF - EC_FLASH_REGION_START, + EC_FLASH_REGION_RO_SIZE); +} + +ZTEST_USER(flash, test_hostcmd_flash_region_info_active) +{ + test_region_info(EC_FLASH_REGION_ACTIVE, + flash_get_rw_offset(system_get_active_copy()) - + EC_FLASH_REGION_START, + CONFIG_EC_WRITABLE_STORAGE_SIZE); +} + +ZTEST_USER(flash, test_hostcmd_flash_region_info_active_wp_ro) +{ + test_region_info(EC_FLASH_REGION_WP_RO, + CONFIG_WP_STORAGE_OFF - EC_FLASH_REGION_START, + CONFIG_WP_STORAGE_SIZE); +} + +ZTEST_USER(flash, test_hostcmd_flash_region_info_active_update) +{ + test_region_info(EC_FLASH_REGION_UPDATE, + flash_get_rw_offset(system_get_update_copy()) - + EC_FLASH_REGION_START, + CONFIG_EC_WRITABLE_STORAGE_SIZE); +} + +ZTEST_USER(flash, test_hostcmd_flash_region_info_active_invalid) +{ + struct ec_response_flash_region_info response; + struct ec_params_flash_region_info params = { + /* Get an invalid region */ + .region = 10, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_FLASH_REGION_INFO, 1, response, params); + + zassert_equal(host_command_process(&args), EC_RES_INVALID_PARAM, NULL); +} + static void flash_reset(void) { /* Set the GPIO WP_L to default */ |