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