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 | |
| 30 | io_sd.addCallout(std::make_shared<HardwareCallout>(fru, iv_priority)); |
| 31 | |
Zane Shelley | 2f92130 | 2021-08-09 13:23:25 -0500 | [diff] [blame] | 32 | Guard::Type guard = Guard::NONE; |
| 33 | if (iv_guard) |
| 34 | { |
| 35 | guard = io_sd.queryCheckstop() ? Guard::FATAL : Guard::NON_FATAL; |
| 36 | } |
| 37 | |
| 38 | io_sd.addGuard(std::make_shared<Guard>(path, guard)); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | } // namespace analyzer |
| 42 | |
| 43 | using namespace analyzer; |
| 44 | |
| 45 | TEST(Resolution, TestSet1) |
| 46 | { |
| 47 | // Create a few resolutions |
| 48 | auto c1 = std::make_shared<HardwareCalloutResolution>( |
Zane Shelley | 2f92130 | 2021-08-09 13:23:25 -0500 | [diff] [blame] | 49 | proc_str, Callout::Priority::HIGH, false); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 50 | |
| 51 | auto c2 = std::make_shared<HardwareCalloutResolution>( |
Zane Shelley | 2f92130 | 2021-08-09 13:23:25 -0500 | [diff] [blame] | 52 | omi_str, Callout::Priority::MED_A, true); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 53 | |
| 54 | auto c3 = std::make_shared<HardwareCalloutResolution>( |
Zane Shelley | 2f92130 | 2021-08-09 13:23:25 -0500 | [diff] [blame] | 55 | core_str, Callout::Priority::MED, true); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 56 | |
| 57 | auto c4 = std::make_shared<ProcedureCalloutResolution>( |
| 58 | ProcedureCallout::NEXTLVL, Callout::Priority::LOW); |
| 59 | |
Zane Shelley | 723fa23 | 2021-08-09 12:02:06 -0500 | [diff] [blame] | 60 | // l1 = (c1, c2) |
| 61 | auto l1 = std::make_shared<ResolutionList>(); |
| 62 | l1->push(c1); |
| 63 | l1->push(c2); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 64 | |
Zane Shelley | 723fa23 | 2021-08-09 12:02:06 -0500 | [diff] [blame] | 65 | // l2 = (c4, c3, c1, c2) |
| 66 | auto l2 = std::make_shared<ResolutionList>(); |
| 67 | l2->push(c4); |
| 68 | l2->push(c3); |
| 69 | l2->push(l1); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 70 | |
| 71 | // Get some ServiceData objects |
| 72 | libhei::Chip chip{chip_str, 0xdeadbeef}; |
| 73 | libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP}; |
Zane Shelley | ca49619 | 2021-08-09 12:05:52 -0500 | [diff] [blame] | 74 | ServiceData sd1{sig, true}; |
| 75 | ServiceData sd2{sig, false}; |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 76 | |
| 77 | // Resolve |
Zane Shelley | 723fa23 | 2021-08-09 12:02:06 -0500 | [diff] [blame] | 78 | l1->resolve(sd1); |
| 79 | l2->resolve(sd2); |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 80 | |
| 81 | // Start verifying |
| 82 | nlohmann::json j{}; |
| 83 | std::string s{}; |
| 84 | |
| 85 | sd1.getCalloutList(j); |
| 86 | s = R"([ |
| 87 | { |
| 88 | "LocationCode": "/proc0", |
| 89 | "Priority": "H" |
| 90 | }, |
| 91 | { |
| 92 | "LocationCode": "/proc0", |
| 93 | "Priority": "A" |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 94 | } |
| 95 | ])"; |
| 96 | ASSERT_EQ(s, j.dump(4)); |
| 97 | |
| 98 | sd1.getGuardList(j); |
| 99 | s = R"([ |
| 100 | { |
| 101 | "Path": "/proc0", |
| 102 | "Type": "NONE" |
| 103 | }, |
| 104 | { |
| 105 | "Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0", |
| 106 | "Type": "FATAL" |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 107 | } |
| 108 | ])"; |
| 109 | ASSERT_EQ(s, j.dump(4)); |
| 110 | |
| 111 | sd2.getCalloutList(j); |
| 112 | s = R"([ |
| 113 | { |
| 114 | "Priority": "L", |
| 115 | "Procedure": "NEXTLVL" |
| 116 | }, |
| 117 | { |
| 118 | "LocationCode": "/proc0", |
| 119 | "Priority": "M" |
| 120 | }, |
| 121 | { |
| 122 | "LocationCode": "/proc0", |
| 123 | "Priority": "H" |
| 124 | }, |
| 125 | { |
| 126 | "LocationCode": "/proc0", |
| 127 | "Priority": "A" |
| 128 | } |
| 129 | ])"; |
| 130 | ASSERT_EQ(s, j.dump(4)); |
| 131 | |
| 132 | sd2.getGuardList(j); |
| 133 | s = R"([ |
| 134 | { |
| 135 | "Path": "/proc0/pib/perv39/eq7/fc1/core1", |
| 136 | "Type": "NON_FATAL" |
| 137 | }, |
| 138 | { |
| 139 | "Path": "/proc0", |
| 140 | "Type": "NONE" |
| 141 | }, |
| 142 | { |
| 143 | "Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0", |
Zane Shelley | 2f92130 | 2021-08-09 13:23:25 -0500 | [diff] [blame] | 144 | "Type": "NON_FATAL" |
Zane Shelley | 0b8368c | 2021-03-18 17:33:41 -0500 | [diff] [blame] | 145 | } |
| 146 | ])"; |
| 147 | ASSERT_EQ(s, j.dump(4)); |
| 148 | } |