blob: d13788056dc40008a8251cc8044123def4b89112 [file] [log] [blame]
Patrick Venture5c4b17b2018-10-04 10:32:22 -07001#include "ipmi.hpp"
Patrick Venturecd8dab42019-01-15 19:57:38 -08002#include "manager_mock.hpp"
Patrick Venture5c4b17b2018-10-04 10:32:22 -07003
Patrick Venture5c4b17b2018-10-04 10:32:22 -07004#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
Patrick Venture00d5f0d2019-05-17 19:21:35 -070027 req->cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite);
Patrick Venture5c4b17b2018-10-04 10:32:22 -070028 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
Patrick Venture00d5f0d2019-05-17 19:21:35 -070056 req->cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite);
Patrick Venture5c4b17b2018-10-04 10:32:22 -070057 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