blob: 61e0b35d8ec76c6fee07324eb3ff585744ff4d96 [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()};
24 std::string guard{fru};
25 if (!iv_path.empty())
26 {
27 guard += "/" + iv_path;
28 }
29
30 io_sd.addCallout(std::make_shared<HardwareCallout>(fru, iv_priority));
31
32 io_sd.addGuard(std::make_shared<Guard>(guard, iv_guard));
33}
34
35} // namespace analyzer
36
37using namespace analyzer;
38
39TEST(Resolution, TestSet1)
40{
41 // Create a few resolutions
42 auto c1 = std::make_shared<HardwareCalloutResolution>(
43 proc_str, Callout::Priority::HIGH, Guard::NONE);
44
45 auto c2 = std::make_shared<HardwareCalloutResolution>(
46 omi_str, Callout::Priority::MED_A, Guard::FATAL);
47
48 auto c3 = std::make_shared<HardwareCalloutResolution>(
49 core_str, Callout::Priority::MED, Guard::NON_FATAL);
50
51 auto c4 = std::make_shared<ProcedureCalloutResolution>(
52 ProcedureCallout::NEXTLVL, Callout::Priority::LOW);
53
54 // l3 = (c1, c2, c3, c4)
55 auto l1 = std::make_shared<LinkResolution>(c1, c2);
56 auto l2 = std::make_shared<LinkResolution>(l1, c3);
57 auto l3 = std::make_shared<LinkResolution>(l2, c4);
58
59 // l5 = (c4, c3, c1, c2)
60 auto l4 = std::make_shared<LinkResolution>(c3, l1);
61 auto l5 = std::make_shared<LinkResolution>(c4, l4);
62
63 // Get some ServiceData objects
64 libhei::Chip chip{chip_str, 0xdeadbeef};
65 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
66 ServiceData sd1{sig};
67 ServiceData sd2{sig};
68
69 // Resolve
70 l3->resolve(sd1);
71 l5->resolve(sd2);
72
73 // Start verifying
74 nlohmann::json j{};
75 std::string s{};
76
77 sd1.getCalloutList(j);
78 s = R"([
79 {
80 "LocationCode": "/proc0",
81 "Priority": "H"
82 },
83 {
84 "LocationCode": "/proc0",
85 "Priority": "A"
86 },
87 {
88 "LocationCode": "/proc0",
89 "Priority": "M"
90 },
91 {
92 "Priority": "L",
93 "Procedure": "NEXTLVL"
94 }
95])";
96 ASSERT_EQ(s, j.dump(4));
97
98 sd1.getGuardList(j);
99 s = R"([
100 {
101 "Path": "/proc0",
102 "Type": "NONE"
103 },
104 {
105 "Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
106 "Type": "FATAL"
107 },
108 {
109 "Path": "/proc0/pib/perv39/eq7/fc1/core1",
110 "Type": "NON_FATAL"
111 }
112])";
113 ASSERT_EQ(s, j.dump(4));
114
115 sd2.getCalloutList(j);
116 s = R"([
117 {
118 "Priority": "L",
119 "Procedure": "NEXTLVL"
120 },
121 {
122 "LocationCode": "/proc0",
123 "Priority": "M"
124 },
125 {
126 "LocationCode": "/proc0",
127 "Priority": "H"
128 },
129 {
130 "LocationCode": "/proc0",
131 "Priority": "A"
132 }
133])";
134 ASSERT_EQ(s, j.dump(4));
135
136 sd2.getGuardList(j);
137 s = R"([
138 {
139 "Path": "/proc0/pib/perv39/eq7/fc1/core1",
140 "Type": "NON_FATAL"
141 },
142 {
143 "Path": "/proc0",
144 "Type": "NONE"
145 },
146 {
147 "Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
148 "Type": "FATAL"
149 }
150])";
151 ASSERT_EQ(s, j.dump(4));
152}