blob: b249ccc8ab17bfc6fce6821ccc2fd792151ee1ec [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
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
Patrick Venture00d5f0d2019-05-17 19:21:35 -070028 req->cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite);
Patrick Ventureef3aead2018-09-12 08:53:29 -070029 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
Patrick Venture41258802018-11-12 10:46:30 -080043 EXPECT_EQ(IPMI_CC_UNSPECIFIED_ERROR,
44 writeBlob(&mgr, request, reply, &dataLen));
Patrick Ventureef3aead2018-09-12 08:53:29 -070045}
46
47TEST(BlobWriteTest, ManagerReturnsTrueWriteSucceeds)
48{
49 // The case where everything works.
50
51 ManagerMock mgr;
52 size_t dataLen;
53 uint8_t request[MAX_IPMI_BUFFER] = {0};
54 uint8_t reply[MAX_IPMI_BUFFER] = {0};
55 auto req = reinterpret_cast<struct BmcBlobWriteTx*>(request);
56
Patrick Venture00d5f0d2019-05-17 19:21:35 -070057 req->cmd = static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite);
Patrick Ventureef3aead2018-09-12 08:53:29 -070058 req->crc = 0;
59 req->sessionId = 0x54;
60 req->offset = 0x100;
61
62 uint8_t expectedBytes[2] = {0x66, 0x67};
63 std::memcpy(req->data, &expectedBytes[0], sizeof(expectedBytes));
64
65 dataLen = sizeof(struct BmcBlobWriteTx) + sizeof(expectedBytes);
66
67 EXPECT_CALL(mgr,
68 write(req->sessionId, req->offset,
69 ElementsAreArray(expectedBytes, sizeof(expectedBytes))))
70 .WillOnce(Return(true));
71
72 EXPECT_EQ(IPMI_CC_OK, writeBlob(&mgr, request, reply, &dataLen));
73}
74} // namespace blobs