convert resolution_test.cpp to use pdbg library

Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: Ibdaa0cf34dd45c75e95ef334793d2adfe41b1f85
diff --git a/test/resolution_test.cpp b/test/resolution_test.cpp
index 4063bcb..8e43138 100644
--- a/test/resolution_test.cpp
+++ b/test/resolution_test.cpp
@@ -2,6 +2,7 @@
 
 #include <analyzer/analyzer_main.hpp>
 #include <analyzer/resolution.hpp>
+#include <util/pdbg.hpp>
 #include <util/trace.hpp>
 
 #include <regex>
@@ -18,255 +19,12 @@
 constexpr auto ocmb_str   = "pib/perv12/mc0/mi0/mcc0/omi0/ocmb0";
 constexpr auto core_str   = "pib/perv39/eq7/fc1/core1";
 
-// Local implementation of this function.
-namespace analyzer
-{
-
-//------------------------------------------------------------------------------
-
-// Helper function to get the root cause chip target path from the service data.
-std::string __getRootCauseChipPath(const ServiceData& i_sd)
-{
-    return std::string{(const char*)i_sd.getRootCause().getChip().getChip()};
-}
-
-//------------------------------------------------------------------------------
-
-// Helper function to get a unit target path from the given unit path, which is
-// a devtree path relative the the containing chip. An empty string indicates
-// the chip target path should be returned.
-std::string __getUnitPath(const std::string& i_chipPath,
-                          const std::string& i_unitPath)
-{
-    auto path = i_chipPath; // default, if i_unitPath is empty
-
-    if (!i_unitPath.empty())
-    {
-        path += "/" + i_unitPath;
-    }
-
-    return path;
-}
-
-//------------------------------------------------------------------------------
-
-// Helper function to get the connected target Path on the other side of the
-// given bus.
-std::tuple<std::string, std::string>
-    __getConnectedPath(const std::string& i_rxPath,
-                       const callout::BusType& i_busType)
-{
-    std::string txUnitPath{};
-    std::string txChipPath{};
-
-    // Need to get the target type from the RX path.
-    const std::regex re{"(/proc0)(.*)/([a-z]+)([0-9]+)"};
-    std::smatch match;
-    std::regex_match(i_rxPath, match, re);
-    assert(5 == match.size());
-    std::string rxType = match[3].str();
-
-    if (callout::BusType::SMP_BUS == i_busType && "smpgroup" == rxType)
-    {
-        // Use the RX unit path on a different processor.
-        txUnitPath = "/proc1" + match[2].str() + "/" + rxType + match[4].str();
-        txChipPath = "/proc1";
-    }
-    else if (callout::BusType::OMI_BUS == i_busType && "omi" == rxType)
-    {
-        // Append the OCMB to the RX path.
-        txUnitPath = i_rxPath + "/ocmb0";
-        txChipPath = txUnitPath;
-    }
-    else if (callout::BusType::OMI_BUS == i_busType && "ocmb" == rxType)
-    {
-        // Strip the OCMB off of the RX path.
-        txUnitPath = match[1].str() + match[2].str();
-        txChipPath = "/proc0";
-    }
-    else
-    {
-        // This would be a code bug.
-        throw std::logic_error("Unsupported config: i_rxTarget=" + i_rxPath +
-                               " i_busType=" + i_busType.getString());
-    }
-
-    assert(!txUnitPath.empty()); // just in case we missed something above
-
-    return std::make_tuple(txUnitPath, txChipPath);
-}
-
-//------------------------------------------------------------------------------
-
-void __calloutTarget(ServiceData& io_sd, const std::string& i_locCode,
-                     const callout::Priority& i_priority, bool i_guard,
-                     const std::string& i_guardPath)
-{
-    nlohmann::json callout;
-    callout["LocationCode"] = i_locCode;
-    callout["Priority"]     = i_priority.getUserDataString();
-    callout["Deconfigured"] = false;
-    callout["Guarded"]      = false; // default
-
-    // Check if guard info should be added.
-    if (i_guard)
-    {
-        auto guardType = io_sd.queryGuardPolicy();
-
-        if (!(callout::GuardType::NONE == guardType))
-        {
-            callout["Guarded"]    = true;
-            callout["Guard Path"] = i_guardPath;
-            callout["Guard Type"] = guardType.getString();
-        }
-    }
-
-    io_sd.addCallout(callout);
-}
-
-//------------------------------------------------------------------------------
-
-void __calloutBackplane(ServiceData& io_sd, const callout::Priority& i_priority)
-{
-    // TODO: There isn't a device tree object for this. So will need to hardcode
-    //       the location code for now. In the future, we will need a mechanism
-    //       to make this data driven.
-
-    nlohmann::json callout;
-    callout["LocationCode"] = "P0";
-    callout["Priority"]     = i_priority.getUserDataString();
-    callout["Deconfigured"] = false;
-    callout["Guarded"]      = false;
-    io_sd.addCallout(callout);
-}
-
-//------------------------------------------------------------------------------
-
-void HardwareCalloutResolution::resolve(ServiceData& io_sd) const
-{
-    // Get the location code and entity path for this target.
-    auto locCode    = __getRootCauseChipPath(io_sd);
-    auto entityPath = __getUnitPath(locCode, iv_unitPath);
-
-    // Add the actual callout to the service data.
-    __calloutTarget(io_sd, locCode, iv_priority, iv_guard, entityPath);
-
-    // Add the callout FFDC to the service data.
-    nlohmann::json ffdc;
-    ffdc["Callout Type"] = "Hardware Callout";
-    ffdc["Target"]       = entityPath;
-    ffdc["Priority"]     = iv_priority.getRegistryString();
-    ffdc["Guard"]        = iv_guard;
-    io_sd.addCalloutFFDC(ffdc);
-}
-
-//------------------------------------------------------------------------------
-
-void ConnectedCalloutResolution::resolve(ServiceData& io_sd) const
-{
-    // Get the chip target path from the root cause signature.
-    auto chipPath = __getRootCauseChipPath(io_sd);
-
-    // Get the endpoint target path for the receiving side of the bus.
-    auto rxPath = __getUnitPath(chipPath, iv_unitPath);
-
-    // Get the endpoint target path for the transfer side of the bus.
-    auto txPath = __getConnectedPath(rxPath, iv_busType);
-
-    // Callout the TX endpoint.
-    __calloutTarget(io_sd, std::get<1>(txPath), iv_priority, iv_guard,
-                    std::get<0>(txPath));
-
-    // Add the callout FFDC to the service data.
-    nlohmann::json ffdc;
-    ffdc["Callout Type"] = "Connected Callout";
-    ffdc["Bus Type"]     = iv_busType.getString();
-    ffdc["Target"]       = std::get<0>(txPath);
-    ffdc["Priority"]     = iv_priority.getRegistryString();
-    ffdc["Guard"]        = iv_guard;
-    io_sd.addCalloutFFDC(ffdc);
-}
-
-//------------------------------------------------------------------------------
-
-void BusCalloutResolution::resolve(ServiceData& io_sd) const
-{
-    // Get the chip target path from the root cause signature.
-    auto chipPath = __getRootCauseChipPath(io_sd);
-
-    // Get the endpoint target path for the receiving side of the bus.
-    auto rxPath = __getUnitPath(chipPath, iv_unitPath);
-
-    // Get the endpoint target path for the transfer side of the bus.
-    auto txPath = __getConnectedPath(rxPath, iv_busType);
-
-    // Callout the RX endpoint.
-    __calloutTarget(io_sd, chipPath, iv_priority, iv_guard, rxPath);
-
-    // Callout the TX endpoint.
-    __calloutTarget(io_sd, std::get<1>(txPath), iv_priority, iv_guard,
-                    std::get<0>(txPath));
-
-    // Callout everything else in between.
-    // TODO: For P10 (OMI bus and XBUS), the callout is simply the backplane.
-    __calloutBackplane(io_sd, iv_priority);
-
-    // Add the callout FFDC to the service data.
-    nlohmann::json ffdc;
-    ffdc["Callout Type"] = "Bus Callout";
-    ffdc["Bus Type"]     = iv_busType.getString();
-    ffdc["RX Target"]    = rxPath;
-    ffdc["TX Target"]    = std::get<0>(txPath);
-    ffdc["Priority"]     = iv_priority.getRegistryString();
-    ffdc["Guard"]        = iv_guard;
-    io_sd.addCalloutFFDC(ffdc);
-}
-
-//------------------------------------------------------------------------------
-
-void ProcedureCalloutResolution::resolve(ServiceData& io_sd) const
-{
-    // Add the actual callout to the service data.
-    nlohmann::json callout;
-    callout["Procedure"] = iv_procedure.getString();
-    callout["Priority"]  = iv_priority.getUserDataString();
-    io_sd.addCallout(callout);
-
-    // Add the callout FFDC to the service data.
-    nlohmann::json ffdc;
-    ffdc["Callout Type"] = "Procedure Callout";
-    ffdc["Procedure"]    = iv_procedure.getString();
-    ffdc["Priority"]     = iv_priority.getRegistryString();
-    io_sd.addCalloutFFDC(ffdc);
-}
-
-//------------------------------------------------------------------------------
-
-void ClockCalloutResolution::resolve(ServiceData& io_sd) const
-{
-    // Callout the clock target.
-    // TODO: For P10, the callout is simply the backplane. Also, there are no
-    //       clock targets in the device tree. So at the moment there is no
-    //       guard support for clock targets.
-    __calloutBackplane(io_sd, iv_priority);
-
-    // Add the callout FFDC to the service data.
-    // TODO: Add the target and guard type if guard is ever supported.
-    nlohmann::json ffdc;
-    ffdc["Callout Type"] = "Clock Callout";
-    ffdc["Clock Type"]   = iv_clockType.getString();
-    ffdc["Priority"]     = iv_priority.getRegistryString();
-    io_sd.addCalloutFFDC(ffdc);
-}
-
-//------------------------------------------------------------------------------
-
-} // namespace analyzer
-
 using namespace analyzer;
 
 TEST(Resolution, TestSet1)
 {
+    pdbg_targets_init(nullptr);
+
     // Create a few resolutions
     auto c1 = std::make_shared<HardwareCalloutResolution>(
         proc_str, callout::Priority::HIGH, false);
@@ -296,7 +54,7 @@
     l2->push(l1);
 
     // Get some ServiceData objects
-    libhei::Chip chip{chip_str, 0xdeadbeef};
+    libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
     libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
     ServiceData sd1{sig, AnalysisType::SYSTEM_CHECKSTOP};
     ServiceData sd2{sig, AnalysisType::TERMINATE_IMMEDIATE};
@@ -319,6 +77,14 @@
     },
     {
         "Deconfigured": false,
+        "EntityPath": [],
+        "GuardType": "GARD_Unrecoverable",
+        "Guarded": true,
+        "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
+        "Priority": "A"
+    },
+    {
+        "Deconfigured": false,
         "Guarded": false,
         "LocationCode": "P0",
         "Priority": "L"
@@ -334,14 +100,28 @@
     },
     {
         "Deconfigured": false,
-        "Guard Path": "/proc0/pib/perv39/eq7/fc1/core1",
-        "Guard Type": "GARD_Predictive",
+        "EntityPath": [],
+        "GuardType": "GARD_Predictive",
         "Guarded": true,
+        "LocationCode": "/proc0/pib/perv39/eq7/fc1/core1",
+        "Priority": "M"
+    },
+    {
+        "Deconfigured": false,
+        "Guarded": false,
         "LocationCode": "/proc0",
         "Priority": "H"
     },
     {
         "Deconfigured": false,
+        "EntityPath": [],
+        "GuardType": "GARD_Predictive",
+        "Guarded": true,
+        "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
+        "Priority": "A"
+    },
+    {
+        "Deconfigured": false,
         "Guarded": false,
         "LocationCode": "P0",
         "Priority": "L"
@@ -352,10 +132,12 @@
 
 TEST(Resolution, HardwareCallout)
 {
+    pdbg_targets_init(nullptr);
+
     auto c1 = std::make_shared<HardwareCalloutResolution>(
         omi_str, callout::Priority::MED_A, true);
 
-    libhei::Chip chip{chip_str, 0xdeadbeef};
+    libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
     libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
     ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
 
@@ -369,10 +151,10 @@
     s = R"([
     {
         "Deconfigured": false,
-        "Guard Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
-        "Guard Type": "GARD_Unrecoverable",
+        "EntityPath": [],
+        "GuardType": "GARD_Unrecoverable",
         "Guarded": true,
-        "LocationCode": "/proc0",
+        "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
         "Priority": "A"
     }
 ])";
