blob: ef3664683829aee91bbf7e0b9b096bc7f36116d4 [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#include <vector>
6
7#include <gtest/gtest.h>
8
9namespace blobs
10{
11
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(BlobReadTest, ManagerReturnsNoData)
19{
20 // Verify that if no data is returned the IPMI command reply has no
21 // payload. The manager, in all failures, will just return 0 bytes.
22
23 ManagerMock mgr;
24 size_t dataLen;
25 uint8_t request[MAX_IPMI_BUFFER] = {0};
26 uint8_t reply[MAX_IPMI_BUFFER] = {0};
27 auto req = reinterpret_cast<struct BmcBlobReadTx*>(request);
28
29 req->cmd = BlobOEMCommands::bmcBlobRead;
30 req->crc = 0;
31 req->sessionId = 0x54;
32 req->offset = 0x100;
33 req->requestedSize = 0x10;
34
35 dataLen = sizeof(struct BmcBlobReadTx);
36
37 std::vector<uint8_t> data;
38
39 EXPECT_CALL(mgr, read(req->sessionId, req->offset, req->requestedSize))
40 .WillOnce(Return(data));
41
42 EXPECT_EQ(IPMI_CC_OK, readBlob(&mgr, request, reply, &dataLen));
43 EXPECT_EQ(sizeof(struct BmcBlobReadRx), dataLen);
44}
45
46TEST(BlobReadTest, ManagerReturnsData)
47{
48 // Verify that if data is returned, it's placed in the expected location.
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 BmcBlobReadTx*>(request);
55
56 req->cmd = BlobOEMCommands::bmcBlobRead;
57 req->crc = 0;
58 req->sessionId = 0x54;
59 req->offset = 0x100;
60 req->requestedSize = 0x10;
61
62 dataLen = sizeof(struct BmcBlobReadTx);
63
64 std::vector<uint8_t> data = {0x02, 0x03, 0x05, 0x06};
65
66 EXPECT_CALL(mgr, read(req->sessionId, req->offset, req->requestedSize))
67 .WillOnce(Return(data));
68
69 EXPECT_EQ(IPMI_CC_OK, readBlob(&mgr, request, reply, &dataLen));
70 EXPECT_EQ(sizeof(struct BmcBlobReadRx) + data.size(), dataLen);
71 EXPECT_EQ(0, std::memcmp(&reply[sizeof(struct BmcBlobReadRx)], data.data(),
72 data.size()));
73}
74
75/* TODO(venture): We need a test that handles other checks such as if the size
76 * requested won't fit into a packet response.
77 */
78} // namespace blobs