blob: 8e43138f2561829700fb30e1a476f57cb97d58a4 [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 Shelleycb766a42022-01-12 17:50:23 -0600238 "Target": "/proc0/pib/perv24/pauc0/iohs0/smpgroup0"
Zane Shelley5d63cef2021-09-17 18:10:17 -0500239 },
240 {
241 "Bus Type": "OMI_BUS",
242 "Callout Type": "Connected Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500243 "Guard": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500244 "Priority": "medium_group_B",
245 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0"
246 },
247 {
248 "Bus Type": "OMI_BUS",
249 "Callout Type": "Connected Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500250 "Guard": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500251 "Priority": "medium_group_C",
252 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
253 }
254])";
255 EXPECT_EQ(s, j.dump(4));
256}
257
Zane Shelley4757a7b2021-09-20 22:23:38 -0500258TEST(Resolution, BusCallout)
259{
Zane Shelleycb766a42022-01-12 17:50:23 -0600260 pdbg_targets_init(nullptr);
261
Zane Shelley4757a7b2021-09-20 22:23:38 -0500262 auto c1 = std::make_shared<HardwareCalloutResolution>(
263 omi_str, callout::Priority::MED_A, true);
264
265 auto c2 = std::make_shared<ConnectedCalloutResolution>(
266 callout::BusType::OMI_BUS, omi_str, callout::Priority::MED_A, true);
267
268 auto c3 = std::make_shared<BusCalloutResolution>(
269 callout::BusType::OMI_BUS, omi_str, callout::Priority::LOW, false);
270
Zane Shelleycb766a42022-01-12 17:50:23 -0600271 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
Zane Shelley4757a7b2021-09-20 22:23:38 -0500272 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelley82be3ab2021-12-07 10:36:08 -0600273 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
Zane Shelley4757a7b2021-09-20 22:23:38 -0500274
275 nlohmann::json j{};
276 std::string s{};
277
278 c1->resolve(sd);
279 c2->resolve(sd);
280 c3->resolve(sd);
281
282 // Callout list
283 j = sd.getCalloutList();
284 s = R"([
285 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500286 "Deconfigured": false,
Zane Shelleycb766a42022-01-12 17:50:23 -0600287 "EntityPath": [],
288 "GuardType": "GARD_Unrecoverable",
Zane Shelley9a738f72021-11-03 20:45:30 -0500289 "Guarded": true,
Zane Shelleycb766a42022-01-12 17:50:23 -0600290 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
Zane Shelley4757a7b2021-09-20 22:23:38 -0500291 "Priority": "A"
292 },
293 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500294 "Deconfigured": false,
Zane Shelleycb766a42022-01-12 17:50:23 -0600295 "EntityPath": [],
296 "GuardType": "GARD_Unrecoverable",
Zane Shelley9a738f72021-11-03 20:45:30 -0500297 "Guarded": true,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500298 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
299 "Priority": "A"
300 },
301 {
Zane Shelley1eff9452021-11-03 13:59:54 -0500302 "Deconfigured": false,
303 "Guarded": false,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500304 "LocationCode": "P0",
305 "Priority": "L"
306 }
307])";
308 EXPECT_EQ(s, j.dump(4));
309
310 // Callout FFDC
311 j = sd.getCalloutFFDC();
312 s = R"([
313 {
314 "Callout Type": "Hardware Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500315 "Guard": true,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500316 "Priority": "medium_group_A",
317 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0"
318 },
319 {
320 "Bus Type": "OMI_BUS",
321 "Callout Type": "Connected Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500322 "Guard": true,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500323 "Priority": "medium_group_A",
324 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
325 },
326 {
327 "Bus Type": "OMI_BUS",
328 "Callout Type": "Bus Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500329 "Guard": false,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500330 "Priority": "low",
331 "RX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
332 "TX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
333 }
334])";
335 EXPECT_EQ(s, j.dump(4));
336}
337
Zane Shelley96d54862021-09-17 11:16:12 -0500338TEST(Resolution, ClockCallout)
339{
Zane Shelleycb766a42022-01-12 17:50:23 -0600340 pdbg_targets_init(nullptr);
341
Zane Shelley96d54862021-09-17 11:16:12 -0500342 auto c1 = std::make_shared<ClockCalloutResolution>(
343 callout::ClockType::OSC_REF_CLOCK_1, callout::Priority::HIGH, false);
344
Zane Shelleycb766a42022-01-12 17:50:23 -0600345 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
Zane Shelley96d54862021-09-17 11:16:12 -0500346 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelley82be3ab2021-12-07 10:36:08 -0600347 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
Zane Shelley96d54862021-09-17 11:16:12 -0500348
349 c1->resolve(sd);
350
351 nlohmann::json j{};
352 std::string s{};
353
354 // Callout list
355 j = sd.getCalloutList();
356 s = R"([
357 {
Zane Shelley1eff9452021-11-03 13:59:54 -0500358 "Deconfigured": false,
359 "Guarded": false,
Zane Shelley96d54862021-09-17 11:16:12 -0500360 "LocationCode": "P0",
361 "Priority": "H"
362 }
363])";
364 EXPECT_EQ(s, j.dump(4));
365
366 // Callout FFDC
367 j = sd.getCalloutFFDC();
368 s = R"([
369 {
370 "Callout Type": "Clock Callout",
371 "Clock Type": "OSC_REF_CLOCK_1",
Zane Shelley1eff9452021-11-03 13:59:54 -0500372 "Priority": "high"
Zane Shelley96d54862021-09-17 11:16:12 -0500373 }
374])";
375 EXPECT_EQ(s, j.dump(4));
376}
377
378TEST(Resolution, ProcedureCallout)
379{
Zane Shelleycb766a42022-01-12 17:50:23 -0600380 pdbg_targets_init(nullptr);
381
Zane Shelley96d54862021-09-17 11:16:12 -0500382 auto c1 = std::make_shared<ProcedureCalloutResolution>(
383 callout::Procedure::NEXTLVL, callout::Priority::LOW);
384
Zane Shelleycb766a42022-01-12 17:50:23 -0600385 libhei::Chip chip{util::pdbg::getTrgt(chip_str), 0xdeadbeef};
Zane Shelley96d54862021-09-17 11:16:12 -0500386 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelley82be3ab2021-12-07 10:36:08 -0600387 ServiceData sd{sig, AnalysisType::SYSTEM_CHECKSTOP};
Zane Shelley96d54862021-09-17 11:16:12 -0500388
389 c1->resolve(sd);
390
391 nlohmann::json j{};
392 std::string s{};
393
394 // Callout list
395 j = sd.getCalloutList();
396 s = R"([
397 {
398 "Priority": "L",
Zane Shelley86ccc452021-11-16 13:10:52 -0600399 "Procedure": "next_level_support"
Zane Shelley96d54862021-09-17 11:16:12 -0500400 }
401])";
402 EXPECT_EQ(s, j.dump(4));
403
404 // Callout FFDC
405 j = sd.getCalloutFFDC();
406 s = R"([
407 {
408 "Callout Type": "Procedure Callout",
409 "Priority": "low",
Zane Shelley86ccc452021-11-16 13:10:52 -0600410 "Procedure": "next_level_support"
Zane Shelley96d54862021-09-17 11:16:12 -0500411 }
412])";
413 EXPECT_EQ(s, j.dump(4));
Zane Shelley0b8368c2021-03-18 17:33:41 -0500414}