Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 1 | #include "helper.hpp" |
| 2 | #include "status.hpp" |
| 3 | |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 4 | #include <ipmiblob/test/blob_interface_mock.hpp> |
| 5 | |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 6 | #include <cstdint> |
| 7 | |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | namespace host_tool |
| 11 | { |
| 12 | using ::testing::Return; |
| 13 | using ::testing::TypedEq; |
| 14 | |
Vivekanand Veeracholan | c7fa2c2 | 2021-02-18 18:05:41 -0800 | [diff] [blame^] | 15 | class HelperTest : public ::testing::Test |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 16 | { |
| 17 | protected: |
| 18 | ipmiblob::BlobInterfaceMock blobMock; |
| 19 | std::uint16_t session = 0xbeef; |
| 20 | }; |
| 21 | |
Vivekanand Veeracholan | c7fa2c2 | 2021-02-18 18:05:41 -0800 | [diff] [blame^] | 22 | TEST_F(HelperTest, PollStatusReturnsAfterSuccess) |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 23 | { |
| 24 | ipmiblob::StatResponse verificationResponse = {}; |
| 25 | /* the other details of the response are ignored, and should be. */ |
| 26 | verificationResponse.metadata.push_back( |
| 27 | static_cast<std::uint8_t>(ipmi_flash::ActionStatus::success)); |
| 28 | |
| 29 | EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) |
| 30 | .WillOnce(Return(verificationResponse)); |
| 31 | |
| 32 | EXPECT_TRUE(pollStatus(session, &blobMock)); |
| 33 | } |
| 34 | |
Vivekanand Veeracholan | c7fa2c2 | 2021-02-18 18:05:41 -0800 | [diff] [blame^] | 35 | TEST_F(HelperTest, PollStatusReturnsAfterFailure) |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 36 | { |
| 37 | ipmiblob::StatResponse verificationResponse = {}; |
| 38 | /* the other details of the response are ignored, and should be. */ |
| 39 | verificationResponse.metadata.push_back( |
| 40 | static_cast<std::uint8_t>(ipmi_flash::ActionStatus::failed)); |
| 41 | |
| 42 | EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) |
| 43 | .WillOnce(Return(verificationResponse)); |
| 44 | |
| 45 | EXPECT_FALSE(pollStatus(session, &blobMock)); |
| 46 | } |
| 47 | |
Vivekanand Veeracholan | c7fa2c2 | 2021-02-18 18:05:41 -0800 | [diff] [blame^] | 48 | TEST_F(HelperTest, MemcpyAlignedOneByte) |
| 49 | { |
| 50 | const char source = 'a'; |
| 51 | char destination; |
| 52 | |
| 53 | EXPECT_EQ(&destination, |
| 54 | memcpyAligned(&destination, &source, sizeof(source))); |
| 55 | EXPECT_EQ(destination, source); |
| 56 | } |
| 57 | |
| 58 | TEST_F(HelperTest, MemcpyAlignedMultiByte) |
| 59 | { |
| 60 | const char source[14] = "abcdefghijklm"; |
| 61 | char destination[14] = "xxxxxxxxxxxxx"; |
| 62 | |
| 63 | EXPECT_EQ(&destination, |
| 64 | memcpyAligned(&destination, &source, sizeof(source))); |
| 65 | EXPECT_EQ(0, memcmp(&destination, &source, sizeof(source))); |
| 66 | } |
| 67 | |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 68 | } // namespace host_tool |