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