1 #include <stdio.h>
2
3 #include <analyzer/analyzer_main.hpp>
4 #include <analyzer/resolution.hpp>
5 #include <util/pdbg.hpp>
6 #include <util/trace.hpp>
7
8 #include <regex>
9
10 #include "gtest/gtest.h"
11
12 // Chip string
13 constexpr auto chip_str = "/proc0";
14
15 // Unit paths
16 constexpr auto proc_str = "";
17 constexpr auto iolink_str = "pib/perv26/pauc1/iohs0/smpgroup0";
18 constexpr auto omi_str = "pib/perv12/mc0/mi0/mcc0/omi0";
19 constexpr auto ocmb_str = "pib/perv12/mc0/mi0/mcc0/omi0/ocmb0";
20 constexpr auto core_str = "pib/perv39/eq7/fc1/core1";
21
22 using namespace analyzer;
23
TEST(Resolution,TestSet1)24 TEST(Resolution, TestSet1)
25 {
26 pdbg_targets_init(nullptr);
27
28 // Create a few resolutions
29 auto c1 = std::make_shared<HardwareCalloutResolution>(
30 proc_str, callout::Priority::HIGH, false);
31
32 auto c2 = std::make_shared<HardwareCalloutResolution>(
33 omi_str, callout::Priority::MED_A, true);
34
35 auto c3 = std::make_shared<HardwareCalloutResolution>(
36 core_str, callout::Priority::MED, true);
37
38 auto c4 = std::make_shared<ProcedureCalloutResolution>(
39 callout::Procedure::NEXTLVL, callout::Priority::LOW);
40
41 auto c5 = std::make_shared<ClockCalloutResolution>(
42 callout::ClockType::OSC_REF_CLOCK_1, callout::Priority::LOW, false);
43
44 // l1 = (c1, c2, c5)
45 auto l1 = std::make_shared<ResolutionList>();
46 l1->push(c1);
47 l1->push(c2);
48 l1->push(c5);
49
50 // l2 = (c4, c3, c1, c2, c5)
51 auto l2 = std::make_shared<ResolutionList>();
52 l2->push(c4);
53 l2->push(c3);
54 l2->push(l1);
55
56 // Get some ServiceData objects
57 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
58 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHIP_CS};
59 ServiceData sd1{sig, AnalysisType::SYSTEM_CHECKSTOP,
60 libhei::IsolationData{}};
61 ServiceData sd2{sig, AnalysisType::TERMINATE_IMMEDIATE,
62 libhei::IsolationData{}};
63
64 // Resolve
65 l1->resolve(sd1);
66 l2->resolve(sd2);
67
68 // Verify the subsystems
69 std::pair<callout::SrcSubsystem, callout::Priority> subsys = {
70 callout::SrcSubsystem::PROCESSOR_FRU, callout::Priority::HIGH};
71 EXPECT_EQ(sd1.getSubsys(), subsys);
72
73 subsys = {callout::SrcSubsystem::PROCESSOR_FRU, callout::Priority::HIGH};
74 EXPECT_EQ(sd2.getSubsys(), subsys);
75
76 // Start verifying
77 nlohmann::json j{};
78 std::string s{};
79
80 j = sd1.getCalloutList();
81 s = R"([
82 {
83 "Deconfigured": false,
84 "Guarded": false,
85 "LocationCode": "/proc0",
86 "Priority": "H"
87 },
88 {
89 "Deconfigured": false,
90 "EntityPath": [],
91 "GuardType": "GARD_Unrecoverable",
92 "Guarded": true,
93 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
94 "Priority": "A"
95 },
96 {
97 "Deconfigured": false,
98 "Guarded": false,
99 "LocationCode": "P0",
100 "Priority": "L"
101 }
102 ])";
103 EXPECT_EQ(s, j.dump(4));
104
105 j = sd2.getCalloutList();
106 s = R"([
107 {
108 "Priority": "L",
109 "Procedure": "next_level_support"
110 },
111 {
112 "Deconfigured": false,
113 "EntityPath": [],
114 "GuardType": "GARD_Predictive",
115 "Guarded": true,
116 "LocationCode": "/proc0/pib/perv39/eq7/fc1/core1",
117 "Priority": "M"
118 },
119 {
120 "Deconfigured": false,
121 "Guarded": false,
122 "LocationCode": "/proc0",
123 "Priority": "H"
124 },
125 {
126 "Deconfigured": false,
127 "EntityPath": [],
128 "GuardType": "GARD_Predictive",
129 "Guarded": true,
130 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
131 "Priority": "A"
132 },
133 {
134 "Deconfigured": false,
135 "Guarded": false,
136 "LocationCode": "P0",
137 "Priority": "L"
138 }
139 ])";
140 EXPECT_EQ(s, j.dump(4));
141 }
142
TEST(Resolution,HardwareCallout)143 TEST(Resolution, HardwareCallout)
144 {
145 pdbg_targets_init(nullptr);
146
147 auto c1 = std::make_shared<HardwareCalloutResolution>(
148 omi_str, callout::Priority::MED_A, true);
149
150 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
151 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHIP_CS};
152 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP,
153 libhei::IsolationData{}};
154
155 c1->resolve(sd);
156
157 // Verify the subsystem
158 std::pair<callout::SrcSubsystem, callout::Priority> subsys = {
159 callout::SrcSubsystem::MEMORY_CTLR, callout::Priority::MED_A};
160 EXPECT_EQ(sd.getSubsys(), subsys);
161
162 nlohmann::json j{};
163 std::string s{};
164
165 // Callout list
166 j = sd.getCalloutList();
167 s = R"([
168 {
169 "Deconfigured": false,
170 "EntityPath": [],
171 "GuardType": "GARD_Unrecoverable",
172 "Guarded": true,
173 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
174 "Priority": "A"
175 }
176 ])";
177 EXPECT_EQ(s, j.dump(4));
178
179 // Callout FFDC
180 j = sd.getCalloutFFDC();
181 s = R"([
182 {
183 "Callout Type": "Hardware Callout",
184 "Guard": true,
185 "Priority": "medium_group_A",
186 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0"
187 }
188 ])";
189 EXPECT_EQ(s, j.dump(4));
190 }
191
TEST(Resolution,ConnectedCallout)192 TEST(Resolution, ConnectedCallout)
193 {
194 pdbg_targets_init(nullptr);
195
196 auto c1 = std::make_shared<ConnectedCalloutResolution>(
197 callout::BusType::SMP_BUS, iolink_str, callout::Priority::MED_A, true);
198
199 auto c2 = std::make_shared<ConnectedCalloutResolution>(
200 callout::BusType::OMI_BUS, ocmb_str, callout::Priority::MED_B, true);
201
202 auto c3 = std::make_shared<ConnectedCalloutResolution>(
203 callout::BusType::OMI_BUS, omi_str, callout::Priority::MED_C, true);
204
205 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
206 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHIP_CS};
207 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP,
208 libhei::IsolationData{}};
209
210 nlohmann::json j{};
211 std::string s{};
212
213 c1->resolve(sd);
214 c2->resolve(sd);
215 c3->resolve(sd);
216
217 // Verify the subsystem
218 std::pair<callout::SrcSubsystem, callout::Priority> subsys = {
219 callout::SrcSubsystem::PROCESSOR_BUS, callout::Priority::MED_A};
220 EXPECT_EQ(sd.getSubsys(), subsys);
221
222 // Callout list
223 j = sd.getCalloutList();
224 s = R"([
225 {
226 "Deconfigured": false,
227 "EntityPath": [],
228 "GuardType": "GARD_Unrecoverable",
229 "Guarded": true,
230 "LocationCode": "/proc1/pib/perv25/pauc0/iohs1/smpgroup0",
231 "Priority": "A"
232 },
233 {
234 "Deconfigured": false,
235 "EntityPath": [],
236 "GuardType": "GARD_Unrecoverable",
237 "Guarded": true,
238 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
239 "Priority": "B"
240 },
241 {
242 "Deconfigured": false,
243 "EntityPath": [],
244 "GuardType": "GARD_Unrecoverable",
245 "Guarded": true,
246 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
247 "Priority": "C"
248 }
249 ])";
250 EXPECT_EQ(s, j.dump(4));
251
252 // Callout FFDC
253 j = sd.getCalloutFFDC();
254 s = R"([
255 {
256 "Bus Type": "SMP_BUS",
257 "Callout Type": "Connected Callout",
258 "Guard": true,
259 "Priority": "medium_group_A",
260 "RX Target": "/proc0/pib/perv26/pauc1/iohs0/smpgroup0",
261 "TX Target": "/proc1/pib/perv25/pauc0/iohs1/smpgroup0"
262 },
263 {
264 "Bus Type": "OMI_BUS",
265 "Callout Type": "Connected Callout",
266 "Guard": true,
267 "Priority": "medium_group_B",
268 "RX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
269 "TX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0"
270 },
271 {
272 "Bus Type": "OMI_BUS",
273 "Callout Type": "Connected Callout",
274 "Guard": true,
275 "Priority": "medium_group_C",
276 "RX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
277 "TX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
278 }
279 ])";
280 EXPECT_EQ(s, j.dump(4));
281 }
282
TEST(Resolution,BusCallout)283 TEST(Resolution, BusCallout)
284 {
285 pdbg_targets_init(nullptr);
286
287 auto c1 = std::make_shared<HardwareCalloutResolution>(
288 omi_str, callout::Priority::MED_A, true);
289
290 auto c2 = std::make_shared<ConnectedCalloutResolution>(
291 callout::BusType::OMI_BUS, omi_str, callout::Priority::MED_A, true);
292
293 auto c3 = std::make_shared<BusCalloutResolution>(
294 callout::BusType::OMI_BUS, omi_str, callout::Priority::LOW, false);
295
296 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
297 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHIP_CS};
298 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP,
299 libhei::IsolationData{}};
300
301 nlohmann::json j{};
302 std::string s{};
303
304 c1->resolve(sd);
305 c2->resolve(sd);
306 c3->resolve(sd);
307
308 // Verify the subsystem
309 std::pair<callout::SrcSubsystem, callout::Priority> subsys = {
310 callout::SrcSubsystem::MEMORY_CTLR, callout::Priority::MED_A};
311 EXPECT_EQ(sd.getSubsys(), subsys);
312
313 // Callout list
314 j = sd.getCalloutList();
315 s = R"([
316 {
317 "Deconfigured": false,
318 "EntityPath": [],
319 "GuardType": "GARD_Unrecoverable",
320 "Guarded": true,
321 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
322 "Priority": "A"
323 },
324 {
325 "Deconfigured": false,
326 "EntityPath": [],
327 "GuardType": "GARD_Unrecoverable",
328 "Guarded": true,
329 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
330 "Priority": "A"
331 },
332 {
333 "Deconfigured": false,
334 "Guarded": false,
335 "LocationCode": "P0",
336 "Priority": "L"
337 }
338 ])";
339 EXPECT_EQ(s, j.dump(4));
340
341 // Callout FFDC
342 j = sd.getCalloutFFDC();
343 s = R"([
344 {
345 "Callout Type": "Hardware Callout",
346 "Guard": true,
347 "Priority": "medium_group_A",
348 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0"
349 },
350 {
351 "Bus Type": "OMI_BUS",
352 "Callout Type": "Connected Callout",
353 "Guard": true,
354 "Priority": "medium_group_A",
355 "RX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
356 "TX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
357 },
358 {
359 "Bus Type": "OMI_BUS",
360 "Callout Type": "Bus Callout",
361 "Guard": false,
362 "Priority": "low",
363 "RX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
364 "TX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
365 }
366 ])";
367 EXPECT_EQ(s, j.dump(4));
368 }
369
TEST(Resolution,ClockCallout)370 TEST(Resolution, ClockCallout)
371 {
372 pdbg_targets_init(nullptr);
373
374 auto c1 = std::make_shared<ClockCalloutResolution>(
375 callout::ClockType::OSC_REF_CLOCK_1, callout::Priority::HIGH, false);
376
377 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
378 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHIP_CS};
379 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP,
380 libhei::IsolationData{}};
381
382 c1->resolve(sd);
383
384 // Verify the subsystem
385 std::pair<callout::SrcSubsystem, callout::Priority> subsys = {
386 callout::SrcSubsystem::CEC_CLOCKS, callout::Priority::HIGH};
387 EXPECT_EQ(sd.getSubsys(), subsys);
388
389 nlohmann::json j{};
390 std::string s{};
391
392 // Callout list
393 j = sd.getCalloutList();
394 s = R"([
395 {
396 "Deconfigured": false,
397 "Guarded": false,
398 "LocationCode": "P0",
399 "Priority": "H"
400 }
401 ])";
402 EXPECT_EQ(s, j.dump(4));
403
404 // Callout FFDC
405 j = sd.getCalloutFFDC();
406 s = R"([
407 {
408 "Callout Type": "Clock Callout",
409 "Clock Type": "OSC_REF_CLOCK_1",
410 "Priority": "high"
411 }
412 ])";
413 EXPECT_EQ(s, j.dump(4));
414 }
415
TEST(Resolution,ProcedureCallout)416 TEST(Resolution, ProcedureCallout)
417 {
418 pdbg_targets_init(nullptr);
419
420 auto c1 = std::make_shared<ProcedureCalloutResolution>(
421 callout::Procedure::NEXTLVL, callout::Priority::LOW);
422
423 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
424 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHIP_CS};
425 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP,
426 libhei::IsolationData{}};
427
428 c1->resolve(sd);
429
430 // Verify the subsystem
431 std::pair<callout::SrcSubsystem, callout::Priority> subsys = {
432 callout::SrcSubsystem::OTHERS, callout::Priority::LOW};
433 EXPECT_EQ(sd.getSubsys(), subsys);
434
435 nlohmann::json j{};
436 std::string s{};
437
438 // Callout list
439 j = sd.getCalloutList();
440 s = R"([
441 {
442 "Priority": "L",
443 "Procedure": "next_level_support"
444 }
445 ])";
446 EXPECT_EQ(s, j.dump(4));
447
448 // Callout FFDC
449 j = sd.getCalloutFFDC();
450 s = R"([
451 {
452 "Callout Type": "Procedure Callout",
453 "Priority": "low",
454 "Procedure": "next_level_support"
455 }
456 ])";
457 EXPECT_EQ(s, j.dump(4));
458 }
459
TEST(Resolution,PartCallout)460 TEST(Resolution, PartCallout)
461 {
462 pdbg_targets_init(nullptr);
463
464 auto c1 = std::make_shared<PartCalloutResolution>(callout::PartType::PNOR,
465 callout::Priority::MED);
466
467 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
468 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHIP_CS};
469 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP,
470 libhei::IsolationData{}};
471
472 c1->resolve(sd);
473
474 // Verify the subsystem
475 std::pair<callout::SrcSubsystem, callout::Priority> subsys = {
476 callout::SrcSubsystem::CEC_HARDWARE, callout::Priority::MED};
477 EXPECT_EQ(sd.getSubsys(), subsys);
478
479 nlohmann::json j{};
480 std::string s{};
481
482 // Callout list
483 j = sd.getCalloutList();
484 s = R"([
485 {
486 "Deconfigured": false,
487 "Guarded": false,
488 "LocationCode": "/bmc0",
489 "Priority": "M"
490 }
491 ])";
492 EXPECT_EQ(s, j.dump(4));
493
494 // Callout FFDC
495 j = sd.getCalloutFFDC();
496 s = R"([
497 {
498 "Callout Type": "Part Callout",
499 "Part Type": "PNOR",
500 "Priority": "medium"
501 }
502 ])";
503 EXPECT_EQ(s, j.dump(4));
504 }
505