1 #include <stdio.h>
2 
3 #include <analyzer/plugins/plugin.hpp>
4 #include <analyzer/util.hpp>
5 #include <util/pdbg.hpp>
6 #include <util/trace.hpp>
7 
8 #include "gtest/gtest.h"
9 
10 //------------------------------------------------------------------------------
11 
12 using namespace analyzer;
13 
14 extern bool g_lpcTimeout;
15 
16 // Test #1: - no LPC timeout
17 TEST(LpcTimeout, TestSet1)
18 {
19     pdbg_targets_init(nullptr);
20 
21     g_lpcTimeout = false; // no timeout
22 
23     libhei::Chip chip{util::pdbg::getTrgt("/proc0"), P10_20};
24 
25     auto plugin = PluginMap::getSingleton().get(chip.getType(), "lpc_timeout");
26 
27     ServiceData sd{libhei::Signature{}, AnalysisType::SYSTEM_CHECKSTOP,
28                    libhei::IsolationData{}};
29 
30     plugin(0, chip, sd);
31 
32     nlohmann::json j{};
33     std::string s{};
34 
35     // Callout list
36     j = sd.getCalloutList();
37     s = R"([
38     {
39         "Priority": "H",
40         "Procedure": "next_level_support"
41     }
42 ])";
43     EXPECT_EQ(s, j.dump(4));
44 
45     // Callout FFDC
46     j = sd.getCalloutFFDC();
47     s = R"([
48     {
49         "Callout Type": "Procedure Callout",
50         "Priority": "high",
51         "Procedure": "next_level_support"
52     }
53 ])";
54     EXPECT_EQ(s, j.dump(4));
55 }
56 
57 // Test #2: - LPC timeout
58 TEST(LpcTimeout, TestSet2)
59 {
60     pdbg_targets_init(nullptr);
61 
62     g_lpcTimeout = true; // force timeout
63 
64     libhei::Chip chip{util::pdbg::getTrgt("/proc0"), P10_20};
65 
66     auto plugin = PluginMap::getSingleton().get(chip.getType(), "lpc_timeout");
67 
68     ServiceData sd{libhei::Signature{}, AnalysisType::SYSTEM_CHECKSTOP,
69                    libhei::IsolationData{}};
70 
71     plugin(0, chip, sd);
72 
73     nlohmann::json j{};
74     std::string s{};
75 
76     // Callout list
77     j = sd.getCalloutList();
78     s = R"([
79     {
80         "Deconfigured": false,
81         "Guarded": false,
82         "LocationCode": "/bmc0",
83         "Priority": "M"
84     },
85     {
86         "Deconfigured": false,
87         "Guarded": false,
88         "LocationCode": "P0",
89         "Priority": "M"
90     },
91     {
92         "Deconfigured": false,
93         "Guarded": false,
94         "LocationCode": "/proc0",
95         "Priority": "M"
96     }
97 ])";
98     EXPECT_EQ(s, j.dump(4));
99 
100     // Callout FFDC
101     j = sd.getCalloutFFDC();
102     s = R"([
103     {
104         "Callout Type": "Part Callout",
105         "Part Type": "PNOR",
106         "Priority": "medium"
107     },
108     {
109         "Callout Type": "Clock Callout",
110         "Clock Type": "OSC_REF_CLOCK_0",
111         "Priority": "medium"
112     },
113     {
114         "Callout Type": "Hardware Callout",
115         "Guard": false,
116         "Priority": "medium",
117         "Target": "/proc0"
118     }
119 ])";
120     EXPECT_EQ(s, j.dump(4));
121 }
122