blob: 9fd49fdcebb602733054e990fa69340005b02955 [file] [log] [blame]
austinfcui35257fd2021-12-09 17:56:00 -06001#include <fcntl.h>
2
Zane Shelleyc7026262022-02-22 16:37:36 -06003#include <test/sim-hw-access.hpp>
austinfcui35257fd2021-12-09 17:56:00 -06004#include <util/pdbg.hpp>
5#include <util/trace.hpp>
6
7#include <limits>
8
9#include "gtest/gtest.h"
10
11TEST(PDBG, PdbgDtsTest1)
12{
13 const char* perv1_fapi_pos_path = "/proc0/pib/perv1";
14 const char* perv12_fapi_pos_path = "/proc0/pib/perv12";
15 const uint32_t perv1_fapi_pos = 1;
16 const uint32_t perv12_fapi_pos = 12;
17
18 pdbg_targets_init(nullptr);
19
20 trace::inf("retrieving fapi pos.");
21 uint32_t attr = std::numeric_limits<uint32_t>::max();
22 pdbg_target* trgt = pdbg_target_from_path(nullptr, perv1_fapi_pos_path);
23 pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
24 trace::inf("perv1 fapi pos in DTS: %u", attr);
25 EXPECT_EQ(attr, perv1_fapi_pos);
26
27 attr = std::numeric_limits<uint32_t>::max();
28 trgt = pdbg_target_from_path(nullptr, perv12_fapi_pos_path);
29 pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
30 trace::inf("perv12 fapi pos in DTS: %u", attr);
31 EXPECT_EQ(attr, perv12_fapi_pos);
32}
33
34TEST(PDBG, PdbgDtsTest2)
35{
36 const char* dimm0_path =
37 "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0/mem_port0/dimm0";
38 const uint32_t index = 0;
39 const uint32_t fapi_pos = 0;
40
41 pdbg_targets_init(nullptr);
42
43 trace::inf("retrieving fapi pos.");
44 uint32_t attr = std::numeric_limits<uint32_t>::max();
45 pdbg_target* trgt = pdbg_target_from_path(nullptr, dimm0_path);
46 pdbg_target_get_attribute(trgt, "index", 4, 1, &attr);
47 trace::inf("index in DTS: %u", attr);
48 EXPECT_EQ(attr, index);
49
50 attr = std::numeric_limits<uint32_t>::max();
51 pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
52 trace::inf("fapi pos in DTS: %u", attr);
53 EXPECT_EQ(attr, fapi_pos);
54}
55
56TEST(PDBG, PdbgDtsTest3)
57{
58 const uint32_t chipId = 0; // ID for proc0.
59 const uint32_t fapiPos = 0; // FAPI Position for proc0.
60
61 pdbg_targets_init(nullptr);
62
63 // Iterate each processor.
64 pdbg_target* procTrgt;
65 pdbg_for_each_class_target("/proc0", procTrgt)
66 {
67 // Active processors only.
68 if (PDBG_TARGET_ENABLED !=
69 pdbg_target_probe(util::pdbg::getPibTrgt(procTrgt)))
70 continue;
71
72 // Process the PROC target.
73 uint32_t attr = std::numeric_limits<uint32_t>::max();
74 pdbg_target_get_attribute(procTrgt, "ATTR_CHIP_ID", 4, 1, &attr);
75 trace::inf("Chip ID: %u", attr);
76 EXPECT_EQ(attr, chipId);
77
78 attr = std::numeric_limits<uint32_t>::max();
79 pdbg_target_get_attribute(procTrgt, "ATTR_FAPI_POS", 4, 1, &attr);
80 trace::inf("ATTR_FAPI_POS: %u", attr);
81 EXPECT_EQ(attr, fapiPos);
82 }
83}
84
85TEST(PDBG, PdbgDtsTest4)
86{
87 const uint32_t index = 1;
88 const uint32_t fapi_pos = 1;
89 const char* perv1_path = "/proc0/pib/perv1";
90
91 pdbg_targets_init(nullptr);
92
93 // Iterate each processor.
94 pdbg_target* trgt;
95 uint32_t attr;
96
97 pdbg_for_each_class_target(perv1_path, trgt)
98 {
99 attr = std::numeric_limits<uint32_t>::max();
100 pdbg_target_get_attribute(trgt, "index", 4, 1, &attr);
101 trace::inf("index in DTS: %u", attr);
102 EXPECT_EQ(attr, index);
103
104 attr = std::numeric_limits<uint32_t>::max();
105 pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
106 trace::inf("fapi pos in DTS: %u", attr);
107 EXPECT_EQ(attr, fapi_pos);
108 }
109}
Zane Shelley2a394cb2022-02-17 22:01:39 -0600110
111TEST(util_pdbg, getParentChip)
112{
113 using namespace util::pdbg;
114 pdbg_targets_init(nullptr);
115
116 auto procChip = getTrgt("/proc0");
117 auto omiUnit = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1");
118
119 EXPECT_EQ(procChip, getParentChip(procChip)); // get self
120 EXPECT_EQ(procChip, getParentChip(omiUnit)); // get unit
121
122 auto ocmbChip = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0");
123 auto memPortUnit =
124 getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0/mem_port0");
125
126 EXPECT_EQ(ocmbChip, getParentChip(ocmbChip)); // get self
127 EXPECT_EQ(ocmbChip, getParentChip(memPortUnit)); // get unit
128}
129
130TEST(util_pdbg, getChipUnit)
131{
132 using namespace util::pdbg;
133 pdbg_targets_init(nullptr);
134
135 auto procChip = getTrgt("/proc0");
136 auto omiUnit = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1");
137 auto omiUnitPos = 5;
138
139 // Get the unit and verify.
140 EXPECT_EQ(omiUnit, getChipUnit(procChip, TYPE_OMI, omiUnitPos));
141
142 // Expect an exception when passing a unit instead of a chip.
143 EXPECT_THROW(getChipUnit(omiUnit, TYPE_OMI, omiUnitPos), std::logic_error);
144
145 // Expect an exception when passing a chip type.
146 EXPECT_THROW(getChipUnit(procChip, TYPE_PROC, omiUnitPos),
147 std::out_of_range);
148
149 // Expect an exception when passing a unit type not on the target chip.
150 EXPECT_THROW(getChipUnit(procChip, TYPE_MEM_PORT, omiUnitPos),
151 std::out_of_range);
152
153 // Expect a nullptr if the target is not found.
154 EXPECT_EQ(nullptr, getChipUnit(procChip, TYPE_OMI, 100));
155
156 auto ocmbChip = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0");
157 auto memPortUnit =
158 getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0/mem_port0");
159 auto memPortUnitPos = 0;
160
161 // Get the unit and verify.
162 EXPECT_EQ(memPortUnit,
163 getChipUnit(ocmbChip, TYPE_MEM_PORT, memPortUnitPos));
164}
Zane Shelleyc7026262022-02-22 16:37:36 -0600165
166TEST(util_pdbg, getScom)
167{
168 using namespace util::pdbg;
169 pdbg_targets_init(nullptr);
170
171 auto procChip = getTrgt("/proc0");
172 auto ocmbChip = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0");
173 auto omiUnit = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1");
174
175 sim::ScomAccess& scom = sim::ScomAccess::getSingleton();
176 scom.flush();
177 scom.add(procChip, 0x11111111, 0x0011223344556677);
178 scom.error(ocmbChip, 0x22222222);
179
180 int rc = 0;
181 uint64_t val = 0;
182
183 // Test good path.
184 rc = getScom(procChip, 0x11111111, val);
185 EXPECT_EQ(0, rc);
186 EXPECT_EQ(0x0011223344556677, val);
187
188 // Test address that has not been added to ScomAccess.
189 rc = getScom(procChip, 0x33333333, val);
190 EXPECT_EQ(0, rc);
191 EXPECT_EQ(0, val);
192
193 // Test SCOM error.
194 rc = getScom(ocmbChip, 0x22222222, val);
195 EXPECT_EQ(1, rc);
196
197 // Test non-chip target.
198 EXPECT_DEATH({ getScom(omiUnit, 0x11111111, val); }, "");
199}
200
201TEST(util_pdbg, getCfam)
202{
203 using namespace util::pdbg;
204 pdbg_targets_init(nullptr);
205
206 auto procChip = getTrgt("/proc0");
207 auto omiUnit = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1");
208
209 sim::CfamAccess& cfam = sim::CfamAccess::getSingleton();
210 cfam.flush();
211 cfam.add(procChip, 0x11111111, 0x00112233);
212 cfam.error(procChip, 0x22222222);
213
214 int rc = 0;
215 uint32_t val = 0;
216
217 // Test good path.
218 rc = getCfam(procChip, 0x11111111, val);
219 EXPECT_EQ(0, rc);
220 EXPECT_EQ(0x00112233, val);
221
222 // Test address that has not been added to CfamAccess.
223 rc = getCfam(procChip, 0x33333333, val);
224 EXPECT_EQ(0, rc);
225 EXPECT_EQ(0, val);
226
227 // Test CFAM error.
228 rc = getCfam(procChip, 0x22222222, val);
229 EXPECT_EQ(1, rc);
230
231 // Test non-chip target.
232 EXPECT_DEATH({ getCfam(omiUnit, 0x11111111, val); }, "");
233}