1 #include "helper.hpp"
2 #include "ipmi.hpp"
3 #include "manager_mock.hpp"
4
5 #include <cstring>
6 #include <vector>
7
8 #include <gtest/gtest.h>
9
10 namespace blobs
11 {
12
13 using ::testing::Return;
14
TEST(BlobReadTest,ManagerReturnsNoData)15 TEST(BlobReadTest, ManagerReturnsNoData)
16 {
17 // Verify that if no data is returned the IPMI command reply has no
18 // payload. The manager, in all failures, will just return 0 bytes.
19 ManagerMock mgr;
20 std::vector<uint8_t> request;
21 struct BmcBlobReadTx req;
22
23 req.crc = 0;
24 req.sessionId = 0x54;
25 req.offset = 0x100;
26 req.requestedSize = 0x10;
27 request.resize(sizeof(struct BmcBlobReadTx));
28 std::memcpy(request.data(), &req, sizeof(struct BmcBlobReadTx));
29 std::vector<uint8_t> data;
30
31 EXPECT_CALL(mgr, read(req.sessionId, req.offset, req.requestedSize))
32 .WillOnce(Return(data));
33
34 auto result = validateReply(readBlob(&mgr, request));
35 EXPECT_EQ(sizeof(struct BmcBlobReadRx), result.size());
36 }
37
TEST(BlobReadTest,ManagerReturnsData)38 TEST(BlobReadTest, ManagerReturnsData)
39 {
40 // Verify that if data is returned, it's placed in the expected location.
41 ManagerMock mgr;
42 std::vector<uint8_t> request;
43 struct BmcBlobReadTx req;
44
45 req.crc = 0;
46 req.sessionId = 0x54;
47 req.offset = 0x100;
48 req.requestedSize = 0x10;
49 request.resize(sizeof(struct BmcBlobReadTx));
50 std::memcpy(request.data(), &req, sizeof(struct BmcBlobReadTx));
51 std::vector<uint8_t> data = {0x02, 0x03, 0x05, 0x06};
52
53 EXPECT_CALL(mgr, read(req.sessionId, req.offset, req.requestedSize))
54 .WillOnce(Return(data));
55
56 auto result = validateReply(readBlob(&mgr, request));
57 EXPECT_EQ(sizeof(struct BmcBlobReadRx) + data.size(), result.size());
58 EXPECT_EQ(0, std::memcmp(&result[sizeof(struct BmcBlobReadRx)], data.data(),
59 data.size()));
60 }
61
62 /* TODO(venture): We need a test that handles other checks such as if the size
63 * requested won't fit into a packet response.
64 */
65 } // namespace blobs
66