Skip to content

Commit abbb248

Browse files
author
Seppo Takalo
committed
Greentea: Fix storage sizes for SecureStore tests.
Previously Greentea tests was not initialising its storage before asking for bd->get_program_size(), causing FlashBlockDevice to return zero. This caused both TDBStorage's to use zero for both parameter to SlicingBlockDevice(bd, 0, 0), effetivaly both then used same addresses for slice. This caused SecureStore tests to fail, because writes to internal RBP storage overwrote keys from external storage. Fine-tune TDBStore sizes, so that all tests can fit into storage.
1 parent 065ff26 commit abbb248

File tree

1 file changed

+18
-6
lines changed
  • features/storage/TESTS/kvstore/general_tests_phase_1

1 file changed

+18
-6
lines changed

features/storage/TESTS/kvstore/general_tests_phase_1/main.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,18 @@ static int kv_setup = TDBStoreSet;
6868

6969
static const int heap_alloc_threshold_size = 4096;
7070

71+
static inline uint32_t align_up(uint32_t val, uint32_t size)
72+
{
73+
return (((val - 1) / size) + 1) * size;
74+
}
75+
7176
/*----------------initialization------------------*/
7277

7378
//init the blockdevice
7479
static void kvstore_init()
7580
{
7681
int res;
77-
size_t erase_size, ul_bd_size, rbp_bd_size;
82+
size_t program_size, erase_size, ul_bd_size, rbp_bd_size;
7883
BlockDevice *sec_bd;
7984

8085
res = bd->init();
@@ -109,10 +114,17 @@ static void kvstore_init()
109114
flash_bd = new FlashSimBlockDevice(bd);
110115
sec_bd = flash_bd;
111116
}
117+
res = sec_bd->init();
118+
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
119+
120+
program_size = sec_bd->get_program_size();
121+
erase_size = sec_bd->get_erase_size();
122+
// We must be able to hold at least 10 small keys (20 program sectors) and master record + internal data
123+
ul_bd_size = align_up(program_size * 40, erase_size);
124+
rbp_bd_size = align_up(program_size * 40, erase_size);
112125

113-
erase_size = sec_bd->get_erase_size();
114-
ul_bd_size = erase_size * 4;
115-
rbp_bd_size = erase_size * 2;
126+
res = sec_bd->deinit();
127+
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
116128

117129
ul_bd = new SlicingBlockDevice(sec_bd, 0, ul_bd_size);
118130
rbp_bd = new SlicingBlockDevice(sec_bd, ul_bd_size, ul_bd_size + rbp_bd_size);
@@ -407,14 +419,14 @@ static void set_several_key_value_sizes()
407419

408420
name[6] = 0;
409421

410-
for (i = 0; i < 26; i++) {
422+
for (i = 0; i < 5; i++) {
411423
c = i + 'a';
412424
name[5] = c;
413425
res = kvstore->set(name, name, sizeof(name), 0);
414426
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
415427
}
416428

417-
for (i = 0; i < 26; i++) {
429+
for (i = 0; i < 5; i++) {
418430
c = i + 'a';
419431
name[5] = c;
420432
res = kvstore->get(name, buffer, sizeof(buffer), &actual_size, 0);

0 commit comments

Comments
 (0)