extend file_handler to support reads
Problem: the upcomming version handler will need to read from files.
Currently file hander (image handler) does not support reads.
Solution: Add read support by providing an optional mode parameter.
Tests added:
FileHanderTest added to
- Test out open for reads
- Test out reading out bytes and verifying size and content
- Test out trying to read beyond EOF
- Test out offset reads that go beyond EOF
Tested:
Existing unit tests pass
New unit tests for reading all pass
Signed-off-by: Jason Ling <jasonling@google.com>
Change-Id: Ie416a6b4b452d8d04fa158bd55989d07a891896f
diff --git a/bmc/firmware-handler/test/firmware_multiplebundle_unittest.cpp b/bmc/firmware-handler/test/firmware_multiplebundle_unittest.cpp
index 20c63a9..58f07c7 100644
--- a/bmc/firmware-handler/test/firmware_multiplebundle_unittest.cpp
+++ b/bmc/firmware-handler/test/firmware_multiplebundle_unittest.cpp
@@ -118,7 +118,7 @@
/* You can only have one file open at a time, and the first firmware file
* you open locks it down
*/
- EXPECT_CALL(*staticImageMock, open(staticLayoutBlobId))
+ EXPECT_CALL(*staticImageMock, open(staticLayoutBlobId, std::ios::out))
.WillOnce(Return(true));
EXPECT_CALL(*bmcPrepareMockPtr, trigger()).WillOnce(Return(true));
@@ -130,14 +130,15 @@
expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
- EXPECT_CALL(*biosImageMock, open(biosBlobId)).Times(0);
+ EXPECT_CALL(*biosImageMock, open(biosBlobId, std::ios::out)).Times(0);
EXPECT_FALSE(handler->open(session, flags, biosBlobId));
}
TEST_F(IpmiOnlyTwoFirmwaresTest, OpeningHashBeforeBiosSucceeds)
{
/* Opening the hash blob does nothing special in this regard. */
- EXPECT_CALL(*hashImageMock, open(hashBlobId)).WillOnce(Return(true));
+ EXPECT_CALL(*hashImageMock, open(hashBlobId, std::ios::out))
+ .WillOnce(Return(true));
EXPECT_TRUE(handler->open(session, flags, hashBlobId));
expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);
@@ -148,7 +149,8 @@
expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
ASSERT_FALSE(handler->canHandleBlob(verifyBlobId));
- EXPECT_CALL(*biosImageMock, open(biosBlobId)).WillOnce(Return(true));
+ EXPECT_CALL(*biosImageMock, open(biosBlobId, std::ios::out))
+ .WillOnce(Return(true));
EXPECT_TRUE(handler->open(session, flags, biosBlobId));
expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);