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 | 9513582 | 2021-08-23 09:00:05 -0500 | [diff] [blame] | 36 | // Add the guard info to the service data. |
| 37 | io_sd.addGuard(path, iv_guard); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 38 | } |
| 39 | |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame] | 40 | //------------------------------------------------------------------------------ |
| 41 | |
| 42 | void ProcedureCalloutResolution::resolve(ServiceData& io_sd) const |
| 43 | { |
| 44 | // Add the actual callout to the service data. |
| 45 | nlohmann::json callout; |
| 46 | callout["Procedure"] = iv_procedure.getString(); |
| 47 | callout["Priority"] = iv_priority.getUserDataString(); |
| 48 | io_sd.addCallout(callout); |
| 49 | } |
| 50 | |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 51 | } // namespace analyzer |
| 52 | |
| 53 | using namespace analyzer; |
| 54 | |
| 55 | TEST(Resolution, TestSet1) |
| 56 | { |
| 57 | // Create a few resolutions |
| 58 | auto c1 = std::make_shared<HardwareCalloutResolution>( |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame] | 59 | proc_str, callout::Priority::HIGH, false); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 60 | |
| 61 | auto c2 = std::make_shared<HardwareCalloutResolution>( |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame] | 62 | omi_str, callout::Priority::MED_A, true); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 63 | |
| 64 | auto c3 = std::make_shared<HardwareCalloutResolution>( |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame] | 65 | core_str, callout::Priority::MED, true); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 66 | |
| 67 | auto c4 = std::make_shared<ProcedureCalloutResolution>( |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame] | 68 | callout::Procedure::NEXTLVL, callout::Priority::LOW); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 69 | |
Zane Shelley | 723fa23 | 2021-08-09 12:02:06 -0500 | [diff] [blame] | 70 | // l1 = (c1, c2) |
| 71 | auto l1 = std::make_shared<ResolutionList>(); |
| 72 | l1->push(c1); |
| 73 | l1->push(c2); |
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 | // l2 = (c4, c3, c1, c2) |
| 76 | auto l2 = std::make_shared<ResolutionList>(); |
| 77 | l2->push(c4); |
| 78 | l2->push(c3); |
| 79 | l2->push(l1); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 80 | |
| 81 | // Get some ServiceData objects |
| 82 | libhei::Chip chip{chip_str, 0xdeadbeef}; |
| 83 | libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP}; |
Zane Shelley | ca49619 | 2021-08-09 12:05:52 -0500 | [diff] [blame] | 84 | ServiceData sd1{sig, true}; |
| 85 | ServiceData sd2{sig, false}; |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 86 | |
| 87 | // Resolve |
Zane Shelley | 723fa23 | 2021-08-09 12:02:06 -0500 | [diff] [blame] | 88 | l1->resolve(sd1); |
| 89 | l2->resolve(sd2); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 90 | |
| 91 | // Start verifying |
| 92 | nlohmann::json j{}; |
| 93 | std::string s{}; |
| 94 | |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame] | 95 | j = sd1.getCalloutList(); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 96 | s = R"([ |
| 97 | { |
| 98 | "LocationCode": "/proc0", |
| 99 | "Priority": "H" |
| 100 | }, |
| 101 | { |
| 102 | "LocationCode": "/proc0", |
| 103 | "Priority": "A" |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 104 | } |
| 105 | ])"; |
| 106 | ASSERT_EQ(s, j.dump(4)); |
| 107 | |
Zane Shelley | c85716c | 2021-08-17 10:54:06 -0500 | [diff] [blame] | 108 | j = sd2.getCalloutList(); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 109 | s = R"([ |
| 110 | { |
| 111 | "Priority": "L", |
| 112 | "Procedure": "NEXTLVL" |
| 113 | }, |
| 114 | { |
| 115 | "LocationCode": "/proc0", |
| 116 | "Priority": "M" |
| 117 | }, |
| 118 | { |
| 119 | "LocationCode": "/proc0", |
| 120 | "Priority": "H" |
| 121 | }, |
| 122 | { |
| 123 | "LocationCode": "/proc0", |
| 124 | "Priority": "A" |
| 125 | } |
| 126 | ])"; |
| 127 | ASSERT_EQ(s, j.dump(4)); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 128 | } |