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 | |
| 9 | // Empty directory condition |
| 10 | ASSERT_THROW(FruParser("./fru_json"), std::exception); |
| 11 | // No master FRU JSON |
| 12 | ASSERT_THROW(FruParser("./fru_jsons/malformed1"), std::exception); |
| 13 | // Malformed master FRU JSON |
| 14 | ASSERT_THROW(FruParser("./fru_jsons/malformed2"), std::exception); |
| 15 | // Malformed FRU JSON |
| 16 | ASSERT_THROW(FruParser("./fru_jsons/malformed3"), std::exception); |
| 17 | |
| 18 | FruParser parser{"./fru_jsons/good"}; |
| 19 | |
| 20 | // Get an item with a single PLDM FRU record |
| 21 | FruRecordInfos cpu{{1, |
| 22 | 1, |
| 23 | {{"xyz.openbmc_project.Inventory.Decorator.Asset", |
| 24 | "PartNumber", "string", 3}, |
| 25 | {"xyz.openbmc_project.Inventory.Decorator.Asset", |
| 26 | "SerialNumber", "string", 4}}}}; |
| 27 | auto cpuInfos = |
| 28 | parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.Cpu"); |
| 29 | ASSERT_EQ(cpuInfos.size(), 1); |
| 30 | ASSERT_EQ(cpu == cpuInfos, true); |
| 31 | |
| 32 | // Get an item type with 2 PLDM FRU records |
| 33 | auto boardInfos = |
| 34 | parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.Board"); |
| 35 | ASSERT_EQ(boardInfos.size(), 2); |
| 36 | |
| 37 | // D-Bus lookup info for FRU information |
| 38 | DBusLookupInfo lookupInfo{"xyz.openbmc_project.Inventory.Manager", |
| 39 | "/xyz/openbmc_project/inventory/system/", |
| 40 | {"xyz.openbmc_project.Inventory.Item.Board", |
| 41 | "xyz.openbmc_project.Inventory.Item.Cpu"}}; |
| 42 | |
| 43 | auto dbusInfo = parser.inventoryLookup(); |
| 44 | ASSERT_EQ(dbusInfo == lookupInfo, true); |
| 45 | |
| 46 | // Search for an invalid item type |
| 47 | ASSERT_THROW( |
| 48 | parser.getRecordInfo("xyz.openbmc_project.Inventory.Item.DIMM"), |
| 49 | std::exception); |
| 50 | } |