Skip to content

Commit

Permalink
Greentea: Fix storage sizes for SecureStore tests.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Seppo Takalo committed Nov 27, 2019
1 parent 2b69466 commit 1be11f8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions features/storage/TESTS/kvstore/general_tests_phase_1/main.cpp
Expand Up @@ -28,6 +28,7 @@
#include "unity/unity.h"
#include "utest/utest.h"
#include "FileSystemStore.h"
#include "features/storage/internal/utils.h"

using namespace utest::v1;
using namespace mbed;
Expand Down Expand Up @@ -74,7 +75,7 @@ static const int heap_alloc_threshold_size = 4096;
static void kvstore_init()
{
int res;
size_t erase_size, ul_bd_size, rbp_bd_size;
size_t program_size, erase_size, ul_bd_size, rbp_bd_size;
BlockDevice *sec_bd;

res = bd->init();
Expand Down Expand Up @@ -109,10 +110,17 @@ static void kvstore_init()
flash_bd = new FlashSimBlockDevice(bd);
sec_bd = flash_bd;
}
res = sec_bd->init();
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);

program_size = sec_bd->get_program_size();
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
ul_bd_size = align_up(program_size * 40, erase_size);
rbp_bd_size = align_up(program_size * 40, erase_size);

erase_size = sec_bd->get_erase_size();
ul_bd_size = erase_size * 4;
rbp_bd_size = erase_size * 2;
res = sec_bd->deinit();
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);

ul_bd = new SlicingBlockDevice(sec_bd, 0, ul_bd_size);
rbp_bd = new SlicingBlockDevice(sec_bd, ul_bd_size, ul_bd_size + rbp_bd_size);
Expand Down Expand Up @@ -424,14 +432,14 @@ static void set_several_key_value_sizes()

name[6] = 0;

for (i = 0; i < 26; i++) {
for (i = 0; i < 5; i++) {
c = i + 'a';
name[5] = c;
res = kvstore->set(name, name, sizeof(name), 0);
TEST_ASSERT_EQUAL_ERROR_CODE(MBED_SUCCESS, res);
}

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

0 comments on commit 1be11f8

Please sign in to comment.