blob: 13c296a81dd4be93b21fdac9cf988074322949a6 [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
19void HardwareCalloutResolution::resolve(ServiceData& io_sd) const
20{
21 auto sig = io_sd.getRootCause();
22
23 std::string fru{(const char*)sig.getChip().getChip()};
Zane Shelley2f921302021-08-09 13:23:25 -050024 std::string path{fru};
Zane Shelley0b8368c2021-03-18 17:33:41 -050025 if (!iv_path.empty())
26 {
Zane Shelley2f921302021-08-09 13:23:25 -050027 path += "/" + iv_path;
Zane Shelley0b8368c2021-03-18 17:33:41 -050028 }
29
Zane Shelleyc85716c2021-08-17 10:54:06 -050030 // Add the actual callout to the service data.
31 nlohmann::json callout;
32 callout["LocationCode"] = fru;
33 callout["Priority"] = iv_priority.getUserDataString();
34 io_sd.addCallout(callout);
Zane Shelley0b8368c2021-03-18 17:33:41 -050035
Zane Shelley2f921302021-08-09 13:23:25 -050036 Guard::Type guard = Guard::NONE;
37 if (iv_guard)
38 {
39 guard = io_sd.queryCheckstop() ? Guard::FATAL : Guard::NON_FATAL;
40 }
41
42 io_sd.addGuard(std::make_shared<Guard>(path, guard));
Zane Shelley0b8368c2021-03-18 17:33:41 -050043}
44
Zane Shelleyc85716c2021-08-17 10:54:06 -050045//------------------------------------------------------------------------------
46
47void ProcedureCalloutResolution::resolve(ServiceData& io_sd) const
48{
49 // Add the actual callout to the service data.
50 nlohmann::json callout;
51 callout["Procedure"] = iv_procedure.getString();
52 callout["Priority"] = iv_priority.getUserDataString();
53 io_sd.addCallout(callout);
54}
55
Zane Shelley0b8368c2021-03-18 17:33:41 -050056} // namespace analyzer
57
58using namespace analyzer;
59
60TEST(Resolution, TestSet1)
61{
62 // Create a few resolutions
63 auto c1 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050064 proc_str, callout::Priority::HIGH, false);
Zane Shelley0b8368c2021-03-18 17:33:41 -050065
66 auto c2 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050067 omi_str, callout::Priority::MED_A, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -050068
69 auto c3 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050070 core_str, callout::Priority::MED, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -050071
72 auto c4 = std::make_shared<ProcedureCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050073 callout::Procedure::NEXTLVL, callout::Priority::LOW);
Zane Shelley0b8368c2021-03-18 17:33:41 -050074
Zane Shelley723fa232021-08-09 12:02:06 -050075 // l1 = (c1, c2)
76 auto l1 = std::make_shared<ResolutionList>();
77 l1->push(c1);
78 l1->push(c2);
Zane Shelley0b8368c2021-03-18 17:33:41 -050079
Zane Shelley723fa232021-08-09 12:02:06 -050080 // l2 = (c4, c3, c1, c2)
81 auto l2 = std::make_shared<ResolutionList>();
82 l2->push(c4);
83 l2->push(c3);
84 l2->push(l1);
Zane Shelley0b8368c2021-03-18 17:33:41 -050085
86 // Get some ServiceData objects
87 libhei::Chip chip{chip_str, 0xdeadbeef};
88 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelleyca496192021-08-09 12:05:52 -050089 ServiceData sd1{sig, true};
90 ServiceData sd2{sig, false};
Zane Shelley0b8368c2021-03-18 17:33:41 -050091
92 // Resolve
Zane Shelley723fa232021-08-09 12:02:06 -050093 l1->resolve(sd1);
94 l2->resolve(sd2);
Zane Shelley0b8368c2021-03-18 17:33:41 -050095
96 // Start verifying
97 nlohmann::json j{};
98 std::string s{};
99
Zane Shelleyc85716c2021-08-17 10:54:06 -0500100 j = sd1.getCalloutList();
Zane Shelley0b8368c2021-03-18 17:33:41 -0500101 s = R"([
102 {
103 "LocationCode": "/proc0",
104 "Priority": "H"
105 },
106 {
107 "LocationCode": "/proc0",
108 "Priority": "A"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500109 }
110])";
111 ASSERT_EQ(s, j.dump(4));
112
113 sd1.getGuardList(j);
114 s = R"([
115 {
116 "Path": "/proc0",
117 "Type": "NONE"
118 },
119 {
120 "Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
121 "Type": "FATAL"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500122 }
123])";
124 ASSERT_EQ(s, j.dump(4));
125
Zane Shelleyc85716c2021-08-17 10:54:06 -0500126 j = sd2.getCalloutList();
Zane Shelley0b8368c2021-03-18 17:33:41 -0500127 s = R"([
128 {
129 "Priority": "L",
130 "Procedure": "NEXTLVL"
131 },
132 {
133 "LocationCode": "/proc0",
134 "Priority": "M"
135 },
136 {
137 "LocationCode": "/proc0",
138 "Priority": "H"
139 },
140 {
141 "LocationCode": "/proc0",
142 "Priority": "A"
143 }
144])";
145 ASSERT_EQ(s, j.dump(4));
146
147 sd2.getGuardList(j);
148 s = R"([
149 {
150 "Path": "/proc0/pib/perv39/eq7/fc1/core1",
151 "Type": "NON_FATAL"
152 },
153 {
154 "Path": "/proc0",
155 "Type": "NONE"
156 },
157 {
158 "Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
Zane Shelley2f921302021-08-09 13:23:25 -0500159 "Type": "NON_FATAL"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500160 }
161])";
162 ASSERT_EQ(s, j.dump(4));
163}