Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 1 | #include "common/utils.hpp" |
| 2 | #include "fw-update/inventory_manager.hpp" |
| 3 | #include "requester/test/mock_request.hpp" |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 4 | #include "test/test_instance_id.hpp" |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 5 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 6 | #include <libpldm/firmware_update.h> |
| 7 | |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | using namespace pldm; |
| 11 | using namespace std::chrono; |
| 12 | using namespace pldm::fw_update; |
| 13 | |
| 14 | class InventoryManagerTest : public testing::Test |
| 15 | { |
| 16 | protected: |
| 17 | InventoryManagerTest() : |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 18 | event(sdeventplus::Event::get_default()), instanceIdDb(), |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 19 | reqHandler(nullptr, event, instanceIdDb, false, seconds(1), 2, |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 20 | milliseconds(100)), |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 21 | inventoryManager(reqHandler, instanceIdDb, outDescriptorMap, |
Unive Tien | eaf79da | 2024-11-25 09:34:39 +0800 | [diff] [blame^] | 22 | outDownstreamDescriptorMap, outComponentInfoMap) |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 23 | {} |
| 24 | |
| 25 | int fd = -1; |
| 26 | sdeventplus::Event event; |
Andrew Jeffery | 7c1dc7e | 2023-04-28 14:52:16 +0930 | [diff] [blame] | 27 | TestInstanceIdDb instanceIdDb; |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 28 | requester::Handler<requester::Request> reqHandler; |
| 29 | InventoryManager inventoryManager; |
| 30 | DescriptorMap outDescriptorMap{}; |
Unive Tien | eaf79da | 2024-11-25 09:34:39 +0800 | [diff] [blame^] | 31 | DownstreamDescriptorMap outDownstreamDescriptorMap{}; |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 32 | ComponentInfoMap outComponentInfoMap{}; |
| 33 | }; |
| 34 | |
| 35 | TEST_F(InventoryManagerTest, handleQueryDeviceIdentifiersResponse) |
| 36 | { |
| 37 | constexpr size_t respPayloadLength1 = 49; |
| 38 | constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength1> |
| 39 | queryDeviceIdentifiersResp1{ |
| 40 | 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, |
| 41 | 0x04, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x02, 0x00, 0x10, 0x00, 0x12, |
| 42 | 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, 0xa0, 0x30, 0xfc, 0x8a, |
| 43 | 0x56, 0x58, 0x7d, 0x5b, 0xFF, 0xFF, 0x0B, 0x00, 0x01, 0x07, 0x4f, |
| 44 | 0x70, 0x65, 0x6e, 0x42, 0x4d, 0x43, 0x01, 0x02}; |
| 45 | auto responseMsg1 = |
| 46 | reinterpret_cast<const pldm_msg*>(queryDeviceIdentifiersResp1.data()); |
| 47 | inventoryManager.queryDeviceIdentifiers(1, responseMsg1, |
| 48 | respPayloadLength1); |
| 49 | |
| 50 | DescriptorMap descriptorMap1{ |
| 51 | {0x01, |
| 52 | {{PLDM_FWUP_IANA_ENTERPRISE_ID, |
| 53 | std::vector<uint8_t>{0x0a, 0x0b, 0x0c, 0xd}}, |
| 54 | {PLDM_FWUP_UUID, |
| 55 | std::vector<uint8_t>{0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, |
| 56 | 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, |
| 57 | 0x5b}}, |
| 58 | {PLDM_FWUP_VENDOR_DEFINED, |
| 59 | std::make_tuple("OpenBMC", std::vector<uint8_t>{0x01, 0x02})}}}}; |
| 60 | |
| 61 | EXPECT_EQ(outDescriptorMap.size(), descriptorMap1.size()); |
| 62 | EXPECT_EQ(outDescriptorMap, descriptorMap1); |
| 63 | |
| 64 | constexpr size_t respPayloadLength2 = 26; |
| 65 | constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength2> |
| 66 | queryDeviceIdentifiersResp2{ |
| 67 | 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x02, |
| 68 | 0x00, 0x10, 0x00, 0xF0, 0x18, 0x87, 0x8C, 0xCB, 0x7D, 0x49, |
| 69 | 0x43, 0x98, 0x00, 0xA0, 0x2F, 0x59, 0x9A, 0xCA, 0x02}; |
| 70 | auto responseMsg2 = |
| 71 | reinterpret_cast<const pldm_msg*>(queryDeviceIdentifiersResp2.data()); |
| 72 | inventoryManager.queryDeviceIdentifiers(2, responseMsg2, |
| 73 | respPayloadLength2); |
| 74 | DescriptorMap descriptorMap2{ |
| 75 | {0x01, |
| 76 | {{PLDM_FWUP_IANA_ENTERPRISE_ID, |
| 77 | std::vector<uint8_t>{0x0a, 0x0b, 0x0c, 0xd}}, |
| 78 | {PLDM_FWUP_UUID, |
| 79 | std::vector<uint8_t>{0x12, 0x44, 0xd2, 0x64, 0x8d, 0x7d, 0x47, 0x18, |
| 80 | 0xa0, 0x30, 0xfc, 0x8a, 0x56, 0x58, 0x7d, |
| 81 | 0x5b}}, |
| 82 | {PLDM_FWUP_VENDOR_DEFINED, |
| 83 | std::make_tuple("OpenBMC", std::vector<uint8_t>{0x01, 0x02})}}}, |
| 84 | {0x02, |
| 85 | {{PLDM_FWUP_UUID, |
| 86 | std::vector<uint8_t>{0xF0, 0x18, 0x87, 0x8C, 0xCB, 0x7D, 0x49, 0x43, |
| 87 | 0x98, 0x00, 0xA0, 0x2F, 0x59, 0x9A, 0xCA, |
| 88 | 0x02}}}}}; |
| 89 | EXPECT_EQ(outDescriptorMap.size(), descriptorMap2.size()); |
| 90 | EXPECT_EQ(outDescriptorMap, descriptorMap2); |
| 91 | } |
| 92 | |
| 93 | TEST_F(InventoryManagerTest, handleQueryDeviceIdentifiersResponseErrorCC) |
| 94 | { |
| 95 | constexpr size_t respPayloadLength = 1; |
| 96 | constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength> |
| 97 | queryDeviceIdentifiersResp{0x00, 0x00, 0x00, 0x01}; |
| 98 | auto responseMsg = |
| 99 | reinterpret_cast<const pldm_msg*>(queryDeviceIdentifiersResp.data()); |
| 100 | inventoryManager.queryDeviceIdentifiers(1, responseMsg, respPayloadLength); |
| 101 | EXPECT_EQ(outDescriptorMap.size(), 0); |
| 102 | } |
| 103 | |
Unive Tien | eaf79da | 2024-11-25 09:34:39 +0800 | [diff] [blame^] | 104 | TEST_F(InventoryManagerTest, handleQueryDownstreamIdentifierResponse) |
| 105 | { |
| 106 | constexpr uint8_t eid = 1; |
| 107 | constexpr uint8_t downstreamDeviceCount = 1; |
| 108 | constexpr uint32_t downstreamDeviceLen = 11; |
| 109 | constexpr size_t respPayloadLength = |
| 110 | PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_RESP_MIN_LEN + downstreamDeviceLen; |
| 111 | |
| 112 | std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength> |
| 113 | queryDownstreamIdentifiersResp{ |
| 114 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, |
| 115 | 0x0B, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, |
| 116 | 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa0, 0x15}; |
| 117 | auto responseMsg = new (queryDownstreamIdentifiersResp.data()) pldm_msg; |
| 118 | |
| 119 | inventoryManager.queryDownstreamIdentifiers(eid, responseMsg, |
| 120 | respPayloadLength); |
| 121 | |
| 122 | DownstreamDevices downstreamDevices = { |
| 123 | {0, |
| 124 | {{PLDM_FWUP_IANA_ENTERPRISE_ID, |
| 125 | std::vector<uint8_t>{0x00, 0x00, 0xa0, 0x15}}}}}; |
| 126 | DownstreamDescriptorMap refDownstreamDescriptorMap{ |
| 127 | {eid, downstreamDevices}}; |
| 128 | |
| 129 | ASSERT_EQ(outDownstreamDescriptorMap.size(), downstreamDeviceCount); |
| 130 | ASSERT_EQ(outDownstreamDescriptorMap.size(), |
| 131 | refDownstreamDescriptorMap.size()); |
| 132 | ASSERT_EQ(outDownstreamDescriptorMap, refDownstreamDescriptorMap); |
| 133 | } |
| 134 | |
| 135 | TEST_F(InventoryManagerTest, handleQueryDownstreamIdentifierResponseErrorCC) |
| 136 | { |
| 137 | constexpr size_t respPayloadLength = 1; |
| 138 | constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength> |
| 139 | queryDownstreamIdentifiersResp{0x00, 0x00, 0x00, 0x01}; |
| 140 | const auto responseMsg = |
| 141 | new (const_cast<unsigned char*>(queryDownstreamIdentifiersResp.data())) |
| 142 | pldm_msg; |
| 143 | inventoryManager.queryDownstreamIdentifiers(1, responseMsg, |
| 144 | respPayloadLength); |
| 145 | |
| 146 | ASSERT_EQ(outDownstreamDescriptorMap.size(), 0); |
| 147 | } |
| 148 | |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 149 | TEST_F(InventoryManagerTest, getFirmwareParametersResponse) |
| 150 | { |
| 151 | // constexpr uint16_t compCount = 2; |
| 152 | // constexpr std::string_view activeCompImageSetVersion{"DeviceVer1.0"}; |
| 153 | // constexpr std::string_view activeCompVersion1{"Comp1v2.0"}; |
| 154 | // constexpr std::string_view activeCompVersion2{"Comp2v3.0"}; |
| 155 | constexpr uint16_t compClassification1 = 10; |
| 156 | constexpr uint16_t compIdentifier1 = 300; |
| 157 | constexpr uint8_t compClassificationIndex1 = 20; |
| 158 | constexpr uint16_t compClassification2 = 16; |
| 159 | constexpr uint16_t compIdentifier2 = 301; |
| 160 | constexpr uint8_t compClassificationIndex2 = 30; |
| 161 | |
| 162 | constexpr size_t respPayloadLength1 = 119; |
| 163 | constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength1> |
| 164 | getFirmwareParametersResp1{ |
| 165 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, |
| 166 | 0x0c, 0x00, 0x00, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x56, 0x65, |
| 167 | 0x72, 0x31, 0x2e, 0x30, 0x0a, 0x00, 0x2c, 0x01, 0x14, 0x00, 0x00, |
| 168 | 0x00, 0x00, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 169 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 170 | 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, |
| 171 | 0x6f, 0x6d, 0x70, 0x31, 0x76, 0x32, 0x2e, 0x30, 0x10, 0x00, 0x2d, |
| 172 | 0x01, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x01, 0x09, 0x00, 0x00, 0x00, |
| 173 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 174 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 175 | 0x00, 0x00, 0x00, 0x43, 0x6f, 0x6d, 0x70, 0x32, 0x76, 0x33, 0x2e, |
| 176 | 0x30}; |
| 177 | auto responseMsg1 = |
| 178 | reinterpret_cast<const pldm_msg*>(getFirmwareParametersResp1.data()); |
| 179 | inventoryManager.getFirmwareParameters(1, responseMsg1, respPayloadLength1); |
| 180 | |
| 181 | ComponentInfoMap componentInfoMap1{ |
| 182 | {1, |
| 183 | {{std::make_pair(compClassification1, compIdentifier1), |
| 184 | compClassificationIndex1}, |
| 185 | {std::make_pair(compClassification2, compIdentifier2), |
| 186 | compClassificationIndex2}}}}; |
| 187 | EXPECT_EQ(outComponentInfoMap.size(), componentInfoMap1.size()); |
| 188 | EXPECT_EQ(outComponentInfoMap, componentInfoMap1); |
| 189 | |
| 190 | // constexpr uint16_t compCount = 1; |
| 191 | // constexpr std::string_view activeCompImageSetVersion{"DeviceVer2.0"}; |
| 192 | // constexpr std::string_view activeCompVersion1{"Comp3v4.0"}; |
| 193 | constexpr uint16_t compClassification3 = 2; |
| 194 | constexpr uint16_t compIdentifier3 = 302; |
| 195 | constexpr uint8_t compClassificationIndex3 = 40; |
| 196 | |
| 197 | constexpr size_t respPayloadLength2 = 119; |
| 198 | constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength2> |
| 199 | getFirmwareParametersResp2{ |
| 200 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, |
| 201 | 0x0c, 0x00, 0x00, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x56, 0x65, |
| 202 | 0x72, 0x32, 0x2e, 0x30, 0x02, 0x00, 0x2e, 0x01, 0x28, 0x00, 0x00, |
| 203 | 0x00, 0x00, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 204 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 205 | 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, |
| 206 | 0x6f, 0x6d, 0x70, 0x33, 0x76, 0x34, 0x2e, 0x30}; |
| 207 | auto responseMsg2 = |
| 208 | reinterpret_cast<const pldm_msg*>(getFirmwareParametersResp2.data()); |
| 209 | inventoryManager.getFirmwareParameters(2, responseMsg2, respPayloadLength2); |
| 210 | |
| 211 | ComponentInfoMap componentInfoMap2{ |
| 212 | {1, |
| 213 | {{std::make_pair(compClassification1, compIdentifier1), |
| 214 | compClassificationIndex1}, |
| 215 | {std::make_pair(compClassification2, compIdentifier2), |
| 216 | compClassificationIndex2}}}, |
| 217 | {2, |
| 218 | {{std::make_pair(compClassification3, compIdentifier3), |
| 219 | compClassificationIndex3}}}}; |
| 220 | EXPECT_EQ(outComponentInfoMap.size(), componentInfoMap2.size()); |
| 221 | EXPECT_EQ(outComponentInfoMap, componentInfoMap2); |
| 222 | } |
| 223 | |
| 224 | TEST_F(InventoryManagerTest, getFirmwareParametersResponseErrorCC) |
| 225 | { |
| 226 | constexpr size_t respPayloadLength = 1; |
| 227 | constexpr std::array<uint8_t, sizeof(pldm_msg_hdr) + respPayloadLength> |
| 228 | getFirmwareParametersResp{0x00, 0x00, 0x00, 0x01}; |
| 229 | auto responseMsg = |
| 230 | reinterpret_cast<const pldm_msg*>(getFirmwareParametersResp.data()); |
| 231 | inventoryManager.getFirmwareParameters(1, responseMsg, respPayloadLength); |
| 232 | EXPECT_EQ(outComponentInfoMap.size(), 0); |
| 233 | } |