blob: df82b4a80baf0e7ed5c5b4f3e2471989fa51ec5c [file] [log] [blame]
Zane Shelley0b8368c2021-03-18 17:33:41 -05001#include <stdio.h>
2
3#include <analyzer/resolution.hpp>
Zane Shelley5d63cef2021-09-17 18:10:17 -05004#include <util/trace.hpp>
5
6#include <regex>
Zane Shelley0b8368c2021-03-18 17:33:41 -05007
8#include "gtest/gtest.h"
9
10// Chip string
11constexpr auto chip_str = "/proc0";
12
13// Unit paths
Zane Shelley5d63cef2021-09-17 18:10:17 -050014constexpr auto proc_str = "";
15constexpr auto iolink_str = "pib/perv24/pauc0/iohs0/smpgroup0";
16constexpr auto omi_str = "pib/perv12/mc0/mi0/mcc0/omi0";
17constexpr auto ocmb_str = "pib/perv12/mc0/mi0/mcc0/omi0/ocmb0";
18constexpr auto core_str = "pib/perv39/eq7/fc1/core1";
Zane Shelley0b8368c2021-03-18 17:33:41 -050019
20// Local implementation of this function.
21namespace analyzer
22{
23
Zane Shelley84721d92021-09-08 13:30:27 -050024//------------------------------------------------------------------------------
25
Zane Shelley96d54862021-09-17 11:16:12 -050026// Helper function to get the root cause chip target path from the service data.
27std::string __getRootCauseChipPath(const ServiceData& i_sd)
28{
29 return std::string{(const char*)i_sd.getRootCause().getChip().getChip()};
30}
31
32//------------------------------------------------------------------------------
33
34// Helper function to get a unit target path from the given unit path, which is
35// a devtree path relative the the containing chip. An empty string indicates
36// the chip target path should be returned.
37std::string __getUnitPath(const std::string& i_chipPath,
38 const std::string& i_unitPath)
39{
40 auto path = i_chipPath; // default, if i_unitPath is empty
41
42 if (!i_unitPath.empty())
43 {
44 path += "/" + i_unitPath;
45 }
46
47 return path;
48}
49
50//------------------------------------------------------------------------------
51
Zane Shelley5d63cef2021-09-17 18:10:17 -050052// Helper function to get the connected target Path on the other side of the
53// given bus.
54std::tuple<std::string, std::string>
55 __getConnectedPath(const std::string& i_rxPath,
56 const callout::BusType& i_busType)
57{
58 std::string txUnitPath{};
59 std::string txChipPath{};
60
61 // Need to get the target type from the RX path.
62 const std::regex re{"(/proc0)(.*)/([a-z]+)([0-9]+)"};
63 std::smatch match;
64 std::regex_match(i_rxPath, match, re);
65 assert(5 == match.size());
66 std::string rxType = match[3].str();
67
68 if (callout::BusType::SMP_BUS == i_busType && "smpgroup" == rxType)
69 {
70 // Use the RX unit path on a different processor.
71 txUnitPath = "/proc1" + match[2].str() + "/" + rxType + match[4].str();
72 txChipPath = "/proc1";
73 }
74 else if (callout::BusType::OMI_BUS == i_busType && "omi" == rxType)
75 {
76 // Append the OCMB to the RX path.
77 txUnitPath = i_rxPath + "/ocmb0";
78 txChipPath = txUnitPath;
79 }
80 else if (callout::BusType::OMI_BUS == i_busType && "ocmb" == rxType)
81 {
82 // Strip the OCMB off of the RX path.
83 txUnitPath = match[1].str() + match[2].str();
84 txChipPath = "/proc0";
85 }
86 else
87 {
88 // This would be a code bug.
89 throw std::logic_error("Unsupported config: i_rxTarget=" + i_rxPath +
90 " i_busType=" + i_busType.getString());
91 }
92
93 assert(!txUnitPath.empty()); // just in case we missed something above
94
95 return std::make_tuple(txUnitPath, txChipPath);
96}
97
98//------------------------------------------------------------------------------
99
Zane Shelley9a738f72021-11-03 20:45:30 -0500100void __calloutTarget(ServiceData& io_sd, const std::string& i_locCode,
101 const callout::Priority& i_priority, bool i_guard)
102{
103 nlohmann::json callout;
104 callout["LocationCode"] = i_locCode;
105 callout["Priority"] = i_priority.getUserDataString();
106 callout["Deconfigured"] = false;
107 callout["Guarded"] = i_guard;
108 io_sd.addCallout(callout);
109}
110
111//------------------------------------------------------------------------------
112
Zane Shelley1eff9452021-11-03 13:59:54 -0500113void __calloutBackplane(ServiceData& io_sd, const callout::Priority& i_priority)
114{
115 // TODO: There isn't a device tree object for this. So will need to hardcode
116 // the location code for now. In the future, we will need a mechanism
117 // to make this data driven.
118
119 nlohmann::json callout;
120 callout["LocationCode"] = "P0";
121 callout["Priority"] = i_priority.getUserDataString();
122 callout["Deconfigured"] = false;
123 callout["Guarded"] = false;
124 io_sd.addCallout(callout);
125}
126
127//------------------------------------------------------------------------------
128
Zane Shelley0b8368c2021-03-18 17:33:41 -0500129void HardwareCalloutResolution::resolve(ServiceData& io_sd) const
130{
Zane Shelley96d54862021-09-17 11:16:12 -0500131 // Get the location code and entity path for this target.
132 auto locCode = __getRootCauseChipPath(io_sd);
133 auto entityPath = __getUnitPath(locCode, iv_unitPath);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500134
Zane Shelleyc85716c2021-08-17 10:54:06 -0500135 // Add the actual callout to the service data.
Zane Shelley9a738f72021-11-03 20:45:30 -0500136 __calloutTarget(io_sd, locCode, iv_priority, iv_guard);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500137
Zane Shelley96d54862021-09-17 11:16:12 -0500138 // Add the callout FFDC to the service data.
139 nlohmann::json ffdc;
140 ffdc["Callout Type"] = "Hardware Callout";
141 ffdc["Target"] = entityPath;
142 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelleya00426f2021-11-04 10:50:50 -0500143 ffdc["Guard"] = iv_guard;
Zane Shelley96d54862021-09-17 11:16:12 -0500144 io_sd.addCalloutFFDC(ffdc);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500145}
146
Zane Shelleyc85716c2021-08-17 10:54:06 -0500147//------------------------------------------------------------------------------
148
Zane Shelley5d63cef2021-09-17 18:10:17 -0500149void ConnectedCalloutResolution::resolve(ServiceData& io_sd) const
150{
151 // Get the chip target path from the root cause signature.
152 auto chipPath = __getRootCauseChipPath(io_sd);
153
154 // Get the endpoint target path for the receiving side of the bus.
155 auto rxPath = __getUnitPath(chipPath, iv_unitPath);
156
157 // Get the endpoint target path for the transfer side of the bus.
158 auto txPath = __getConnectedPath(rxPath, iv_busType);
159
160 // Callout the TX endpoint.
Zane Shelley9a738f72021-11-03 20:45:30 -0500161 __calloutTarget(io_sd, std::get<1>(txPath), iv_priority, iv_guard);
Zane Shelley5d63cef2021-09-17 18:10:17 -0500162
Zane Shelley5d63cef2021-09-17 18:10:17 -0500163 // Add the callout FFDC to the service data.
164 nlohmann::json ffdc;
165 ffdc["Callout Type"] = "Connected Callout";
166 ffdc["Bus Type"] = iv_busType.getString();
167 ffdc["Target"] = std::get<0>(txPath);
168 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelleya00426f2021-11-04 10:50:50 -0500169 ffdc["Guard"] = iv_guard;
Zane Shelley5d63cef2021-09-17 18:10:17 -0500170 io_sd.addCalloutFFDC(ffdc);
171}
172
173//------------------------------------------------------------------------------
174
Zane Shelley4757a7b2021-09-20 22:23:38 -0500175void BusCalloutResolution::resolve(ServiceData& io_sd) const
176{
177 // Get the chip target path from the root cause signature.
178 auto chipPath = __getRootCauseChipPath(io_sd);
179
180 // Get the endpoint target path for the receiving side of the bus.
181 auto rxPath = __getUnitPath(chipPath, iv_unitPath);
182
183 // Get the endpoint target path for the transfer side of the bus.
184 auto txPath = __getConnectedPath(rxPath, iv_busType);
185
186 // Callout the RX endpoint.
Zane Shelley9a738f72021-11-03 20:45:30 -0500187 __calloutTarget(io_sd, chipPath, iv_priority, iv_guard);
Zane Shelley4757a7b2021-09-20 22:23:38 -0500188
189 // Callout the TX endpoint.
Zane Shelley9a738f72021-11-03 20:45:30 -0500190 __calloutTarget(io_sd, std::get<1>(txPath), iv_priority, iv_guard);
Zane Shelley4757a7b2021-09-20 22:23:38 -0500191
192 // Callout everything else in between.
193 // TODO: For P10 (OMI bus and XBUS), the callout is simply the backplane.
Zane Shelley1eff9452021-11-03 13:59:54 -0500194 __calloutBackplane(io_sd, iv_priority);
Zane Shelley4757a7b2021-09-20 22:23:38 -0500195
Zane Shelley4757a7b2021-09-20 22:23:38 -0500196 // Add the callout FFDC to the service data.
197 nlohmann::json ffdc;
198 ffdc["Callout Type"] = "Bus Callout";
199 ffdc["Bus Type"] = iv_busType.getString();
200 ffdc["RX Target"] = rxPath;
201 ffdc["TX Target"] = std::get<0>(txPath);
202 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelleya00426f2021-11-04 10:50:50 -0500203 ffdc["Guard"] = iv_guard;
Zane Shelley4757a7b2021-09-20 22:23:38 -0500204 io_sd.addCalloutFFDC(ffdc);
205}
206
207//------------------------------------------------------------------------------
208
Zane Shelleyc85716c2021-08-17 10:54:06 -0500209void ProcedureCalloutResolution::resolve(ServiceData& io_sd) const
210{
211 // Add the actual callout to the service data.
212 nlohmann::json callout;
213 callout["Procedure"] = iv_procedure.getString();
214 callout["Priority"] = iv_priority.getUserDataString();
215 io_sd.addCallout(callout);
Zane Shelley96d54862021-09-17 11:16:12 -0500216
217 // Add the callout FFDC to the service data.
218 nlohmann::json ffdc;
219 ffdc["Callout Type"] = "Procedure Callout";
220 ffdc["Procedure"] = iv_procedure.getString();
221 ffdc["Priority"] = iv_priority.getRegistryString();
222 io_sd.addCalloutFFDC(ffdc);
Zane Shelleyc85716c2021-08-17 10:54:06 -0500223}
224
Zane Shelley84721d92021-09-08 13:30:27 -0500225//------------------------------------------------------------------------------
226
227void ClockCalloutResolution::resolve(ServiceData& io_sd) const
228{
Zane Shelley1eff9452021-11-03 13:59:54 -0500229 // Callout the clock target.
230 // TODO: For P10, the callout is simply the backplane. Also, there are no
231 // clock targets in the device tree. So at the moment there is no
232 // guard support for clock targets.
233 __calloutBackplane(io_sd, iv_priority);
Zane Shelley96d54862021-09-17 11:16:12 -0500234
235 // Add the callout FFDC to the service data.
Zane Shelley1eff9452021-11-03 13:59:54 -0500236 // TODO: Add the target and guard type if guard is ever supported.
Zane Shelley96d54862021-09-17 11:16:12 -0500237 nlohmann::json ffdc;
238 ffdc["Callout Type"] = "Clock Callout";
239 ffdc["Clock Type"] = iv_clockType.getString();
Zane Shelley96d54862021-09-17 11:16:12 -0500240 ffdc["Priority"] = iv_priority.getRegistryString();
Zane Shelley96d54862021-09-17 11:16:12 -0500241 io_sd.addCalloutFFDC(ffdc);
Zane Shelley84721d92021-09-08 13:30:27 -0500242}
243
244//------------------------------------------------------------------------------
245
Zane Shelley0b8368c2021-03-18 17:33:41 -0500246} // namespace analyzer
247
248using namespace analyzer;
249
250TEST(Resolution, TestSet1)
251{
252 // Create a few resolutions
253 auto c1 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -0500254 proc_str, callout::Priority::HIGH, false);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500255
256 auto c2 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -0500257 omi_str, callout::Priority::MED_A, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500258
259 auto c3 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -0500260 core_str, callout::Priority::MED, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500261
262 auto c4 = std::make_shared<ProcedureCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -0500263 callout::Procedure::NEXTLVL, callout::Priority::LOW);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500264
Zane Shelley84721d92021-09-08 13:30:27 -0500265 auto c5 = std::make_shared<ClockCalloutResolution>(
266 callout::ClockType::OSC_REF_CLOCK_1, callout::Priority::LOW, false);
267
268 // l1 = (c1, c2, c5)
Zane Shelley723fa232021-08-09 12:02:06 -0500269 auto l1 = std::make_shared<ResolutionList>();
270 l1->push(c1);
271 l1->push(c2);
Zane Shelley84721d92021-09-08 13:30:27 -0500272 l1->push(c5);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500273
Zane Shelley84721d92021-09-08 13:30:27 -0500274 // l2 = (c4, c3, c1, c2, c5)
Zane Shelley723fa232021-08-09 12:02:06 -0500275 auto l2 = std::make_shared<ResolutionList>();
276 l2->push(c4);
277 l2->push(c3);
278 l2->push(l1);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500279
280 // Get some ServiceData objects
281 libhei::Chip chip{chip_str, 0xdeadbeef};
282 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelleyca496192021-08-09 12:05:52 -0500283 ServiceData sd1{sig, true};
284 ServiceData sd2{sig, false};
Zane Shelley0b8368c2021-03-18 17:33:41 -0500285
286 // Resolve
Zane Shelley723fa232021-08-09 12:02:06 -0500287 l1->resolve(sd1);
288 l2->resolve(sd2);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500289
290 // Start verifying
291 nlohmann::json j{};
292 std::string s{};
293
Zane Shelleyc85716c2021-08-17 10:54:06 -0500294 j = sd1.getCalloutList();
Zane Shelley0b8368c2021-03-18 17:33:41 -0500295 s = R"([
296 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500297 "Deconfigured": false,
298 "Guarded": false,
Zane Shelley0b8368c2021-03-18 17:33:41 -0500299 "LocationCode": "/proc0",
300 "Priority": "H"
301 },
302 {
Zane Shelley1eff9452021-11-03 13:59:54 -0500303 "Deconfigured": false,
304 "Guarded": false,
Zane Shelley84721d92021-09-08 13:30:27 -0500305 "LocationCode": "P0",
306 "Priority": "L"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500307 }
308])";
Zane Shelley96d54862021-09-17 11:16:12 -0500309 EXPECT_EQ(s, j.dump(4));
Zane Shelley0b8368c2021-03-18 17:33:41 -0500310
Zane Shelleyc85716c2021-08-17 10:54:06 -0500311 j = sd2.getCalloutList();
Zane Shelley0b8368c2021-03-18 17:33:41 -0500312 s = R"([
313 {
314 "Priority": "L",
315 "Procedure": "NEXTLVL"
316 },
317 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500318 "Deconfigured": false,
319 "Guarded": true,
Zane Shelley0b8368c2021-03-18 17:33:41 -0500320 "LocationCode": "/proc0",
Zane Shelley0b8368c2021-03-18 17:33:41 -0500321 "Priority": "H"
322 },
323 {
Zane Shelley1eff9452021-11-03 13:59:54 -0500324 "Deconfigured": false,
325 "Guarded": false,
Zane Shelley84721d92021-09-08 13:30:27 -0500326 "LocationCode": "P0",
327 "Priority": "L"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500328 }
329])";
Zane Shelley96d54862021-09-17 11:16:12 -0500330 EXPECT_EQ(s, j.dump(4));
331}
332
333TEST(Resolution, HardwareCallout)
334{
335 auto c1 = std::make_shared<HardwareCalloutResolution>(
336 omi_str, callout::Priority::MED_A, true);
337
338 libhei::Chip chip{chip_str, 0xdeadbeef};
339 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
340 ServiceData sd{sig, true};
341
342 c1->resolve(sd);
343
344 nlohmann::json j{};
345 std::string s{};
346
347 // Callout list
348 j = sd.getCalloutList();
349 s = R"([
350 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500351 "Deconfigured": false,
352 "Guarded": true,
Zane Shelley96d54862021-09-17 11:16:12 -0500353 "LocationCode": "/proc0",
354 "Priority": "A"
355 }
356])";
357 EXPECT_EQ(s, j.dump(4));
358
359 // Callout FFDC
360 j = sd.getCalloutFFDC();
361 s = R"([
362 {
363 "Callout Type": "Hardware Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500364 "Guard": true,
Zane Shelley96d54862021-09-17 11:16:12 -0500365 "Priority": "medium_group_A",
366 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0"
367 }
368])";
369 EXPECT_EQ(s, j.dump(4));
370}
371
Zane Shelley5d63cef2021-09-17 18:10:17 -0500372TEST(Resolution, ConnectedCallout)
373{
374 auto c1 = std::make_shared<ConnectedCalloutResolution>(
375 callout::BusType::SMP_BUS, iolink_str, callout::Priority::MED_A, true);
376
377 auto c2 = std::make_shared<ConnectedCalloutResolution>(
378 callout::BusType::OMI_BUS, ocmb_str, callout::Priority::MED_B, true);
379
380 auto c3 = std::make_shared<ConnectedCalloutResolution>(
381 callout::BusType::OMI_BUS, omi_str, callout::Priority::MED_C, true);
382
383 libhei::Chip chip{chip_str, 0xdeadbeef};
384 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
385 ServiceData sd{sig, true};
386
387 nlohmann::json j{};
388 std::string s{};
389
390 c1->resolve(sd);
391 c2->resolve(sd);
392 c3->resolve(sd);
393
394 // Callout list
395 j = sd.getCalloutList();
396 s = R"([
397 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500398 "Deconfigured": false,
399 "Guarded": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500400 "LocationCode": "/proc1",
401 "Priority": "A"
402 },
403 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500404 "Deconfigured": false,
405 "Guarded": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500406 "LocationCode": "/proc0",
407 "Priority": "B"
408 },
409 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500410 "Deconfigured": false,
411 "Guarded": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500412 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
413 "Priority": "C"
414 }
415])";
416 EXPECT_EQ(s, j.dump(4));
417
418 // Callout FFDC
419 j = sd.getCalloutFFDC();
420 s = R"([
421 {
422 "Bus Type": "SMP_BUS",
423 "Callout Type": "Connected Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500424 "Guard": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500425 "Priority": "medium_group_A",
426 "Target": "/proc1/pib/perv24/pauc0/iohs0/smpgroup0"
427 },
428 {
429 "Bus Type": "OMI_BUS",
430 "Callout Type": "Connected Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500431 "Guard": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500432 "Priority": "medium_group_B",
433 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0"
434 },
435 {
436 "Bus Type": "OMI_BUS",
437 "Callout Type": "Connected Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500438 "Guard": true,
Zane Shelley5d63cef2021-09-17 18:10:17 -0500439 "Priority": "medium_group_C",
440 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
441 }
442])";
443 EXPECT_EQ(s, j.dump(4));
444}
445
Zane Shelley4757a7b2021-09-20 22:23:38 -0500446TEST(Resolution, BusCallout)
447{
448 auto c1 = std::make_shared<HardwareCalloutResolution>(
449 omi_str, callout::Priority::MED_A, true);
450
451 auto c2 = std::make_shared<ConnectedCalloutResolution>(
452 callout::BusType::OMI_BUS, omi_str, callout::Priority::MED_A, true);
453
454 auto c3 = std::make_shared<BusCalloutResolution>(
455 callout::BusType::OMI_BUS, omi_str, callout::Priority::LOW, false);
456
457 libhei::Chip chip{chip_str, 0xdeadbeef};
458 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
459 ServiceData sd{sig, true};
460
461 nlohmann::json j{};
462 std::string s{};
463
464 c1->resolve(sd);
465 c2->resolve(sd);
466 c3->resolve(sd);
467
468 // Callout list
469 j = sd.getCalloutList();
470 s = R"([
471 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500472 "Deconfigured": false,
473 "Guarded": true,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500474 "LocationCode": "/proc0",
475 "Priority": "A"
476 },
477 {
Zane Shelley9a738f72021-11-03 20:45:30 -0500478 "Deconfigured": false,
479 "Guarded": true,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500480 "LocationCode": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0",
481 "Priority": "A"
482 },
483 {
Zane Shelley1eff9452021-11-03 13:59:54 -0500484 "Deconfigured": false,
485 "Guarded": false,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500486 "LocationCode": "P0",
487 "Priority": "L"
488 }
489])";
490 EXPECT_EQ(s, j.dump(4));
491
492 // Callout FFDC
493 j = sd.getCalloutFFDC();
494 s = R"([
495 {
496 "Callout Type": "Hardware Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500497 "Guard": true,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500498 "Priority": "medium_group_A",
499 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0"
500 },
501 {
502 "Bus Type": "OMI_BUS",
503 "Callout Type": "Connected Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500504 "Guard": true,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500505 "Priority": "medium_group_A",
506 "Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
507 },
508 {
509 "Bus Type": "OMI_BUS",
510 "Callout Type": "Bus Callout",
Zane Shelleya00426f2021-11-04 10:50:50 -0500511 "Guard": false,
Zane Shelley4757a7b2021-09-20 22:23:38 -0500512 "Priority": "low",
513 "RX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
514 "TX Target": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0"
515 }
516])";
517 EXPECT_EQ(s, j.dump(4));
518}
519
Zane Shelley96d54862021-09-17 11:16:12 -0500520TEST(Resolution, ClockCallout)
521{
522 auto c1 = std::make_shared<ClockCalloutResolution>(
523 callout::ClockType::OSC_REF_CLOCK_1, callout::Priority::HIGH, false);
524
525 libhei::Chip chip{chip_str, 0xdeadbeef};
526 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
527 ServiceData sd{sig, true};
528
529 c1->resolve(sd);
530
531 nlohmann::json j{};
532 std::string s{};
533
534 // Callout list
535 j = sd.getCalloutList();
536 s = R"([
537 {
Zane Shelley1eff9452021-11-03 13:59:54 -0500538 "Deconfigured": false,
539 "Guarded": false,
Zane Shelley96d54862021-09-17 11:16:12 -0500540 "LocationCode": "P0",
541 "Priority": "H"
542 }
543])";
544 EXPECT_EQ(s, j.dump(4));
545
546 // Callout FFDC
547 j = sd.getCalloutFFDC();
548 s = R"([
549 {
550 "Callout Type": "Clock Callout",
551 "Clock Type": "OSC_REF_CLOCK_1",
Zane Shelley1eff9452021-11-03 13:59:54 -0500552 "Priority": "high"
Zane Shelley96d54862021-09-17 11:16:12 -0500553 }
554])";
555 EXPECT_EQ(s, j.dump(4));
556}
557
558TEST(Resolution, ProcedureCallout)
559{
560 auto c1 = std::make_shared<ProcedureCalloutResolution>(
561 callout::Procedure::NEXTLVL, callout::Priority::LOW);
562
563 libhei::Chip chip{chip_str, 0xdeadbeef};
564 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
565 ServiceData sd{sig, true};
566
567 c1->resolve(sd);
568
569 nlohmann::json j{};
570 std::string s{};
571
572 // Callout list
573 j = sd.getCalloutList();
574 s = R"([
575 {
576 "Priority": "L",
577 "Procedure": "NEXTLVL"
578 }
579])";
580 EXPECT_EQ(s, j.dump(4));
581
582 // Callout FFDC
583 j = sd.getCalloutFFDC();
584 s = R"([
585 {
586 "Callout Type": "Procedure Callout",
587 "Priority": "low",
588 "Procedure": "NEXTLVL"
589 }
590])";
591 EXPECT_EQ(s, j.dump(4));
Zane Shelley0b8368c2021-03-18 17:33:41 -0500592}