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