1 #include "ipmi.hpp"
2 #include "manager_mock.hpp"
3 
4 #include <cstring>
5 #include <vector>
6 
7 #include <gtest/gtest.h>
8 
9 namespace blobs
10 {
11 
12 using ::testing::Return;
13 
14 // ipmid.hpp isn't installed where we can grab it and this value is per BMC
15 // SoC.
16 #define MAX_IPMI_BUFFER 64
17 
18 // the request here is only the subcommand byte and therefore there's no invalid
19 // length check, etc to handle within the method.
20 
21 TEST(BlobCountTest, ReturnsZeroBlobs)
22 {
23     // Calling BmcBlobGetCount if there are no handlers registered should just
24     // return that there are 0 blobs.
25 
26     ManagerMock mgr;
27     size_t dataLen;
28     uint8_t reply[MAX_IPMI_BUFFER] = {0};
29     struct BmcBlobCountTx req;
30     struct BmcBlobCountRx rep;
31     uint8_t* request = reinterpret_cast<uint8_t*>(&req);
32 
33     req.cmd = BlobOEMCommands::bmcBlobGetCount;
34     dataLen = sizeof(req);
35 
36     rep.crc = 0;
37     rep.blobCount = 0;
38 
39     EXPECT_CALL(mgr, buildBlobList()).WillOnce(Return(0));
40 
41     EXPECT_EQ(IPMI_CC_OK, getBlobCount(&mgr, request, reply, &dataLen));
42 
43     EXPECT_EQ(sizeof(rep), dataLen);
44     EXPECT_EQ(0, std::memcmp(reply, &rep, sizeof(rep)));
45 }
46 
47 TEST(BlobCountTest, ReturnsTwoBlobs)
48 {
49     // Calling BmcBlobGetCount with one handler registered that knows of two
50     // blobs will return that it found two blobs.
51 
52     ManagerMock mgr;
53     size_t dataLen;
54     uint8_t reply[MAX_IPMI_BUFFER] = {0};
55     struct BmcBlobCountTx req;
56     struct BmcBlobCountRx rep;
57     uint8_t* request = reinterpret_cast<uint8_t*>(&req);
58 
59     req.cmd = BlobOEMCommands::bmcBlobGetCount;
60     dataLen = sizeof(req);
61 
62     rep.crc = 0;
63     rep.blobCount = 2;
64 
65     EXPECT_CALL(mgr, buildBlobList()).WillOnce(Return(2));
66 
67     EXPECT_EQ(IPMI_CC_OK, getBlobCount(&mgr, request, reply, &dataLen));
68 
69     EXPECT_EQ(sizeof(rep), dataLen);
70     EXPECT_EQ(0, std::memcmp(reply, &rep, sizeof(rep)));
71 }
72 } // namespace blobs
73