blob: edea82bdc795383659e4e17a6c56fa7f29da6526 [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 <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
Patrick Venture00d5f0d2019-05-17 19:21:35 -070028 req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate);
Patrick Ventureef3aead2018-09-12 08:53:29 -070029 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
Patrick Venture00d5f0d2019-05-17 19:21:35 -070051 req.cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate);
Patrick Ventureef3aead2018-09-12 08:53:29 -070052 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);
William A. Kennington III117912d2021-06-15 18:22:44 -070064 EXPECT_EQ(0, std::memcmp(rep + 1, blobId.c_str(), blobId.length() + 1));
Patrick Ventureef3aead2018-09-12 08:53:29 -070065}
66} // namespace blobs