Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 1 | #include "libpldmresponder/fru_parser.hpp" |
| 2 | |
| 3 | #include <gtest/gtest.h> |
Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 4 | TEST(FruParser, allScenarios) |
| 5 | { |
| 6 | using namespace pldm::responder::fru_parser; |
| 7 | |
Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 8 | FruParser parser{"./fru_jsons/good"}; |
| 9 | |
| 10 | // Get an item with a single PLDM FRU record |
Deepak Kodihalli | da07960 | 2020-08-05 03:23:03 -0500 | [diff] [blame] | 11 | FruRecordInfos cpu{ |
| 12 | {1, |
| 13 | 1, |
| 14 | {{"xyz.openbmc_project.Inventory.Decorator.Asset", "Model", "string", |
| 15 | 2}, |
| 16 | {"xyz.openbmc_project.Inventory.Decorator.Asset", "PartNumber", |
| 17 | "string", 3}, |
| 18 | {"xyz.openbmc_project.Inventory.Decorator.Asset", "SerialNumber", |
| 19 | "string", 4}, |
| 20 | {"xyz.openbmc_project.Inventory.Decorator.Asset", "Manufacturer", |
| 21 | "string", 5}, |
| 22 | {"xyz.openbmc_project.Inventory.Item", "PrettyName", "string", 8}, |
| 23 | {"xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag", |
| 24 | "string", 11}, |
| 25 | {"xyz.openbmc_project.Inventory.Decorator.Revision", "Version", |
| 26 | "string", 10}}}, |
| 27 | {1, |
| 28 | 1, |
| 29 | {{"xyz.openbmc_project.Inventory.Decorator.Asset", "PartNumber", |
| 30 | "string", 3}, |
| 31 | {"xyz.openbmc_project.Inventory.Decorator.Asset", "SerialNumber", |
| 32 | "string", 4}}}}; |
Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 33 | auto cpuInfos = |
| 34 | parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.Cpu"); |
Deepak Kodihalli | da07960 | 2020-08-05 03:23:03 -0500 | [diff] [blame] | 35 | ASSERT_EQ(cpuInfos.size(), 2); |
Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 36 | ASSERT_EQ(cpu == cpuInfos, true); |
| 37 | |
Deepak Kodihalli | da07960 | 2020-08-05 03:23:03 -0500 | [diff] [blame] | 38 | // Get an item type with 3 PLDM FRU records |
Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 39 | auto boardInfos = |
| 40 | parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.Board"); |
Deepak Kodihalli | da07960 | 2020-08-05 03:23:03 -0500 | [diff] [blame] | 41 | ASSERT_EQ(boardInfos.size(), 3); |
Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 42 | |
| 43 | // D-Bus lookup info for FRU information |
Deepak Kodihalli | da07960 | 2020-08-05 03:23:03 -0500 | [diff] [blame] | 44 | DBusLookupInfo lookupInfo{ |
| 45 | "xyz.openbmc_project.Inventory.Manager", |
| 46 | "/xyz/openbmc_project/inventory", |
| 47 | {"xyz.openbmc_project.Inventory.Item.Chassis", |
| 48 | "xyz.openbmc_project.Inventory.Item.Board", |
Jayashankar Padath | a137f90 | 2021-06-04 07:16:11 -0500 | [diff] [blame] | 49 | "xyz.openbmc_project.Inventory.Item.PCIeDevice", |
Deepak Kodihalli | da07960 | 2020-08-05 03:23:03 -0500 | [diff] [blame] | 50 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard", |
Jayashankar Padath | a137f90 | 2021-06-04 07:16:11 -0500 | [diff] [blame] | 51 | "xyz.openbmc_project.Inventory.Item.Dimm", |
Deepak Kodihalli | da07960 | 2020-08-05 03:23:03 -0500 | [diff] [blame] | 52 | "xyz.openbmc_project.Inventory.Item.Panel", |
Jayashankar Padath | a137f90 | 2021-06-04 07:16:11 -0500 | [diff] [blame] | 53 | "xyz.openbmc_project.Inventory.Item.DiskBackplane", |
| 54 | "xyz.openbmc_project.Inventory.Item.Fan", |
Deepak Kodihalli | da07960 | 2020-08-05 03:23:03 -0500 | [diff] [blame] | 55 | "xyz.openbmc_project.Inventory.Item.PowerSupply", |
Jayashankar Padath | a137f90 | 2021-06-04 07:16:11 -0500 | [diff] [blame] | 56 | "xyz.openbmc_project.Inventory.Item.Battery", |
Deepak Kodihalli | da07960 | 2020-08-05 03:23:03 -0500 | [diff] [blame] | 57 | "xyz.openbmc_project.Inventory.Item.Vrm", |
| 58 | "xyz.openbmc_project.Inventory.Item.Cpu", |
| 59 | "xyz.openbmc_project.Inventory.Item.Bmc", |
Jayashankar Padath | a137f90 | 2021-06-04 07:16:11 -0500 | [diff] [blame] | 60 | "xyz.openbmc_project.Inventory.Item.Connector", |
| 61 | "xyz.openbmc_project.Inventory.Item.PCIeSlot", |
| 62 | "xyz.openbmc_project.Inventory.Item.System", |
| 63 | "xyz.openbmc_project.Inventory.Item.Tpm"}}; |
Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 64 | auto dbusInfo = parser.inventoryLookup(); |
| 65 | ASSERT_EQ(dbusInfo == lookupInfo, true); |
| 66 | |
Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 67 | ASSERT_THROW( |
| 68 | parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.DIMM"), |
| 69 | std::exception); |
| 70 | } |