blob: 7b1b470d5d415adcc090a94f54a5892a4ab09f39 [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",
49 "xyz.openbmc_project.Inventory.Item.Board.Motherboard",
50 "xyz.openbmc_project.Inventory.Item.Panel",
51 "xyz.openbmc_project.Inventory.Item.PowerSupply",
52 "xyz.openbmc_project.Inventory.Item.Vrm",
53 "xyz.openbmc_project.Inventory.Item.Cpu",
54 "xyz.openbmc_project.Inventory.Item.Bmc",
55 "xyz.openbmc_project.Inventory.Item.Dimm",
56 "xyz.openbmc_project.Inventory.Item.Tpm",
57 "xyz.openbmc_project.Inventory.Item.System"}};
Tom Joseph151d5332019-11-17 22:21:45 +053058 auto dbusInfo = parser.inventoryLookup();
59 ASSERT_EQ(dbusInfo == lookupInfo, true);
60
Tom Joseph151d5332019-11-17 22:21:45 +053061 ASSERT_THROW(
62 parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.DIMM"),
63 std::exception);
64}