| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 1 | #include "common/test/mocked_utils.hpp" |
| 2 | #include "fw-update/firmware_inventory.hpp" |
| 3 | #include "fw-update/firmware_inventory_manager.hpp" |
| Unive Tien | ee2bd8a | 2025-10-30 08:11:06 +0000 | [diff] [blame^] | 4 | #include "test/test_instance_id.hpp" |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 5 | |
| 6 | #include <gmock/gmock.h> |
| 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | using namespace pldm; |
| 10 | using namespace std::chrono; |
| 11 | using namespace pldm::fw_update; |
| 12 | |
| 13 | // Helper class for testing: inherits FirmwareInventory and exposes protected |
| 14 | class FirmwareInventoryTest : public pldm::fw_update::FirmwareInventory |
| 15 | { |
| 16 | public: |
| 17 | using FirmwareInventory::FirmwareInventory; |
| 18 | |
| 19 | const std::string& getSoftwarePath() const |
| 20 | { |
| 21 | return this->softwarePath; |
| 22 | } |
| 23 | const SoftwareAssociationDefinitions& getAssociation() const |
| 24 | { |
| 25 | return this->association; |
| 26 | } |
| 27 | const SoftwareVersion& getVersion() const |
| 28 | { |
| 29 | return this->version; |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | class FirmwareInventoryManagerTest : public FirmwareInventoryManager |
| 34 | { |
| 35 | public: |
| 36 | FirmwareInventoryManagerTest(const pldm::utils::DBusHandler* handler, |
| Unive Tien | ee2bd8a | 2025-10-30 08:11:06 +0000 | [diff] [blame^] | 37 | const Configurations& config, |
| 38 | AggregateUpdateManager& updateManager) : |
| 39 | FirmwareInventoryManager(handler, config, updateManager) |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 40 | {} |
| 41 | |
| 42 | SoftwareMap& getSoftwareMap() |
| 43 | { |
| 44 | return softwareMap; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | TEST(GetBoardPath_WithMockHandler, ReturnsExpectedBoardPath) |
| 49 | { |
| 50 | MockdBusHandler mockHandler; |
| 51 | InventoryPath inventoryPath = |
| 52 | "/xyz/openbmc_project/inventory/system/board/PLDM_Device"; |
| 53 | pldm::utils::GetAncestorsResponse fakeResponse = {{inventoryPath, {}}}; |
| 54 | EXPECT_CALL(mockHandler, getAncestors) |
| 55 | .WillOnce(::testing::Return(fakeResponse)); |
| 56 | |
| 57 | Configurations configurations; |
| 58 | std::string boardInventoryPath = |
| 59 | "/xyz/openbmc_project/inventory/system/board/PLDM_Device"; |
| 60 | pldm::eid endpointId = 1; |
| 61 | pldm::UUID endpointUuid = "uuid"; |
| 62 | pldm::MctpMedium endpointMedium = "medium"; |
| 63 | pldm::NetworkId endpointNetId = 0; |
| 64 | pldm::MctpInfoName endpointName = "BMC"; |
| 65 | pldm::MctpInfo endpointInfo = std::make_tuple( |
| 66 | endpointId, endpointUuid, endpointMedium, endpointNetId, endpointName); |
| 67 | configurations[boardInventoryPath] = endpointInfo; |
| 68 | |
| Unive Tien | ee2bd8a | 2025-10-30 08:11:06 +0000 | [diff] [blame^] | 69 | Event event(sdeventplus::Event::get_default()); |
| 70 | TestInstanceIdDb instanceIdDb; |
| 71 | requester::Handler<requester::Request> handler( |
| 72 | nullptr, event, instanceIdDb, false, seconds(1), 2, milliseconds(100)); |
| 73 | |
| 74 | DescriptorMap descriptorMap{}; |
| 75 | ComponentInfoMap componentInfoMap{}; |
| 76 | |
| 77 | AggregateUpdateManager updateManager(event, handler, instanceIdDb, |
| 78 | descriptorMap, componentInfoMap); |
| 79 | |
| 80 | FirmwareInventoryManagerTest inventoryManager(&mockHandler, configurations, |
| 81 | updateManager); |
| Unive Tien | 7ad45b4 | 2025-08-18 06:04:53 +0000 | [diff] [blame] | 82 | |
| 83 | SoftwareIdentifier softwareIdentifier{endpointId, 100}; |
| 84 | SoftwareName softwareName{"TestDevice"}; |
| 85 | std::string firmwareVersion{"1.0.0"}; |
| 86 | Descriptors firmwareDescriptors; |
| 87 | ComponentInfo firmwareComponentInfo; |
| 88 | |
| 89 | inventoryManager.createFirmwareEntry( |
| 90 | softwareIdentifier, softwareName, firmwareVersion, firmwareDescriptors, |
| 91 | firmwareComponentInfo); |
| 92 | ASSERT_TRUE(inventoryManager.getSoftwareMap().contains(softwareIdentifier)); |
| 93 | |
| 94 | auto inventoryIt = |
| 95 | inventoryManager.getSoftwareMap().find(softwareIdentifier); |
| 96 | ASSERT_NE(inventoryIt, inventoryManager.getSoftwareMap().end()); |
| 97 | const auto* inventory = |
| 98 | static_cast<FirmwareInventoryTest*>(inventoryIt->second.get()); |
| 99 | ASSERT_NE(inventory, nullptr); |
| 100 | EXPECT_NE(inventory->getSoftwarePath().find( |
| 101 | "/xyz/openbmc_project/software/PLDM_Device_TestDevice_"), |
| 102 | std::string::npos); |
| 103 | EXPECT_EQ(inventory->getVersion().version(), firmwareVersion); |
| 104 | } |