blob: fff3a56a1cdffd0fe13db39241608f4c3098e668 [file] [log] [blame]
Patrick Venture786a5412019-05-13 07:40:22 -07001#include <cstdint>
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 Venture786a5412019-05-13 07:40:22 -07005#include <memory>
6#include <vector>
Patrick Venture123b5c02019-03-05 14:01:00 -08007
8#include <gtest/gtest.h>
9
Patrick Venture1470bec2019-03-06 07:33:12 -080010namespace ipmiblob
Patrick Venture123b5c02019-03-05 14:01:00 -080011{
12CrcInterface* crcIntf = nullptr;
13
14std::uint16_t generateCrc(const std::vector<std::uint8_t>& data)
15{
16 return (crcIntf) ? crcIntf->generateCrc(data) : 0x00;
17}
18
Patrick Venture958f1ce2019-05-31 17:07:25 -070019using ::testing::ContainerEq;
Patrick Venture123b5c02019-03-05 14:01:00 -080020using ::testing::Eq;
21using ::testing::Return;
22
23class BlobHandlerTest : public ::testing::Test
24{
25 protected:
26 void SetUp() override
27 {
28 crcIntf = &crcMock;
29 }
30
31 CrcMock crcMock;
Patrick Venture786a5412019-05-13 07:40:22 -070032
33 std::unique_ptr<IpmiInterface> CreateIpmiMock()
34 {
35 return std::make_unique<IpmiInterfaceMock>();
36 }
Patrick Venture123b5c02019-03-05 14:01:00 -080037};
38
39TEST_F(BlobHandlerTest, getCountIpmiHappy)
40{
41 /* Verify returns the value specified by the IPMI response. */
Patrick Venture786a5412019-05-13 07:40:22 -070042 auto ipmi = CreateIpmiMock();
43 IpmiInterfaceMock* ipmiMock =
44 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
45 BlobHandler blob(std::move(ipmi));
46
Patrick Venture123b5c02019-03-05 14:01:00 -080047 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -070048 0xcf, 0xc2, 0x00,
49 static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobGetCount)};
Patrick Venture123b5c02019-03-05 14:01:00 -080050
51 /* return 1 blob count. */
52 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
53 0x01, 0x00, 0x00, 0x00};
54
55 std::vector<std::uint8_t> bytes = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -070056 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes)))
57 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -080058
Patrick Venture958f1ce2019-05-31 17:07:25 -070059 EXPECT_CALL(*ipmiMock,
60 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
61 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -080062 EXPECT_EQ(1, blob.getBlobCount());
63}
64
65TEST_F(BlobHandlerTest, enumerateBlobIpmiHappy)
66{
67 /* Verify returns the name specified by the IPMI response. */
Patrick Venture786a5412019-05-13 07:40:22 -070068 auto ipmi = CreateIpmiMock();
69 IpmiInterfaceMock* ipmiMock =
70 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
71 BlobHandler blob(std::move(ipmi));
72
Patrick Venture123b5c02019-03-05 14:01:00 -080073 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -070074 0xcf, 0xc2,
75 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate),
76 0x00, 0x00,
77 0x01, 0x00,
Patrick Venture123b5c02019-03-05 14:01:00 -080078 0x00, 0x00};
79
80 /* return value. */
81 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
82 'a', 'b', 'c', 'd', 0x00};
83
84 std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd', 0x00};
85 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -070086 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
87 .WillOnce(Return(0x00));
88 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes)))
89 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -080090
Patrick Venture958f1ce2019-05-31 17:07:25 -070091 EXPECT_CALL(*ipmiMock,
92 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
93 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -080094 EXPECT_STREQ("abcd", blob.enumerateBlob(1).c_str());
95}
96
97TEST_F(BlobHandlerTest, enumerateBlobIpmiNoBytes)
98{
99 /* Simulate a case where the IPMI command returns no data. */
Patrick Venture786a5412019-05-13 07:40:22 -0700100 auto ipmi = CreateIpmiMock();
101 IpmiInterfaceMock* ipmiMock =
102 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
103 BlobHandler blob(std::move(ipmi));
104
Patrick Venture123b5c02019-03-05 14:01:00 -0800105 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700106 0xcf, 0xc2,
107 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate),
108 0x00, 0x00,
109 0x01, 0x00,
Patrick Venture123b5c02019-03-05 14:01:00 -0800110 0x00, 0x00};
111
112 /* return value. */
113 std::vector<std::uint8_t> resp = {};
114
115 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700116 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
117 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800118
Patrick Venture958f1ce2019-05-31 17:07:25 -0700119 EXPECT_CALL(*ipmiMock,
120 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
121 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800122 EXPECT_STREQ("", blob.enumerateBlob(1).c_str());
123}
124
125TEST_F(BlobHandlerTest, getBlobListIpmiHappy)
126{
127 /* Verify returns the list built via the above two commands. */
Patrick Venture786a5412019-05-13 07:40:22 -0700128 auto ipmi = CreateIpmiMock();
129 IpmiInterfaceMock* ipmiMock =
130 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
131 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800132
133 std::vector<std::uint8_t> request1 = {
Patrick Venture44474642019-05-20 19:11:04 -0700134 0xcf, 0xc2, 0x00,
135 static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobGetCount)};
Patrick Venture123b5c02019-03-05 14:01:00 -0800136
137 /* return 1 blob count. */
138 std::vector<std::uint8_t> resp1 = {0xcf, 0xc2, 0x00, 0x00, 0x00,
139 0x01, 0x00, 0x00, 0x00};
140
141 std::vector<std::uint8_t> bytes1 = {0x01, 0x00, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700142 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes1)))
143 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800144
Patrick Venture958f1ce2019-05-31 17:07:25 -0700145 EXPECT_CALL(*ipmiMock,
146 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request1)))
147 .WillOnce(Return(resp1));
Patrick Venture123b5c02019-03-05 14:01:00 -0800148
149 std::vector<std::uint8_t> request2 = {
Patrick Venture44474642019-05-20 19:11:04 -0700150 0xcf, 0xc2,
151 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate),
152 0x00, 0x00,
153 0x00, 0x00,
Patrick Venture123b5c02019-03-05 14:01:00 -0800154 0x00, 0x00};
155
156 /* return value. */
157 std::vector<std::uint8_t> resp2 = {0xcf, 0xc2, 0x00, 0x00, 0x00,
158 'a', 'b', 'c', 'd', 0x00};
159
160 std::vector<std::uint8_t> reqCrc = {0x00, 0x00, 0x00, 0x00};
161 std::vector<std::uint8_t> bytes2 = {'a', 'b', 'c', 'd', 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700162 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
163 .WillOnce(Return(0x00));
164 EXPECT_CALL(crcMock, generateCrc(ContainerEq(bytes2)))
165 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800166
Patrick Venture958f1ce2019-05-31 17:07:25 -0700167 EXPECT_CALL(*ipmiMock,
168 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request2)))
169 .WillOnce(Return(resp2));
Patrick Venture123b5c02019-03-05 14:01:00 -0800170
171 /* A std::string is not nul-terminated by default. */
172 std::vector<std::string> expectedList = {std::string{"abcd"}};
173
174 EXPECT_EQ(expectedList, blob.getBlobList());
175}
176
177TEST_F(BlobHandlerTest, getStatWithMetadata)
178{
179 /* Stat received metadata. */
Patrick Venture786a5412019-05-13 07:40:22 -0700180 auto ipmi = CreateIpmiMock();
181 IpmiInterfaceMock* ipmiMock =
182 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
183 BlobHandler blob(std::move(ipmi));
184
Patrick Venture123b5c02019-03-05 14:01:00 -0800185 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700186 0xcf, 0xc2,
187 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobStat),
188 0x00, 0x00,
189 'a', 'b',
190 'c', 'd',
191 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800192
193 /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */
194 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, 0xff,
195 0x00, 0x00, 0x00, 0x00, 0x02, 0x34, 0x45};
196
197 std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
198 std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, 0x00,
199 0x00, 0x02, 0x34, 0x45};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700200 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
201 .WillOnce(Return(0x00));
202 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
203 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800204
Patrick Venture958f1ce2019-05-31 17:07:25 -0700205 EXPECT_CALL(*ipmiMock,
206 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
207 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800208
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 = {0x34, 0x45};
213 EXPECT_EQ(metadata, meta.metadata);
214}
215
216TEST_F(BlobHandlerTest, getStatNoMetadata)
217{
218 /* Stat received no metadata. */
Patrick Venture786a5412019-05-13 07:40:22 -0700219 auto ipmi = CreateIpmiMock();
220 IpmiInterfaceMock* ipmiMock =
221 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
222 BlobHandler blob(std::move(ipmi));
223
Patrick Venture123b5c02019-03-05 14:01:00 -0800224 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700225 0xcf, 0xc2,
226 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobStat),
227 0x00, 0x00,
228 'a', 'b',
229 'c', 'd',
230 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800231
232 /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */
233 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff,
234 0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
235
236 std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
237 std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00,
238 0x00, 0x00, 0x00};
239
Patrick Venture958f1ce2019-05-31 17:07:25 -0700240 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
241 .WillOnce(Return(0x00));
242 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
243 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800244
Patrick Venture958f1ce2019-05-31 17:07:25 -0700245 EXPECT_CALL(*ipmiMock,
246 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
247 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800248
249 auto meta = blob.getStat("abcd");
250 EXPECT_EQ(meta.blob_state, 0xffff);
251 EXPECT_EQ(meta.size, 0x00);
252 std::vector<std::uint8_t> metadata = {};
253 EXPECT_EQ(metadata, meta.metadata);
254}
255
Patrick Venture16a99a62019-05-03 17:21:30 -0700256TEST_F(BlobHandlerTest, getSessionStatNoMetadata)
257{
258 /* The get session stat succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700259 auto ipmi = CreateIpmiMock();
260 IpmiInterfaceMock* ipmiMock =
261 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
262 BlobHandler blob(std::move(ipmi));
Patrick Venture16a99a62019-05-03 17:21:30 -0700263
264 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700265 0xcf, 0xc2,
266 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobSessionStat),
267 0x00, 0x00,
268 0x01, 0x00};
Patrick Venture16a99a62019-05-03 17:21:30 -0700269
270 /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */
271 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff,
272 0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
273
274 std::vector<std::uint8_t> reqCrc = {0x01, 0x00};
275 std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00,
276 0x00, 0x00, 0x00};
277
Patrick Venture958f1ce2019-05-31 17:07:25 -0700278 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
279 .WillOnce(Return(0x00));
280 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
281 .WillOnce(Return(0x00));
Patrick Venture16a99a62019-05-03 17:21:30 -0700282
Patrick Venture958f1ce2019-05-31 17:07:25 -0700283 EXPECT_CALL(*ipmiMock,
284 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
285 .WillOnce(Return(resp));
Patrick Venture16a99a62019-05-03 17:21:30 -0700286
287 auto meta = blob.getStat(0x0001);
288 EXPECT_EQ(meta.blob_state, 0xffff);
289 EXPECT_EQ(meta.size, 0x00);
290 std::vector<std::uint8_t> metadata = {};
291 EXPECT_EQ(metadata, meta.metadata);
292}
293
Patrick Venture123b5c02019-03-05 14:01:00 -0800294TEST_F(BlobHandlerTest, openBlobSucceeds)
295{
296 /* The open blob succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700297 auto ipmi = CreateIpmiMock();
298 IpmiInterfaceMock* ipmiMock =
299 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
300 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800301
302 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700303 0xcf, 0xc2,
304 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobOpen),
305 0x00, 0x00,
306 0x02, 0x04,
307 'a', 'b',
308 'c', 'd',
Patrick Venture123b5c02019-03-05 14:01:00 -0800309 0x00};
310
311 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xfe, 0xed};
312
313 std::vector<std::uint8_t> reqCrc = {0x02, 0x04, 'a', 'b', 'c', 'd', 0x00};
314 std::vector<std::uint8_t> respCrc = {0xfe, 0xed};
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 Venture123b5c02019-03-05 14:01:00 -0800319
Patrick Venture958f1ce2019-05-31 17:07:25 -0700320 EXPECT_CALL(*ipmiMock,
321 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
322 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800323
324 const int writeBit = (1 << 1);
325 const int lpcBit = (1 << 10);
326
327 auto session = blob.openBlob("abcd", writeBit | lpcBit);
328 EXPECT_EQ(0xedfe, session);
329}
330
331TEST_F(BlobHandlerTest, closeBlobSucceeds)
332{
333 /* The close succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700334 auto ipmi = CreateIpmiMock();
335 IpmiInterfaceMock* ipmiMock =
336 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
337 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800338
339 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700340 0xcf, 0xc2,
341 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobClose),
342 0x00, 0x00,
343 0x01, 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800344 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
345 std::vector<std::uint8_t> reqCrc = {0x01, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700346 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
347 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800348
Patrick Venture958f1ce2019-05-31 17:07:25 -0700349 EXPECT_CALL(*ipmiMock,
350 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
351 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800352
353 blob.closeBlob(0x0001);
354}
355
Patrick Venture8865e402019-05-14 13:29:10 -0700356TEST_F(BlobHandlerTest, commitSucceedsNoData)
357{
358 /* The commit succeeds. */
359 auto ipmi = CreateIpmiMock();
360 IpmiInterfaceMock* ipmiMock =
361 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
362 BlobHandler blob(std::move(ipmi));
363
364 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700365 0xcf, 0xc2,
366 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobCommit),
367 0x00, 0x00,
368 0x01, 0x00,
Patrick Venture8865e402019-05-14 13:29:10 -0700369 0x00};
370
371 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
372 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700373 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
374 .WillOnce(Return(0x00));
Patrick Venture8865e402019-05-14 13:29:10 -0700375
Patrick Venture958f1ce2019-05-31 17:07:25 -0700376 EXPECT_CALL(*ipmiMock,
377 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
378 .WillOnce(Return(resp));
Patrick Venture8865e402019-05-14 13:29:10 -0700379
380 blob.commit(0x0001, {});
381}
382
Patrick Venture123b5c02019-03-05 14:01:00 -0800383TEST_F(BlobHandlerTest, writeBytesSucceeds)
384{
385 /* The write bytes succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700386 auto ipmi = CreateIpmiMock();
387 IpmiInterfaceMock* ipmiMock =
388 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
389 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800390
391 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700392 0xcf, 0xc2,
393 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite),
394 0x00, 0x00,
395 0x01, 0x00,
396 0x00, 0x00,
397 0x00, 0x00,
398 'a', 'b',
399 'c', 'd'};
Patrick Venture123b5c02019-03-05 14:01:00 -0800400
401 std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd'};
402 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
403 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00,
404 0x00, 'a', 'b', 'c', 'd'};
Patrick Venture958f1ce2019-05-31 17:07:25 -0700405 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
406 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800407
Patrick Venture958f1ce2019-05-31 17:07:25 -0700408 EXPECT_CALL(*ipmiMock,
409 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
410 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800411
412 blob.writeBytes(0x0001, 0, bytes);
413}
414
415TEST_F(BlobHandlerTest, readBytesSucceeds)
416{
417 /* The reading of bytes succeeds. */
Patrick Venture786a5412019-05-13 07:40:22 -0700418 auto ipmi = CreateIpmiMock();
419 IpmiInterfaceMock* ipmiMock =
420 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
421 BlobHandler blob(std::move(ipmi));
Patrick Venture123b5c02019-03-05 14:01:00 -0800422
423 std::vector<std::uint8_t> request = {
Patrick Venture44474642019-05-20 19:11:04 -0700424 0xcf, 0xc2,
425 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobRead),
426 0x00, 0x00,
427 0x01, 0x00,
428 0x00, 0x00,
429 0x00, 0x00,
430 0x04, 0x00,
431 0x00, 0x00};
Patrick Venture123b5c02019-03-05 14:01:00 -0800432
433 std::vector<std::uint8_t> expectedBytes = {'a', 'b', 'c', 'd'};
434 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00,
435 'a', 'b', 'c', 'd'};
436 std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00,
437 0x00, 0x04, 0x00, 0x00, 0x00};
438 std::vector<std::uint8_t> respCrc = {'a', 'b', 'c', 'd'};
439
Patrick Venture958f1ce2019-05-31 17:07:25 -0700440 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
441 .WillOnce(Return(0x00));
442 EXPECT_CALL(crcMock, generateCrc(ContainerEq(respCrc)))
443 .WillOnce(Return(0x00));
Patrick Venture123b5c02019-03-05 14:01:00 -0800444
Patrick Venture958f1ce2019-05-31 17:07:25 -0700445 EXPECT_CALL(*ipmiMock,
446 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
447 .WillOnce(Return(resp));
Patrick Venture123b5c02019-03-05 14:01:00 -0800448
449 EXPECT_EQ(blob.readBytes(0x0001, 0, 4), expectedBytes);
450}
451
Brandon Kimcc4ef0c2019-10-18 10:08:37 -0700452TEST_F(BlobHandlerTest, deleteBlobSucceeds)
453{
454 /* The delete succeeds. */
455 auto ipmi = CreateIpmiMock();
456 IpmiInterfaceMock* ipmiMock =
457 reinterpret_cast<IpmiInterfaceMock*>(ipmi.get());
458 BlobHandler blob(std::move(ipmi));
459
460 std::vector<std::uint8_t> request = {
461 0xcf, 0xc2,
462 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobDelete),
463 0x00, 0x00,
464 'a', 'b',
465 'c', 'd',
466 0x00};
467
468 std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00};
469 std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00};
470 EXPECT_CALL(crcMock, generateCrc(ContainerEq(reqCrc)))
471 .WillOnce(Return(0x00));
472
473 EXPECT_CALL(*ipmiMock,
474 sendPacket(ipmiOEMNetFn, ipmiOEMBlobCmd, ContainerEq(request)))
475 .WillOnce(Return(resp));
476
477 blob.deleteBlob("abcd");
478}
479
Patrick Venture1470bec2019-03-06 07:33:12 -0800480} // namespace ipmiblob