blob: 267ae43493b209d20dde467f00e5c80ebba710c2 [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 <vector>
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
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
21TEST(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
47TEST(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