xref: /openbmc/phosphor-ipmi-blobs/test/ipmi_enumerate_unittest.cpp (revision ef3aeadc9be37c47d0627e576e81a74a5bb9e94f)
1*ef3aeadcSPatrick Venture #include "ipmi.hpp"
2*ef3aeadcSPatrick Venture #include "manager_mock.hpp"
3*ef3aeadcSPatrick Venture 
4*ef3aeadcSPatrick Venture #include <cstring>
5*ef3aeadcSPatrick Venture #include <string>
6*ef3aeadcSPatrick Venture 
7*ef3aeadcSPatrick Venture #include <gtest/gtest.h>
8*ef3aeadcSPatrick Venture 
9*ef3aeadcSPatrick Venture namespace blobs
10*ef3aeadcSPatrick Venture {
11*ef3aeadcSPatrick Venture 
12*ef3aeadcSPatrick Venture using ::testing::Return;
13*ef3aeadcSPatrick Venture 
14*ef3aeadcSPatrick Venture // ipmid.hpp isn't installed where we can grab it and this value is per BMC
15*ef3aeadcSPatrick Venture // SoC.
16*ef3aeadcSPatrick Venture #define MAX_IPMI_BUFFER 64
17*ef3aeadcSPatrick Venture 
18*ef3aeadcSPatrick Venture TEST(BlobEnumerateTest, VerifyIfRequestByIdInvalidReturnsFailure)
19*ef3aeadcSPatrick Venture {
20*ef3aeadcSPatrick Venture     // This tests to verify that if the index is invalid, it'll return failure.
21*ef3aeadcSPatrick Venture 
22*ef3aeadcSPatrick Venture     ManagerMock mgr;
23*ef3aeadcSPatrick Venture     size_t dataLen;
24*ef3aeadcSPatrick Venture     uint8_t reply[MAX_IPMI_BUFFER] = {0};
25*ef3aeadcSPatrick Venture     struct BmcBlobEnumerateTx req;
26*ef3aeadcSPatrick Venture     uint8_t* request = reinterpret_cast<uint8_t*>(&req);
27*ef3aeadcSPatrick Venture 
28*ef3aeadcSPatrick Venture     req.cmd = BlobOEMCommands::bmcBlobEnumerate;
29*ef3aeadcSPatrick Venture     req.blobIdx = 0;
30*ef3aeadcSPatrick Venture     dataLen = sizeof(struct BmcBlobEnumerateTx);
31*ef3aeadcSPatrick Venture 
32*ef3aeadcSPatrick Venture     EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(""));
33*ef3aeadcSPatrick Venture 
34*ef3aeadcSPatrick Venture     EXPECT_EQ(IPMI_CC_INVALID, enumerateBlob(&mgr, request, reply, &dataLen));
35*ef3aeadcSPatrick Venture }
36*ef3aeadcSPatrick Venture 
37*ef3aeadcSPatrick Venture TEST(BlobEnumerateTest, BoringRequestByIdAndReceive)
38*ef3aeadcSPatrick Venture {
39*ef3aeadcSPatrick Venture     // This tests that if an index into the blob_id cache is valid, the command
40*ef3aeadcSPatrick Venture     // will return the blobId.
41*ef3aeadcSPatrick Venture 
42*ef3aeadcSPatrick Venture     ManagerMock mgr;
43*ef3aeadcSPatrick Venture     size_t dataLen;
44*ef3aeadcSPatrick Venture     uint8_t reply[MAX_IPMI_BUFFER] = {0};
45*ef3aeadcSPatrick Venture     struct BmcBlobEnumerateTx req;
46*ef3aeadcSPatrick Venture     struct BmcBlobEnumerateRx* rep;
47*ef3aeadcSPatrick Venture     uint8_t* request = reinterpret_cast<uint8_t*>(&req);
48*ef3aeadcSPatrick Venture     std::string blobId = "/asdf";
49*ef3aeadcSPatrick Venture 
50*ef3aeadcSPatrick Venture     req.cmd = BlobOEMCommands::bmcBlobEnumerate;
51*ef3aeadcSPatrick Venture     req.blobIdx = 0;
52*ef3aeadcSPatrick Venture     dataLen = sizeof(struct BmcBlobEnumerateTx);
53*ef3aeadcSPatrick Venture 
54*ef3aeadcSPatrick Venture     EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(blobId));
55*ef3aeadcSPatrick Venture 
56*ef3aeadcSPatrick Venture     EXPECT_EQ(IPMI_CC_OK, enumerateBlob(&mgr, request, reply, &dataLen));
57*ef3aeadcSPatrick Venture 
58*ef3aeadcSPatrick Venture     // We're expecting this as a response.
59*ef3aeadcSPatrick Venture     // blobId.length + 1 + sizeof(uint16_t);
60*ef3aeadcSPatrick Venture     EXPECT_EQ(blobId.length() + 1 + sizeof(uint16_t), dataLen);
61*ef3aeadcSPatrick Venture 
62*ef3aeadcSPatrick Venture     rep = reinterpret_cast<struct BmcBlobEnumerateRx*>(reply);
63*ef3aeadcSPatrick Venture     EXPECT_EQ(0, std::memcmp(rep->blobId, blobId.c_str(), blobId.length() + 1));
64*ef3aeadcSPatrick Venture }
65*ef3aeadcSPatrick Venture } // namespace blobs
66