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