blob: c7effaaf44f615e1e41a7e041bb5ea57ea6dd2b7 [file] [log] [blame]
Unive Tien7ad45b42025-08-18 06:04:53 +00001#include "common/test/mocked_utils.hpp"
2#include "fw-update/firmware_inventory.hpp"
3#include "fw-update/firmware_inventory_manager.hpp"
Unive Tienee2bd8a2025-10-30 08:11:06 +00004#include "test/test_instance_id.hpp"
Unive Tien7ad45b42025-08-18 06:04:53 +00005
6#include <gmock/gmock.h>
7#include <gtest/gtest.h>
8
9using namespace pldm;
10using namespace std::chrono;
11using namespace pldm::fw_update;
12
13// Helper class for testing: inherits FirmwareInventory and exposes protected
14class 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
33class FirmwareInventoryManagerTest : public FirmwareInventoryManager
34{
35 public:
36 FirmwareInventoryManagerTest(const pldm::utils::DBusHandler* handler,
Unive Tienee2bd8a2025-10-30 08:11:06 +000037 const Configurations& config,
38 AggregateUpdateManager& updateManager) :
39 FirmwareInventoryManager(handler, config, updateManager)
Unive Tien7ad45b42025-08-18 06:04:53 +000040 {}
41
42 SoftwareMap& getSoftwareMap()
43 {
44 return softwareMap;
45 }
46};
47
48TEST(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 Tienee2bd8a2025-10-30 08:11:06 +000069 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 Tien7ad45b42025-08-18 06:04:53 +000082
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}