blob: 8219d755e59838670ae8283db687f2a8a2d54dc8 [file] [log] [blame]
Tom Joseph151d5332019-11-17 22:21:45 +05301#include "libpldmresponder/fru_parser.hpp"
2
3#include <gtest/gtest.h>
Tom Joseph151d5332019-11-17 22:21:45 +05304TEST(FruParser, allScenarios)
5{
6 using namespace pldm::responder::fru_parser;
7
Tom Joseph151d5332019-11-17 22:21:45 +05308 FruParser parser{"./fru_jsons/good"};
9
10 // Get an item with a single PLDM FRU record
Deepak Kodihallida079602020-08-05 03:23:03 -050011 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 Joseph151d5332019-11-17 22:21:45 +053033 auto cpuInfos =
34 parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.Cpu");
Deepak Kodihallida079602020-08-05 03:23:03 -050035 ASSERT_EQ(cpuInfos.size(), 2);
Tom Joseph151d5332019-11-17 22:21:45 +053036 ASSERT_EQ(cpu == cpuInfos, true);
37
Deepak Kodihallida079602020-08-05 03:23:03 -050038 // Get an item type with 3 PLDM FRU records
Tom Joseph151d5332019-11-17 22:21:45 +053039 auto boardInfos =
40 parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.Board");
Deepak Kodihallida079602020-08-05 03:23:03 -050041 ASSERT_EQ(boardInfos.size(), 3);
Tom Joseph151d5332019-11-17 22:21:45 +053042
43 // D-Bus lookup info for FRU information
Deepak Kodihallida079602020-08-05 03:23:03 -050044 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 Padatha137f902021-06-04 07:16:11 -050049 "xyz.openbmc_project.Inventory.Item.PCIeDevice",
Deepak Kodihallida079602020-08-05 03:23:03 -050050 "xyz.openbmc_project.Inventory.Item.Board.Motherboard",
Jayashankar Padatha137f902021-06-04 07:16:11 -050051 "xyz.openbmc_project.Inventory.Item.Dimm",
Deepak Kodihallida079602020-08-05 03:23:03 -050052 "xyz.openbmc_project.Inventory.Item.Panel",
Jayashankar Padatha137f902021-06-04 07:16:11 -050053 "xyz.openbmc_project.Inventory.Item.DiskBackplane",
54 "xyz.openbmc_project.Inventory.Item.Fan",
Deepak Kodihallida079602020-08-05 03:23:03 -050055 "xyz.openbmc_project.Inventory.Item.PowerSupply",
Jayashankar Padatha137f902021-06-04 07:16:11 -050056 "xyz.openbmc_project.Inventory.Item.Battery",
Deepak Kodihallida079602020-08-05 03:23:03 -050057 "xyz.openbmc_project.Inventory.Item.Vrm",
58 "xyz.openbmc_project.Inventory.Item.Cpu",
59 "xyz.openbmc_project.Inventory.Item.Bmc",
Jayashankar Padatha137f902021-06-04 07:16:11 -050060 "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 Joseph151d5332019-11-17 22:21:45 +053064 auto dbusInfo = parser.inventoryLookup();
65 ASSERT_EQ(dbusInfo == lookupInfo, true);
66
Tom Joseph151d5332019-11-17 22:21:45 +053067 ASSERT_THROW(
68 parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.DIMM"),
69 std::exception);
70}