blob: 0f1dfcd48237b8b3d743eca863370fa90caf950e [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 Shelley95135822021-08-23 09:00:05 -050036 // Add the guard info to the service data.
37 io_sd.addGuard(path, iv_guard);
Zane Shelley0b8368c2021-03-18 17:33:41 -050038}
39
Zane Shelleyc85716c2021-08-17 10:54:06 -050040//------------------------------------------------------------------------------
41
42void ProcedureCalloutResolution::resolve(ServiceData& io_sd) const
43{
44 // Add the actual callout to the service data.
45 nlohmann::json callout;
46 callout["Procedure"] = iv_procedure.getString();
47 callout["Priority"] = iv_priority.getUserDataString();
48 io_sd.addCallout(callout);
49}
50
Zane Shelley0b8368c2021-03-18 17:33:41 -050051} // namespace analyzer
52
53using namespace analyzer;
54
55TEST(Resolution, TestSet1)
56{
57 // Create a few resolutions
58 auto c1 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050059 proc_str, callout::Priority::HIGH, false);
Zane Shelley0b8368c2021-03-18 17:33:41 -050060
61 auto c2 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050062 omi_str, callout::Priority::MED_A, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -050063
64 auto c3 = std::make_shared<HardwareCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050065 core_str, callout::Priority::MED, true);
Zane Shelley0b8368c2021-03-18 17:33:41 -050066
67 auto c4 = std::make_shared<ProcedureCalloutResolution>(
Zane Shelleyc85716c2021-08-17 10:54:06 -050068 callout::Procedure::NEXTLVL, callout::Priority::LOW);
Zane Shelley0b8368c2021-03-18 17:33:41 -050069
Zane Shelley723fa232021-08-09 12:02:06 -050070 // l1 = (c1, c2)
71 auto l1 = std::make_shared<ResolutionList>();
72 l1->push(c1);
73 l1->push(c2);
Zane Shelley0b8368c2021-03-18 17:33:41 -050074
Zane Shelley723fa232021-08-09 12:02:06 -050075 // l2 = (c4, c3, c1, c2)
76 auto l2 = std::make_shared<ResolutionList>();
77 l2->push(c4);
78 l2->push(c3);
79 l2->push(l1);
Zane Shelley0b8368c2021-03-18 17:33:41 -050080
81 // Get some ServiceData objects
82 libhei::Chip chip{chip_str, 0xdeadbeef};
83 libhei::Signature sig{chip, 0xabcd, 0, 0, libhei::ATTN_TYPE_CHECKSTOP};
Zane Shelleyca496192021-08-09 12:05:52 -050084 ServiceData sd1{sig, true};
85 ServiceData sd2{sig, false};
Zane Shelley0b8368c2021-03-18 17:33:41 -050086
87 // Resolve
Zane Shelley723fa232021-08-09 12:02:06 -050088 l1->resolve(sd1);
89 l2->resolve(sd2);
Zane Shelley0b8368c2021-03-18 17:33:41 -050090
91 // Start verifying
92 nlohmann::json j{};
93 std::string s{};
94
Zane Shelleyc85716c2021-08-17 10:54:06 -050095 j = sd1.getCalloutList();
Zane Shelley0b8368c2021-03-18 17:33:41 -050096 s = R"([
97 {
98 "LocationCode": "/proc0",
99 "Priority": "H"
100 },
101 {
102 "LocationCode": "/proc0",
103 "Priority": "A"
Zane Shelley0b8368c2021-03-18 17:33:41 -0500104 }
105])";
106 ASSERT_EQ(s, j.dump(4));
107
Zane Shelleyc85716c2021-08-17 10:54:06 -0500108 j = sd2.getCalloutList();
Zane Shelley0b8368c2021-03-18 17:33:41 -0500109 s = R"([
110 {
111 "Priority": "L",
112 "Procedure": "NEXTLVL"
113 },
114 {
115 "LocationCode": "/proc0",
116 "Priority": "M"
117 },
118 {
119 "LocationCode": "/proc0",
120 "Priority": "H"
121 },
122 {
123 "LocationCode": "/proc0",
124 "Priority": "A"
125 }
126])";
127 ASSERT_EQ(s, j.dump(4));
Zane Shelley0b8368c2021-03-18 17:33:41 -0500128}