Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 1 | #include <cstdint> |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 2 | #include <ipmiblob/blob_handler.hpp> |
Patrick Venture | 1681f7f | 2019-03-07 12:59:29 -0800 | [diff] [blame] | 3 | #include <ipmiblob/test/crc_mock.hpp> |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 4 | #include <ipmiblob/test/ipmi_interface_mock.hpp> |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 5 | #include <memory> |
| 6 | #include <vector> |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 10 | namespace ipmiblob |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 11 | { |
| 12 | CrcInterface* crcIntf = nullptr; |
| 13 | |
| 14 | std::uint16_t generateCrc(const std::vector<std::uint8_t>& data) |
| 15 | { |
| 16 | return (crcIntf) ? crcIntf->generateCrc(data) : 0x00; |
| 17 | } |
| 18 | |
| 19 | using ::testing::Eq; |
| 20 | using ::testing::Return; |
| 21 | |
| 22 | class BlobHandlerTest : public ::testing::Test |
| 23 | { |
| 24 | protected: |
| 25 | void SetUp() override |
| 26 | { |
| 27 | crcIntf = &crcMock; |
| 28 | } |
| 29 | |
| 30 | CrcMock crcMock; |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 31 | |
| 32 | std::unique_ptr<IpmiInterface> CreateIpmiMock() |
| 33 | { |
| 34 | return std::make_unique<IpmiInterfaceMock>(); |
| 35 | } |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | TEST_F(BlobHandlerTest, getCountIpmiHappy) |
| 39 | { |
| 40 | /* Verify returns the value specified by the IPMI response. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 41 | auto ipmi = CreateIpmiMock(); |
| 42 | IpmiInterfaceMock* ipmiMock = |
| 43 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 44 | BlobHandler blob(std::move(ipmi)); |
| 45 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 46 | std::vector<std::uint8_t> request = { |
| 47 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobGetCount}; |
| 48 | |
| 49 | /* return 1 blob count. */ |
| 50 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 51 | 0x01, 0x00, 0x00, 0x00}; |
| 52 | |
| 53 | std::vector<std::uint8_t> bytes = {0x01, 0x00, 0x00, 0x00}; |
| 54 | EXPECT_CALL(crcMock, generateCrc(Eq(bytes))).WillOnce(Return(0x00)); |
| 55 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 56 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 57 | EXPECT_EQ(1, blob.getBlobCount()); |
| 58 | } |
| 59 | |
| 60 | TEST_F(BlobHandlerTest, enumerateBlobIpmiHappy) |
| 61 | { |
| 62 | /* Verify returns the name specified by the IPMI response. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 63 | auto ipmi = CreateIpmiMock(); |
| 64 | IpmiInterfaceMock* ipmiMock = |
| 65 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 66 | BlobHandler blob(std::move(ipmi)); |
| 67 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 68 | std::vector<std::uint8_t> request = { |
| 69 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobEnumerate, |
| 70 | 0x00, 0x00, 0x01, 0x00, |
| 71 | 0x00, 0x00}; |
| 72 | |
| 73 | /* return value. */ |
| 74 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 75 | 'a', 'b', 'c', 'd', 0x00}; |
| 76 | |
| 77 | std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd', 0x00}; |
| 78 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00}; |
| 79 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 80 | EXPECT_CALL(crcMock, generateCrc(Eq(bytes))).WillOnce(Return(0x00)); |
| 81 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 82 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 83 | EXPECT_STREQ("abcd", blob.enumerateBlob(1).c_str()); |
| 84 | } |
| 85 | |
| 86 | TEST_F(BlobHandlerTest, enumerateBlobIpmiNoBytes) |
| 87 | { |
| 88 | /* Simulate a case where the IPMI command returns no data. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 89 | auto ipmi = CreateIpmiMock(); |
| 90 | IpmiInterfaceMock* ipmiMock = |
| 91 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 92 | BlobHandler blob(std::move(ipmi)); |
| 93 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 94 | std::vector<std::uint8_t> request = { |
| 95 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobEnumerate, |
| 96 | 0x00, 0x00, 0x01, 0x00, |
| 97 | 0x00, 0x00}; |
| 98 | |
| 99 | /* return value. */ |
| 100 | std::vector<std::uint8_t> resp = {}; |
| 101 | |
| 102 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00}; |
| 103 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 104 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 105 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 106 | EXPECT_STREQ("", blob.enumerateBlob(1).c_str()); |
| 107 | } |
| 108 | |
| 109 | TEST_F(BlobHandlerTest, getBlobListIpmiHappy) |
| 110 | { |
| 111 | /* Verify returns the list built via the above two commands. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 112 | auto ipmi = CreateIpmiMock(); |
| 113 | IpmiInterfaceMock* ipmiMock = |
| 114 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 115 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 116 | |
| 117 | std::vector<std::uint8_t> request1 = { |
| 118 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobGetCount}; |
| 119 | |
| 120 | /* return 1 blob count. */ |
| 121 | std::vector<std::uint8_t> resp1 = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 122 | 0x01, 0x00, 0x00, 0x00}; |
| 123 | |
| 124 | std::vector<std::uint8_t> bytes1 = {0x01, 0x00, 0x00, 0x00}; |
| 125 | EXPECT_CALL(crcMock, generateCrc(Eq(bytes1))).WillOnce(Return(0x00)); |
| 126 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 127 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request1))).WillOnce(Return(resp1)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 128 | |
| 129 | std::vector<std::uint8_t> request2 = { |
| 130 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobEnumerate, |
| 131 | 0x00, 0x00, 0x00, 0x00, |
| 132 | 0x00, 0x00}; |
| 133 | |
| 134 | /* return value. */ |
| 135 | std::vector<std::uint8_t> resp2 = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 136 | 'a', 'b', 'c', 'd', 0x00}; |
| 137 | |
| 138 | std::vector<std::uint8_t> reqCrc = {0x00, 0x00, 0x00, 0x00}; |
| 139 | std::vector<std::uint8_t> bytes2 = {'a', 'b', 'c', 'd', 0x00}; |
| 140 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 141 | EXPECT_CALL(crcMock, generateCrc(Eq(bytes2))).WillOnce(Return(0x00)); |
| 142 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 143 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request2))).WillOnce(Return(resp2)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 144 | |
| 145 | /* A std::string is not nul-terminated by default. */ |
| 146 | std::vector<std::string> expectedList = {std::string{"abcd"}}; |
| 147 | |
| 148 | EXPECT_EQ(expectedList, blob.getBlobList()); |
| 149 | } |
| 150 | |
| 151 | TEST_F(BlobHandlerTest, getStatWithMetadata) |
| 152 | { |
| 153 | /* Stat received metadata. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 154 | auto ipmi = CreateIpmiMock(); |
| 155 | IpmiInterfaceMock* ipmiMock = |
| 156 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 157 | BlobHandler blob(std::move(ipmi)); |
| 158 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 159 | std::vector<std::uint8_t> request = { |
| 160 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobStat, |
| 161 | 0x00, 0x00, 'a', 'b', |
| 162 | 'c', 'd', 0x00}; |
| 163 | |
| 164 | /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */ |
| 165 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, 0xff, |
| 166 | 0x00, 0x00, 0x00, 0x00, 0x02, 0x34, 0x45}; |
| 167 | |
| 168 | std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00}; |
| 169 | std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, 0x00, |
| 170 | 0x00, 0x02, 0x34, 0x45}; |
| 171 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 172 | EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00)); |
| 173 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 174 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 175 | |
| 176 | auto meta = blob.getStat("abcd"); |
| 177 | EXPECT_EQ(meta.blob_state, 0xffff); |
| 178 | EXPECT_EQ(meta.size, 0x00); |
| 179 | std::vector<std::uint8_t> metadata = {0x34, 0x45}; |
| 180 | EXPECT_EQ(metadata, meta.metadata); |
| 181 | } |
| 182 | |
| 183 | TEST_F(BlobHandlerTest, getStatNoMetadata) |
| 184 | { |
| 185 | /* Stat received no metadata. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 186 | auto ipmi = CreateIpmiMock(); |
| 187 | IpmiInterfaceMock* ipmiMock = |
| 188 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 189 | BlobHandler blob(std::move(ipmi)); |
| 190 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 191 | std::vector<std::uint8_t> request = { |
| 192 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobStat, |
| 193 | 0x00, 0x00, 'a', 'b', |
| 194 | 'c', 'd', 0x00}; |
| 195 | |
| 196 | /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */ |
| 197 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, |
| 198 | 0xff, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 199 | |
| 200 | std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00}; |
| 201 | std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, |
| 202 | 0x00, 0x00, 0x00}; |
| 203 | |
| 204 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 205 | EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00)); |
| 206 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 207 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 208 | |
| 209 | auto meta = blob.getStat("abcd"); |
| 210 | EXPECT_EQ(meta.blob_state, 0xffff); |
| 211 | EXPECT_EQ(meta.size, 0x00); |
| 212 | std::vector<std::uint8_t> metadata = {}; |
| 213 | EXPECT_EQ(metadata, meta.metadata); |
| 214 | } |
| 215 | |
Patrick Venture | 16a99a6 | 2019-05-03 17:21:30 -0700 | [diff] [blame] | 216 | TEST_F(BlobHandlerTest, getSessionStatNoMetadata) |
| 217 | { |
| 218 | /* The get session stat succeeds. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 219 | auto ipmi = CreateIpmiMock(); |
| 220 | IpmiInterfaceMock* ipmiMock = |
| 221 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 222 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 16a99a6 | 2019-05-03 17:21:30 -0700 | [diff] [blame] | 223 | |
| 224 | std::vector<std::uint8_t> request = { |
| 225 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobSessionStat, |
| 226 | 0x00, 0x00, 0x01, 0x00}; |
| 227 | |
| 228 | /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */ |
| 229 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, |
| 230 | 0xff, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 231 | |
| 232 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00}; |
| 233 | std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, |
| 234 | 0x00, 0x00, 0x00}; |
| 235 | |
| 236 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 237 | EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00)); |
| 238 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 239 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 16a99a6 | 2019-05-03 17:21:30 -0700 | [diff] [blame] | 240 | |
| 241 | auto meta = blob.getStat(0x0001); |
| 242 | EXPECT_EQ(meta.blob_state, 0xffff); |
| 243 | EXPECT_EQ(meta.size, 0x00); |
| 244 | std::vector<std::uint8_t> metadata = {}; |
| 245 | EXPECT_EQ(metadata, meta.metadata); |
| 246 | } |
| 247 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 248 | TEST_F(BlobHandlerTest, openBlobSucceeds) |
| 249 | { |
| 250 | /* The open blob succeeds. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 251 | auto ipmi = CreateIpmiMock(); |
| 252 | IpmiInterfaceMock* ipmiMock = |
| 253 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 254 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 255 | |
| 256 | std::vector<std::uint8_t> request = { |
| 257 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobOpen, |
| 258 | 0x00, 0x00, 0x02, 0x04, |
| 259 | 'a', 'b', 'c', 'd', |
| 260 | 0x00}; |
| 261 | |
| 262 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xfe, 0xed}; |
| 263 | |
| 264 | std::vector<std::uint8_t> reqCrc = {0x02, 0x04, 'a', 'b', 'c', 'd', 0x00}; |
| 265 | std::vector<std::uint8_t> respCrc = {0xfe, 0xed}; |
| 266 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 267 | EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00)); |
| 268 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 269 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 270 | |
| 271 | const int writeBit = (1 << 1); |
| 272 | const int lpcBit = (1 << 10); |
| 273 | |
| 274 | auto session = blob.openBlob("abcd", writeBit | lpcBit); |
| 275 | EXPECT_EQ(0xedfe, session); |
| 276 | } |
| 277 | |
| 278 | TEST_F(BlobHandlerTest, closeBlobSucceeds) |
| 279 | { |
| 280 | /* The close succeeds. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 281 | auto ipmi = CreateIpmiMock(); |
| 282 | IpmiInterfaceMock* ipmiMock = |
| 283 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 284 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 285 | |
| 286 | std::vector<std::uint8_t> request = { |
| 287 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobClose, |
| 288 | 0x00, 0x00, 0x01, 0x00}; |
| 289 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00}; |
| 290 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00}; |
| 291 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 292 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 293 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 294 | |
| 295 | blob.closeBlob(0x0001); |
| 296 | } |
| 297 | |
| 298 | TEST_F(BlobHandlerTest, writeBytesSucceeds) |
| 299 | { |
| 300 | /* The write bytes succeeds. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 301 | auto ipmi = CreateIpmiMock(); |
| 302 | IpmiInterfaceMock* ipmiMock = |
| 303 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 304 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 305 | |
| 306 | std::vector<std::uint8_t> request = { |
| 307 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobWrite, |
| 308 | 0x00, 0x00, 0x01, 0x00, |
| 309 | 0x00, 0x00, 0x00, 0x00, |
| 310 | 'a', 'b', 'c', 'd'}; |
| 311 | |
| 312 | std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd'}; |
| 313 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00}; |
| 314 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00, |
| 315 | 0x00, 'a', 'b', 'c', 'd'}; |
| 316 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 317 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 318 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 319 | |
| 320 | blob.writeBytes(0x0001, 0, bytes); |
| 321 | } |
| 322 | |
| 323 | TEST_F(BlobHandlerTest, readBytesSucceeds) |
| 324 | { |
| 325 | /* The reading of bytes succeeds. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 326 | auto ipmi = CreateIpmiMock(); |
| 327 | IpmiInterfaceMock* ipmiMock = |
| 328 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 329 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 330 | |
| 331 | std::vector<std::uint8_t> request = { |
| 332 | 0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobRead, |
| 333 | 0x00, 0x00, 0x01, 0x00, |
| 334 | 0x00, 0x00, 0x00, 0x00, |
| 335 | 0x04, 0x00, 0x00, 0x00}; |
| 336 | |
| 337 | std::vector<std::uint8_t> expectedBytes = {'a', 'b', 'c', 'd'}; |
| 338 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 339 | 'a', 'b', 'c', 'd'}; |
| 340 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00, |
| 341 | 0x00, 0x04, 0x00, 0x00, 0x00}; |
| 342 | std::vector<std::uint8_t> respCrc = {'a', 'b', 'c', 'd'}; |
| 343 | |
| 344 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 345 | EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00)); |
| 346 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame^] | 347 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 348 | |
| 349 | EXPECT_EQ(blob.readBytes(0x0001, 0, 4), expectedBytes); |
| 350 | } |
| 351 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 352 | } // namespace ipmiblob |