| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 1 | #include <stdio.h> | 
|  | 2 |  | 
|  | 3 | #include <analyzer/resolution.hpp> | 
|  | 4 |  | 
|  | 5 | #include "gtest/gtest.h" | 
|  | 6 |  | 
|  | 7 | // Chip string | 
|  | 8 | constexpr auto chip_str = "/proc0"; | 
|  | 9 |  | 
|  | 10 | // Unit paths | 
|  | 11 | constexpr auto proc_str = ""; | 
|  | 12 | constexpr auto omi_str  = "pib/perv12/mc0/mi0/mcc0/omi0"; | 
|  | 13 | constexpr auto core_str = "pib/perv39/eq7/fc1/core1"; | 
|  | 14 |  | 
|  | 15 | // Local implementation of this function. | 
|  | 16 | namespace analyzer | 
|  | 17 | { | 
|  | 18 |  | 
|  | 19 | void HardwareCalloutResolution::resolve(ServiceData& io_sd) const | 
|  | 20 | { | 
|  | 21 | auto sig = io_sd.getRootCause(); | 
|  | 22 |  | 
|  | 23 | std::string fru{(const char*)sig.getChip().getChip()}; | 
| Zane Shelley | 2f92130 | 2021-08-09 13:23:25 -0500 | [diff] [blame] | 24 | std::string path{fru}; | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 25 | if (!iv_path.empty()) | 
|  | 26 | { | 
| Zane Shelley | 2f92130 | 2021-08-09 13:23:25 -0500 | [diff] [blame] | 27 | path += "/" + iv_path; | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 28 | } | 
|  | 29 |  | 
| Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 30 | // Add the actual callout to the service data. | 
|  | 31 | nlohmann::json callout; | 
|  | 32 | callout["LocationCode"] = fru; | 
|  | 33 | callout["Priority"]     = iv_priority.getUserDataString(); | 
|  | 34 | io_sd.addCallout(callout); | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 35 |  | 
| Zane Shelley | 2f92130 | 2021-08-09 13:23:25 -0500 | [diff] [blame] | 36 | Guard::Type guard = Guard::NONE; | 
|  | 37 | if (iv_guard) | 
|  | 38 | { | 
|  | 39 | guard = io_sd.queryCheckstop() ? Guard::FATAL : Guard::NON_FATAL; | 
|  | 40 | } | 
|  | 41 |  | 
|  | 42 | io_sd.addGuard(std::make_shared<Guard>(path, guard)); | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 43 | } | 
|  | 44 |  | 
| Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 45 | //------------------------------------------------------------------------------ | 
|  | 46 |  | 
|  | 47 | void ProcedureCalloutResolution::resolve(ServiceData& io_sd) const | 
|  | 48 | { | 
|  | 49 | // Add the actual callout to the service data. | 
|  | 50 | nlohmann::json callout; | 
|  | 51 | callout["Procedure"] = iv_procedure.getString(); | 
|  | 52 | callout["Priority"]  = iv_priority.getUserDataString(); | 
|  | 53 | io_sd.addCallout(callout); | 
|  | 54 | } | 
|  | 55 |  | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 56 | } // namespace analyzer | 
|  | 57 |  | 
|  | 58 | using namespace analyzer; | 
|  | 59 |  | 
|  | 60 | TEST(Resolution, TestSet1) | 
|  | 61 | { | 
|  | 62 | // Create a few resolutions | 
|  | 63 | auto c1 = std::make_shared<HardwareCalloutResolution>( | 
| Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 64 | proc_str, callout::Priority::HIGH, false); | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 65 |  | 
|  | 66 | auto c2 = std::make_shared<HardwareCalloutResolution>( | 
| Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 67 | omi_str, callout::Priority::MED_A, true); | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 68 |  | 
|  | 69 | auto c3 = std::make_shared<HardwareCalloutResolution>( | 
| Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 70 | core_str, callout::Priority::MED, true); | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 71 |  | 
|  | 72 | auto c4 = std::make_shared<ProcedureCalloutResolution>( | 
| Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 73 | callout::Procedure::NEXTLVL, callout::Priority::LOW); | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 74 |  | 
| Zane Shelley | 723fa23 | 2021-08-09 12:02:06 -0500 | [diff] [blame] | 75 | // l1 = (c1, c2) | 
|  | 76 | auto l1 = std::make_shared<ResolutionList>(); | 
|  | 77 | l1->push(c1); | 
|  | 78 | l1->push(c2); | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 79 |  | 
| Zane Shelley | 723fa23 | 2021-08-09 12:02:06 -0500 | [diff] [blame] | 80 | // l2 = (c4, c3, c1, c2) | 
|  | 81 | auto l2 = std::make_shared<ResolutionList>(); | 
|  | 82 | l2->push(c4); | 
|  | 83 | l2->push(c3); | 
|  | 84 | l2->push(l1); | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 85 |  | 
|  | 86 | // Get some ServiceData objects | 
|  | 87 | libhei::Chip chip{chip_str, 0xdeadbeef}; | 
|  | 88 | libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP}; | 
| Zane Shelley | ca49619 | 2021-08-09 12:05:52 -0500 | [diff] [blame] | 89 | ServiceData sd1{sig, true}; | 
|  | 90 | ServiceData sd2{sig, false}; | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 91 |  | 
|  | 92 | // Resolve | 
| Zane Shelley | 723fa23 | 2021-08-09 12:02:06 -0500 | [diff] [blame] | 93 | l1->resolve(sd1); | 
|  | 94 | l2->resolve(sd2); | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 95 |  | 
|  | 96 | // Start verifying | 
|  | 97 | nlohmann::json j{}; | 
|  | 98 | std::string s{}; | 
|  | 99 |  | 
| Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 100 | j = sd1.getCalloutList(); | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 101 | s = R"([ | 
|  | 102 | { | 
|  | 103 | "LocationCode": "/proc0", | 
|  | 104 | "Priority": "H" | 
|  | 105 | }, | 
|  | 106 | { | 
|  | 107 | "LocationCode": "/proc0", | 
|  | 108 | "Priority": "A" | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 109 | } | 
|  | 110 | ])"; | 
|  | 111 | ASSERT_EQ(s, j.dump(4)); | 
|  | 112 |  | 
|  | 113 | sd1.getGuardList(j); | 
|  | 114 | s = R"([ | 
|  | 115 | { | 
|  | 116 | "Path": "/proc0", | 
|  | 117 | "Type": "NONE" | 
|  | 118 | }, | 
|  | 119 | { | 
|  | 120 | "Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0", | 
|  | 121 | "Type": "FATAL" | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 122 | } | 
|  | 123 | ])"; | 
|  | 124 | ASSERT_EQ(s, j.dump(4)); | 
|  | 125 |  | 
| Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame^] | 126 | j = sd2.getCalloutList(); | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 127 | s = R"([ | 
|  | 128 | { | 
|  | 129 | "Priority": "L", | 
|  | 130 | "Procedure": "NEXTLVL" | 
|  | 131 | }, | 
|  | 132 | { | 
|  | 133 | "LocationCode": "/proc0", | 
|  | 134 | "Priority": "M" | 
|  | 135 | }, | 
|  | 136 | { | 
|  | 137 | "LocationCode": "/proc0", | 
|  | 138 | "Priority": "H" | 
|  | 139 | }, | 
|  | 140 | { | 
|  | 141 | "LocationCode": "/proc0", | 
|  | 142 | "Priority": "A" | 
|  | 143 | } | 
|  | 144 | ])"; | 
|  | 145 | ASSERT_EQ(s, j.dump(4)); | 
|  | 146 |  | 
|  | 147 | sd2.getGuardList(j); | 
|  | 148 | s = R"([ | 
|  | 149 | { | 
|  | 150 | "Path": "/proc0/pib/perv39/eq7/fc1/core1", | 
|  | 151 | "Type": "NON_FATAL" | 
|  | 152 | }, | 
|  | 153 | { | 
|  | 154 | "Path": "/proc0", | 
|  | 155 | "Type": "NONE" | 
|  | 156 | }, | 
|  | 157 | { | 
|  | 158 | "Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0", | 
| Zane Shelley | 2f92130 | 2021-08-09 13:23:25 -0500 | [diff] [blame] | 159 | "Type": "NON_FATAL" | 
| Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 160 | } | 
|  | 161 | ])"; | 
|  | 162 | ASSERT_EQ(s, j.dump(4)); | 
|  | 163 | } |