| #include "pcie.hpp" | |
| #include <cstddef> | |
| #include <memory> | |
| #include <string> | |
| #include <utility> | |
| #include <gtest/gtest.h> | |
| #include "absl/log/log.h" | |
| #include "boost/beast/http/status.hpp" // NOLINT | |
| #include "http_response.hpp" | |
| #include "dbus_utility.hpp" | |
| #include "test/redfish-core/lib/snapshot_fixture.hpp" | |
| #include <nlohmann/json.hpp> | |
| #include "managed_store.hpp" | |
| #include "managed_store_types.hpp" | |
| #include "test/g3/mock_managed_store.hpp" | |
| #include "test/g3/mock_managed_store_test.hpp" | |
| #include "sdbusplus/message/native_types.hpp" | |
| namespace redfish { | |
| namespace { | |
| using ::dbus::utility::DBusPropertiesMap; | |
| using ::dbus::utility::DbusVariantType; | |
| using ::dbus::utility::MapperGetSubTreePathsResponse; | |
| using ::dbus::utility::MapperGetSubTreeResponse; | |
| using ::managedStore::KeyType; | |
| using ::managedStore::ValueType; | |
| using ::managedStore::ManagedType::kManagedPropertyMap; | |
| using ::managedStore::ManagedType::kManagedSubtreePaths; | |
| TEST_F(SnapshotFixture_Platform5_Config7, GetPCIeDeviceSuccess) { | |
| handleSystemPCIeDeviceGet(app_, CreateRequest(), share_async_resp_, "system", | |
| "chassis8_1_Link_0"); | |
| RunIoUntilDone(); | |
| LOG(INFO) << share_async_resp_->res.jsonValue.dump(2); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(json["@odata.id"], | |
| "/redfish/v1/Systems/system/PCIeDevices/chassis8_1_Link_0"); | |
| EXPECT_EQ(json["@odata.type"], "#PCIeDevice.v1_4_0.PCIeDevice"); | |
| EXPECT_EQ(json["Id"], "chassis8_1_Link_0"); | |
| EXPECT_EQ(json["Name"], "PCIe Device"); | |
| EXPECT_EQ(json["Manufacturer"], "Manufacturer"); | |
| EXPECT_EQ(json["DeviceType"], "SingleFunction"); | |
| nlohmann::json& functions = json["PCIeFunctions"]; | |
| EXPECT_EQ( | |
| functions["@odata.id"], | |
| "/redfish/v1/Systems/system/PCIeDevices/chassis8_1_Link_0/PCIeFunctions"); | |
| nlohmann::json& interface = json["PCIeInterface"]; | |
| EXPECT_EQ(interface.size(), 2); | |
| EXPECT_EQ(interface["PCIeType"], "Gen5"); | |
| EXPECT_EQ(interface["LanesInUse"], 8); | |
| nlohmann::json& chassis = json["Links"]["Chassis"]; | |
| EXPECT_EQ(chassis.size(), 1); | |
| EXPECT_EQ(chassis["@odata.id"], "/redfish/v1/Chassis/chassis8_1"); | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| } | |
| TEST_F(SnapshotFixture_Platform5_Config7, GetPCIeDeviceZeroLanesInUse) { | |
| KeyType key(kManagedPropertyMap, "xyz.openbmc_project.Hb16Manager", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/pcie/chassis8_1_Link_0"), | |
| "xyz.openbmc_project.Inventory.Item.PCIeDevice"); | |
| ASSERT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore( | |
| key, | |
| managedStore::MockManagedStoreTest::CreateValueType( | |
| DBusPropertiesMap({ | |
| std::make_pair("Manufacturer", | |
| DbusVariantType("Manufacturer")), | |
| std::make_pair("DeviceType", | |
| DbusVariantType("SingleFunction")), | |
| std::make_pair("LanesInUse", | |
| DbusVariantType(static_cast<size_t>(0))), | |
| std::make_pair( | |
| "GenerationInUse", | |
| DbusVariantType("xyz.openbmc_project.Inventory.Item." | |
| "PCIeSlot.Generations.Gen5")), | |
| }))) | |
| .ok()); | |
| handleSystemPCIeDeviceGet(app_, CreateRequest(), share_async_resp_, "system", | |
| "chassis8_1_Link_0"); | |
| RunIoUntilDone(); | |
| LOG(INFO) << share_async_resp_->res.jsonValue.dump(2); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(json, nlohmann::json::parse(R"({ | |
| "@odata.id": "/redfish/v1/Systems/system/PCIeDevices/chassis8_1_Link_0", | |
| "@odata.type": "#PCIeDevice.v1_4_0.PCIeDevice", | |
| "DeviceType": "SingleFunction", | |
| "Id": "chassis8_1_Link_0", | |
| "Links": { | |
| "Chassis": { | |
| "@odata.id": "/redfish/v1/Chassis/chassis8_1" | |
| } | |
| }, | |
| "Manufacturer": "Manufacturer", | |
| "Name": "PCIe Device", | |
| "PCIeFunctions": { | |
| "@odata.id": "/redfish/v1/Systems/system/PCIeDevices/chassis8_1_Link_0/PCIeFunctions" | |
| }, | |
| "PCIeInterface": { | |
| "LanesInUse": 0, | |
| "PCIeType": "Gen5" | |
| } | |
| })")); | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| } | |
| TEST_F(SnapshotFixture_Platform5_Config7, GetPCIeDeviceMaxLanes) { | |
| KeyType key(kManagedPropertyMap, "xyz.openbmc_project.Hb16Manager", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/pcie/chassis8_1_Link_0"), | |
| "xyz.openbmc_project.Inventory.Item.PCIeDevice"); | |
| ASSERT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore( | |
| key, | |
| managedStore::MockManagedStoreTest::CreateValueType( | |
| DBusPropertiesMap({ | |
| std::make_pair("Manufacturer", | |
| DbusVariantType("Manufacturer")), | |
| std::make_pair("DeviceType", | |
| DbusVariantType("SingleFunction")), | |
| std::make_pair("LanesInUse", | |
| DbusVariantType(static_cast<size_t>(8))), | |
| std::make_pair("MaxLanes", | |
| DbusVariantType(static_cast<size_t>(16))), | |
| std::make_pair( | |
| "GenerationInUse", | |
| DbusVariantType("xyz.openbmc_project.Inventory.Item." | |
| "PCIeSlot.Generations.Gen5")), | |
| }))) | |
| .ok()); | |
| handleSystemPCIeDeviceGet(app_, CreateRequest(), share_async_resp_, "system", | |
| "chassis8_1_Link_0"); | |
| RunIoUntilDone(); | |
| LOG(INFO) << share_async_resp_->res.jsonValue.dump(2); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(json, nlohmann::json::parse(R"({ | |
| "@odata.id": "/redfish/v1/Systems/system/PCIeDevices/chassis8_1_Link_0", | |
| "@odata.type": "#PCIeDevice.v1_4_0.PCIeDevice", | |
| "DeviceType": "SingleFunction", | |
| "Id": "chassis8_1_Link_0", | |
| "Links": { | |
| "Chassis": { | |
| "@odata.id": "/redfish/v1/Chassis/chassis8_1" | |
| } | |
| }, | |
| "Manufacturer": "Manufacturer", | |
| "Name": "PCIe Device", | |
| "PCIeFunctions": { | |
| "@odata.id": "/redfish/v1/Systems/system/PCIeDevices/chassis8_1_Link_0/PCIeFunctions" | |
| }, | |
| "PCIeInterface": { | |
| "LanesInUse": 8, | |
| "MaxLanes": 16, | |
| "PCIeType": "Gen5" | |
| } | |
| })")); | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| } | |
| TEST_F(SnapshotFixture_Platform5_Config7, GetPCIeDeviceMissing) { | |
| handleSystemPCIeDeviceGet(app_, CreateRequest(), share_async_resp_, "system", | |
| "missing"); | |
| RunIoUntilDone(); | |
| LOG(INFO) << share_async_resp_->res.jsonValue.dump(2); | |
| EXPECT_EQ(share_async_resp_->res.result(), | |
| boost::beast::http::status::not_found); | |
| } | |
| TEST_F(SnapshotFixture_Platform5_Config7, GetPCIeDeviceWrongSystem) { | |
| handleSystemPCIeDeviceGet(app_, CreateRequest(), share_async_resp_, "asdf", | |
| "chassis8_1_Link_0"); | |
| RunIoUntilDone(); | |
| LOG(INFO) << share_async_resp_->res.jsonValue.dump(2); | |
| EXPECT_EQ(share_async_resp_->res.result(), | |
| boost::beast::http::status::not_found); | |
| } | |
| TEST_F(SnapshotFixture_Platform5_Config7, getPCIeFunctionCollectionAvailable) { | |
| handleSystemPCIeFunctionCollectionGet( | |
| app_, CreateRequest(), share_async_resp_, "system", "chassis8_1_Link_0"); | |
| RunIoUntilDone(); | |
| LOG(INFO) << share_async_resp_->res.jsonValue.dump(2); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ( | |
| json["@odata.id"], | |
| "/redfish/v1/Systems/system/PCIeDevices/chassis8_1_Link_0/PCIeFunctions"); | |
| EXPECT_EQ(json["@odata.type"], | |
| "#PCIeFunctionCollection.PCIeFunctionCollection"); | |
| EXPECT_EQ(json["Name"], "PCIe Function Collection"); | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| } | |
| TEST_F(SnapshotFixture_Platform5_Config7, getPCIeFunctionGet) { | |
| KeyType key(kManagedPropertyMap, "xyz.openbmc_project.Hb16Manager", | |
| sdbusplus::message::object_path( | |
| "/xyz/openbmc_project/inventory/pcie/chassis8_1_Link_0"), | |
| "xyz.openbmc_project.Inventory.Item.PCIeDevice"); | |
| ASSERT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore( | |
| key, managedStore::MockManagedStoreTest::CreateValueType( | |
| DBusPropertiesMap({std::make_pair( | |
| "Function1DeviceId", DbusVariantType("OK"))}))) | |
| .ok()); | |
| handleSystemPCIeFunctionGet(app_, CreateRequest(), share_async_resp_, | |
| "system", "chassis8_1_Link_0", "1"); | |
| RunIoUntilDone(); | |
| LOG(INFO) << share_async_resp_->res.jsonValue.dump(2); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(json["@odata.id"], | |
| "/redfish/v1/Systems/system/PCIeDevices/chassis8_1_Link_0/" | |
| "PCIeFunctions/1"); | |
| EXPECT_EQ(json["@odata.type"], "#PCIeFunction.v1_2_0.PCIeFunction"); | |
| EXPECT_EQ(json["Name"], "PCIe Function"); | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| } | |
| MapperGetSubTreePathsResponse CreateMockSystemSubTree() { | |
| return MapperGetSubTreePathsResponse( | |
| {"/xyz/openbmc_project/inventory/system/board/platform5/system1", | |
| "/xyz/openbmc_project/inventory/system/board/platform5/system2"}); | |
| } | |
| TEST_F(SnapshotFixture_Platform5_Config7, GetMultiHostsPCIeDeviceSuccess) { | |
| std::string systemName = "system1"; | |
| KeyType key1(kManagedSubtreePaths, "/", 0, | |
| {"xyz.openbmc_project.Inventory.Item.System"}); | |
| std::shared_ptr<ValueType> mockSystemSubTreeResponse = | |
| managedStore::MockManagedStoreTest::CreateValueType( | |
| CreateMockSystemSubTree()); | |
| ASSERT_TRUE( | |
| dynamic_cast<managedStore::MockSerializedManagedObjectStore*>( | |
| managedStore::GetManagedObjectStore()) | |
| ->upsertMockObjectIntoManagedStore(key1, mockSystemSubTreeResponse) | |
| .ok()); | |
| handlePCIeDeviceCollectionGet(app_, CreateRequest(), share_async_resp_, | |
| systemName); | |
| RunIoUntilDone(); | |
| LOG(INFO) << share_async_resp_->res.jsonValue.dump(2); | |
| EXPECT_EQ(share_async_resp_->res.result(), boost::beast::http::status::ok); | |
| nlohmann::json& json = share_async_resp_->res.jsonValue; | |
| EXPECT_EQ(json["@odata.id"], "/redfish/v1/Systems/system1/PCIeDevices"); | |
| EXPECT_EQ(json["@odata.type"], "#PCIeDeviceCollection.PCIeDeviceCollection"); | |
| EXPECT_EQ(json["Name"], "PCIe Device Collection"); | |
| } | |
| } // namespace | |
| } // namespace redfish |