Support uint64_t Bus and Address properties for RawEeproms. On 64-bit platforms, FruDevice registers Bus and Address properties as uint64_t (size_t) rather than uint32_t. Support unpacking both uint32_t and uint64_t variant types in handleRawEepromMemberGet to prevent property lookup failures. Google-Bug-Id:558424309 PiperOrigin-RevId: 978007124 Change-Id: I87099153f31555e55f72be67eede828eed3657e7
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp index ff0471d..7b8abc8 100644 --- a/redfish-core/lib/managers.hpp +++ b/redfish-core/lib/managers.hpp
@@ -2748,12 +2748,20 @@ if (b != nullptr) { bus = *b; hasBus = true; + } else if (const uint64_t* b64 = + std::get_if<uint64_t>(&value)) { + bus = static_cast<uint32_t>(*b64); + hasBus = true; } } else if (propertyName == "Address") { const uint32_t* a = std::get_if<uint32_t>(&value); if (a != nullptr) { address = *a; hasAddress = true; + } else if (const uint64_t* a64 = + std::get_if<uint64_t>(&value)) { + address = static_cast<uint32_t>(*a64); + hasAddress = true; } } }
diff --git a/test/redfish-core/lib/manager_test.cpp b/test/redfish-core/lib/manager_test.cpp index f382ae1..368dcff 100644 --- a/test/redfish-core/lib/manager_test.cpp +++ b/test/redfish-core/lib/manager_test.cpp
@@ -659,6 +659,84 @@ EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); } +// Tests handleRawEepromMemberGet on 64-bit platforms (e.g., aarch64), +// where FruDevice registers Bus and Address properties as uint64_t (size_t) +// rather than uint32_t. +TEST_F(SnapshotFixture, handleRawEepromMemberGetUint64) { + std::string rawId = "Eeprom1"; + KeyType rawObjKey( + ManagedType::kManagedMapperObject, + "/xyz/openbmc_project/FruDevice/" + rawId, + std::vector<std::string>{ + "xyz.openbmc_project.Inventory.Item.I2CDevice"}); + dbus::utility::MapperGetObject rawObjVal = { + {"xyz.openbmc_project.FruDevice", + {"xyz.openbmc_project.Inventory.Item.I2CDevice"}}}; + ASSERT_TRUE( + dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( + managedStore::GetManagedObjectStore()) + ->upsertMockObjectIntoManagedStore( + rawObjKey, + managedStore::MockManagedStoreTest::CreateValueType(rawObjVal)) + .ok()); + + KeyType key(ManagedType::kManagedPropertyMap, "xyz.openbmc_project.FruDevice", + "/xyz/openbmc_project/FruDevice/" + rawId, + "xyz.openbmc_project.Inventory.Item.I2CDevice"); + + DBusPropertiesMap props = { + {std::make_pair("Bus", DbusVariantType(static_cast<uint64_t>(2)))}, + {std::make_pair("Address", DbusVariantType(static_cast<uint64_t>(81)))}, + }; + + ASSERT_TRUE( + dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( + managedStore::GetManagedObjectStore()) + ->upsertMockObjectIntoManagedStore( + key, managedStore::MockManagedStoreTest::CreateValueType(props)) + .ok()); + + EXPECT_CALL( + *dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( + managedStore::GetManagedObjectStore()), + PostDbusCallToIoContextThreadSafe( + testing::_, + testing::An< + absl::AnyInvocable<void(const boost::system::error_code&, + const std::vector<uint8_t>&)>&&>(), + "xyz.openbmc_project.FruDevice", "/xyz/openbmc_project/FruDevice", + "xyz.openbmc_project.FruDeviceManager", "GetRawFru", + testing::Eq(static_cast<uint16_t>(2)), + testing::Eq(static_cast<uint8_t>(81)))) + .WillOnce( + managedStore:: + SimulateSuccessfulAsyncPostDbusCallThreadSafeWithValueAction< + std::vector<uint8_t>>:: + SimulateSuccessfulAsyncPostDbusCallWithValue( + std::make_shared<std::vector<uint8_t>>( + std::vector<uint8_t>{1, 2, 3}))); + + handleRawEepromMemberGet(app_, CreateRequest(), share_async_resp_, rawId); + + RunIoUntilDone(); + + nlohmann::json& json = share_async_resp_->res.jsonValue; + EXPECT_EQ(json, nlohmann::json::parse(R"({ + "@odata.id": "/redfish/v1/Managers/bmc/Oem/Google/FruDevice/RawEeproms/Eeprom1", + "@odata.type": "#GoogleFruDevice.v1_0_0.RawEeprom", + "Id": "Eeprom1", + "Name": "Google Raw EEPROM", + "Bus": 2, + "Address": 81, + "Status": { + "State": "Enabled" + }, + "RawData": [1, 2, 3], + "HexdumpFormattedRawData": "0000: 01 02 03 | ... |\n" + })")); + EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); +} + TEST_F(SnapshotFixture, handleRawEepromMemberGetZeroLength) { std::string rawId = "Eeprom1"; KeyType key(ManagedType::kManagedPropertyMap, "xyz.openbmc_project.FruDevice",