@@ -393,6 +175,8 @@
 
 TEST(Resolution, ConnectedCallout)
 {
+    pdbg_targets_init(nullptr);
+
     auto c1 = std::make_shared<ConnectedCalloutResolution>(
         callout::BusType::SMP_BUS, iolink_str, callout::Priority::MED_A, true);
 
@@ -402,7 +186,7 @@
     auto c3 = std::make_shared<ConnectedCalloutResolution>(
         callout::BusType::OMI_BUS, omi_str, callout::Priority::MED_C, true);
 
-    libhei::Chip chip{chip_str, 0xdeadbeef};
+    libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
     libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
     ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
 
@@ -418,24 +202,24 @@
     s = R"([
     {
         "Deconfigured": false,
-        "Guard Path": "/proc1/pib/perv24/pauc0/iohs0/smpgroup0",
-        "Guard Type": "GARD_Unrecoverable",
+        "EntityPath": [],
+        "GuardType": "GARD_Unrecoverable",
         "Guarded": true,
-        "LocationCode": "/proc1",
+        "LocationCode": "/proc0/pib/perv24/pauc0/iohs0/smpgroup0",
         "Priority": "A"
     },
     {
         "Deconfigured": false,
-        "Guard Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
-        "Guard Type": "GARD_Unrecoverable",
+        "EntityPath": [],
+        "GuardType": "GARD_Unrecoverable",
         "Guarded": true,
-        "LocationCode": "/proc0",
+        "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
         "Priority": "B"
     },
     {
         "Deconfigured": false,
-        "Guard Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
-        "Guard Type": "GARD_Unrecoverable",
+        "EntityPath": [],
+        "GuardType": "GARD_Unrecoverable",
         "Guarded": true,
         "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
         "Priority": "C"
@@ -451,7 +235,7 @@
         "Callout Type": "Connected Callout",
         "Guard": true,
         "Priority": "medium_group_A",
-        "Target": "/proc1/pib/perv24/pauc0/iohs0/smpgroup0"
+        "Target": "/proc0/pib/perv24/pauc0/iohs0/smpgroup0"
     },
     {
         "Bus Type": "OMI_BUS",
@@ -473,6 +257,8 @@
 
 TEST(Resolution, BusCallout)
 {
+    pdbg_targets_init(nullptr);
+
     auto c1 = std::make_shared<HardwareCalloutResolution>(
         omi_str, callout::Priority::MED_A, true);
 
@@ -482,7 +268,7 @@
     auto c3 = std::make_shared<BusCalloutResolution>(
         callout::BusType::OMI_BUS, omi_str, callout::Priority::LOW, false);
 
-    libhei::Chip chip{chip_str, 0xdeadbeef};
+    libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
     libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
     ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
 
@@ -498,16 +284,16 @@
     s = R"([
     {
         "Deconfigured": false,
-        "Guard Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
-        "Guard Type": "GARD_Unrecoverable",
+        "EntityPath": [],
+        "GuardType": "GARD_Unrecoverable",
         "Guarded": true,
-        "LocationCode": "/proc0",
+        "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
         "Priority": "A"
     },
     {
         "Deconfigured": false,
-        "Guard Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
-        "Guard Type": "GARD_Unrecoverable",
+        "EntityPath": [],
+        "GuardType": "GARD_Unrecoverable",
         "Guarded": true,
         "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
         "Priority": "A"
@@ -551,10 +337,12 @@
 
 TEST(Resolution, ClockCallout)
 {
+    pdbg_targets_init(nullptr);
+
     auto c1 = std::make_shared<ClockCalloutResolution>(
         callout::ClockType::OSC_REF_CLOCK_1, callout::Priority::HIGH, false);
 
-    libhei::Chip chip{chip_str, 0xdeadbeef};
+    libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
     libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
     ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
 
@@ -589,10 +377,12 @@
 
 TEST(Resolution, ProcedureCallout)
 {
+    pdbg_targets_init(nullptr);
+
     auto c1 = std::make_shared<ProcedureCalloutResolution>(
         callout::Procedure::NEXTLVL, callout::Priority::LOW);
 
-    libhei::Chip chip{chip_str, 0xdeadbeef};
+    libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
     libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
     ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};