blob: c894d01ef2d0747d7ccfde9e7bbc0450acb35c56 [file] [log] [blame]
Zane Shelley0b8368c2021-03-18 17:33:41 -05001#include <stdio.h>
2
Zane Shelley82be3ab2021-12-07 10:36:08 -06003#include <analyzer/analyzer_main.hpp>
Zane Shelley0b8368c2021-03-18 17:33:41 -05004#include <analyzer/resolution.hpp>
Zane Shelleycb766a42022-01-12 17:50:23 -06005#include <util/pdbg.hpp>
Zane Shelley5d63cef2021-09-17 18:10:17 -05006#include <util/trace.hpp>
7
8#include <regex>
Zane Shelley0b8368c2021-03-18 17:33:41 -05009
10#include "gtest/gtest.h"
11
12// Chip string
13constexpr auto chip_str = "/proc0";
14
15// Unit paths
Zane Shelley5d63cef2021-09-17 18:10:17 -050016constexpr auto proc_str = "";
17constexpr auto iolink_str = "pib/perv24/pauc0/iohs0/smpgroup0";
18constexpr auto omi_str = "pib/perv12/mc0/mi0/mcc0/omi0";
19constexpr auto ocmb_str = "pib/perv12/mc0/mi0/mcc0/omi0/ocmb0";
20constexpr auto core_str = "pib/perv39/eq7/fc1/core1";
Zane Shelley0b8368c2021-03-18 17:33:41 -050021
Zane Shelley0b8368c2021-03-18 17:33:41 -050022using namespace analyzer;
23
24TEST(Resolution, TestSet1)
25{
Zane Shelleycb766a42022-01-12 17:50:23 -060026 pdbg_targets_init(nullptr);
27
Zane Shelley0b8368c2021-03-18 17:33:41 -050028 // Create a few resolutions
29 auto c1 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050030 proc_str, callout::Priority::HIGH, false);
Zane Shelley0b8368c2021-03-18 17:33:41 -050031
32 auto c2 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050033 omi_str, callout::Priority::MED_A, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -050034
35 auto c3 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050036 core_str, callout::Priority::MED, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -050037
38 auto c4 = std::make_shared<ProcedureCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050039 callout::Procedure::NEXTLVL, callout::Priority::LOW);
Zane Shelley0b8368c2021-03-18 17:33:41 -050040
Zane Shelley84721d92021-09-08 13:30:27 -050041 auto c5 = std::make_shared<ClockCalloutResolution>(
42 callout::ClockType::OSC_REF_CLOCK_1, callout::Priority::LOW, false);
43
44 // l1 = (c1, c2, c5)
Zane Shelley723fa232021-08-09 12:02:06 -050045 auto l1 = std::make_shared<ResolutionList>();
46 l1->push(c1);
47 l1->push(c2);
Zane Shelley84721d92021-09-08 13:30:27 -050048 l1->push(c5);
Zane Shelley0b8368c2021-03-18 17:33:41 -050049
Zane Shelley84721d92021-09-08 13:30:27 -050050 // l2 = (c4, c3, c1, c2, c5)
Zane Shelley723fa232021-08-09 12:02:06 -050051 auto l2 = std::make_shared<ResolutionList>();
52 l2->push(c4);
53 l2->push(c3);
54 l2->push(l1);
Zane Shelley0b8368c2021-03-18 17:33:41 -050055
56 // Get some ServiceData objects
Zane Shelleycb766a42022-01-12 17:50:23 -060057 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
Zane Shelley0b8368c2021-03-18 17:33:41 -050058 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelley82be3ab2021-12-07 10:36:08 -060059 ServiceData sd1{sig, AnalysisType::SYSTEM_CHECKSTOP};
60 ServiceData sd2{sig, AnalysisType::TERMINATE_IMMEDIATE};
Zane Shelley0b8368c2021-03-18 17:33:41 -050061
62 // Resolve
Zane Shelley723fa232021-08-09 12:02:06 -050063 l1->resolve(sd1);
64 l2->resolve(sd2);
Zane Shelley0b8368c2021-03-18 17:33:41 -050065
66 // Start verifying
67 nlohmann::json j{};
68 std::string s{};
69
Zane Shelleyc85716c2021-08-17 10:54:06 -050070 j = sd1.getCalloutList();
Zane Shelley0b8368c2021-03-18 17:33:41 -050071 s = R"([
72 {
Zane Shelley9a738f72021-11-03 20:45:30 -050073 "Deconfigured": false,
74 "Guarded": false,
Zane Shelley0b8368c2021-03-18 17:33:41 -050075 "LocationCode": "/proc0",
76 "Priority": "H"
77 },
78 {
Zane Shelley1eff9452021-11-03 13:59:54 -050079 "Deconfigured": false,
Zane Shelleycb766a42022-01-12 17:50:23 -060080 "EntityPath": [],
81 "GuardType": "GARD_Unrecoverable",
82 "Guarded": true,
83 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
84 "Priority": "A"
85 },
86 {
87 "Deconfigured": false,
Zane Shelley1eff9452021-11-03 13:59:54 -050088 "Guarded": false,
Zane Shelley84721d92021-09-08 13:30:27 -050089 "LocationCode": "P0",
90 "Priority": "L"
Zane Shelley0b8368c2021-03-18 17:33:41 -050091 }
92])";
Zane Shelley96d54862021-09-17 11:16:12 -050093 EXPECT_EQ(s, j.dump(4));
Zane Shelley0b8368c2021-03-18 17:33:41 -050094
Zane Shelleyc85716c2021-08-17 10:54:06 -050095 j = sd2.getCalloutList();
Zane Shelley0b8368c2021-03-18 17:33:41 -050096 s = R"([
97 {
98 "Priority": "L",
Zane Shelley86ccc452021-11-16 13:10:52 -060099 "Procedure": "next_level_support"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500100 },
101 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500102 "Deconfigured": false,
Zane Shelleycb766a42022-01-12 17:50:23 -0600103 "EntityPath": [],
104 "GuardType": "GARD_Predictive",
Zane Shelley9a738f72021-11-03 20:45:30 -0500105 "Guarded": true,
Zane Shelleycb766a42022-01-12 17:50:23 -0600106 "LocationCode": "/proc0/pib/perv39/eq7/fc1/core1",
107 "Priority": "M"
108 },
109 {
110 "Deconfigured": false,
111 "Guarded": false,
Zane Shelley0b8368c2021-03-18 17:33:41 -0500112 "LocationCode": "/proc0",
Zane Shelley0b8368c2021-03-18 17:33:41 -0500113 "Priority": "H"
114 },
115 {
Zane Shelley1eff9452021-11-03 13:59:54 -0500116 "Deconfigured": false,
Zane Shelleycb766a42022-01-12 17:50:23 -0600117 "EntityPath": [],
118 "GuardType": "GARD_Predictive",
119 "Guarded": true,
120 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
121 "Priority": "A"
122 },
123 {
124 "Deconfigured": false,
Zane Shelley1eff9452021-11-03 13:59:54 -0500125 "Guarded": false,
Zane Shelley84721d92021-09-08 13:30:27 -0500126 "LocationCode": "P0",
127 "Priority": "L"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500128 }
129])";
Zane Shelley96d54862021-09-17 11:16:12 -0500130 EXPECT_EQ(s, j.dump(4));
131}
132
133TEST(Resolution, HardwareCallout)
134{
Zane Shelleycb766a42022-01-12 17:50:23 -0600135 pdbg_targets_init(nullptr);
136
Zane Shelley96d54862021-09-17 11:16:12 -0500137 auto c1 = std::make_shared<HardwareCalloutResolution>(
138 omi_str, callout::Priority::MED_A, true);
139
Zane Shelleycb766a42022-01-12 17:50:23 -0600140 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
Zane Shelley96d54862021-09-17 11:16:12 -0500141 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelley82be3ab2021-12-07 10:36:08 -0600142 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
Zane Shelley96d54862021-09-17 11:16:12 -0500143
144 c1->resolve(sd);
145
146 nlohmann::json j{};
147 std::string s{};
148
149 // Callout list
150 j = sd.getCalloutList();
151 s = R"([
152 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500153 "Deconfigured": false,
Zane Shelleycb766a42022-01-12 17:50:23 -0600154 "EntityPath": [],
155 "GuardType": "GARD_Unrecoverable",
Zane Shelley9a738f72021-11-03 20:45:30 -0500156 "Guarded": true,
Zane Shelleycb766a42022-01-12 17:50:23 -0600157 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
Zane Shelley96d54862021-09-17 11:16:12 -0500158 "Priority": "A"
159 }
160])";
161 EXPECT_EQ(s, j.dump(4));
162
163 // Callout FFDC
164 j = sd.getCalloutFFDC();
165 s = R"([
166 {
167 "Callout Type": "Hardware Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500168 "Guard": true,
Zane Shelley96d54862021-09-17 11:16:12 -0500169 "Priority": "medium_group_A",
170 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0"
171 }
172])";
173 EXPECT_EQ(s, j.dump(4));
174}
175
Zane Shelley5d63cef2021-09-17 18:10:17 -0500176TEST(Resolution, ConnectedCallout)
177{
Zane Shelleycb766a42022-01-12 17:50:23 -0600178 pdbg_targets_init(nullptr);
179
Zane Shelley5d63cef2021-09-17 18:10:17 -0500180 auto c1 = std::make_shared<ConnectedCalloutResolution>(
181 callout::BusType::SMP_BUS, iolink_str, callout::Priority::MED_A, true);
182
183 auto c2 = std::make_shared<ConnectedCalloutResolution>(
184 callout::BusType::OMI_BUS, ocmb_str, callout::Priority::MED_B, true);
185
186 auto c3 = std::make_shared<ConnectedCalloutResolution>(
187 callout::BusType::OMI_BUS, omi_str, callout::Priority::MED_C, true);
188
Zane Shelleycb766a42022-01-12 17:50:23 -0600189 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
Zane Shelley5d63cef2021-09-17 18:10:17 -0500190 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelley82be3ab2021-12-07 10:36:08 -0600191 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
Zane Shelley5d63cef2021-09-17 18:10:17 -0500192
193 nlohmann::json j{};
194 std::string s{};
195
196 c1->resolve(sd);
197 c2->resolve(sd);
198 c3->resolve(sd);
199
200 // Callout list
201 j = sd.getCalloutList();
202 s = R"([
203 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500204 "Deconfigured": false,
Zane Shelleycb766a42022-01-12 17:50:23 -0600205 "EntityPath": [],
206 "GuardType": "GARD_Unrecoverable",
Zane Shelley9a738f72021-11-03 20:45:30 -0500207 "Guarded": true,
Zane Shelleycb766a42022-01-12 17:50:23 -0600208 "LocationCode": "/proc0/pib/perv24/pauc0/iohs0/smpgroup0",
Zane Shelley5d63cef2021-09-17 18:10:17 -0500209 "Priority": "A"
210 },
211 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500212 "Deconfigured": false,
Zane Shelleycb766a42022-01-12 17:50:23 -0600213 "EntityPath": [],
214 "GuardType": "GARD_Unrecoverable",
Zane Shelley9a738f72021-11-03 20:45:30 -0500215 "Guarded": true,
Zane Shelleycb766a42022-01-12 17:50:23 -0600216 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
Zane Shelley5d63cef2021-09-17 18:10:17 -0500217 "Priority": "B"
218 },
219 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500220 "Deconfigured": false,
Zane Shelleycb766a42022-01-12 17:50:23 -0600221 "EntityPath": [],
222 "GuardType": "GARD_Unrecoverable",
Zane Shelley9a738f72021-11-03 20:45:30 -0500223 "Guarded": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500224 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
225 "Priority": "C"
226 }
227])";
228 EXPECT_EQ(s, j.dump(4));
229
230 // Callout FFDC
231 j = sd.getCalloutFFDC();
232 s = R"([
233 {
234 "Bus Type": "SMP_BUS",
235 "Callout Type": "Connected Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500236 "Guard": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500237 "Priority": "medium_group_A",
Zane Shelley37acb282022-01-10 16:05:22 -0600238 "RX Target": "/proc0/pib/perv24/pauc0/iohs0/smpgroup0",
239 "TX Target": "/proc0/pib/perv24/pauc0/iohs0/smpgroup0"
Zane Shelley5d63cef2021-09-17 18:10:17 -0500240 },
241 {
242 "Bus Type": "OMI_BUS",
243 "Callout Type": "Connected Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500244 "Guard": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500245 "Priority": "medium_group_B",
Zane Shelley37acb282022-01-10 16:05:22 -0600246 "RX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
247 "TX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0"
Zane Shelley5d63cef2021-09-17 18:10:17 -0500248 },
249 {
250 "Bus Type": "OMI_BUS",
251 "Callout Type": "Connected Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500252 "Guard": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500253 "Priority": "medium_group_C",
Zane Shelley37acb282022-01-10 16:05:22 -0600254 "RX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
255 "TX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
Zane Shelley5d63cef2021-09-17 18:10:17 -0500256 }
257])";
258 EXPECT_EQ(s, j.dump(4));
259}
260
Zane Shelley4757a7b2021-09-20 22:23:38 -0500261TEST(Resolution, BusCallout)
262{
Zane Shelleycb766a42022-01-12 17:50:23 -0600263 pdbg_targets_init(nullptr);
264
Zane Shelley4757a7b2021-09-20 22:23:38 -0500265 auto c1 = std::make_shared<HardwareCalloutResolution>(
266 omi_str, callout::Priority::MED_A, true);
267
268 auto c2 = std::make_shared<ConnectedCalloutResolution>(
269 callout::BusType::OMI_BUS, omi_str, callout::Priority::MED_A, true);
270
271 auto c3 = std::make_shared<BusCalloutResolution>(
272 callout::BusType::OMI_BUS, omi_str, callout::Priority::LOW, false);
273
Zane Shelleycb766a42022-01-12 17:50:23 -0600274 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
Zane Shelley4757a7b2021-09-20 22:23:38 -0500275 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelley82be3ab2021-12-07 10:36:08 -0600276 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
Zane Shelley4757a7b2021-09-20 22:23:38 -0500277
278 nlohmann::json j{};
279 std::string s{};
280
281 c1->resolve(sd);
282 c2->resolve(sd);
283 c3->resolve(sd);
284
285 // Callout list
286 j = sd.getCalloutList();
287 s = R"([
288 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500289 "Deconfigured": false,
Zane Shelleycb766a42022-01-12 17:50:23 -0600290 "EntityPath": [],
291 "GuardType": "GARD_Unrecoverable",
Zane Shelley9a738f72021-11-03 20:45:30 -0500292 "Guarded": true,
Zane Shelleycb766a42022-01-12 17:50:23 -0600293 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
Zane Shelley4757a7b2021-09-20 22:23:38 -0500294 "Priority": "A"
295 },
296 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500297 "Deconfigured": false,
Zane Shelleycb766a42022-01-12 17:50:23 -0600298 "EntityPath": [],
299 "GuardType": "GARD_Unrecoverable",
Zane Shelley9a738f72021-11-03 20:45:30 -0500300 "Guarded": true,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500301 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
302 "Priority": "A"
303 },
304 {
Zane Shelley1eff9452021-11-03 13:59:54 -0500305 "Deconfigured": false,
306 "Guarded": false,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500307 "LocationCode": "P0",
308 "Priority": "L"
309 }
310])";
311 EXPECT_EQ(s, j.dump(4));
312
313 // Callout FFDC
314 j = sd.getCalloutFFDC();
315 s = R"([
316 {
317 "Callout Type": "Hardware Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500318 "Guard": true,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500319 "Priority": "medium_group_A",
320 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0"
321 },
322 {
323 "Bus Type": "OMI_BUS",
324 "Callout Type": "Connected Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500325 "Guard": true,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500326 "Priority": "medium_group_A",
Zane Shelley37acb282022-01-10 16:05:22 -0600327 "RX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
328 "TX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
Zane Shelley4757a7b2021-09-20 22:23:38 -0500329 },
330 {
331 "Bus Type": "OMI_BUS",
332 "Callout Type": "Bus Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500333 "Guard": false,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500334 "Priority": "low",
335 "RX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
336 "TX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
337 }
338])";
339 EXPECT_EQ(s, j.dump(4));
340}
341
Zane Shelley96d54862021-09-17 11:16:12 -0500342TEST(Resolution, ClockCallout)
343{
Zane Shelleycb766a42022-01-12 17:50:23 -0600344 pdbg_targets_init(nullptr);
345
Zane Shelley96d54862021-09-17 11:16:12 -0500346 auto c1 = std::make_shared<ClockCalloutResolution>(
347 callout::ClockType::OSC_REF_CLOCK_1, callout::Priority::HIGH, false);
348
Zane Shelleycb766a42022-01-12 17:50:23 -0600349 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
Zane Shelley96d54862021-09-17 11:16:12 -0500350 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelley82be3ab2021-12-07 10:36:08 -0600351 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
Zane Shelley96d54862021-09-17 11:16:12 -0500352
353 c1->resolve(sd);
354
355 nlohmann::json j{};
356 std::string s{};
357
358 // Callout list
359 j = sd.getCalloutList();
360 s = R"([
361 {
Zane Shelley1eff9452021-11-03 13:59:54 -0500362 "Deconfigured": false,
363 "Guarded": false,
Zane Shelley96d54862021-09-17 11:16:12 -0500364 "LocationCode": "P0",
365 "Priority": "H"
366 }
367])";
368 EXPECT_EQ(s, j.dump(4));
369
370 // Callout FFDC
371 j = sd.getCalloutFFDC();
372 s = R"([
373 {
374 "Callout Type": "Clock Callout",
375 "Clock Type": "OSC_REF_CLOCK_1",
Zane Shelley1eff9452021-11-03 13:59:54 -0500376 "Priority": "high"
Zane Shelley96d54862021-09-17 11:16:12 -0500377 }
378])";
379 EXPECT_EQ(s, j.dump(4));
380}
381
382TEST(Resolution, ProcedureCallout)
383{
Zane Shelleycb766a42022-01-12 17:50:23 -0600384 pdbg_targets_init(nullptr);
385
Zane Shelley96d54862021-09-17 11:16:12 -0500386 auto c1 = std::make_shared<ProcedureCalloutResolution>(
387 callout::Procedure::NEXTLVL, callout::Priority::LOW);
388
Zane Shelleycb766a42022-01-12 17:50:23 -0600389 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
Zane Shelley96d54862021-09-17 11:16:12 -0500390 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelley82be3ab2021-12-07 10:36:08 -0600391 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
Zane Shelley96d54862021-09-17 11:16:12 -0500392
393 c1->resolve(sd);
394
395 nlohmann::json j{};
396 std::string s{};
397
398 // Callout list
399 j = sd.getCalloutList();
400 s = R"([
401 {
402 "Priority": "L",
Zane Shelley86ccc452021-11-16 13:10:52 -0600403 "Procedure": "next_level_support"
Zane Shelley96d54862021-09-17 11:16:12 -0500404 }
405])";
406 EXPECT_EQ(s, j.dump(4));
407
408 // Callout FFDC
409 j = sd.getCalloutFFDC();
410 s = R"([
411 {
412 "Callout Type": "Procedure Callout",
413 "Priority": "low",
Zane Shelley86ccc452021-11-16 13:10:52 -0600414 "Procedure": "next_level_support"
Zane Shelley96d54862021-09-17 11:16:12 -0500415 }
416])";
417 EXPECT_EQ(s, j.dump(4));
Zane Shelley0b8368c2021-03-18 17:33:41 -0500418}