summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2023-02-03 13:34:43 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-02-15 19:00:57 +0000
commitbca2869e404b32d3e6b624084465c8c75f2d6891 (patch)
tree9349aec64e8e96f629a98f72c878323d45509f0f
parente8b715d1b2c0b35996413a5439cf63551807873a (diff)
downloadchrome-ec-bca2869e404b32d3e6b624084465c8c75f2d6891.tar.gz
zephyr: test: Test 'flashwrite' console command
Test operation and various edge conditions of `flashwrite`. BUG=None BRANCH=None TEST=./twister -v -i -c -s drivers/drivers.flash Change-Id: I02e90d020719b96c88c0a5b8ff1cb9bb83e853ca Signed-off-by: Tristan Honscheid <honscheid@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4224878 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r--zephyr/test/drivers/flash/src/flash.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/zephyr/test/drivers/flash/src/flash.c b/zephyr/test/drivers/flash/src/flash.c
index 905d526fba..f5ee17bb24 100644
--- a/zephyr/test/drivers/flash/src/flash.c
+++ b/zephyr/test/drivers/flash/src/flash.c
@@ -598,6 +598,53 @@ ZTEST_USER(flash, test_console_cmd_flash_erase__happy)
zassert_equal(output, 0xFFFFFFFF, "Got %08x", output);
}
+ZTEST_USER(flash, test_console_cmd_flash_write__flash_locked)
+{
+ /* Force write protection on */
+ zassert_ok(crec_flash_physical_protect_now(1));
+
+ CHECK_CONSOLE_CMD("flashwrite 0x1000 0x1000", NULL,
+ EC_ERROR_ACCESS_DENIED);
+}
+
+ZTEST_USER(flash, test_console_cmd_flash_write__bad_args)
+{
+ /* No args*/
+ CHECK_CONSOLE_CMD("flashwrite", NULL, EC_ERROR_PARAM_COUNT);
+
+ /* Check for 1 of 2 required args */
+ CHECK_CONSOLE_CMD("flashwrite 0x1000", NULL, EC_ERROR_PARAM_COUNT);
+
+ /* Check for alpha arg instead of number*/
+ CHECK_CONSOLE_CMD("flashwrite xyz 100", NULL, EC_ERROR_PARAM1);
+ CHECK_CONSOLE_CMD("flashwrite 100 xyz", NULL, EC_ERROR_PARAM2);
+}
+
+ZTEST_USER(flash, test_console_cmd_flash_write__too_big)
+{
+ CHECK_CONSOLE_CMD("flashwrite 0x10000 " STRINGIFY(INT_MAX), NULL,
+ EC_ERROR_INVAL);
+}
+
+ZTEST_USER(flash, test_console_cmd_flash_write__happy)
+{
+ /* Write 4 bytes. The bytes written are autogenerated and just the
+ * pattern 00 01 02 03.
+ */
+ CHECK_CONSOLE_CMD("flashwrite 0x10000 4", NULL, EC_SUCCESS);
+
+ uint32_t output;
+ static const uint8_t expected[] = { 0x00, 0x01, 0x02, 0x03 };
+
+ /* Check for pattern */
+ zassert_ok(read_flash_helper32(0x10000, &output));
+ zassert_mem_equal(&output, &expected, sizeof(expected));
+
+ /* Check the space after to ensure it is still erased. */
+ zassert_ok(read_flash_helper32(0x10000 + 4, &output));
+ zassert_equal(output, 0xFFFFFFFF, "Got %08x", output);
+}
+
/**
* @brief Prepare a region of flash for the test_crec_flash_is_erased* tests
*