Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 1 | #include <cstdint> |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 2 | #include <ipmiblob/blob_handler.hpp> |
Patrick Venture | 1681f7f | 2019-03-07 12:59:29 -0800 | [diff] [blame] | 3 | #include <ipmiblob/test/crc_mock.hpp> |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 4 | #include <ipmiblob/test/ipmi_interface_mock.hpp> |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 5 | #include <memory> |
| 6 | #include <vector> |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 10 | namespace ipmiblob |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 11 | { |
| 12 | CrcInterface* crcIntf = nullptr; |
| 13 | |
| 14 | std::uint16_t generateCrc(const std::vector<std::uint8_t>& data) |
| 15 | { |
| 16 | return (crcIntf) ? crcIntf->generateCrc(data) : 0x00; |
| 17 | } |
| 18 | |
| 19 | using ::testing::Eq; |
| 20 | using ::testing::Return; |
| 21 | |
| 22 | class BlobHandlerTest : public ::testing::Test |
| 23 | { |
| 24 | protected: |
| 25 | void SetUp() override |
| 26 | { |
| 27 | crcIntf = &crcMock; |
| 28 | } |
| 29 | |
| 30 | CrcMock crcMock; |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 31 | |
| 32 | std::unique_ptr<IpmiInterface> CreateIpmiMock() |
| 33 | { |
| 34 | return std::make_unique<IpmiInterfaceMock>(); |
| 35 | } |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | TEST_F(BlobHandlerTest, getCountIpmiHappy) |
| 39 | { |
| 40 | /* Verify returns the value specified by the IPMI response. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 41 | auto ipmi = CreateIpmiMock(); |
| 42 | IpmiInterfaceMock* ipmiMock = |
| 43 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 44 | BlobHandler blob(std::move(ipmi)); |
| 45 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 46 | std::vector<std::uint8_t> request = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 47 | 0xcf, 0xc2, 0x00, |
| 48 | static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobGetCount)}; |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 49 | |
| 50 | /* return 1 blob count. */ |
| 51 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 52 | 0x01, 0x00, 0x00, 0x00}; |
| 53 | |
| 54 | std::vector<std::uint8_t> bytes = {0x01, 0x00, 0x00, 0x00}; |
| 55 | EXPECT_CALL(crcMock, generateCrc(Eq(bytes))).WillOnce(Return(0x00)); |
| 56 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 57 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 58 | EXPECT_EQ(1, blob.getBlobCount()); |
| 59 | } |
| 60 | |
| 61 | TEST_F(BlobHandlerTest, enumerateBlobIpmiHappy) |
| 62 | { |
| 63 | /* Verify returns the name specified by the IPMI response. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 64 | auto ipmi = CreateIpmiMock(); |
| 65 | IpmiInterfaceMock* ipmiMock = |
| 66 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 67 | BlobHandler blob(std::move(ipmi)); |
| 68 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 69 | std::vector<std::uint8_t> request = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 70 | 0xcf, 0xc2, |
| 71 | 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate), |
| 72 | 0x00, 0x00, |
| 73 | 0x01, 0x00, |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 74 | 0x00, 0x00}; |
| 75 | |
| 76 | /* return value. */ |
| 77 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 78 | 'a', 'b', 'c', 'd', 0x00}; |
| 79 | |
| 80 | std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd', 0x00}; |
| 81 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00}; |
| 82 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 83 | EXPECT_CALL(crcMock, generateCrc(Eq(bytes))).WillOnce(Return(0x00)); |
| 84 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 85 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 86 | EXPECT_STREQ("abcd", blob.enumerateBlob(1).c_str()); |
| 87 | } |
| 88 | |
| 89 | TEST_F(BlobHandlerTest, enumerateBlobIpmiNoBytes) |
| 90 | { |
| 91 | /* Simulate a case where the IPMI command returns no data. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 92 | auto ipmi = CreateIpmiMock(); |
| 93 | IpmiInterfaceMock* ipmiMock = |
| 94 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 95 | BlobHandler blob(std::move(ipmi)); |
| 96 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 97 | std::vector<std::uint8_t> request = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 98 | 0xcf, 0xc2, |
| 99 | 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate), |
| 100 | 0x00, 0x00, |
| 101 | 0x01, 0x00, |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 102 | 0x00, 0x00}; |
| 103 | |
| 104 | /* return value. */ |
| 105 | std::vector<std::uint8_t> resp = {}; |
| 106 | |
| 107 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00}; |
| 108 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 109 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 110 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 111 | EXPECT_STREQ("", blob.enumerateBlob(1).c_str()); |
| 112 | } |
| 113 | |
| 114 | TEST_F(BlobHandlerTest, getBlobListIpmiHappy) |
| 115 | { |
| 116 | /* Verify returns the list built via the above two commands. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 117 | auto ipmi = CreateIpmiMock(); |
| 118 | IpmiInterfaceMock* ipmiMock = |
| 119 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 120 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 121 | |
| 122 | std::vector<std::uint8_t> request1 = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 123 | 0xcf, 0xc2, 0x00, |
| 124 | static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobGetCount)}; |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 125 | |
| 126 | /* return 1 blob count. */ |
| 127 | std::vector<std::uint8_t> resp1 = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 128 | 0x01, 0x00, 0x00, 0x00}; |
| 129 | |
| 130 | std::vector<std::uint8_t> bytes1 = {0x01, 0x00, 0x00, 0x00}; |
| 131 | EXPECT_CALL(crcMock, generateCrc(Eq(bytes1))).WillOnce(Return(0x00)); |
| 132 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 133 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request1))).WillOnce(Return(resp1)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 134 | |
| 135 | std::vector<std::uint8_t> request2 = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 136 | 0xcf, 0xc2, |
| 137 | 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobEnumerate), |
| 138 | 0x00, 0x00, |
| 139 | 0x00, 0x00, |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 140 | 0x00, 0x00}; |
| 141 | |
| 142 | /* return value. */ |
| 143 | std::vector<std::uint8_t> resp2 = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 144 | 'a', 'b', 'c', 'd', 0x00}; |
| 145 | |
| 146 | std::vector<std::uint8_t> reqCrc = {0x00, 0x00, 0x00, 0x00}; |
| 147 | std::vector<std::uint8_t> bytes2 = {'a', 'b', 'c', 'd', 0x00}; |
| 148 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 149 | EXPECT_CALL(crcMock, generateCrc(Eq(bytes2))).WillOnce(Return(0x00)); |
| 150 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 151 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request2))).WillOnce(Return(resp2)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 152 | |
| 153 | /* A std::string is not nul-terminated by default. */ |
| 154 | std::vector<std::string> expectedList = {std::string{"abcd"}}; |
| 155 | |
| 156 | EXPECT_EQ(expectedList, blob.getBlobList()); |
| 157 | } |
| 158 | |
| 159 | TEST_F(BlobHandlerTest, getStatWithMetadata) |
| 160 | { |
| 161 | /* Stat received metadata. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 162 | auto ipmi = CreateIpmiMock(); |
| 163 | IpmiInterfaceMock* ipmiMock = |
| 164 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 165 | BlobHandler blob(std::move(ipmi)); |
| 166 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 167 | std::vector<std::uint8_t> request = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 168 | 0xcf, 0xc2, |
| 169 | 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobStat), |
| 170 | 0x00, 0x00, |
| 171 | 'a', 'b', |
| 172 | 'c', 'd', |
| 173 | 0x00}; |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 174 | |
| 175 | /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */ |
| 176 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, 0xff, |
| 177 | 0x00, 0x00, 0x00, 0x00, 0x02, 0x34, 0x45}; |
| 178 | |
| 179 | std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00}; |
| 180 | std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, 0x00, |
| 181 | 0x00, 0x02, 0x34, 0x45}; |
| 182 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 183 | EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00)); |
| 184 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 185 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 186 | |
| 187 | auto meta = blob.getStat("abcd"); |
| 188 | EXPECT_EQ(meta.blob_state, 0xffff); |
| 189 | EXPECT_EQ(meta.size, 0x00); |
| 190 | std::vector<std::uint8_t> metadata = {0x34, 0x45}; |
| 191 | EXPECT_EQ(metadata, meta.metadata); |
| 192 | } |
| 193 | |
| 194 | TEST_F(BlobHandlerTest, getStatNoMetadata) |
| 195 | { |
| 196 | /* Stat received no metadata. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 197 | auto ipmi = CreateIpmiMock(); |
| 198 | IpmiInterfaceMock* ipmiMock = |
| 199 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 200 | BlobHandler blob(std::move(ipmi)); |
| 201 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 202 | std::vector<std::uint8_t> request = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 203 | 0xcf, 0xc2, |
| 204 | 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobStat), |
| 205 | 0x00, 0x00, |
| 206 | 'a', 'b', |
| 207 | 'c', 'd', |
| 208 | 0x00}; |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 209 | |
| 210 | /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */ |
| 211 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, |
| 212 | 0xff, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 213 | |
| 214 | std::vector<std::uint8_t> reqCrc = {'a', 'b', 'c', 'd', 0x00}; |
| 215 | std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, |
| 216 | 0x00, 0x00, 0x00}; |
| 217 | |
| 218 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 219 | EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00)); |
| 220 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 221 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 222 | |
| 223 | auto meta = blob.getStat("abcd"); |
| 224 | EXPECT_EQ(meta.blob_state, 0xffff); |
| 225 | EXPECT_EQ(meta.size, 0x00); |
| 226 | std::vector<std::uint8_t> metadata = {}; |
| 227 | EXPECT_EQ(metadata, meta.metadata); |
| 228 | } |
| 229 | |
Patrick Venture | 16a99a6 | 2019-05-03 17:21:30 -0700 | [diff] [blame] | 230 | TEST_F(BlobHandlerTest, getSessionStatNoMetadata) |
| 231 | { |
| 232 | /* The get session stat succeeds. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 233 | auto ipmi = CreateIpmiMock(); |
| 234 | IpmiInterfaceMock* ipmiMock = |
| 235 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 236 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 16a99a6 | 2019-05-03 17:21:30 -0700 | [diff] [blame] | 237 | |
| 238 | std::vector<std::uint8_t> request = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 239 | 0xcf, 0xc2, |
| 240 | 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobSessionStat), |
| 241 | 0x00, 0x00, |
| 242 | 0x01, 0x00}; |
Patrick Venture | 16a99a6 | 2019-05-03 17:21:30 -0700 | [diff] [blame] | 243 | |
| 244 | /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */ |
| 245 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, |
| 246 | 0xff, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 247 | |
| 248 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00}; |
| 249 | std::vector<std::uint8_t> respCrc = {0xff, 0xff, 0x00, 0x00, |
| 250 | 0x00, 0x00, 0x00}; |
| 251 | |
| 252 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 253 | EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00)); |
| 254 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 255 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 16a99a6 | 2019-05-03 17:21:30 -0700 | [diff] [blame] | 256 | |
| 257 | auto meta = blob.getStat(0x0001); |
| 258 | EXPECT_EQ(meta.blob_state, 0xffff); |
| 259 | EXPECT_EQ(meta.size, 0x00); |
| 260 | std::vector<std::uint8_t> metadata = {}; |
| 261 | EXPECT_EQ(metadata, meta.metadata); |
| 262 | } |
| 263 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 264 | TEST_F(BlobHandlerTest, openBlobSucceeds) |
| 265 | { |
| 266 | /* The open blob succeeds. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 267 | auto ipmi = CreateIpmiMock(); |
| 268 | IpmiInterfaceMock* ipmiMock = |
| 269 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 270 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 271 | |
| 272 | std::vector<std::uint8_t> request = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 273 | 0xcf, 0xc2, |
| 274 | 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobOpen), |
| 275 | 0x00, 0x00, |
| 276 | 0x02, 0x04, |
| 277 | 'a', 'b', |
| 278 | 'c', 'd', |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 279 | 0x00}; |
| 280 | |
| 281 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xfe, 0xed}; |
| 282 | |
| 283 | std::vector<std::uint8_t> reqCrc = {0x02, 0x04, 'a', 'b', 'c', 'd', 0x00}; |
| 284 | std::vector<std::uint8_t> respCrc = {0xfe, 0xed}; |
| 285 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 286 | EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00)); |
| 287 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 288 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 289 | |
| 290 | const int writeBit = (1 << 1); |
| 291 | const int lpcBit = (1 << 10); |
| 292 | |
| 293 | auto session = blob.openBlob("abcd", writeBit | lpcBit); |
| 294 | EXPECT_EQ(0xedfe, session); |
| 295 | } |
| 296 | |
| 297 | TEST_F(BlobHandlerTest, closeBlobSucceeds) |
| 298 | { |
| 299 | /* The close succeeds. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 300 | auto ipmi = CreateIpmiMock(); |
| 301 | IpmiInterfaceMock* ipmiMock = |
| 302 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 303 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 304 | |
| 305 | std::vector<std::uint8_t> request = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 306 | 0xcf, 0xc2, |
| 307 | 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobClose), |
| 308 | 0x00, 0x00, |
| 309 | 0x01, 0x00}; |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 310 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00}; |
| 311 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00}; |
| 312 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 313 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 314 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 315 | |
| 316 | blob.closeBlob(0x0001); |
| 317 | } |
| 318 | |
Patrick Venture | 8865e40 | 2019-05-14 13:29:10 -0700 | [diff] [blame] | 319 | TEST_F(BlobHandlerTest, commitSucceedsNoData) |
| 320 | { |
| 321 | /* The commit succeeds. */ |
| 322 | auto ipmi = CreateIpmiMock(); |
| 323 | IpmiInterfaceMock* ipmiMock = |
| 324 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 325 | BlobHandler blob(std::move(ipmi)); |
| 326 | |
| 327 | std::vector<std::uint8_t> request = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 328 | 0xcf, 0xc2, |
| 329 | 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobCommit), |
| 330 | 0x00, 0x00, |
| 331 | 0x01, 0x00, |
Patrick Venture | 8865e40 | 2019-05-14 13:29:10 -0700 | [diff] [blame] | 332 | 0x00}; |
| 333 | |
| 334 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00}; |
| 335 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00}; |
| 336 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 337 | |
| 338 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
| 339 | |
| 340 | blob.commit(0x0001, {}); |
| 341 | } |
| 342 | |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 343 | TEST_F(BlobHandlerTest, writeBytesSucceeds) |
| 344 | { |
| 345 | /* The write bytes succeeds. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 346 | auto ipmi = CreateIpmiMock(); |
| 347 | IpmiInterfaceMock* ipmiMock = |
| 348 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 349 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 350 | |
| 351 | std::vector<std::uint8_t> request = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 352 | 0xcf, 0xc2, |
| 353 | 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobWrite), |
| 354 | 0x00, 0x00, |
| 355 | 0x01, 0x00, |
| 356 | 0x00, 0x00, |
| 357 | 0x00, 0x00, |
| 358 | 'a', 'b', |
| 359 | 'c', 'd'}; |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 360 | |
| 361 | std::vector<std::uint8_t> bytes = {'a', 'b', 'c', 'd'}; |
| 362 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00}; |
| 363 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00, |
| 364 | 0x00, 'a', 'b', 'c', 'd'}; |
| 365 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 366 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 367 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 368 | |
| 369 | blob.writeBytes(0x0001, 0, bytes); |
| 370 | } |
| 371 | |
| 372 | TEST_F(BlobHandlerTest, readBytesSucceeds) |
| 373 | { |
| 374 | /* The reading of bytes succeeds. */ |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 375 | auto ipmi = CreateIpmiMock(); |
| 376 | IpmiInterfaceMock* ipmiMock = |
| 377 | reinterpret_cast<IpmiInterfaceMock*>(ipmi.get()); |
| 378 | BlobHandler blob(std::move(ipmi)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 379 | |
| 380 | std::vector<std::uint8_t> request = { |
Patrick Venture | 4447464 | 2019-05-20 19:11:04 -0700 | [diff] [blame] | 381 | 0xcf, 0xc2, |
| 382 | 0x00, static_cast<std::uint8_t>(BlobOEMCommands::bmcBlobRead), |
| 383 | 0x00, 0x00, |
| 384 | 0x01, 0x00, |
| 385 | 0x00, 0x00, |
| 386 | 0x00, 0x00, |
| 387 | 0x04, 0x00, |
| 388 | 0x00, 0x00}; |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 389 | |
| 390 | std::vector<std::uint8_t> expectedBytes = {'a', 'b', 'c', 'd'}; |
| 391 | std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, |
| 392 | 'a', 'b', 'c', 'd'}; |
| 393 | std::vector<std::uint8_t> reqCrc = {0x01, 0x00, 0x00, 0x00, 0x00, |
| 394 | 0x00, 0x04, 0x00, 0x00, 0x00}; |
| 395 | std::vector<std::uint8_t> respCrc = {'a', 'b', 'c', 'd'}; |
| 396 | |
| 397 | EXPECT_CALL(crcMock, generateCrc(Eq(reqCrc))).WillOnce(Return(0x00)); |
| 398 | EXPECT_CALL(crcMock, generateCrc(Eq(respCrc))).WillOnce(Return(0x00)); |
| 399 | |
Patrick Venture | 786a541 | 2019-05-13 07:40:22 -0700 | [diff] [blame] | 400 | EXPECT_CALL(*ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp)); |
Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame] | 401 | |
| 402 | EXPECT_EQ(blob.readBytes(0x0001, 0, 4), expectedBytes); |
| 403 | } |
| 404 | |
Patrick Venture | 1470bec | 2019-03-06 07:33:12 -0800 | [diff] [blame] | 405 | } // namespace ipmiblob |