blob: 12cf1bc610c726deb06c96de81c1ee90e533d641 [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
7#include <gtest/gtest.h>
Patrick Ventureef3aead2018-09-12 08:53:29 -07008namespace blobs
9{
10
11using ::testing::ElementsAreArray;
12using ::testing::Return;
13
Patrick Ventureef3aead2018-09-12 08:53:29 -070014TEST(BlobWriteTest, ManagerReturnsFailureReturnsFailure)
15{
16 // This verifies a failure from the manager is passed back.
Patrick Ventureef3aead2018-09-12 08:53:29 -070017 ManagerMock mgr;
Willy Tu067ece12022-06-16 02:07:06 -070018 std::vector<uint8_t> request;
19 struct BmcBlobWriteTx req;
Patrick Ventureef3aead2018-09-12 08:53:29 -070020
Willy Tu067ece12022-06-16 02:07:06 -070021 req.crc = 0;
22 req.sessionId = 0x54;
23 req.offset = 0x100;
Patrick Ventureef3aead2018-09-12 08:53:29 -070024
Willy Tu067ece12022-06-16 02:07:06 -070025 request.resize(sizeof(struct BmcBlobWriteTx));
26 std::memcpy(request.data(), &req, sizeof(struct BmcBlobWriteTx));
Patrick Ventureef3aead2018-09-12 08:53:29 -070027
Willy Tu067ece12022-06-16 02:07:06 -070028 std::array<uint8_t, 2> expectedBytes = {0x66, 0x67};
29 request.insert(request.end(), expectedBytes.begin(), expectedBytes.end());
Patrick Ventureef3aead2018-09-12 08:53:29 -070030
Willy Tu067ece12022-06-16 02:07:06 -070031 EXPECT_CALL(
32 mgr, write(req.sessionId, req.offset, ElementsAreArray(expectedBytes)))
Patrick Ventureef3aead2018-09-12 08:53:29 -070033 .WillOnce(Return(false));
34
Willy Tu067ece12022-06-16 02:07:06 -070035 EXPECT_EQ(ipmi::responseUnspecifiedError(), writeBlob(&mgr, request));
Patrick Ventureef3aead2018-09-12 08:53:29 -070036}
37
38TEST(BlobWriteTest, ManagerReturnsTrueWriteSucceeds)
39{
40 // The case where everything works.
41
42 ManagerMock mgr;
Willy Tu067ece12022-06-16 02:07:06 -070043 std::vector<uint8_t> request;
44 struct BmcBlobWriteTx req;
Patrick Ventureef3aead2018-09-12 08:53:29 -070045
Willy Tu067ece12022-06-16 02:07:06 -070046 req.crc = 0;
47 req.sessionId = 0x54;
48 req.offset = 0x100;
Patrick Ventureef3aead2018-09-12 08:53:29 -070049
Willy Tu067ece12022-06-16 02:07:06 -070050 request.resize(sizeof(struct BmcBlobWriteTx));
51 std::memcpy(request.data(), &req, sizeof(struct BmcBlobWriteTx));
Patrick Ventureef3aead2018-09-12 08:53:29 -070052
Willy Tu067ece12022-06-16 02:07:06 -070053 std::array<uint8_t, 2> expectedBytes = {0x66, 0x67};
54 request.insert(request.end(), expectedBytes.begin(), expectedBytes.end());
Patrick Ventureef3aead2018-09-12 08:53:29 -070055
Willy Tu067ece12022-06-16 02:07:06 -070056 EXPECT_CALL(
57 mgr, write(req.sessionId, req.offset, ElementsAreArray(expectedBytes)))
Patrick Ventureef3aead2018-09-12 08:53:29 -070058 .WillOnce(Return(true));
59
Willy Tu067ece12022-06-16 02:07:06 -070060 EXPECT_EQ(ipmi::responseSuccess(std::vector<uint8_t>{}),
61 writeBlob(&mgr, request));
Patrick Ventureef3aead2018-09-12 08:53:29 -070062}
63} // namespace blobs