Skip to content

Commit

Permalink
erase is done when a write is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielsantosphilips committed Oct 29, 2024
1 parent d7c11ea commit 3b0d022
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
13 changes: 8 additions & 5 deletions services/util/ConfigurationStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,17 @@ namespace services
++operationId;
writeRequested = false;
writingBlob = true;
Serialize(*activeBlob, [this, thisId]()
activeBlob->Erase([this, thisId]()
{
inactiveBlob->Erase([this, thisId]()
Serialize(*activeBlob, [this, thisId]()
{
BlobWriteDone();
NotifyObservers([thisId](ConfigurationStoreObserver& observer)
inactiveBlob->Erase([this, thisId]()
{
observer.OperationDone(thisId);
BlobWriteDone();
NotifyObservers([thisId](ConfigurationStoreObserver& observer)
{
observer.OperationDone(thisId);
});
});
});
});
Expand Down
35 changes: 26 additions & 9 deletions services/util/test/TestConfigurationStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ TEST_F(ConfigurationStoreTest, after_successful_blob_load_configuration_is_avail
OnLoaded(success);
});

EXPECT_CALL(configurationBlob2, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
onRecoverDone(true);
//EXPECT_CALL(configurationBlob2, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));

EXPECT_CALL(configurationBlob1, CurrentBlob()).WillOnce(testing::Return(infra::ByteRange()));
EXPECT_CALL(dataInstance, Deserialize(testing::_));
EXPECT_CALL(*this, OnLoaded(true));
onEraseDone();
//onEraseDone();
onRecoverDone(true);
}

TEST_F(ConfigurationStoreTest, after_successful_blob_load_from_second_flash_configuration_is_available)
Expand Down Expand Up @@ -356,9 +356,13 @@ TEST_F(ConfigurationStoreTest, Write_writes_to_blob)
{
formatter.PutFixed32(1);
}));
EXPECT_CALL(configurationBlob1, Write(4, testing::_)).WillOnce(testing::SaveArg<1>(&onWriteDone));

EXPECT_CALL(configurationBlob1, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
configurationStore.Write();

EXPECT_CALL(configurationBlob1, Write(4, testing::_)).WillOnce(testing::SaveArg<1>(&onWriteDone));
onEraseDone();

EXPECT_CALL(configurationBlob2, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
onWriteDone();

Expand All @@ -374,13 +378,10 @@ TEST_F(ConfigurationStoreTest, Write_writes_to_other_blob_than_recovered)
OnLoaded(success);
});

EXPECT_CALL(configurationBlob2, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
onRecoverDone(true);

EXPECT_CALL(configurationBlob1, CurrentBlob()).WillOnce(testing::Return(infra::ByteRange()));
EXPECT_CALL(dataInstance, Deserialize(testing::_));
EXPECT_CALL(*this, OnLoaded(true));
onEraseDone();
onRecoverDone(true);

infra::Function<void()> onWriteDone;
std::array<uint8_t, 32> data;
Expand All @@ -389,9 +390,13 @@ TEST_F(ConfigurationStoreTest, Write_writes_to_other_blob_than_recovered)
{
formatter.PutFixed32(1);
}));
EXPECT_CALL(configurationBlob2, Write(4, testing::_)).WillOnce(testing::SaveArg<1>(&onWriteDone));

EXPECT_CALL(configurationBlob2, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
configurationStore.Write();

EXPECT_CALL(configurationBlob2, Write(4, testing::_)).WillOnce(testing::SaveArg<1>(&onWriteDone));
onEraseDone();

EXPECT_CALL(configurationBlob1, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
onWriteDone();

Expand All @@ -410,9 +415,12 @@ TEST_F(ConfigurationStoreTest, double_Write_is_held)
{
formatter.PutFixed32(1);
}));

EXPECT_CALL(configurationBlob1, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
EXPECT_CALL(configurationBlob1, Write(4, testing::_)).WillOnce(testing::SaveArg<1>(&onWriteDone));
EXPECT_EQ(0, configurationStore.Write());
EXPECT_EQ(1, configurationStore.Write());
onEraseDone();

EXPECT_CALL(configurationBlob2, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
onWriteDone();
Expand All @@ -422,9 +430,12 @@ TEST_F(ConfigurationStoreTest, double_Write_is_held)
{
formatter.PutFixed32(1);
}));
infra::Function<void()> onEraseDoneBlob2;
EXPECT_CALL(configurationBlob2, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDoneBlob2));
EXPECT_CALL(configurationBlob2, Write(4, testing::_)).WillOnce(testing::SaveArg<1>(&onWriteDone));
EXPECT_CALL(observer, OperationDone(0));
onEraseDone();
onEraseDoneBlob2();

EXPECT_CALL(configurationBlob1, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
onWriteDone();
Expand All @@ -446,8 +457,10 @@ TEST_F(ConfigurationStoreTest, during_Lock_Write_is_held)
{
formatter.PutFixed32(1);
}));
EXPECT_CALL(configurationBlob1, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
EXPECT_CALL(configurationBlob1, Write(4, testing::_)).WillOnce(testing::SaveArg<1>(&onWriteDone));
lock = infra::none;
onEraseDone();
}

TEST_F(ConfigurationStoreTest, onDone_is_called_when_done)
Expand All @@ -461,9 +474,11 @@ TEST_F(ConfigurationStoreTest, onDone_is_called_when_done)
{
formatter.PutFixed32(1);
}));
EXPECT_CALL(configurationBlob1, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
EXPECT_CALL(configurationBlob1, Write(4, testing::_)).WillOnce(testing::SaveArg<1>(&onWriteDone));

EXPECT_EQ(0, configurationStore.Write());
onEraseDone();

EXPECT_CALL(configurationBlob2, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
onWriteDone();
Expand Down Expand Up @@ -514,8 +529,10 @@ TEST_F(ConfigurationStoreTest, ConfigurationStoreAccess_writes_ConfigurationStor
{
formatter.PutFixed32(1);
}));
EXPECT_CALL(configurationBlob1, Erase(testing::_)).WillOnce(testing::SaveArg<0>(&onEraseDone));
EXPECT_CALL(configurationBlob1, Write(4, testing::_)).WillOnce(testing::SaveArg<1>(&onWriteDone));
access.Write();
onEraseDone();
}

class FactoryDefaultConfigurationStoreTest
Expand Down

0 comments on commit 3b0d022

Please sign in to comment.