blob: 184c686c403c23c68294b9fd106e1b48eb804e9d [file] [log] [blame]
Patrick Ventureef3aead2018-09-12 08:53:29 -07001#include "ipmi.hpp"
Patrick Ventureef3aead2018-09-12 08:53:29 -07002
Patrick Venture7210b312018-10-03 14:01:35 -07003#include <blobs-ipmid/test/manager_mock.hpp>
Patrick Ventureef3aead2018-09-12 08:53:29 -07004#include <cstring>
5#include <string>
6
7#include <gtest/gtest.h>
8
9namespace blobs
10{
11
12using ::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
18TEST(BlobEnumerateTest, VerifyIfRequestByIdInvalidReturnsFailure)
19{
20 // This tests to verify that if the index is invalid, it'll return failure.
21
22 ManagerMock mgr;
23 size_t dataLen;
24 uint8_t reply[MAX_IPMI_BUFFER] = {0};
25 struct BmcBlobEnumerateTx req;
26 uint8_t* request = reinterpret_cast<uint8_t*>(&req);
27
28 req.cmd = BlobOEMCommands::bmcBlobEnumerate;
29 req.blobIdx = 0;
30 dataLen = sizeof(struct BmcBlobEnumerateTx);
31
32 EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(""));
33
Patrick Venture41258802018-11-12 10:46:30 -080034 EXPECT_EQ(IPMI_CC_INVALID_FIELD_REQUEST,
35 enumerateBlob(&mgr, request, reply, &dataLen));
Patrick Ventureef3aead2018-09-12 08:53:29 -070036}
37
38TEST(BlobEnumerateTest, BoringRequestByIdAndReceive)
39{
40 // This tests that if an index into the blob_id cache is valid, the command
41 // will return the blobId.
42
43 ManagerMock mgr;
44 size_t dataLen;
45 uint8_t reply[MAX_IPMI_BUFFER] = {0};
46 struct BmcBlobEnumerateTx req;
47 struct BmcBlobEnumerateRx* rep;
48 uint8_t* request = reinterpret_cast<uint8_t*>(&req);
49 std::string blobId = "/asdf";
50
51 req.cmd = BlobOEMCommands::bmcBlobEnumerate;
52 req.blobIdx = 0;
53 dataLen = sizeof(struct BmcBlobEnumerateTx);
54
55 EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(blobId));
56
57 EXPECT_EQ(IPMI_CC_OK, enumerateBlob(&mgr, request, reply, &dataLen));
58
59 // We're expecting this as a response.
60 // blobId.length + 1 + sizeof(uint16_t);
61 EXPECT_EQ(blobId.length() + 1 + sizeof(uint16_t), dataLen);
62
63 rep = reinterpret_cast<struct BmcBlobEnumerateRx*>(reply);
64 EXPECT_EQ(0, std::memcmp(rep->blobId, blobId.c_str(), blobId.length() + 1));
65}
66} // namespace blobs