blob: 9121d97ca713bf7d2dbb1b179704ca8605ad18c8 [file] [log] [blame]
Patrick Venture79e131f2018-08-01 13:34:35 -07001#include "flash-ipmi.hpp"
2#include "ipmi.hpp"
3
4#include "updater_mock.hpp"
5
6#include <cstring>
7#include <gtest/gtest.h>
8
9using ::testing::ElementsAreArray;
10using ::testing::Return;
11using ::testing::StrictMock;
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
Patrick Venture79e131f2018-08-01 13:34:35 -070017TEST(IpmiFlashData, DataReceivedIsPassedOnOk)
18{
19 // If valid data was passed in, it'll pass it onto the update handler.
20
21 StrictMock<UpdaterMock> updater;
22
23 size_t dataLen;
24 uint8_t request[MAX_IPMI_BUFFER] = {0};
25 uint8_t reply[MAX_IPMI_BUFFER] = {0};
26
27 struct ChunkHdr tx;
28 tx.cmd = FlashSubCmds::flashDataBlock;
29 tx.offset = 0x00;
30 std::memcpy(request, &tx, sizeof(tx));
31
32 uint8_t bytes[] = {0x04, 0x05};
33 std::memcpy(&request[sizeof(struct ChunkHdr)], bytes, sizeof(bytes));
34
35 dataLen = sizeof(struct ChunkHdr) + sizeof(bytes);
36
37 EXPECT_CALL(updater,
38 flashData(0x00, ElementsAreArray(bytes, sizeof(bytes))))
39 .WillOnce(Return(true));
40
41 EXPECT_EQ(IPMI_CC_OK, dataBlock(&updater, request, reply, &dataLen));
42 EXPECT_EQ(sizeof(uint8_t), dataLen);
43 EXPECT_EQ(0, reply[0]);
44}