Skip to content

Commit 539ace2

Browse files
committed
When the opening of the file on the OTA storage device for the update file fails then the OTA logic should transition to the OTAState::Error state and set OTAError::StorageOpenFailed
1 parent 60bd9ae commit 539ace2

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

extras/test/src/test_OTALogic.cpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ 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]")
52+
TEST_CASE("OTAStorage initialisation fails ", "[OTAStorage::init() -> returns false]")
5353
{
5454
Mock<OTAStorage> ota_storage;
5555

@@ -65,7 +65,7 @@ TEST_CASE("OTAStorage initialisation failed ", "[OTAStorage::init() -> returns f
6565
/* Perform test */
6666
OTALogic ota_logic(ota_storage.get());
6767

68-
WHEN("OTALogic::update() is called ")
68+
WHEN("OTALogic::update() is called")
6969
{
7070
ota_logic.update();
7171
THEN("The OTA logic should be in the 'Error' state")
@@ -74,7 +74,42 @@ TEST_CASE("OTAStorage initialisation failed ", "[OTAStorage::init() -> returns f
7474
}
7575
THEN("The OTA error should be set to OTAError::StorageInitFailed")
7676
{
77-
REQUIRE(ota_logic.update() == OTAError::StorageInitFailed);
77+
REQUIRE(ota_logic.error() == OTAError::StorageInitFailed);
78+
}
79+
}
80+
}
81+
82+
/**************************************************************************************/
83+
84+
TEST_CASE("OTAStorage opening of storage file fails ", "[OTAStorage::open() -> returns false]")
85+
{
86+
Mock<OTAStorage> ota_storage;
87+
88+
/* Configure mock object */
89+
When(Method(ota_storage, init)).Return(true);
90+
When(Method(ota_storage, open)).Return(false);
91+
Fake(Method(ota_storage, write));
92+
Fake(Method(ota_storage, close));
93+
Fake(Method(ota_storage, remove));
94+
Fake(Method(ota_storage, deinit));
95+
96+
97+
/* Perform test */
98+
OTALogic ota_logic(ota_storage.get());
99+
100+
WHEN("OTALogic::update() is called and some bytes have been received")
101+
{
102+
uint8_t const SOME_FAKE_DATA[16] = {0};
103+
ota_logic.onOTADataReceived(SOME_FAKE_DATA, sizeof(SOME_FAKE_DATA));
104+
ota_logic.update();
105+
106+
THEN("The OTA logic should be in the 'Error' state")
107+
{
108+
REQUIRE(ota_logic.state() == OTAState::Error);
109+
}
110+
THEN("The OTA error should be set to OTAError::StorageOpenFailed")
111+
{
112+
REQUIRE(ota_logic.error() == OTAError::StorageOpenFailed);
78113
}
79114
}
80115
}

src/utility/ota/OTALogic.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ OTAState OTALogic::handle_StartDownload()
112112
{
113113
if(_ota_storage.open()) {
114114
return OTAState::WaitForHeader;
115+
} else {
116+
_ota_error = OTAError::StorageOpenFailed;
117+
return OTAState::Error;
115118
}
116-
return OTAState::Error;
117119
}
118120

119121
OTAState OTALogic::handle_WaitForHeader()

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, StorageInitFailed, ChecksumMismatch
46+
None, StorageInitFailed, StorageOpenFailed, ChecksumMismatch
4747
};
4848

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

0 commit comments

Comments
 (0)