blob: a9ec6391ccba02ad28b07b9c9f12cc6bc9c01bea [file] [log] [blame]
Brandon Kim714e3882020-06-22 12:36:32 -07001#include <ipmiblob/blob_errors.hpp>
Patrick Venture123b5c02019-03-05 14:01:00 -08002#include <ipmiblob/blob_handler.hpp>
Patrick Venture1681f7f2019-03-07 12:59:29 -08003#include <ipmiblob/test/crc_mock.hpp>
Patrick Venture123b5c02019-03-05 14:01:00 -08004#include <ipmiblob/test/ipmi_interface_mock.hpp>
Patrick Venture60edc612020-06-24 15:06:41 -07005
6#include <cstdint>
Patrick Venture786a5412019-05-13 07:40:22 -07007#include <memory>
8#include <vector>
Patrick Venture123b5c02019-03-05 14:01:00 -08009
10#include <gtest/gtest.h>
11
Patrick Venture1470bec2019-03-06 07:33:12 -080012namespace ipmiblob
Patrick Venture123b5c02019-03-05 14:01:00 -080013{
14CrcInterface* crcIntf = nullptr;
15
16std::uint16_t generateCrc(const std::vector<std::uint8_t>& data)
17{
18 return (crcIntf) ? crcIntf->generateCrc(data) : 0x00;
19}
20
Patrick Venture958f1ce2019-05-31 17:07:25 -070021using ::testing::ContainerEq;
Patrick Venture123b5c02019-03-05 14:01:00 -080022using ::testing::Eq;
23using ::testing::Return;
24
25class BlobHandlerTest : public ::testing::Test
26{
27 protected:
28 void SetUp() override
29 {
30 crcIntf = &crcMock;
31 }
32
33 CrcMock crcMock;
Patrick Venture786a5412019-05-13 07:40:22 -070034
35 std::unique_ptr<IpmiInterface> CreateIpmiMock()
36 {
37 return std::make_unique<IpmiInterfaceMock>();
38 }
Patrick Venture123b5c02019-03-05 14:01:00 -080039};
40
41TEST_F(BlobHandlerTest, getCountIpmiHappy)
42{
43 /* Verify returns the value specified by the IPMI response. */
Patrick Venture786a5412019-05-13 07:40:22 -070044 auto ipmi = CreateIpmiMock();
45 IpmiInterfaceMock* ipmiMock =
46 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
47 BlobHandler blob(std::move(ipmi));
48
Patrick Venture123b5c02019-03-05 14:01:00 -080049 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -070050 0xcf, 0xc2, 0x00,
51 static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobGetCount)};
Patrick Venture123b5c02019-03-05 14:01:00 -080052
53 /* return 1 blob count. */
54 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
55 0x01, 0x00, 0x00, 0x00};
56
57 std::vector<std::uint8_t> bytes = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -070058 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes)))
59 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -080060
Patrick Venture958f1ce2019-05-31 17:07:25 -070061 EXPECT_CALL(*ipmiMock,
62 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
63 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -080064 EXPECT_EQ(1, blob.getBlobCount());
65}
66
67TEST_F(BlobHandlerTest, enumerateBlobIpmiHappy)
68{
69 /* Verify returns the name specified by the IPMI response. */
Patrick Venture786a5412019-05-13 07:40:22 -070070 auto ipmi = CreateIpmiMock();
71 IpmiInterfaceMock* ipmiMock =
72 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
73 BlobHandler blob(std::move(ipmi));
74
Patrick Venture123b5c02019-03-05 14:01:00 -080075 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -070076 0xcf, 0xc2,
77 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate),
78 0x00, 0x00,
79 0x01, 0x00,
Patrick Venture123b5c02019-03-05 14:01:00 -080080 0x00, 0x00};
81
82 /* return value. */
83 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
84 'a', 'b', 'c', 'd', 0x00};
85
86 std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd', 0x00};
87 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -070088 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
89 .WillOnce(Return(0x00));
90 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes)))
91 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -080092
Patrick Venture958f1ce2019-05-31 17:07:25 -070093 EXPECT_CALL(*ipmiMock,
94 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
95 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -080096 EXPECT_STREQ("abcd", blob.enumerateBlob(1).c_str());
97}
98
99TEST_F(BlobHandlerTest, enumerateBlobIpmiNoBytes)
100{
101 /* Simulate a case where the IPMI command returns no data. */
Patrick Venture786a5412019-05-13 07:40:22 -0700102 auto ipmi = CreateIpmiMock();
103 IpmiInterfaceMock* ipmiMock =
104 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
105 BlobHandler blob(std::move(ipmi));
106
Patrick Venture123b5c02019-03-05 14:01:00 -0800107 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700108 0xcf, 0xc2,
109 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate),
110 0x00, 0x00,
111 0x01, 0x00,
Patrick Venture123b5c02019-03-05 14:01:00 -0800112 0x00, 0x00};
113
114 /* return value. */
115 std::vector<std::uint8_t> resp = {};
116
117 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700118 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
119 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800120
Patrick Venture958f1ce2019-05-31 17:07:25 -0700121 EXPECT_CALL(*ipmiMock,
122 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
123 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800124 EXPECT_STREQ("", blob.enumerateBlob(1).c_str());
125}
126
127TEST_F(BlobHandlerTest, getBlobListIpmiHappy)
128{
129 /* Verify returns the list built via the above two commands. */
Patrick Venture786a5412019-05-13 07:40:22 -0700130 auto ipmi = CreateIpmiMock();
131 IpmiInterfaceMock* ipmiMock =
132 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
133 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800134
135 std::vector<std::uint8_t> request1 = {
Patrick Venture44474642019-05-20 19:11:04 -0700136 0xcf, 0xc2, 0x00,
137 static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobGetCount)};
Patrick Venture123b5c02019-03-05 14:01:00 -0800138
139 /* return 1 blob count. */
140 std::vector<std::uint8_t> resp1 = {0xcf, 0xc2, 0x00, 0x00, 0x00,
141 0x01, 0x00, 0x00, 0x00};
142
143 std::vector<std::uint8_t> bytes1 = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700144 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes1)))
145 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800146
Patrick Venture958f1ce2019-05-31 17:07:25 -0700147 EXPECT_CALL(*ipmiMock,
148 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request1)))
149 .WillOnce(Return(resp1));
Patrick Venture123b5c02019-03-05 14:01:00 -0800150
151 std::vector<std::uint8_t> request2 = {
Patrick Venture44474642019-05-20 19:11:04 -0700152 0xcf, 0xc2,
153 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate),
154 0x00, 0x00,
155 0x00, 0x00,
Patrick Venture123b5c02019-03-05 14:01:00 -0800156 0x00, 0x00};
157
158 /* return value. */
159 std::vector<std::uint8_t> resp2 = {0xcf, 0xc2, 0x00, 0x00, 0x00,
160 'a', 'b', 'c', 'd', 0x00};
161
162 std::vector<std::uint8_t> reqCrc = {0x00, 0x00, 0x00, 0x00};
163 std::vector<std::uint8_t> bytes2 = {'a', 'b', 'c', 'd', 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700164 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
165 .WillOnce(Return(0x00));
166 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes2)))
167 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800168
Patrick Venture958f1ce2019-05-31 17:07:25 -0700169 EXPECT_CALL(*ipmiMock,
170 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request2)))
171 .WillOnce(Return(resp2));
Patrick Venture123b5c02019-03-05 14:01:00 -0800172
173 /* A std::string is not nul-terminated by default. */
174 std::vector<std::string> expectedList = {std::string{"abcd"}};
175
176 EXPECT_EQ(expectedList, blob.getBlobList());
177}
178
179TEST_F(BlobHandlerTest, getStatWithMetadata)
180{
181 /* Stat received metadata. */
Patrick Venture786a5412019-05-13 07:40:22 -0700182 auto ipmi = CreateIpmiMock();
183 IpmiInterfaceMock* ipmiMock =
184 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
185 BlobHandler blob(std::move(ipmi));
186
Patrick Venture123b5c02019-03-05 14:01:00 -0800187 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700188 0xcf, 0xc2,
189 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobStat),
190 0x00, 0x00,
191 'a', 'b',
192 'c', 'd',
193 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800194
195 /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */
196 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, 0xff,
197 0x00, 0x00, 0x00, 0x00, 0x02, 0x34, 0x45};
198
199 std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
200 std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, 0x00,
201 0x00, 0x02, 0x34, 0x45};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700202 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
203 .WillOnce(Return(0x00));
204 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
205 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800206
Patrick Venture958f1ce2019-05-31 17:07:25 -0700207 EXPECT_CALL(*ipmiMock,
208 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
209 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800210
211 auto meta = blob.getStat("abcd");
212 EXPECT_EQ(meta.blob_state, 0xffff);
213 EXPECT_EQ(meta.size, 0x00);
214 std::vector<std::uint8_t> metadata = {0x34, 0x45};
215 EXPECT_EQ(metadata, meta.metadata);
216}
217
Brandon Kim714e3882020-06-22 12:36:32 -0700218TEST_F(BlobHandlerTest, getStatWithWrongMetadataLength)
219{
220 /* Stat fails when wrong metadata length is received */
221 auto ipmi = CreateIpmiMock();
222 IpmiInterfaceMock* ipmiMock =
223 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
224 BlobHandler blob(std::move(ipmi));
225
226 std::vector<std::uint8_t> request = {
227 0xcf, 0xc2,
228 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobStat),
229 0x00, 0x00,
230 'a', 'b',
231 'c', 'd',
232 0x00};
233
234 /* return blob_state: 0xffff, size: 0x00, len: 1, metadata 0x3445 */
235 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, 0xff,
236 0x00, 0x00, 0x00, 0x00, 0x01, 0x34, 0x45};
237
238 std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
239 std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, 0x00,
240 0x00, 0x01, 0x34, 0x45};
241 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
242 .WillOnce(Return(0x00));
243 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
244 .WillOnce(Return(0x00));
245
246 EXPECT_CALL(*ipmiMock,
247 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
248 .WillOnce(Return(resp));
249
250 EXPECT_THROW(blob.getStat("abcd"), BlobException);
251}
252
Patrick Venture123b5c02019-03-05 14:01:00 -0800253TEST_F(BlobHandlerTest, getStatNoMetadata)
254{
255 /* Stat received no metadata. */
Patrick Venture786a5412019-05-13 07:40:22 -0700256 auto ipmi = CreateIpmiMock();
257 IpmiInterfaceMock* ipmiMock =
258 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
259 BlobHandler blob(std::move(ipmi));
260
Patrick Venture123b5c02019-03-05 14:01:00 -0800261 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700262 0xcf, 0xc2,
263 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobStat),
264 0x00, 0x00,
265 'a', 'b',
266 'c', 'd',
267 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800268
Brandon Kim714e3882020-06-22 12:36:32 -0700269 /* return blob_state: 0xffff, size: 0x00, metadata 0x0000 */
Patrick Venture123b5c02019-03-05 14:01:00 -0800270 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff,
271 0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
272
273 std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
274 std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00,
275 0x00, 0x00, 0x00};
276
Patrick Venture958f1ce2019-05-31 17:07:25 -0700277 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
278 .WillOnce(Return(0x00));
279 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
280 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800281
Patrick Venture958f1ce2019-05-31 17:07:25 -0700282 EXPECT_CALL(*ipmiMock,
283 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
284 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800285
286 auto meta = blob.getStat("abcd");
287 EXPECT_EQ(meta.blob_state, 0xffff);
288 EXPECT_EQ(meta.size, 0x00);
289 std::vector<std::uint8_t> metadata = {};
290 EXPECT_EQ(metadata, meta.metadata);
291}
292
Patrick Venture16a99a62019-05-03 17:21:30 -0700293TEST_F(BlobHandlerTest, getSessionStatNoMetadata)
294{
295 /* The get session stat succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700296 auto ipmi = CreateIpmiMock();
297 IpmiInterfaceMock* ipmiMock =
298 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
299 BlobHandler blob(std::move(ipmi));
Patrick Venture16a99a62019-05-03 17:21:30 -0700300
301 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700302 0xcf, 0xc2,
303 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobSessionStat),
304 0x00, 0x00,
305 0x01, 0x00};
Patrick Venture16a99a62019-05-03 17:21:30 -0700306
Brandon Kim714e3882020-06-22 12:36:32 -0700307 /* return blob_state: 0xffff, size: 0x00, metadata 0x0000 */
Patrick Venture16a99a62019-05-03 17:21:30 -0700308 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff,
309 0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
310
311 std::vector<std::uint8_t> reqCrc = {0x01, 0x00};
312 std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00,
313 0x00, 0x00, 0x00};
314
Patrick Venture958f1ce2019-05-31 17:07:25 -0700315 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
316 .WillOnce(Return(0x00));
317 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
318 .WillOnce(Return(0x00));
Patrick Venture16a99a62019-05-03 17:21:30 -0700319
Patrick Venture958f1ce2019-05-31 17:07:25 -0700320 EXPECT_CALL(*ipmiMock,
321 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
322 .WillOnce(Return(resp));
Patrick Venture16a99a62019-05-03 17:21:30 -0700323
324 auto meta = blob.getStat(0x0001);
325 EXPECT_EQ(meta.blob_state, 0xffff);
326 EXPECT_EQ(meta.size, 0x00);
327 std::vector<std::uint8_t> metadata = {};
328 EXPECT_EQ(metadata, meta.metadata);
329}
330
Brandon Kim714e3882020-06-22 12:36:32 -0700331TEST_F(BlobHandlerTest, getSessionStatEmptyResp)
332{
333 /* The get session stat fails after getting empty response */
334 auto ipmi = CreateIpmiMock();
335 IpmiInterfaceMock* ipmiMock =
336 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
337 BlobHandler blob(std::move(ipmi));
338
339 std::vector<std::uint8_t> request = {
340 0xcf, 0xc2,
341 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobSessionStat),
342 0x00, 0x00,
343 0x01, 0x00};
344
345 std::vector<std::uint8_t> resp;
346 std::vector<std::uint8_t> reqCrc = {0x01, 0x00};
347
348 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
349 .WillOnce(Return(0x00));
350
351 EXPECT_CALL(*ipmiMock,
352 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
353 .WillOnce(Return(resp));
354
355 EXPECT_THROW(blob.getStat(0x0001), BlobException);
356}
357
358TEST_F(BlobHandlerTest, getSessionStatInvalidHeader)
359{
360 /* The get session stat fails after getting a response shorter than the
361 * expected headersize but with the expected OEN
362 */
363 auto ipmi = CreateIpmiMock();
364 IpmiInterfaceMock* ipmiMock =
365 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
366 BlobHandler blob(std::move(ipmi));
367
368 std::vector<std::uint8_t> request = {
369 0xcf, 0xc2,
370 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobSessionStat),
371 0x00, 0x00,
372 0x01, 0x00};
373
374 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00};
375 std::vector<std::uint8_t> reqCrc = {0x01, 0x00};
376
377 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
378 .WillOnce(Return(0x00));
379
380 EXPECT_CALL(*ipmiMock,
381 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
382 .WillOnce(Return(resp));
383
384 EXPECT_THROW(blob.getStat(0x0001), BlobException);
385}
386
Patrick Venture123b5c02019-03-05 14:01:00 -0800387TEST_F(BlobHandlerTest, openBlobSucceeds)
388{
389 /* The open blob succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700390 auto ipmi = CreateIpmiMock();
391 IpmiInterfaceMock* ipmiMock =
392 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
393 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800394
395 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700396 0xcf, 0xc2,
397 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobOpen),
398 0x00, 0x00,
399 0x02, 0x04,
400 'a', 'b',
401 'c', 'd',
Patrick Venture123b5c02019-03-05 14:01:00 -0800402 0x00};
403
404 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xfe, 0xed};
405
406 std::vector<std::uint8_t> reqCrc = {0x02, 0x04, 'a', 'b', 'c', 'd', 0x00};
407 std::vector<std::uint8_t> respCrc = {0xfe, 0xed};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700408 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
409 .WillOnce(Return(0x00));
410 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
411 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800412
Patrick Venture958f1ce2019-05-31 17:07:25 -0700413 EXPECT_CALL(*ipmiMock,
414 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
415 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800416
417 const int writeBit = (1 << 1);
418 const int lpcBit = (1 << 10);
419
420 auto session = blob.openBlob("abcd", writeBit | lpcBit);
421 EXPECT_EQ(0xedfe, session);
422}
423
424TEST_F(BlobHandlerTest, closeBlobSucceeds)
425{
426 /* The close succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700427 auto ipmi = CreateIpmiMock();
428 IpmiInterfaceMock* ipmiMock =
429 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
430 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800431
432 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700433 0xcf, 0xc2,
434 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobClose),
435 0x00, 0x00,
436 0x01, 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800437 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
438 std::vector<std::uint8_t> reqCrc = {0x01, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700439 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
440 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800441
Patrick Venture958f1ce2019-05-31 17:07:25 -0700442 EXPECT_CALL(*ipmiMock,
443 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
444 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800445
446 blob.closeBlob(0x0001);
447}
448
Patrick Venture8865e402019-05-14 13:29:10 -0700449TEST_F(BlobHandlerTest, commitSucceedsNoData)
450{
451 /* The commit succeeds. */
452 auto ipmi = CreateIpmiMock();
453 IpmiInterfaceMock* ipmiMock =
454 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
455 BlobHandler blob(std::move(ipmi));
456
457 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700458 0xcf, 0xc2,
459 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobCommit),
460 0x00, 0x00,
461 0x01, 0x00,
Patrick Venture8865e402019-05-14 13:29:10 -0700462 0x00};
463
464 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
465 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700466 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
467 .WillOnce(Return(0x00));
Patrick Venture8865e402019-05-14 13:29:10 -0700468
Patrick Venture958f1ce2019-05-31 17:07:25 -0700469 EXPECT_CALL(*ipmiMock,
470 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
471 .WillOnce(Return(resp));
Patrick Venture8865e402019-05-14 13:29:10 -0700472
473 blob.commit(0x0001, {});
474}
475
Patrick Venture123b5c02019-03-05 14:01:00 -0800476TEST_F(BlobHandlerTest, writeBytesSucceeds)
477{
478 /* The write bytes succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700479 auto ipmi = CreateIpmiMock();
480 IpmiInterfaceMock* ipmiMock =
481 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
482 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800483
484 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700485 0xcf, 0xc2,
486 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite),
487 0x00, 0x00,
488 0x01, 0x00,
489 0x00, 0x00,
490 0x00, 0x00,
491 'a', 'b',
492 'c', 'd'};
Patrick Venture123b5c02019-03-05 14:01:00 -0800493
494 std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd'};
495 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
496 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00,
497 0x00, 'a', 'b', 'c', 'd'};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700498 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
499 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800500
Patrick Venture958f1ce2019-05-31 17:07:25 -0700501 EXPECT_CALL(*ipmiMock,
502 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
503 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800504
505 blob.writeBytes(0x0001, 0, bytes);
506}
507
508TEST_F(BlobHandlerTest, readBytesSucceeds)
509{
510 /* The reading of bytes succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700511 auto ipmi = CreateIpmiMock();
512 IpmiInterfaceMock* ipmiMock =
513 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
514 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800515
516 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700517 0xcf, 0xc2,
518 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobRead),
519 0x00, 0x00,
520 0x01, 0x00,
521 0x00, 0x00,
522 0x00, 0x00,
523 0x04, 0x00,
524 0x00, 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800525
526 std::vector<std::uint8_t> expectedBytes = {'a', 'b', 'c', 'd'};
527 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
528 'a', 'b', 'c', 'd'};
529 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00,
530 0x00, 0x04, 0x00, 0x00, 0x00};
531 std::vector<std::uint8_t> respCrc = {'a', 'b', 'c', 'd'};
532
Patrick Venture958f1ce2019-05-31 17:07:25 -0700533 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
534 .WillOnce(Return(0x00));
535 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
536 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800537
Patrick Venture958f1ce2019-05-31 17:07:25 -0700538 EXPECT_CALL(*ipmiMock,
539 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
540 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800541
542 EXPECT_EQ(blob.readBytes(0x0001, 0, 4), expectedBytes);
543}
544
Brandon Kimcc4ef0c2019-10-18 10:08:37 -0700545TEST_F(BlobHandlerTest, deleteBlobSucceeds)
546{
547 /* The delete succeeds. */
548 auto ipmi = CreateIpmiMock();
549 IpmiInterfaceMock* ipmiMock =
550 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
551 BlobHandler blob(std::move(ipmi));
552
553 std::vector<std::uint8_t> request = {
554 0xcf, 0xc2,
555 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobDelete),
556 0x00, 0x00,
557 'a', 'b',
558 'c', 'd',
559 0x00};
560
561 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
562 std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
563 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
564 .WillOnce(Return(0x00));
565
566 EXPECT_CALL(*ipmiMock,
567 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
568 .WillOnce(Return(resp));
569
570 blob.deleteBlob("abcd");
571}
572
Patrick Venture1470bec2019-03-06 07:33:12 -0800573} // namespace ipmiblob