diff options
-rw-r--r-- | zephyr/test/drivers/flash/src/flash.c | 47 |
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 * |