blob: 2d634520bf778181f8df91b6060a3941096aa05e [file] [log] [blame]
Patrick Venture5c4b17b2018-10-04 10:32:22 -07001#include "ipmi.hpp"
2
3#include <blobs-ipmid/test/manager_mock.hpp>
4#include <cstring>
5
6#include <gtest/gtest.h>
7
8namespace blobs
9{
10using ::testing::ElementsAreArray;
11using ::testing::Return;
12
13// ipmid.hpp isn't installed where we can grab it and this value is per BMC
14// SoC.
15#define MAX_IPMI_BUFFER 64
16
17TEST(BlobWriteMetaTest, ManagerReturnsFailureReturnsFailure)
18{
19 // This verifies a failure from the manager is passed back.
20
21 ManagerMock mgr;
22 size_t dataLen;
23 uint8_t request[MAX_IPMI_BUFFER] = {0};
24 uint8_t reply[MAX_IPMI_BUFFER] = {0};
25 auto req = reinterpret_cast<struct BmcBlobWriteMetaTx*>(request);
26
27 req->cmd = BlobOEMCommands::bmcBlobWrite;
28 req->crc = 0;
29 req->sessionId = 0x54;
30 req->offset = 0x100;
31
32 uint8_t expectedBytes[2] = {0x66, 0x67};
33 std::memcpy(req->data, &expectedBytes[0], sizeof(expectedBytes));
34
35 dataLen = sizeof(struct BmcBlobWriteMetaTx) + sizeof(expectedBytes);
36
37 EXPECT_CALL(
38 mgr, writeMeta(req->sessionId, req->offset,
39 ElementsAreArray(expectedBytes, sizeof(expectedBytes))))
40 .WillOnce(Return(false));
41
Patrick Venture41258802018-11-12 10:46:30 -080042 EXPECT_EQ(IPMI_CC_UNSPECIFIED_ERROR,
43 writeMeta(&mgr, request, reply, &dataLen));
Patrick Venture5c4b17b2018-10-04 10:32:22 -070044}
45
46TEST(BlobWriteMetaTest, ManagerReturnsTrueWriteSucceeds)
47{
48 // The case where everything works.
49
50 ManagerMock mgr;
51 size_t dataLen;
52 uint8_t request[MAX_IPMI_BUFFER] = {0};
53 uint8_t reply[MAX_IPMI_BUFFER] = {0};
54 auto req = reinterpret_cast<struct BmcBlobWriteMetaTx*>(request);
55
56 req->cmd = BlobOEMCommands::bmcBlobWrite;
57 req->crc = 0;
58 req->sessionId = 0x54;
59 req->offset = 0x100;
60
61 uint8_t expectedBytes[2] = {0x66, 0x67};
62 std::memcpy(req->data, &expectedBytes[0], sizeof(expectedBytes));
63
64 dataLen = sizeof(struct BmcBlobWriteMetaTx) + sizeof(expectedBytes);
65
66 EXPECT_CALL(
67 mgr, writeMeta(req->sessionId, req->offset,
68 ElementsAreArray(expectedBytes, sizeof(expectedBytes))))
69 .WillOnce(Return(true));
70
71 EXPECT_EQ(IPMI_CC_OK, writeMeta(&mgr, request, reply, &dataLen));
72}
73} // namespace blobs