Skip to content

Commit 60bd9ae

Browse files
committed
When the OTAStorage::init operation fails the OTA logic should transition to OTAState::Error and indicate that the error is of type OTAError::StorageInitFailed
1 parent 6c3a6ce commit 60bd9ae

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

extras/test/src/test_OTALogic.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,38 @@ void simulateOTABinaryReception(OTALogic & ota_logic, OTAData const & ota_test_d
4949
TEST CODE
5050
**************************************************************************************/
5151

52+
TEST_CASE("OTAStorage initialisation failed ", "[OTAStorage::init() -> returns false]")
53+
{
54+
Mock<OTAStorage> ota_storage;
55+
56+
/* Configure mock object */
57+
When(Method(ota_storage, init)).Return(false);
58+
Fake(Method(ota_storage, open));
59+
Fake(Method(ota_storage, write));
60+
Fake(Method(ota_storage, close));
61+
Fake(Method(ota_storage, remove));
62+
Fake(Method(ota_storage, deinit));
63+
64+
65+
/* Perform test */
66+
OTALogic ota_logic(ota_storage.get());
67+
68+
WHEN("OTALogic::update() is called ")
69+
{
70+
ota_logic.update();
71+
THEN("The OTA logic should be in the 'Error' state")
72+
{
73+
REQUIRE(ota_logic.state() == OTAState::Error);
74+
}
75+
THEN("The OTA error should be set to OTAError::StorageInitFailed")
76+
{
77+
REQUIRE(ota_logic.update() == OTAError::StorageInitFailed);
78+
}
79+
}
80+
}
81+
82+
/**************************************************************************************/
83+
5284
TEST_CASE("Valid OTA data is received ", "[OTALogic]")
5385
{
5486
Mock<OTAStorage> ota_storage;
@@ -98,6 +130,8 @@ TEST_CASE("Valid OTA data is received ", "[OTALogic]")
98130
}
99131
}
100132

133+
/**************************************************************************************/
134+
101135
TEST_CASE("Invalid OTA data is received ", "[OTALogic - CRC wrong]")
102136
{
103137
Mock<OTAStorage> ota_storage;

src/utility/ota/OTALogic.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ OTAState OTALogic::handle_Init()
9494
{
9595
if (_ota_storage.init()) {
9696
return OTAState::Idle;
97+
} else {
98+
_ota_error = OTAError::StorageInitFailed;
99+
return OTAState::Error;
97100
}
98-
return OTAState::Error;
99101
}
100102

101103
OTAState OTALogic::handle_Idle()

src/utility/ota/OTALogic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ enum class OTAState
4343

4444
enum class OTAError
4545
{
46-
None, ChecksumMismatch
46+
None, StorageInitFailed, ChecksumMismatch
4747
};
4848

4949
/******************************************************************************

0 commit comments

Comments
 (0)