mirror of https://github.com/ARMmbed/mbed-os.git
Improve reliability of KVStore general tests
In kvstore_init, prior to initializing the kvstore, erase the underlying block storage device. This ensures that each test run starts from a consistent state and avoids failures that can result if a previous test run left the storage in an inconsistent state.pull/12060/head
parent
9243abb6be
commit
d8f47bdaa3
|
@ -78,6 +78,12 @@ 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;
|
||||
|
@ -85,6 +91,11 @@ static void kvstore_init()
|
|||
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);
|
||||
|
||||
|
@ -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();
|
||||
|
|
|
@ -78,6 +78,12 @@ 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;
|
||||
|
@ -85,6 +91,11 @@ static void kvstore_init()
|
|||
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);
|
||||
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue