Skip to content

Commit

Permalink
extend storage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AsiiaPine committed Aug 12, 2024
1 parent ba4783e commit f1f3030
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
5 changes: 3 additions & 2 deletions libparams/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ int8_t paramsSave() {
}
int8_t res = 0;
if (standby_rom != NULL) {
// write params to redundant rom
// write params to standby rom
romBeginWrite(standby_rom);
res = _save(standby_rom);
romEndWrite(standby_rom);
// erase rom if save was successful
// if save was successful erase active rom
// and switch roms
if (res == 0) {
RomDriverInstance* buffer = standby_rom;
standby_rom = active_rom;
Expand Down
58 changes: 51 additions & 7 deletions tests/unit_tests/test_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,31 @@ typedef enum {
#define STRING_PARAMS_AMOUNT ((ParamIndex_t)2)

#define NUMBER_OF_PARAMS (INTEGER_PARAMS_AMOUNT + STRING_PARAMS_AMOUNT)
extern RomDriverInstance* active_rom;
extern RomDriverInstance* standby_rom;
extern IntegerParamValue_t integer_values_pool[];


class RedundantRomStorageDriverTest : public ::testing::Test {
protected:
size_t primary_rom_addr;
size_t redundant_rom_addr;
void SetUp() override {
paramsInit(INTEGER_PARAMS_AMOUNT, STRING_PARAMS_AMOUNT, -1, 1);
EXPECT_NE(active_rom, nullptr);
paramsInitRedundantPage();
EXPECT_NE(standby_rom, nullptr);
primary_rom_addr = active_rom->addr;
redundant_rom_addr = standby_rom->addr;
paramsLoad();
}

void TearDown() override {
active_rom = nullptr;
standby_rom = nullptr;
}
};

class SinglePageStorageDriverTest : public ::testing::Test {
protected:
RomDriverInstance rom;
Expand Down Expand Up @@ -68,13 +91,6 @@ TEST_F(EmptyStorageDriverTest, initializeWithInvalidaPageIndex) {
ASSERT_EQ(LIBPARAMS_UNKNOWN_ERROR, paramsInit(INTEGER_PARAMS_AMOUNT, STRING_PARAMS_AMOUNT, -1, 2));
}

// Test 1.6: initialize redundant rom
TEST(RedundantRom, init) {
paramsInit(0, 0, -1, 1); // reset storage
ASSERT_EQ(LIBPARAMS_OK, paramsInitRedundantPage());
}


// Test Case 2: Load Parameters
// Test 2.1: Load Parameters Successfully
TEST_F(SinglePageStorageDriverTest, loadParametersSuccessfully) {
Expand Down Expand Up @@ -304,6 +320,34 @@ TEST_F(SinglePageStorageDriverTest, test_paramsSetStringValue) {
ASSERT_EQ(0, paramsSetStringValue(NODE_NAME, MAX_STRING_LENGTH + 1, nullptr));
}

TEST_F(RedundantRomStorageDriverTest, pageSwitchAfterSave) {
ASSERT_EQ(active_rom->addr, primary_rom_addr);
ASSERT_EQ(standby_rom->addr, redundant_rom_addr);

paramsSave();
ASSERT_EQ(active_rom->addr, redundant_rom_addr);
ASSERT_EQ(standby_rom->addr, primary_rom_addr);

ASSERT_TRUE(standby_rom->erased);
}


TEST_F(RedundantRomStorageDriverTest, pageEraseAfterSave) {
ASSERT_EQ(active_rom->addr, primary_rom_addr);
ASSERT_EQ(standby_rom->addr, redundant_rom_addr);

paramsSave();
ASSERT_EQ(active_rom->addr, redundant_rom_addr);
ASSERT_EQ(standby_rom->addr, primary_rom_addr);
// standby rom has to be erased
ASSERT_TRUE(standby_rom->erased);
romRead(standby_rom, 0, (uint8_t*)integer_values_pool, 4);
ASSERT_EQ(integer_values_pool[0], 0);

romRead(active_rom, 0, (uint8_t*)integer_values_pool, 4);
ASSERT_NE(integer_values_pool[0], 0);
}

int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_yaml_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class YamlParamsTestBase : public ::testing::Test{
}
};

// Case 1. Check YamlParameters initialization with different parameters tuples
// Case 1. Check YamlParameters initialization with different parameters sets

struct InitParameters {
uint8_t* flash_ptr;
Expand Down

0 comments on commit f1f3030

Please sign in to comment.