blob: 7cf95dd4030df8e993e958811f899ac3ac9f90b8 [file] [log] [blame]
Zane Shelley0b8368c2021-03-18 17:33:41 -05001#include <stdio.h>
2
3#include <analyzer/resolution.hpp>
4
5#include "gtest/gtest.h"
6
7// Chip string
8constexpr auto chip_str = "/proc0";
9
10// Unit paths
11constexpr auto proc_str = "";
12constexpr auto omi_str = "pib/perv12/mc0/mi0/mcc0/omi0";
13constexpr auto core_str = "pib/perv39/eq7/fc1/core1";
14
15// Local implementation of this function.
16namespace analyzer
17{
18
Zane Shelley84721d92021-09-08 13:30:27 -050019//------------------------------------------------------------------------------
20
Zane Shelley0b8368c2021-03-18 17:33:41 -050021void HardwareCalloutResolution::resolve(ServiceData& io_sd) const
22{
23 auto sig = io_sd.getRootCause();
24
25 std::string fru{(const char*)sig.getChip().getChip()};
Zane Shelley2f921302021-08-09 13:23:25 -050026 std::string path{fru};
Zane Shelley0b8368c2021-03-18 17:33:41 -050027 if (!iv_path.empty())
28 {
Zane Shelley2f921302021-08-09 13:23:25 -050029 path += "/" + iv_path;
Zane Shelley0b8368c2021-03-18 17:33:41 -050030 }
31
Zane Shelleyc85716c2021-08-17 10:54:06 -050032 // Add the actual callout to the service data.
33 nlohmann::json callout;
34 callout["LocationCode"] = fru;
35 callout["Priority"] = iv_priority.getUserDataString();
36 io_sd.addCallout(callout);
Zane Shelley0b8368c2021-03-18 17:33:41 -050037
Zane Shelley95135822021-08-23 09:00:05 -050038 // Add the guard info to the service data.
39 io_sd.addGuard(path, iv_guard);
Zane Shelley0b8368c2021-03-18 17:33:41 -050040}
41
Zane Shelleyc85716c2021-08-17 10:54:06 -050042//------------------------------------------------------------------------------
43
44void ProcedureCalloutResolution::resolve(ServiceData& io_sd) const
45{
46 // Add the actual callout to the service data.
47 nlohmann::json callout;
48 callout["Procedure"] = iv_procedure.getString();
49 callout["Priority"] = iv_priority.getUserDataString();
50 io_sd.addCallout(callout);
51}
52
Zane Shelley84721d92021-09-08 13:30:27 -050053//------------------------------------------------------------------------------
54
55void ClockCalloutResolution::resolve(ServiceData& io_sd) const
56{
57 auto sig = io_sd.getRootCause();
58
59 std::string fru{"P0"};
60 std::string path{(const char*)sig.getChip().getChip()};
61
62 // Add the actual callout to the service data.
63 nlohmann::json callout;
64 callout["LocationCode"] = fru;
65 callout["Priority"] = iv_priority.getUserDataString();
66 io_sd.addCallout(callout);
67
68 // Add the guard info to the service data.
69 io_sd.addGuard(path, iv_guard);
70}
71
72//------------------------------------------------------------------------------
73
Zane Shelley0b8368c2021-03-18 17:33:41 -050074} // namespace analyzer
75
76using namespace analyzer;
77
78TEST(Resolution, TestSet1)
79{
80 // Create a few resolutions
81 auto c1 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050082 proc_str, callout::Priority::HIGH, false);
Zane Shelley0b8368c2021-03-18 17:33:41 -050083
84 auto c2 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050085 omi_str, callout::Priority::MED_A, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -050086
87 auto c3 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050088 core_str, callout::Priority::MED, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -050089
90 auto c4 = std::make_shared<ProcedureCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050091 callout::Procedure::NEXTLVL, callout::Priority::LOW);
Zane Shelley0b8368c2021-03-18 17:33:41 -050092
Zane Shelley84721d92021-09-08 13:30:27 -050093 auto c5 = std::make_shared<ClockCalloutResolution>(
94 callout::ClockType::OSC_REF_CLOCK_1, callout::Priority::LOW, false);
95
96 // l1 = (c1, c2, c5)
Zane Shelley723fa232021-08-09 12:02:06 -050097 auto l1 = std::make_shared<ResolutionList>();
98 l1->push(c1);
99 l1->push(c2);
Zane Shelley84721d92021-09-08 13:30:27 -0500100 l1->push(c5);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500101
Zane Shelley84721d92021-09-08 13:30:27 -0500102 // l2 = (c4, c3, c1, c2, c5)
Zane Shelley723fa232021-08-09 12:02:06 -0500103 auto l2 = std::make_shared<ResolutionList>();
104 l2->push(c4);
105 l2->push(c3);
106 l2->push(l1);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500107
108 // Get some ServiceData objects
109 libhei::Chip chip{chip_str, 0xdeadbeef};
110 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelleyca496192021-08-09 12:05:52 -0500111 ServiceData sd1{sig, true};
112 ServiceData sd2{sig, false};
Zane Shelley0b8368c2021-03-18 17:33:41 -0500113
114 // Resolve
Zane Shelley723fa232021-08-09 12:02:06 -0500115 l1->resolve(sd1);
116 l2->resolve(sd2);
Zane Shelley0b8368c2021-03-18 17:33:41 -0500117
118 // Start verifying
119 nlohmann::json j{};
120 std::string s{};
121
Zane Shelleyc85716c2021-08-17 10:54:06 -0500122 j = sd1.getCalloutList();
Zane Shelley0b8368c2021-03-18 17:33:41 -0500123 s = R"([
124 {
125 "LocationCode": "/proc0",
126 "Priority": "H"
127 },
128 {
129 "LocationCode": "/proc0",
130 "Priority": "A"
Zane Shelley84721d92021-09-08 13:30:27 -0500131 },
132 {
133 "LocationCode": "P0",
134 "Priority": "L"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500135 }
136])";
137 ASSERT_EQ(s, j.dump(4));
138
Zane Shelleyc85716c2021-08-17 10:54:06 -0500139 j = sd2.getCalloutList();
Zane Shelley0b8368c2021-03-18 17:33:41 -0500140 s = R"([
141 {
142 "Priority": "L",
143 "Procedure": "NEXTLVL"
144 },
145 {
146 "LocationCode": "/proc0",
147 "Priority": "M"
148 },
149 {
150 "LocationCode": "/proc0",
151 "Priority": "H"
152 },
153 {
154 "LocationCode": "/proc0",
155 "Priority": "A"
Zane Shelley84721d92021-09-08 13:30:27 -0500156 },
157 {
158 "LocationCode": "P0",
159 "Priority": "L"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500160 }
161])";
162 ASSERT_EQ(s, j.dump(4));
Zane Shelley0b8368c2021-03-18 17:33:41 -0500163}