Patrick Venture | c79faa1 | 2018-12-12 13:12:21 -0800 | [diff] [blame^] | 1 | #include "blob_handler.hpp" |
| 2 | #include "ipmi_interface_mock.hpp" |
| 3 | |
| 4 | #include <gtest/gtest.h> |
| 5 | |
| 6 | std::uint16_t expectedCrc = 0; |
| 7 | |
| 8 | std::uint16_t generateCrc(const std::vector<std::uint8_t>& data) |
| 9 | { |
| 10 | return expectedCrc; |
| 11 | } |
| 12 | |
| 13 | using ::testing::Eq; |
| 14 | using ::testing::Return; |
| 15 | |
| 16 | TEST(BlobHandler, getCountIpmiHappy) |
| 17 | { |
| 18 | /* Verify returns the value specified by the IPMI response. */ |
| 19 | IpmiInterfaceMock ipmiMock; |
| 20 | BlobHandler blob(&ipmiMock); |
| 21 | std::vector<std::uint8_t> request = { |
| 22 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobGetCount}; |
| 23 | |
| 24 | /* return 1 blob count. */ |
| 25 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 26 | 0x01, 0x00, 0x00, 0x00}; |
| 27 | |
| 28 | EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
| 29 | EXPECT_EQ(1, blob.getBlobCount()); |
| 30 | } |
| 31 | |
| 32 | TEST(BlobHandler, enumerateBlobIpmiHappy) |
| 33 | { |
| 34 | /* Verify returns the name specified by the IPMI response. */ |
| 35 | IpmiInterfaceMock ipmiMock; |
| 36 | BlobHandler blob(&ipmiMock); |
| 37 | std::vector<std::uint8_t> request = { |
| 38 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobEnumerate, |
| 39 | 0x00, 0x00, 0x01, 0x00, |
| 40 | 0x00, 0x00}; |
| 41 | |
| 42 | /* return value. */ |
| 43 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 44 | 'a', 'b', 'c', 'd'}; |
| 45 | |
| 46 | EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
| 47 | EXPECT_STREQ("abcd", blob.enumerateBlob(1).c_str()); |
| 48 | } |
| 49 | |
| 50 | TEST(BlobHandler, enumerateBlobIpmiNoBytes) |
| 51 | { |
| 52 | /* Simulate a case where the IPMI command returns no data. */ |
| 53 | IpmiInterfaceMock ipmiMock; |
| 54 | BlobHandler blob(&ipmiMock); |
| 55 | std::vector<std::uint8_t> request = { |
| 56 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobEnumerate, |
| 57 | 0x00, 0x00, 0x01, 0x00, |
| 58 | 0x00, 0x00}; |
| 59 | |
| 60 | /* return value. */ |
| 61 | std::vector<std::uint8_t> resp = {}; |
| 62 | |
| 63 | EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
| 64 | EXPECT_STREQ("", blob.enumerateBlob(1).c_str()); |
| 65 | } |
| 66 | |
| 67 | TEST(BlobHandler, getBlobListIpmiHappy) |
| 68 | { |
| 69 | /* Verify returns the list built via the above two commands. */ |
| 70 | IpmiInterfaceMock ipmiMock; |
| 71 | BlobHandler blob(&ipmiMock); |
| 72 | |
| 73 | std::vector<std::uint8_t> request1 = { |
| 74 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobGetCount}; |
| 75 | |
| 76 | /* return 1 blob count. */ |
| 77 | std::vector<std::uint8_t> resp1 = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 78 | 0x01, 0x00, 0x00, 0x00}; |
| 79 | |
| 80 | EXPECT_CALL(ipmiMock, sendPacket(Eq(request1))).WillOnce(Return(resp1)); |
| 81 | |
| 82 | std::vector<std::uint8_t> request2 = { |
| 83 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobEnumerate, |
| 84 | 0x00, 0x00, 0x00, 0x00, |
| 85 | 0x00, 0x00}; |
| 86 | |
| 87 | /* return value. */ |
| 88 | std::vector<std::uint8_t> resp2 = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 89 | 'a', 'b', 'c', 'd'}; |
| 90 | |
| 91 | EXPECT_CALL(ipmiMock, sendPacket(Eq(request2))).WillOnce(Return(resp2)); |
| 92 | |
| 93 | std::vector<std::string> expectedList = {"abcd"}; |
| 94 | |
| 95 | EXPECT_EQ(expectedList, blob.getBlobList()); |
| 96 | } |