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