summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2019-04-30 10:33:47 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-05-01 11:02:59 -0700
commit15bd8639ef6df248b4474808bd21d80b0c19bac4 (patch)
tree64bb5fd2113ab11b9849b30ee676781ced33e8bf /test
parent13089909211c5289c46d22a3cb7fb9b06efcd917 (diff)
downloadchrome-ec-15bd8639ef6df248b4474808bd21d80b0c19bac4.tar.gz
nvmem: add test of recovery from interrupted saves
Add a test which introduces corrupted objects in the flash and verifies that the initialization function is able to recover. BRANCH=cr50, cr50-mp BUG=b:69907320, b:129710256 TEST='make run-nvmem' succeeds Change-Id: Ibb7d8181dfdeb097b79087cdae824564ec28921f Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1590044 Reviewed-by: Andrey Pronin <apronin@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/nvmem.c14
-rw-r--r--test/nvmem_test.h3
2 files changed, 16 insertions, 1 deletions
diff --git a/test/nvmem.c b/test/nvmem.c
index a7e339ebf1..52cf40138a 100644
--- a/test/nvmem.c
+++ b/test/nvmem.c
@@ -828,6 +828,7 @@ static int test_nvmem_incomplete_transaction(void)
uint16_t offsets[MAX_OFFSETS];
size_t num_objects;
uint8_t buf[nvmem_user_sizes[NVMEM_TPM]];
+ uint8_t *p;
TEST_ASSERT(prepare_post_migration_nvmem() == EC_SUCCESS);
num_objects = fill_obj_offsets(offsets, ARRAY_SIZE(offsets));
@@ -859,6 +860,19 @@ static int test_nvmem_incomplete_transaction(void)
num_objects = fill_obj_offsets(offsets, ARRAY_SIZE(offsets));
TEST_ASSERT(num_objects == 7);
+ /*
+ * Now, let's modify an object and introduce corruption when saving
+ * it.
+ */
+ p = evictable_offs_to_addr(offsets[4]);
+ p[10] ^= 0x55;
+ failure_mode = TEST_FAILED_HASH;
+ new_nvmem_save();
+ failure_mode = TEST_NO_FAILURE;
+
+ /* And verify that nvmem can still successfully initialize. */
+ TEST_ASSERT(nvmem_init() == EC_SUCCESS);
+
return EC_SUCCESS;
}
diff --git a/test/nvmem_test.h b/test/nvmem_test.h
index 9e050582ac..6aba855bfe 100644
--- a/test/nvmem_test.h
+++ b/test/nvmem_test.h
@@ -19,7 +19,8 @@ enum test_failure_mode {
TEST_FAIL_WHEN_INVALIDATING,
TEST_FAIL_WHEN_COMPACTING,
TEST_FAIL_SAVING_VAR,
- TEST_FAIL_FINALIZING_VAR
+ TEST_FAIL_FINALIZING_VAR,
+ TEST_FAILED_HASH
};
extern enum test_failure_mode failure_mode;