Skip to content

Improve reliability of KVStore general tests #12060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions features/storage/TESTS/kvstore/general_tests_phase_1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,24 @@ static inline uint32_t align_up(uint32_t val, uint32_t size)
//init the blockdevice
static void kvstore_init()
{
// This directly corresponds to the pages allocated for each of the SecureStore block devices
// For the others it may not match exactly to the space that is used, but it is expected to
// be a close enough approximation to act as a guideline for how much of the block device we
// need to erase in order to ensure a stable initial condition.
const size_t PAGES_ESTIMATE = 40;

int res;
size_t program_size, erase_size, ul_bd_size, rbp_bd_size;
BlockDevice *sec_bd;

res = bd->init();
TEST_ASSERT_EQUAL_ERROR_CODE(0, res);
int erase_val = bd->get_erase_value();
// Clear out any stale data that might be left from a previous test.
// Multiply by 2 because SecureStore requires two underlying block devices of this size
size_t bytes_to_erase = align_up(2 * PAGES_ESTIMATE * bd->get_program_size(), bd->get_erase_size());

bd->erase(0, bytes_to_erase);
res = bd->deinit();
TEST_ASSERT_EQUAL_ERROR_CODE(0, res);

Expand Down Expand Up @@ -121,9 +132,8 @@ static void kvstore_init()
erase_size = sec_bd->get_erase_size();
// We must be able to hold at least 10 small keys (20 program sectors) and master record + internal data
// but minimum of 2 erase sectors, so that the garbage collection way work
ul_bd_size = align_up(program_size * 40, erase_size * 2);
rbp_bd_size = align_up(program_size * 40, erase_size * 2);

ul_bd_size = align_up(program_size * PAGES_ESTIMATE, erase_size * 2);
rbp_bd_size = align_up(program_size * PAGES_ESTIMATE, erase_size * 2);
TEST_ASSERT((ul_bd_size + rbp_bd_size) < sec_bd->size());

res = sec_bd->deinit();
Expand Down
15 changes: 13 additions & 2 deletions features/storage/TESTS/kvstore/general_tests_phase_2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,24 @@ static inline uint32_t align_up(uint32_t val, uint32_t size)
//init the blockdevice
static void kvstore_init()
{
// This directly corresponds to the pages allocated for each of the SecureStore block devices
// For the others it may not match exactly to the space that is used, but it is expected to
// be a close enough approximation to act as a guideline for how much of the block device we
// need to erase in order to ensure a stable initial condition.
const size_t PAGES_ESTIMATE = 40;

int res;
size_t program_size, erase_size, ul_bd_size, rbp_bd_size;
BlockDevice *sec_bd;

res = bd->init();
TEST_ASSERT_EQUAL_ERROR_CODE(0, res);
int erase_val = bd->get_erase_value();
// Clear out any stale data that might be left from a previous test
// Multiply by 2 because SecureStore requires two underlying block devices of this size
size_t bytes_to_erase = align_up(2 * PAGES_ESTIMATE * bd->get_program_size(), bd->get_erase_size());

bd->erase(0, bytes_to_erase);
res = bd->deinit();
TEST_ASSERT_EQUAL_ERROR_CODE(0, res);

Expand Down Expand Up @@ -121,8 +132,8 @@ static void kvstore_init()
erase_size = sec_bd->get_erase_size();
// We must be able to hold at least 10 small keys (20 program sectors) and master record + internal data
// but minimum of 2 erase sectors, so that the garbage collection way work
ul_bd_size = align_up(program_size * 40, erase_size * 2);
rbp_bd_size = align_up(program_size * 40, erase_size * 2);
ul_bd_size = align_up(program_size * PAGES_ESTIMATE, erase_size * 2);
rbp_bd_size = align_up(program_size * PAGES_ESTIMATE, erase_size * 2);

res = sec_bd->deinit();
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
Expand Down