1 #include <stdio.h>
2 
3 #include <analyzer/plugins/plugin.hpp>
4 #include <hei_util.hpp>
5 #include <test/sim-hw-access.hpp>
6 #include <util/pdbg.hpp>
7 #include <util/trace.hpp>
8 
9 #include "gtest/gtest.h"
10 
11 using namespace analyzer;
12 
13 static const auto nodeId =
14     static_cast<libhei::NodeId_t>(libhei::hash<libhei::NodeId_t>("TOD_ERROR"));
15 
16 TEST(TodStepCheckFault, MdmtFault)
17 {
18     pdbg_targets_init(nullptr);
19 
20     auto proc0 = util::pdbg::getTrgt("/proc0");
21     auto proc1 = util::pdbg::getTrgt("/proc1");
22 
23     libhei::Chip chip0{proc0, P10_20};
24     libhei::Chip chip1{proc1, P10_20};
25 
26     sim::ScomAccess& scom = sim::ScomAccess::getSingleton();
27     scom.flush();
28 
29     // TOD_ERROR[14]    = 0b1   step check on primary config master select 0
30     scom.add(proc0, 0x00040030, 0x0002000000000000); // TOD_ERROR
31 
32     // TOD_PSS_MSS_STATUS[0:2] = 0b000  primary config is active
33     // TOD_PSS_MSS_STATUS[12]  = 0b0    primary config master select 0
34     // TOD_PSS_MSS_STATUS[13]  = 0b1    primary config master TOD
35     // TOD_PSS_MSS_STATUS[14]  = 0b1    primary config master drawer
36     scom.add(proc0, 0x00040008, 0x0006000000000000);
37 
38     // TOD_ERROR[17]    = 0b1   internal step check
39     // TOD_ERROR[21]    = 0b1   step check on primary config slave select 1
40     scom.add(proc1, 0x00040030, 0x0000440000000000); // TOD_ERROR
41 
42     // TOD_PSS_MSS_STATUS[0:2] = 0b000  primary config is active
43     // TOD_PSS_MSS_STATUS[15]  = 0b1    primary config slave path select 1
44     scom.add(proc1, 0x00040008, 0x0001000000000000);
45 
46     // TOD_PRI_PORT_1_CTRL[0:2] = 0b001  IOHS 1
47     scom.add(proc1, 0x00040002, 0x2000000000000000);
48 
49     // TOD_ERROR(0)[14] step check error on master select 0
50     libhei::Signature sig0{chip0, nodeId, 0, 14, libhei::ATTN_TYPE_CHECKSTOP};
51 
52     // TOD_ERROR(0)[17] internal step check error
53     libhei::Signature sig1{chip1, nodeId, 0, 17, libhei::ATTN_TYPE_CHECKSTOP};
54 
55     // TOD_ERROR(0)[21] step check error on slave select 1
56     libhei::Signature sig2{chip1, nodeId, 0, 21, libhei::ATTN_TYPE_CHECKSTOP};
57 
58     libhei::IsolationData isoData{};
59     isoData.addSignature(sig0);
60     isoData.addSignature(sig1);
61     isoData.addSignature(sig2);
62     ServiceData sd{sig1, AnalysisType::SYSTEM_CHECKSTOP, isoData};
63 
64     // Call the plugin.
65     auto plugin =
66         PluginMap::getSingleton().get(chip1.getType(), "tod_step_check_fault");
67 
68     plugin(0, chip1, sd);
69 
70     nlohmann::json j{};
71     std::string s{};
72 
73     // Callout list
74     j = sd.getCalloutList();
75     s = R"([
76     {
77         "Deconfigured": false,
78         "Guarded": false,
79         "LocationCode": "P0",
80         "Priority": "M"
81     },
82     {
83         "Deconfigured": false,
84         "Guarded": false,
85         "LocationCode": "/proc0",
86         "Priority": "M"
87     }
88 ])";
89     EXPECT_EQ(s, j.dump(4));
90 
91     // Callout FFDC
92     j = sd.getCalloutFFDC();
93     s = R"([
94     {
95         "Callout Type": "Clock Callout",
96         "Clock Type": "TOD_CLOCK",
97         "Priority": "medium"
98     },
99     {
100         "Callout Type": "Hardware Callout",
101         "Guard": false,
102         "Priority": "medium",
103         "Target": "/proc0"
104     }
105 ])";
106     EXPECT_EQ(s, j.dump(4));
107 }
108