blob: 2fa22b29a85a1dcc90b4d2f07a82c1412bce254b [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#include <string>
6
7#include <gtest/gtest.h>
8
9namespace blobs
10{
11
12using ::testing::Invoke;
13using ::testing::NotNull;
14using ::testing::Return;
15using ::testing::StrEq;
16
17// ipmid.hpp isn't installed where we can grab it and this value is per BMC
18// SoC.
19#define MAX_IPMI_BUFFER 64
20
21TEST(BlobCloseTest, ManagerRejectsCloseReturnsFailure)
22{
23 // The session manager returned failure to close, which we need to pass on.
24
25 ManagerMock mgr;
26 uint16_t sessionId = 0x54;
27 size_t dataLen;
28 uint8_t request[MAX_IPMI_BUFFER] = {0};
29 uint8_t reply[MAX_IPMI_BUFFER] = {0};
30 struct BmcBlobCloseTx req;
31
32 req.cmd = BlobOEMCommands::bmcBlobClose;
33 req.crc = 0;
34 req.sessionId = sessionId;
35
36 dataLen = sizeof(req);
37
38 std::memcpy(request, &req, sizeof(req));
39
40 EXPECT_CALL(mgr, close(sessionId)).WillOnce(Return(false));
Patrick Venture41258802018-11-12 10:46:30 -080041 EXPECT_EQ(IPMI_CC_UNSPECIFIED_ERROR,
42 closeBlob(&mgr, request, reply, &dataLen));
Patrick Ventureef3aead2018-09-12 08:53:29 -070043}
44
45TEST(BlobCloseTest, BlobClosedReturnsSuccess)
46{
47 // Verify that if all goes right, success is returned.
48
49 ManagerMock mgr;
50 uint16_t sessionId = 0x54;
51 size_t dataLen;
52 uint8_t request[MAX_IPMI_BUFFER] = {0};
53 uint8_t reply[MAX_IPMI_BUFFER] = {0};
54 struct BmcBlobCloseTx req;
55
56 req.cmd = BlobOEMCommands::bmcBlobClose;
57 req.crc = 0;
58 req.sessionId = sessionId;
59
60 dataLen = sizeof(req);
61
62 std::memcpy(request, &req, sizeof(req));
63
64 EXPECT_CALL(mgr, close(sessionId)).WillOnce(Return(true));
65 EXPECT_EQ(IPMI_CC_OK, closeBlob(&mgr, request, reply, &dataLen));
66}
67} // namespace blobs