blob: e8b3f71c9919e57f7e1f38f1dc12901258b7d50b [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
30 io_sd.addCallout(std::make_shared<HardwareCallout>(fru, iv_priority));
31
Zane Shelley2f921302021-08-09 13:23:25 -050032 Guard::Type guard = Guard::NONE;
33 if (iv_guard)
34 {
35 guard = io_sd.queryCheckstop() ? Guard::FATAL : Guard::NON_FATAL;
36 }
37
38 io_sd.addGuard(std::make_shared<Guard>(path, guard));
Zane Shelley0b8368c2021-03-18 17:33:41 -050039}
40
41} // namespace analyzer
42
43using namespace analyzer;
44
45TEST(Resolution, TestSet1)
46{
47 // Create a few resolutions
48 auto c1 = std::make_shared<HardwareCalloutResolution>(
Zane Shelley2f921302021-08-09 13:23:25 -050049 proc_str, Callout::Priority::HIGH, false);
Zane Shelley0b8368c2021-03-18 17:33:41 -050050
51 auto c2 = std::make_shared<HardwareCalloutResolution>(
Zane Shelley2f921302021-08-09 13:23:25 -050052 omi_str, Callout::Priority::MED_A, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -050053
54 auto c3 = std::make_shared<HardwareCalloutResolution>(
Zane Shelley2f921302021-08-09 13:23:25 -050055 core_str, Callout::Priority::MED, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -050056
57 auto c4 = std::make_shared<ProcedureCalloutResolution>(
58 ProcedureCallout::NEXTLVL, Callout::Priority::LOW);
59
Zane Shelley723fa232021-08-09 12:02:06 -050060 // l1 = (c1, c2)
61 auto l1 = std::make_shared<ResolutionList>();
62 l1->push(c1);
63 l1->push(c2);
Zane Shelley0b8368c2021-03-18 17:33:41 -050064
Zane Shelley723fa232021-08-09 12:02:06 -050065 // l2 = (c4, c3, c1, c2)
66 auto l2 = std::make_shared<ResolutionList>();
67 l2->push(c4);
68 l2->push(c3);
69 l2->push(l1);
Zane Shelley0b8368c2021-03-18 17:33:41 -050070
71 // Get some ServiceData objects
72 libhei::Chip chip{chip_str, 0xdeadbeef};
73 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelleyca496192021-08-09 12:05:52 -050074 ServiceData sd1{sig, true};
75 ServiceData sd2{sig, false};
Zane Shelley0b8368c2021-03-18 17:33:41 -050076
77 // Resolve
Zane Shelley723fa232021-08-09 12:02:06 -050078 l1->resolve(sd1);
79 l2->resolve(sd2);
Zane Shelley0b8368c2021-03-18 17:33:41 -050080
81 // Start verifying
82 nlohmann::json j{};
83 std::string s{};
84
85 sd1.getCalloutList(j);
86 s = R"([
87 {
88 "LocationCode": "/proc0",
89 "Priority": "H"
90 },
91 {
92 "LocationCode": "/proc0",
93 "Priority": "A"
Zane Shelley0b8368c2021-03-18 17:33:41 -050094 }
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"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500107 }
108])";
109 ASSERT_EQ(s, j.dump(4));
110
111 sd2.getCalloutList(j);
112 s = R"([
113 {
114 "Priority": "L",
115 "Procedure": "NEXTLVL"
116 },
117 {
118 "LocationCode": "/proc0",
119 "Priority": "M"
120 },
121 {
122 "LocationCode": "/proc0",
123 "Priority": "H"
124 },
125 {
126 "LocationCode": "/proc0",
127 "Priority": "A"
128 }
129])";
130 ASSERT_EQ(s, j.dump(4));
131
132 sd2.getGuardList(j);
133 s = R"([
134 {
135 "Path": "/proc0/pib/perv39/eq7/fc1/core1",
136 "Type": "NON_FATAL"
137 },
138 {
139 "Path": "/proc0",
140 "Type": "NONE"
141 },
142 {
143 "Path": "/proc0/pib/perv12/mc0/mi0/mcc0/omi0",
Zane Shelley2f921302021-08-09 13:23:25 -0500144 "Type": "NON_FATAL"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500145 }
146])";
147 ASSERT_EQ(s, j.dump(4));
148}