Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 1 | #include "libpldmresponder/fru_parser.hpp" |
| 2 | |
| 3 | #include <gtest/gtest.h> |
| 4 | |
| 5 | TEST(FruParser, allScenarios) |
| 6 | { |
| 7 | using namespace pldm::responder::fru_parser; |
| 8 | |
Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 9 | // No master FRU JSON |
| 10 | ASSERT_THROW(FruParser("./fru_jsons/malformed1"), std::exception); |
| 11 | // Malformed master FRU JSON |
| 12 | ASSERT_THROW(FruParser("./fru_jsons/malformed2"), std::exception); |
| 13 | // Malformed FRU JSON |
| 14 | ASSERT_THROW(FruParser("./fru_jsons/malformed3"), std::exception); |
| 15 | |
| 16 | FruParser parser{"./fru_jsons/good"}; |
| 17 | |
| 18 | // Get an item with a single PLDM FRU record |
| 19 | FruRecordInfos cpu{{1, |
| 20 | 1, |
| 21 | {{"xyz.openbmc_project.Inventory.Decorator.Asset", |
| 22 | "PartNumber", "string", 3}, |
| 23 | {"xyz.openbmc_project.Inventory.Decorator.Asset", |
| 24 | "SerialNumber", "string", 4}}}}; |
| 25 | auto cpuInfos = |
| 26 | parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.Cpu"); |
| 27 | ASSERT_EQ(cpuInfos.size(), 1); |
| 28 | ASSERT_EQ(cpu == cpuInfos, true); |
| 29 | |
| 30 | // Get an item type with 2 PLDM FRU records |
| 31 | auto boardInfos = |
| 32 | parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.Board"); |
| 33 | ASSERT_EQ(boardInfos.size(), 2); |
| 34 | |
| 35 | // D-Bus lookup info for FRU information |
| 36 | DBusLookupInfo lookupInfo{"xyz.openbmc_project.Inventory.Manager", |
| 37 | "/xyz/openbmc_project/inventory/system/", |
| 38 | {"xyz.openbmc_project.Inventory.Item.Board", |
| 39 | "xyz.openbmc_project.Inventory.Item.Cpu"}}; |
| 40 | |
| 41 | auto dbusInfo = parser.inventoryLookup(); |
| 42 | ASSERT_EQ(dbusInfo == lookupInfo, true); |
| 43 | |
| 44 | // Search for an invalid item type |
| 45 | ASSERT_THROW( |
| 46 | parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.DIMM"), |
| 47 | std::exception); |
| 48 | } |