blob: 3b64d5711b34e7d982ab4564b0df55510e71921a [file] [log] [blame]
Patrick Venture123b5c02019-03-05 14:01:00 -08001#include <ipmiblob/blob_handler.hpp>
Patrick Venture1681f7f2019-03-07 12:59:29 -08002#include <ipmiblob/test/crc_mock.hpp>
Patrick Venture123b5c02019-03-05 14:01:00 -08003#include <ipmiblob/test/ipmi_interface_mock.hpp>
Patrick Venture60edc612020-06-24 15:06:41 -07004
5#include <cstdint>
Patrick Venture786a5412019-05-13 07:40:22 -07006#include <memory>
7#include <vector>
Patrick Venture123b5c02019-03-05 14:01:00 -08008
9#include <gtest/gtest.h>
10
Patrick Venture1470bec2019-03-06 07:33:12 -080011namespace ipmiblob
Patrick Venture123b5c02019-03-05 14:01:00 -080012{
13CrcInterface* crcIntf = nullptr;
14
15std::uint16_t generateCrc(const std::vector<std::uint8_t>& data)
16{
17 return (crcIntf) ? crcIntf->generateCrc(data) : 0x00;
18}
19
Patrick Venture958f1ce2019-05-31 17:07:25 -070020using ::testing::ContainerEq;
Patrick Venture123b5c02019-03-05 14:01:00 -080021using ::testing::Eq;
22using ::testing::Return;
23
24class BlobHandlerTest : public ::testing::Test
25{
26 protected:
27 void SetUp() override
28 {
29 crcIntf = &crcMock;
30 }
31
32 CrcMock crcMock;
Patrick Venture786a5412019-05-13 07:40:22 -070033
34 std::unique_ptr<IpmiInterface> CreateIpmiMock()
35 {
36 return std::make_unique<IpmiInterfaceMock>();
37 }
Patrick Venture123b5c02019-03-05 14:01:00 -080038};
39
40TEST_F(BlobHandlerTest, getCountIpmiHappy)
41{
42 /* Verify returns the value specified by the IPMI response. */
Patrick Venture786a5412019-05-13 07:40:22 -070043 auto ipmi = CreateIpmiMock();
44 IpmiInterfaceMock* ipmiMock =
45 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
46 BlobHandler blob(std::move(ipmi));
47
Patrick Venture123b5c02019-03-05 14:01:00 -080048 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -070049 0xcf, 0xc2, 0x00,
50 static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobGetCount)};
Patrick Venture123b5c02019-03-05 14:01:00 -080051
52 /* return 1 blob count. */
53 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
54 0x01, 0x00, 0x00, 0x00};
55
56 std::vector<std::uint8_t> bytes = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -070057 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes)))
58 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -080059
Patrick Venture958f1ce2019-05-31 17:07:25 -070060 EXPECT_CALL(*ipmiMock,
61 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
62 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -080063 EXPECT_EQ(1, blob.getBlobCount());
64}
65
66TEST_F(BlobHandlerTest, enumerateBlobIpmiHappy)
67{
68 /* Verify returns the name specified by the IPMI response. */
Patrick Venture786a5412019-05-13 07:40:22 -070069 auto ipmi = CreateIpmiMock();
70 IpmiInterfaceMock* ipmiMock =
71 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
72 BlobHandler blob(std::move(ipmi));
73
Patrick Venture123b5c02019-03-05 14:01:00 -080074 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -070075 0xcf, 0xc2,
76 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate),
77 0x00, 0x00,
78 0x01, 0x00,
Patrick Venture123b5c02019-03-05 14:01:00 -080079 0x00, 0x00};
80
81 /* return value. */
82 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
83 'a', 'b', 'c', 'd', 0x00};
84
85 std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd', 0x00};
86 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -070087 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
88 .WillOnce(Return(0x00));
89 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes)))
90 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -080091
Patrick Venture958f1ce2019-05-31 17:07:25 -070092 EXPECT_CALL(*ipmiMock,
93 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
94 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -080095 EXPECT_STREQ("abcd", blob.enumerateBlob(1).c_str());
96}
97
98TEST_F(BlobHandlerTest, enumerateBlobIpmiNoBytes)
99{
100 /* Simulate a case where the IPMI command returns no data. */
Patrick Venture786a5412019-05-13 07:40:22 -0700101 auto ipmi = CreateIpmiMock();
102 IpmiInterfaceMock* ipmiMock =
103 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
104 BlobHandler blob(std::move(ipmi));
105
Patrick Venture123b5c02019-03-05 14:01:00 -0800106 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700107 0xcf, 0xc2,
108 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate),
109 0x00, 0x00,
110 0x01, 0x00,
Patrick Venture123b5c02019-03-05 14:01:00 -0800111 0x00, 0x00};
112
113 /* return value. */
114 std::vector<std::uint8_t> resp = {};
115
116 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700117 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
118 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800119
Patrick Venture958f1ce2019-05-31 17:07:25 -0700120 EXPECT_CALL(*ipmiMock,
121 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
122 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800123 EXPECT_STREQ("", blob.enumerateBlob(1).c_str());
124}
125
126TEST_F(BlobHandlerTest, getBlobListIpmiHappy)
127{
128 /* Verify returns the list built via the above two commands. */
Patrick Venture786a5412019-05-13 07:40:22 -0700129 auto ipmi = CreateIpmiMock();
130 IpmiInterfaceMock* ipmiMock =
131 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
132 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800133
134 std::vector<std::uint8_t> request1 = {
Patrick Venture44474642019-05-20 19:11:04 -0700135 0xcf, 0xc2, 0x00,
136 static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobGetCount)};
Patrick Venture123b5c02019-03-05 14:01:00 -0800137
138 /* return 1 blob count. */
139 std::vector<std::uint8_t> resp1 = {0xcf, 0xc2, 0x00, 0x00, 0x00,
140 0x01, 0x00, 0x00, 0x00};
141
142 std::vector<std::uint8_t> bytes1 = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700143 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes1)))
144 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800145
Patrick Venture958f1ce2019-05-31 17:07:25 -0700146 EXPECT_CALL(*ipmiMock,
147 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request1)))
148 .WillOnce(Return(resp1));
Patrick Venture123b5c02019-03-05 14:01:00 -0800149
150 std::vector<std::uint8_t> request2 = {
Patrick Venture44474642019-05-20 19:11:04 -0700151 0xcf, 0xc2,
152 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate),
153 0x00, 0x00,
154 0x00, 0x00,
Patrick Venture123b5c02019-03-05 14:01:00 -0800155 0x00, 0x00};
156
157 /* return value. */
158 std::vector<std::uint8_t> resp2 = {0xcf, 0xc2, 0x00, 0x00, 0x00,
159 'a', 'b', 'c', 'd', 0x00};
160
161 std::vector<std::uint8_t> reqCrc = {0x00, 0x00, 0x00, 0x00};
162 std::vector<std::uint8_t> bytes2 = {'a', 'b', 'c', 'd', 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700163 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
164 .WillOnce(Return(0x00));
165 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes2)))
166 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800167
Patrick Venture958f1ce2019-05-31 17:07:25 -0700168 EXPECT_CALL(*ipmiMock,
169 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request2)))
170 .WillOnce(Return(resp2));
Patrick Venture123b5c02019-03-05 14:01:00 -0800171
172 /* A std::string is not nul-terminated by default. */
173 std::vector<std::string> expectedList = {std::string{"abcd"}};
174
175 EXPECT_EQ(expectedList, blob.getBlobList());
176}
177
178TEST_F(BlobHandlerTest, getStatWithMetadata)
179{
180 /* Stat received metadata. */
Patrick Venture786a5412019-05-13 07:40:22 -0700181 auto ipmi = CreateIpmiMock();
182 IpmiInterfaceMock* ipmiMock =
183 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
184 BlobHandler blob(std::move(ipmi));
185
Patrick Venture123b5c02019-03-05 14:01:00 -0800186 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700187 0xcf, 0xc2,
188 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobStat),
189 0x00, 0x00,
190 'a', 'b',
191 'c', 'd',
192 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800193
194 /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */
195 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, 0xff,
196 0x00, 0x00, 0x00, 0x00, 0x02, 0x34, 0x45};
197
198 std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
199 std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, 0x00,
200 0x00, 0x02, 0x34, 0x45};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700201 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
202 .WillOnce(Return(0x00));
203 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
204 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800205
Patrick Venture958f1ce2019-05-31 17:07:25 -0700206 EXPECT_CALL(*ipmiMock,
207 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
208 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800209
210 auto meta = blob.getStat("abcd");
211 EXPECT_EQ(meta.blob_state, 0xffff);
212 EXPECT_EQ(meta.size, 0x00);
213 std::vector<std::uint8_t> metadata = {0x34, 0x45};
214 EXPECT_EQ(metadata, meta.metadata);
215}
216
217TEST_F(BlobHandlerTest, getStatNoMetadata)
218{
219 /* Stat received no metadata. */
Patrick Venture786a5412019-05-13 07:40:22 -0700220 auto ipmi = CreateIpmiMock();
221 IpmiInterfaceMock* ipmiMock =
222 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
223 BlobHandler blob(std::move(ipmi));
224
Patrick Venture123b5c02019-03-05 14:01:00 -0800225 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700226 0xcf, 0xc2,
227 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobStat),
228 0x00, 0x00,
229 'a', 'b',
230 'c', 'd',
231 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800232
233 /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */
234 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff,
235 0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
236
237 std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
238 std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00,
239 0x00, 0x00, 0x00};
240
Patrick Venture958f1ce2019-05-31 17:07:25 -0700241 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
242 .WillOnce(Return(0x00));
243 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
244 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800245
Patrick Venture958f1ce2019-05-31 17:07:25 -0700246 EXPECT_CALL(*ipmiMock,
247 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
248 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800249
250 auto meta = blob.getStat("abcd");
251 EXPECT_EQ(meta.blob_state, 0xffff);
252 EXPECT_EQ(meta.size, 0x00);
253 std::vector<std::uint8_t> metadata = {};
254 EXPECT_EQ(metadata, meta.metadata);
255}
256
Patrick Venture16a99a62019-05-03 17:21:30 -0700257TEST_F(BlobHandlerTest, getSessionStatNoMetadata)
258{
259 /* The get session stat succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700260 auto ipmi = CreateIpmiMock();
261 IpmiInterfaceMock* ipmiMock =
262 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
263 BlobHandler blob(std::move(ipmi));
Patrick Venture16a99a62019-05-03 17:21:30 -0700264
265 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700266 0xcf, 0xc2,
267 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobSessionStat),
268 0x00, 0x00,
269 0x01, 0x00};
Patrick Venture16a99a62019-05-03 17:21:30 -0700270
271 /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */
272 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff,
273 0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
274
275 std::vector<std::uint8_t> reqCrc = {0x01, 0x00};
276 std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00,
277 0x00, 0x00, 0x00};
278
Patrick Venture958f1ce2019-05-31 17:07:25 -0700279 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
280 .WillOnce(Return(0x00));
281 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
282 .WillOnce(Return(0x00));
Patrick Venture16a99a62019-05-03 17:21:30 -0700283
Patrick Venture958f1ce2019-05-31 17:07:25 -0700284 EXPECT_CALL(*ipmiMock,
285 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
286 .WillOnce(Return(resp));
Patrick Venture16a99a62019-05-03 17:21:30 -0700287
288 auto meta = blob.getStat(0x0001);
289 EXPECT_EQ(meta.blob_state, 0xffff);
290 EXPECT_EQ(meta.size, 0x00);
291 std::vector<std::uint8_t> metadata = {};
292 EXPECT_EQ(metadata, meta.metadata);
293}
294
Patrick Venture123b5c02019-03-05 14:01:00 -0800295TEST_F(BlobHandlerTest, openBlobSucceeds)
296{
297 /* The open blob succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700298 auto ipmi = CreateIpmiMock();
299 IpmiInterfaceMock* ipmiMock =
300 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
301 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800302
303 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700304 0xcf, 0xc2,
305 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobOpen),
306 0x00, 0x00,
307 0x02, 0x04,
308 'a', 'b',
309 'c', 'd',
Patrick Venture123b5c02019-03-05 14:01:00 -0800310 0x00};
311
312 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xfe, 0xed};
313
314 std::vector<std::uint8_t> reqCrc = {0x02, 0x04, 'a', 'b', 'c', 'd', 0x00};
315 std::vector<std::uint8_t> respCrc = {0xfe, 0xed};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700316 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
317 .WillOnce(Return(0x00));
318 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
319 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800320
Patrick Venture958f1ce2019-05-31 17:07:25 -0700321 EXPECT_CALL(*ipmiMock,
322 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
323 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800324
325 const int writeBit = (1 << 1);
326 const int lpcBit = (1 << 10);
327
328 auto session = blob.openBlob("abcd", writeBit | lpcBit);
329 EXPECT_EQ(0xedfe, session);
330}
331
332TEST_F(BlobHandlerTest, closeBlobSucceeds)
333{
334 /* The close succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700335 auto ipmi = CreateIpmiMock();
336 IpmiInterfaceMock* ipmiMock =
337 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
338 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800339
340 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700341 0xcf, 0xc2,
342 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobClose),
343 0x00, 0x00,
344 0x01, 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800345 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
346 std::vector<std::uint8_t> reqCrc = {0x01, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700347 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
348 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800349
Patrick Venture958f1ce2019-05-31 17:07:25 -0700350 EXPECT_CALL(*ipmiMock,
351 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
352 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800353
354 blob.closeBlob(0x0001);
355}
356
Patrick Venture8865e402019-05-14 13:29:10 -0700357TEST_F(BlobHandlerTest, commitSucceedsNoData)
358{
359 /* The commit succeeds. */
360 auto ipmi = CreateIpmiMock();
361 IpmiInterfaceMock* ipmiMock =
362 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
363 BlobHandler blob(std::move(ipmi));
364
365 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700366 0xcf, 0xc2,
367 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobCommit),
368 0x00, 0x00,
369 0x01, 0x00,
Patrick Venture8865e402019-05-14 13:29:10 -0700370 0x00};
371
372 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
373 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700374 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
375 .WillOnce(Return(0x00));
Patrick Venture8865e402019-05-14 13:29:10 -0700376
Patrick Venture958f1ce2019-05-31 17:07:25 -0700377 EXPECT_CALL(*ipmiMock,
378 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
379 .WillOnce(Return(resp));
Patrick Venture8865e402019-05-14 13:29:10 -0700380
381 blob.commit(0x0001, {});
382}
383
Patrick Venture123b5c02019-03-05 14:01:00 -0800384TEST_F(BlobHandlerTest, writeBytesSucceeds)
385{
386 /* The write bytes succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700387 auto ipmi = CreateIpmiMock();
388 IpmiInterfaceMock* ipmiMock =
389 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
390 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800391
392 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700393 0xcf, 0xc2,
394 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite),
395 0x00, 0x00,
396 0x01, 0x00,
397 0x00, 0x00,
398 0x00, 0x00,
399 'a', 'b',
400 'c', 'd'};
Patrick Venture123b5c02019-03-05 14:01:00 -0800401
402 std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd'};
403 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
404 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00,
405 0x00, 'a', 'b', 'c', 'd'};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700406 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
407 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800408
Patrick Venture958f1ce2019-05-31 17:07:25 -0700409 EXPECT_CALL(*ipmiMock,
410 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
411 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800412
413 blob.writeBytes(0x0001, 0, bytes);
414}
415
416TEST_F(BlobHandlerTest, readBytesSucceeds)
417{
418 /* The reading of bytes succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700419 auto ipmi = CreateIpmiMock();
420 IpmiInterfaceMock* ipmiMock =
421 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
422 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800423
424 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700425 0xcf, 0xc2,
426 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobRead),
427 0x00, 0x00,
428 0x01, 0x00,
429 0x00, 0x00,
430 0x00, 0x00,
431 0x04, 0x00,
432 0x00, 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800433
434 std::vector<std::uint8_t> expectedBytes = {'a', 'b', 'c', 'd'};
435 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
436 'a', 'b', 'c', 'd'};
437 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00,
438 0x00, 0x04, 0x00, 0x00, 0x00};
439 std::vector<std::uint8_t> respCrc = {'a', 'b', 'c', 'd'};
440
Patrick Venture958f1ce2019-05-31 17:07:25 -0700441 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
442 .WillOnce(Return(0x00));
443 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
444 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800445
Patrick Venture958f1ce2019-05-31 17:07:25 -0700446 EXPECT_CALL(*ipmiMock,
447 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
448 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800449
450 EXPECT_EQ(blob.readBytes(0x0001, 0, 4), expectedBytes);
451}
452
Brandon Kimcc4ef0c2019-10-18 10:08:37 -0700453TEST_F(BlobHandlerTest, deleteBlobSucceeds)
454{
455 /* The delete succeeds. */
456 auto ipmi = CreateIpmiMock();
457 IpmiInterfaceMock* ipmiMock =
458 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
459 BlobHandler blob(std::move(ipmi));
460
461 std::vector<std::uint8_t> request = {
462 0xcf, 0xc2,
463 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobDelete),
464 0x00, 0x00,
465 'a', 'b',
466 'c', 'd',
467 0x00};
468
469 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
470 std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
471 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
472 .WillOnce(Return(0x00));
473
474 EXPECT_CALL(*ipmiMock,
475 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
476 .WillOnce(Return(resp));
477
478 blob.deleteBlob("abcd");
479}
480
Patrick Venture1470bec2019-03-06 07:33:12 -0800481} // namespace ipmiblob