blob: 041a8cb167f41904860cb96ba448793083e9ca59 [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
34 EXPECT_EQ(IPMI_CC_INVALID, enumerateBlob(&mgr, request, reply, &dataLen));
35}
36
37TEST(BlobEnumerateTest, BoringRequestByIdAndReceive)
38{
39 // This tests that if an index into the blob_id cache is valid, the command
40 // will return the blobId.
41
42 ManagerMock mgr;
43 size_t dataLen;
44 uint8_t reply[MAX_IPMI_BUFFER] = {0};
45 struct BmcBlobEnumerateTx req;
46 struct BmcBlobEnumerateRx* rep;
47 uint8_t* request = reinterpret_cast<uint8_t*>(&req);
48 std::string blobId = "/asdf";
49
50 req.cmd = BlobOEMCommands::bmcBlobEnumerate;
51 req.blobIdx = 0;
52 dataLen = sizeof(struct BmcBlobEnumerateTx);
53
54 EXPECT_CALL(mgr, getBlobId(req.blobIdx)).WillOnce(Return(blobId));
55
56 EXPECT_EQ(IPMI_CC_OK, enumerateBlob(&mgr, request, reply, &dataLen));
57
58 // We're expecting this as a response.
59 // blobId.length + 1 + sizeof(uint16_t);
60 EXPECT_EQ(blobId.length() + 1 + sizeof(uint16_t), dataLen);
61
62 rep = reinterpret_cast<struct BmcBlobEnumerateRx*>(reply);
63 EXPECT_EQ(0, std::memcmp(rep->blobId, blobId.c_str(), blobId.length() + 1));
64}
65} // namespace blobs