diff options
author | Yuval Peress <peress@google.com> | 2022-11-16 02:56:27 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-11-18 17:20:06 +0000 |
commit | 2c07deae07162b1ce86bd5251c575408b4403f0a (patch) | |
tree | 366509ac239c21ab86cbe276f0b8f2df44fd7acb | |
parent | 100bf6c96e2499dbf126afb57fedc565545e6c28 (diff) | |
download | chrome-ec-2c07deae07162b1ce86bd5251c575408b4403f0a.tar.gz |
test: test memory mapped storage config
Add a new binary variant for memory mapped storage. Add tests for
All the edge cases around the flash memory as well as verify that
reads and writes work. As done in other tests, an override is added
to common/flash.c allowing us to provide our own buffer to intercept
the flash address.
BRANCH=none
BUG=none
TEST=twister
Signed-off-by: Yuval Peress <peress@google.com>
Change-Id: Icca8ac74a6c98a93b995162efb87b3f5fa111a8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4030065
Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r-- | common/flash.c | 10 | ||||
-rw-r--r-- | zephyr/test/drivers/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/Kconfig | 4 | ||||
-rw-r--r-- | zephyr/test/drivers/memmap/CMakeLists.txt | 5 | ||||
-rw-r--r-- | zephyr/test/drivers/memmap/src/main.c | 88 | ||||
-rw-r--r-- | zephyr/test/drivers/testcase.yaml | 3 |
6 files changed, 111 insertions, 0 deletions
diff --git a/common/flash.c b/common/flash.c index de042e76cb..4f3f578eed 100644 --- a/common/flash.c +++ b/common/flash.c @@ -232,6 +232,13 @@ static int flash_range_ok(int offset, int size_req, int align) } #ifdef CONFIG_MAPPED_STORAGE + +/** + * A test public variable allowing us to override the base address of + * flash_physical_dataptr(). + */ +test_export_static const char *flash_physical_dataptr_override; + /** * Get the physical memory address of a flash offset * @@ -245,6 +252,9 @@ static int flash_range_ok(int offset, int size_req, int align) */ static const char *flash_physical_dataptr(int offset) { + if (IS_ENABLED(TEST_BUILD) && flash_physical_dataptr_override != NULL) { + return flash_physical_dataptr_override + offset; + } return (char *)((uintptr_t)CONFIG_MAPPED_STORAGE_BASE + offset); } diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt index dd8ab61b59..863c9cb8b6 100644 --- a/zephyr/test/drivers/CMakeLists.txt +++ b/zephyr/test/drivers/CMakeLists.txt @@ -50,6 +50,7 @@ add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_BUTTON button) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_CONSOLE console) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_HOST_CMD_THREAD host_command_thread) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_PI3USB9201 bc12_pi3usb9201) +add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_MEMMAP memmap) get_target_property(TEST_SOURCES_NEW app SOURCES) diff --git a/zephyr/test/drivers/Kconfig b/zephyr/test/drivers/Kconfig index 496bfd2ac0..07b387f2c6 100644 --- a/zephyr/test/drivers/Kconfig +++ b/zephyr/test/drivers/Kconfig @@ -126,4 +126,8 @@ config LINK_TEST_SUITE_HOST_CMD_THREAD config LINK_TEST_SUITE_PI3USB9201 bool "Link and test the pi3usb9201 tests" +config LINK_TEST_SUITE_MEMMAP + bool "Link and test memory mapped tests for common/flash.c" + select PLATFORM_EC_MAPPED_STORAGE + source "Kconfig.zephyr" diff --git a/zephyr/test/drivers/memmap/CMakeLists.txt b/zephyr/test/drivers/memmap/CMakeLists.txt new file mode 100644 index 0000000000..9386414deb --- /dev/null +++ b/zephyr/test/drivers/memmap/CMakeLists.txt @@ -0,0 +1,5 @@ +# Copyright 2022 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +target_sources(app PRIVATE src/main.c) diff --git a/zephyr/test/drivers/memmap/src/main.c b/zephyr/test/drivers/memmap/src/main.c new file mode 100644 index 0000000000..67c27b5c8d --- /dev/null +++ b/zephyr/test/drivers/memmap/src/main.c @@ -0,0 +1,88 @@ +/* Copyright 2022 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <stdio.h> +#include <string.h> +#include <zephyr/ztest.h> + +#include "flash.h" +#include "host_command.h" +#include "test/drivers/test_state.h" + +extern const char *flash_physical_dataptr_override; + +static char flash[CONFIG_FLASH_SIZE_BYTES]; + +static void after(void *f) +{ + ARG_UNUSED(f); + flash_physical_dataptr_override = NULL; +} + +ZTEST_SUITE(memmap, drivers_predicate_post_main, NULL, NULL, after, NULL); + +ZTEST(memmap, test_crec_flash_dataptr__invalid) +{ + zassert_equal(-1, crec_flash_dataptr(/*offset=*/-1, /*size_req=*/1, + /*align=*/1, /*ptrp=*/NULL)); +} + +ZTEST(memmap, test_crec_flash_dataptr) +{ + const char *ptr = NULL; + + zassert_equal(CONFIG_PLATFORM_EC_FLASH_SIZE_BYTES, + crec_flash_dataptr(0, 1, 1, &ptr)); + zassert_equal(CONFIG_PLATFORM_EC_MAPPED_STORAGE_BASE, (uintptr_t)ptr); +} + +ZTEST(memmap, test_crec_flash_is_erased__invalid_args) +{ + zassert_equal(0, crec_flash_is_erased(/*offset=*/0, /*size=*/-1)); +} + +ZTEST(memmap, test_crec_flash_is_erased__fail) +{ + sprintf(flash, "non empty data"); + flash_physical_dataptr_override = flash; + zassert_equal(0, crec_flash_is_erased(/*offset=*/0, /*size=*/8)); +} + +ZTEST(memmap, test_crec_flash_is_erased__pass) +{ + memset(flash, 0xff, 32); + flash_physical_dataptr_override = flash; + zassert_equal(1, crec_flash_is_erased(/*offset=*/0, /*size=*/32)); +} + +ZTEST(memmap, test_crec_flash_read__invalid_args) +{ + zassert_equal(EC_ERROR_INVAL, crec_flash_read(/*offset=*/-1, /*size=*/0, + /*data=*/NULL)); +} + +ZTEST(memmap, test_crec_flash_read) +{ + char output[16] = { 0 }; + + sprintf(flash, "0123456789abcdef"); + flash_physical_dataptr_override = flash; + + zassert_ok(crec_flash_read(/*offset=*/0, ARRAY_SIZE(output), output)); + zassert_mem_equal(output, flash, ARRAY_SIZE(output)); +} + +ZTEST(memmap, test_crec_flash_write__invalid_args) +{ + zassert_equal(EC_ERROR_INVAL, + crec_flash_write(/*offset=*/-1, /*size=*/0, + /*data=*/NULL)); +} + +ZTEST(memmap, test_crec_flash_erase__invalid_args) +{ + zassert_equal(EC_ERROR_INVAL, + crec_flash_erase(/*offset=*/-1, /*size=*/0)); +} diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index 9548596026..2a2f8157f8 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -216,3 +216,6 @@ tests: drivers.pi3usb9201: extra_configs: - CONFIG_LINK_TEST_SUITE_PI3USB9201=y + drivers.memmap: + extra_configs: + - CONFIG_LINK_TEST_SUITE_MEMMAP=y |