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