Skip to content

Commit 1be11f8

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 2b69466 commit 1be11f8

File tree

1 file changed

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

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "unity/unity.h"
2929
#include "utest/utest.h"
3030
#include "FileSystemStore.h"
31+
#include "features/storage/internal/utils.h"
3132

3233
using namespace utest::v1;
3334
using namespace mbed;
@@ -74,7 +75,7 @@ static const int heap_alloc_threshold_size = 4096;
7475
static void kvstore_init()
7576
{
7677
int res;
77-
size_t erase_size, ul_bd_size, rbp_bd_size;
78+
size_t program_size, erase_size, ul_bd_size, rbp_bd_size;
7879
BlockDevice *sec_bd;
7980

8081
res = bd->init();
@@ -109,10 +110,17 @@ static void kvstore_init()
109110
flash_bd = new FlashSimBlockDevice(bd);
110111
sec_bd = flash_bd;
111112
}
113+
res = sec_bd->init();
114+
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
115+
116+
program_size = sec_bd->get_program_size();
117+
erase_size = sec_bd->get_erase_size();
118+
// We must be able to hold at least 10 small keys (20 program sectors) and master record + internal data
119+
ul_bd_size = align_up(program_size * 40, erase_size);
120+
rbp_bd_size = align_up(program_size * 40, erase_size);
112121

113-
erase_size = sec_bd->get_erase_size();
114-
ul_bd_size = erase_size * 4;
115-
rbp_bd_size = erase_size * 2;
122+
res = sec_bd->deinit();
123+
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
116124

117125
ul_bd = new SlicingBlockDevice(sec_bd, 0, ul_bd_size);
118126
rbp_bd = new SlicingBlockDevice(sec_bd, ul_bd_size, ul_bd_size + rbp_bd_size);
@@ -424,14 +432,14 @@ static void set_several_key_value_sizes()
424432

425433
name[6] = 0;
426434

427-
for (i = 0; i < 26; i++) {
435+
for (i = 0; i < 5; i++) {
428436
c = i + 'a';
429437
name[5] = c;
430438
res = kvstore->set(name, name, sizeof(name), 0);
431439
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
432440
}
433441

434-
for (i = 0; i < 26; i++) {
442+
for (i = 0; i < 5; i++) {
435443
c = i + 'a';
436444
name[5] = c;
437445
res = kvstore->get(name, buffer, sizeof(buffer), &actual_size, 0);

0 commit comments

Comments
 (0)