summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-09-07 14:21:58 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-10 01:49:08 +0000
commit3e170bfead1657604b2cad884abbbb70269ed6ee (patch)
tree5af52ad9605062710a5996103232616743a4a25e
parent50fee8d0021835b2a41519f4e58fac7e2574846f (diff)
downloadchrome-ec-3e170bfead1657604b2cad884abbbb70269ed6ee.tar.gz
zephyr: vstore: Test remaining pieces of vstore
Add a test for the sysjump-triggeed sysjump functionality . BUG=b:243982872 BRANCH=none TEST=./twister -c -T zephyr/test/drivers/ -s drivers.default To try just that test: twister-out/native_posix/drivers.default/zephyr/zephyr.elf \ -test=vstore:test_vstore_state Change-Id: Idd2fca21059b599e8aed38551a7be78d2e6e77c6 Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3883774 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--zephyr/fake/system_fake.c12
-rw-r--r--zephyr/test/drivers/default/src/vstore.c61
2 files changed, 73 insertions, 0 deletions
diff --git a/zephyr/fake/system_fake.c b/zephyr/fake/system_fake.c
index 4a5df444cc..75beb62b23 100644
--- a/zephyr/fake/system_fake.c
+++ b/zephyr/fake/system_fake.c
@@ -3,13 +3,25 @@
* found in the LICENSE file.
*/
+#include <setjmp.h>
+
#include "system.h"
#include "system_fake.h"
static enum ec_image shrspi_image_copy = EC_IMAGE_RO;
+/* setjmp environment to use for reboot (NULL if none) */
+static jmp_buf *jump_env;
+
+void system_fake_setenv(jmp_buf *env)
+{
+ jump_env = env;
+}
+
void system_jump_to_booter(void)
{
+ if (jump_env)
+ longjmp(*jump_env, 1);
}
uint32_t system_get_lfw_address(void)
diff --git a/zephyr/test/drivers/default/src/vstore.c b/zephyr/test/drivers/default/src/vstore.c
index cbdbe65ccc..7b2fa9d1fe 100644
--- a/zephyr/test/drivers/default/src/vstore.c
+++ b/zephyr/test/drivers/default/src/vstore.c
@@ -3,10 +3,17 @@
* found in the LICENSE file.
*/
+#include <setjmp.h>
+
+#include <console.h>
+#include <zephyr/fff.h>
+#include <zephyr/shell/shell_dummy.h>
#include <zephyr/ztest.h>
#include "ec_commands.h"
#include "host_command.h"
+#include "system.h"
+#include "system_fake.h"
#include "vstore.h"
#include "test/drivers/test_state.h"
@@ -167,3 +174,57 @@ ZTEST_USER(vstore, test_vstore_write_read)
do_vstore_write_read(0);
do_vstore_write_read(1);
}
+
+ZTEST_USER(vstore, test_vstore_state)
+{
+ struct ec_params_vstore_write write_params = {
+ .slot = 0,
+ /* .data is set up below */
+ };
+ struct host_cmd_handler_args write_args =
+ BUILD_HOST_COMMAND_PARAMS(EC_CMD_VSTORE_WRITE, 0, write_params);
+
+ struct ec_params_reboot_ec reboot_params = {
+ .cmd = EC_REBOOT_JUMP_RW,
+ };
+ struct host_cmd_handler_args reboot_args =
+ BUILD_HOST_COMMAND_PARAMS(EC_CMD_REBOOT_EC, 0, reboot_params);
+ struct ec_response_vstore_info info_response;
+ struct host_cmd_handler_args info_args = BUILD_HOST_COMMAND_RESPONSE(
+ EC_CMD_VSTORE_INFO, 0, info_response);
+ jmp_buf env;
+ int i;
+
+ shell_backend_dummy_clear_output(get_ec_shell());
+ system_common_pre_init();
+
+ for (i = 0; i < EC_VSTORE_SLOT_SIZE; i++)
+ write_params.data[i] = i + 1;
+
+ /* Write to a slot */
+ zassert_ok(host_command_process(&write_args), NULL);
+ zassert_ok(write_args.result, NULL);
+
+ /* Set up so we get back to this test on a reboot */
+ if (!setjmp(env)) {
+ system_fake_setenv(&env);
+
+ /* Reboot to RW */
+ zassert_ok(host_command_process(&reboot_args), NULL);
+
+ /* Does not return unless something went wrong */
+ zassert_unreachable("Failed to reboot");
+ }
+
+ /* the reboot should end up here: check the slot is still locked */
+ zassert_ok(host_command_process(&info_args), NULL);
+ zassert_ok(info_args.result, NULL);
+ zassert_equal(info_args.response_size, sizeof(info_response), NULL);
+ zassert_equal(info_response.slot_count, CONFIG_VSTORE_SLOT_COUNT,
+ "response.slot_count = %d", info_response.slot_count);
+ zassert_equal(info_response.slot_locked, 1 << 0,
+ "response.slot_locked = %#x", info_response.slot_locked);
+
+ /* Clear locks to put things into a normal state */
+ vstore_clear_lock();
+}