blob: 6c942da63676c36ca9c0166a4c53671669049e5c [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
Manojkiran Eda03b01ca2021-06-29 08:55:09 +05308 FruParser parser{"./fru_jsons/good",
9 "./fru_jsons/fru_master/fru_master.json"};
Tom Joseph151d5332019-11-17 22:21:45 +053010
11 // Get an item with a single PLDM FRU record
Deepak Kodihallida079602020-08-05 03:23:03 -050012 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}}}};
Tom Joseph151d5332019-11-17 22:21:45 +053034 auto cpuInfos =
35 parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.Cpu");
Deepak Kodihallida079602020-08-05 03:23:03 -050036 ASSERT_EQ(cpuInfos.size(), 2);
Tom Joseph151d5332019-11-17 22:21:45 +053037 ASSERT_EQ(cpu == cpuInfos, true);
38
Deepak Kodihallida079602020-08-05 03:23:03 -050039 // Get an item type with 3 PLDM FRU records
Tom Joseph151d5332019-11-17 22:21:45 +053040 auto boardInfos =
41 parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.Board");
Deepak Kodihallida079602020-08-05 03:23:03 -050042 ASSERT_EQ(boardInfos.size(), 3);
Tom Joseph151d5332019-11-17 22:21:45 +053043
44 // D-Bus lookup info for FRU information
Deepak Kodihallida079602020-08-05 03:23:03 -050045 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",
Jayashankar Padatha137f902021-06-04 07:16:11 -050050 "xyz.openbmc_project.Inventory.Item.PCIeDevice",
Deepak Kodihallida079602020-08-05 03:23:03 -050051 "xyz.openbmc_project.Inventory.Item.Board.Motherboard",
Jayashankar Padatha137f902021-06-04 07:16:11 -050052 "xyz.openbmc_project.Inventory.Item.Dimm",
Deepak Kodihallida079602020-08-05 03:23:03 -050053 "xyz.openbmc_project.Inventory.Item.Panel",
Jayashankar Padatha137f902021-06-04 07:16:11 -050054 "xyz.openbmc_project.Inventory.Item.DiskBackplane",
55 "xyz.openbmc_project.Inventory.Item.Fan",
Deepak Kodihallida079602020-08-05 03:23:03 -050056 "xyz.openbmc_project.Inventory.Item.PowerSupply",
Jayashankar Padatha137f902021-06-04 07:16:11 -050057 "xyz.openbmc_project.Inventory.Item.Battery",
Deepak Kodihallida079602020-08-05 03:23:03 -050058 "xyz.openbmc_project.Inventory.Item.Vrm",
59 "xyz.openbmc_project.Inventory.Item.Cpu",
60 "xyz.openbmc_project.Inventory.Item.Bmc",
Jayashankar Padatha137f902021-06-04 07:16:11 -050061 "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"}};
Tom Joseph151d5332019-11-17 22:21:45 +053065 auto dbusInfo = parser.inventoryLookup();
66 ASSERT_EQ(dbusInfo == lookupInfo, true);
67
Tom Joseph151d5332019-11-17 22:21:45 +053068 ASSERT_THROW(
69 parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.DIMM"),
70 std::exception);
71}