blob: 34fc33d7caa1705451b90b67d3f48a902328a448 [file] [log] [blame]
Patrick Ventureef3aead2018-09-12 08:53:29 -07001#include "ipmi.hpp"
Patrick Venturecd8dab42019-01-15 19:57:38 -08002#include "manager_mock.hpp"
Patrick Ventureef3aead2018-09-12 08:53:29 -07003
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
Patrick Venture00d5f0d2019-05-17 19:21:35 -070033 req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobGetCount);
Patrick Ventureef3aead2018-09-12 08:53:29 -070034 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
Patrick Venture00d5f0d2019-05-17 19:21:35 -070059 req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobGetCount);
Patrick Ventureef3aead2018-09-12 08:53:29 -070060 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