blob: 7b5e45f43e520399e184e3049440a024aac98256 [file] [log] [blame]
Patrick Ventureef3aead2018-09-12 08:53:29 -07001#include "ipmi.hpp"
Patrick Ventureef3aead2018-09-12 08:53:29 -07002
Patrick Venture7210b312018-10-03 14:01:35 -07003#include <blobs-ipmid/test/manager_mock.hpp>
Patrick Ventureef3aead2018-09-12 08:53:29 -07004#include <cstring>
5
6#include <gtest/gtest.h>
7
8namespace blobs
9{
10
11using ::testing::ElementsAreArray;
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(BlobWriteTest, ManagerReturnsFailureReturnsFailure)
19{
20 // This verifies a failure from the manager is passed back.
21
22 ManagerMock mgr;
23 size_t dataLen;
24 uint8_t request[MAX_IPMI_BUFFER] = {0};
25 uint8_t reply[MAX_IPMI_BUFFER] = {0};
26 auto req = reinterpret_cast<struct BmcBlobWriteTx*>(request);
27
28 req->cmd = BlobOEMCommands::bmcBlobWrite;
29 req->crc = 0;
30 req->sessionId = 0x54;
31 req->offset = 0x100;
32
33 uint8_t expectedBytes[2] = {0x66, 0x67};
34 std::memcpy(req->data, &expectedBytes[0], sizeof(expectedBytes));
35
36 dataLen = sizeof(struct BmcBlobWriteTx) + sizeof(expectedBytes);
37
38 EXPECT_CALL(mgr,
39 write(req->sessionId, req->offset,
40 ElementsAreArray(expectedBytes, sizeof(expectedBytes))))
41 .WillOnce(Return(false));
42
43 EXPECT_EQ(IPMI_CC_INVALID, writeBlob(&mgr, request, reply, &dataLen));
44}
45
46TEST(BlobWriteTest, 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 BmcBlobWriteTx*>(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 BmcBlobWriteTx) + sizeof(expectedBytes);
65
66 EXPECT_CALL(mgr,
67 write(req->sessionId, req->offset,
68 ElementsAreArray(expectedBytes, sizeof(expectedBytes))))
69 .WillOnce(Return(true));
70
71 EXPECT_EQ(IPMI_CC_OK, writeBlob(&mgr, request, reply, &dataLen));
72}
73} // namespace blobs