blob: 80e1cbc4be82ef96bbacdddce9de8d6b4c3543ad [file] [log] [blame]
Willy Tu067ece12022-06-16 02:07:06 -07001#include "helper.hpp"
Patrick Ventureef3aead2018-09-12 08:53:29 -07002#include "ipmi.hpp"
Patrick Venturecd8dab42019-01-15 19:57:38 -08003#include "manager_mock.hpp"
Patrick Ventureef3aead2018-09-12 08:53:29 -07004
Patrick Ventureef3aead2018-09-12 08:53:29 -07005#include <cstring>
6#include <vector>
7
8#include <gtest/gtest.h>
9
10namespace blobs
11{
12
13using ::testing::Return;
14
Patrick Ventureef3aead2018-09-12 08:53:29 -070015TEST(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.
Patrick Ventureef3aead2018-09-12 08:53:29 -070019 ManagerMock mgr;
Willy Tu067ece12022-06-16 02:07:06 -070020 std::vector<uint8_t> request;
21 struct BmcBlobReadTx req;
Patrick Ventureef3aead2018-09-12 08:53:29 -070022
Willy Tu067ece12022-06-16 02:07:06 -070023 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));
Patrick Ventureef3aead2018-09-12 08:53:29 -070029 std::vector<uint8_t> data;
30
Willy Tu067ece12022-06-16 02:07:06 -070031 EXPECT_CALL(mgr, read(req.sessionId, req.offset, req.requestedSize))
Patrick Ventureef3aead2018-09-12 08:53:29 -070032 .WillOnce(Return(data));
33
Willy Tu067ece12022-06-16 02:07:06 -070034 auto result = validateReply(readBlob(&mgr, request));
35 EXPECT_EQ(sizeof(struct BmcBlobReadRx), result.size());
Patrick Ventureef3aead2018-09-12 08:53:29 -070036}
37
38TEST(BlobReadTest, ManagerReturnsData)
39{
40 // Verify that if data is returned, it's placed in the expected location.
Patrick Ventureef3aead2018-09-12 08:53:29 -070041 ManagerMock mgr;
Willy Tu067ece12022-06-16 02:07:06 -070042 std::vector<uint8_t> request;
43 struct BmcBlobReadTx req;
Patrick Ventureef3aead2018-09-12 08:53:29 -070044
Willy Tu067ece12022-06-16 02:07:06 -070045 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));
Patrick Ventureef3aead2018-09-12 08:53:29 -070051 std::vector<uint8_t> data = {0x02, 0x03, 0x05, 0x06};
52
Willy Tu067ece12022-06-16 02:07:06 -070053 EXPECT_CALL(mgr, read(req.sessionId, req.offset, req.requestedSize))
Patrick Ventureef3aead2018-09-12 08:53:29 -070054 .WillOnce(Return(data));
55
Willy Tu067ece12022-06-16 02:07:06 -070056 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(),
Patrick Ventureef3aead2018-09-12 08:53:29 -070059 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