xref: /openbmc/openpower-hw-diags/test/test-pdbg-dts.cpp (revision 27dd6368d4e6b1fd03610503356f24eb08a16c02)
108c21c25SZane Shelley #include <fcntl.h>
2e81eb15dSaustinfcui #include <libpdbg.h>
308c21c25SZane Shelley 
4e81eb15dSaustinfcui #include <hei_main.hpp>
5c7026261SZane Shelley #include <test/sim-hw-access.hpp>
608c21c25SZane Shelley #include <util/pdbg.hpp>
708c21c25SZane Shelley #include <util/trace.hpp>
808c21c25SZane Shelley 
908c21c25SZane Shelley #include <limits>
10e81eb15dSaustinfcui #include <vector>
1108c21c25SZane Shelley 
1208c21c25SZane Shelley #include "gtest/gtest.h"
1308c21c25SZane Shelley 
TEST(PDBG,PdbgDtsTest1)1408c21c25SZane Shelley TEST(PDBG, PdbgDtsTest1)
1508c21c25SZane Shelley {
1608c21c25SZane Shelley     const char* perv1_fapi_pos_path = "/proc0/pib/perv1";
1708c21c25SZane Shelley     const char* perv12_fapi_pos_path = "/proc0/pib/perv12";
1808c21c25SZane Shelley     const uint32_t perv1_fapi_pos = 1;
1908c21c25SZane Shelley     const uint32_t perv12_fapi_pos = 12;
2008c21c25SZane Shelley 
2108c21c25SZane Shelley     pdbg_targets_init(nullptr);
2208c21c25SZane Shelley 
2308c21c25SZane Shelley     trace::inf("retrieving fapi pos.");
2408c21c25SZane Shelley     uint32_t attr = std::numeric_limits<uint32_t>::max();
2508c21c25SZane Shelley     pdbg_target* trgt = pdbg_target_from_path(nullptr, perv1_fapi_pos_path);
2608c21c25SZane Shelley     pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
2708c21c25SZane Shelley     trace::inf("perv1 fapi pos in DTS: %u", attr);
2808c21c25SZane Shelley     EXPECT_EQ(attr, perv1_fapi_pos);
2908c21c25SZane Shelley 
3008c21c25SZane Shelley     attr = std::numeric_limits<uint32_t>::max();
3108c21c25SZane Shelley     trgt = pdbg_target_from_path(nullptr, perv12_fapi_pos_path);
3208c21c25SZane Shelley     pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
3308c21c25SZane Shelley     trace::inf("perv12 fapi pos in DTS: %u", attr);
3408c21c25SZane Shelley     EXPECT_EQ(attr, perv12_fapi_pos);
3508c21c25SZane Shelley }
3608c21c25SZane Shelley 
TEST(PDBG,PdbgDtsTest2)3708c21c25SZane Shelley TEST(PDBG, PdbgDtsTest2)
3808c21c25SZane Shelley {
3908c21c25SZane Shelley     const char* dimm0_path =
4008c21c25SZane Shelley         "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0/mem_port0/dimm0";
4108c21c25SZane Shelley     const uint32_t index = 0;
4208c21c25SZane Shelley     const uint32_t fapi_pos = 0;
4308c21c25SZane Shelley 
4408c21c25SZane Shelley     pdbg_targets_init(nullptr);
4508c21c25SZane Shelley 
4608c21c25SZane Shelley     trace::inf("retrieving fapi pos.");
4708c21c25SZane Shelley     uint32_t attr = std::numeric_limits<uint32_t>::max();
4808c21c25SZane Shelley     pdbg_target* trgt = pdbg_target_from_path(nullptr, dimm0_path);
4908c21c25SZane Shelley     pdbg_target_get_attribute(trgt, "index", 4, 1, &attr);
5008c21c25SZane Shelley     trace::inf("index in DTS: %u", attr);
5108c21c25SZane Shelley     EXPECT_EQ(attr, index);
5208c21c25SZane Shelley 
5308c21c25SZane Shelley     attr = std::numeric_limits<uint32_t>::max();
5408c21c25SZane Shelley     pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
5508c21c25SZane Shelley     trace::inf("fapi pos in DTS: %u", attr);
5608c21c25SZane Shelley     EXPECT_EQ(attr, fapi_pos);
5708c21c25SZane Shelley }
5808c21c25SZane Shelley 
TEST(PDBG,PdbgDtsTest3)5908c21c25SZane Shelley TEST(PDBG, PdbgDtsTest3)
6008c21c25SZane Shelley {
6108c21c25SZane Shelley     const uint32_t chipId = 0;  // ID for proc0.
6208c21c25SZane Shelley     const uint32_t fapiPos = 0; // FAPI Position for proc0.
6308c21c25SZane Shelley 
6408c21c25SZane Shelley     pdbg_targets_init(nullptr);
6508c21c25SZane Shelley 
6608c21c25SZane Shelley     // Iterate each processor.
6708c21c25SZane Shelley     pdbg_target* procTrgt;
6808c21c25SZane Shelley     pdbg_for_each_class_target("/proc0", procTrgt)
6908c21c25SZane Shelley     {
7008c21c25SZane Shelley         // Active processors only.
7108c21c25SZane Shelley         if (PDBG_TARGET_ENABLED !=
7208c21c25SZane Shelley             pdbg_target_probe(util::pdbg::getPibTrgt(procTrgt)))
7308c21c25SZane Shelley             continue;
7408c21c25SZane Shelley 
7508c21c25SZane Shelley         // Process the PROC target.
7608c21c25SZane Shelley         uint32_t attr = std::numeric_limits<uint32_t>::max();
7708c21c25SZane Shelley         pdbg_target_get_attribute(procTrgt, "ATTR_CHIP_ID", 4, 1, &attr);
7808c21c25SZane Shelley         trace::inf("Chip ID: %u", attr);
7908c21c25SZane Shelley         EXPECT_EQ(attr, chipId);
8008c21c25SZane Shelley 
8108c21c25SZane Shelley         attr = std::numeric_limits<uint32_t>::max();
8208c21c25SZane Shelley         pdbg_target_get_attribute(procTrgt, "ATTR_FAPI_POS", 4, 1, &attr);
8308c21c25SZane Shelley         trace::inf("ATTR_FAPI_POS: %u", attr);
8408c21c25SZane Shelley         EXPECT_EQ(attr, fapiPos);
8508c21c25SZane Shelley     }
8608c21c25SZane Shelley }
8708c21c25SZane Shelley 
TEST(PDBG,PdbgDtsTest4)8808c21c25SZane Shelley TEST(PDBG, PdbgDtsTest4)
8908c21c25SZane Shelley {
9008c21c25SZane Shelley     const uint32_t index = 1;
9108c21c25SZane Shelley     const uint32_t fapi_pos = 1;
9208c21c25SZane Shelley     const char* perv1_path = "/proc0/pib/perv1";
9308c21c25SZane Shelley 
9408c21c25SZane Shelley     pdbg_targets_init(nullptr);
9508c21c25SZane Shelley 
9608c21c25SZane Shelley     // Iterate each processor.
9708c21c25SZane Shelley     pdbg_target* trgt;
9808c21c25SZane Shelley     uint32_t attr;
9908c21c25SZane Shelley 
10008c21c25SZane Shelley     pdbg_for_each_class_target(perv1_path, trgt)
10108c21c25SZane Shelley     {
10208c21c25SZane Shelley         attr = std::numeric_limits<uint32_t>::max();
10308c21c25SZane Shelley         pdbg_target_get_attribute(trgt, "index", 4, 1, &attr);
10408c21c25SZane Shelley         trace::inf("index in DTS: %u", attr);
10508c21c25SZane Shelley         EXPECT_EQ(attr, index);
10608c21c25SZane Shelley 
10708c21c25SZane Shelley         attr = std::numeric_limits<uint32_t>::max();
10808c21c25SZane Shelley         pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
10908c21c25SZane Shelley         trace::inf("fapi pos in DTS: %u", attr);
11008c21c25SZane Shelley         EXPECT_EQ(attr, fapi_pos);
11108c21c25SZane Shelley     }
11208c21c25SZane Shelley }
1132a394cbbSZane Shelley 
TEST(util_pdbg,getParentChip)1142a394cbbSZane Shelley TEST(util_pdbg, getParentChip)
1152a394cbbSZane Shelley {
1162a394cbbSZane Shelley     using namespace util::pdbg;
1172a394cbbSZane Shelley     pdbg_targets_init(nullptr);
1182a394cbbSZane Shelley 
1192a394cbbSZane Shelley     auto procChip = getTrgt("/proc0");
1202a394cbbSZane Shelley     auto omiUnit = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1");
1212a394cbbSZane Shelley 
1222a394cbbSZane Shelley     EXPECT_EQ(procChip, getParentChip(procChip)); // get self
1232a394cbbSZane Shelley     EXPECT_EQ(procChip, getParentChip(omiUnit));  // get unit
1242a394cbbSZane Shelley 
1252a394cbbSZane Shelley     auto ocmbChip = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0");
1262a394cbbSZane Shelley     auto memPortUnit =
1272a394cbbSZane Shelley         getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0/mem_port0");
1282a394cbbSZane Shelley 
1292a394cbbSZane Shelley     EXPECT_EQ(ocmbChip, getParentChip(ocmbChip));    // get self
1302a394cbbSZane Shelley     EXPECT_EQ(ocmbChip, getParentChip(memPortUnit)); // get unit
1312a394cbbSZane Shelley }
1322a394cbbSZane Shelley 
TEST(util_pdbg,getChipUnit)1332a394cbbSZane Shelley TEST(util_pdbg, getChipUnit)
1342a394cbbSZane Shelley {
1352a394cbbSZane Shelley     using namespace util::pdbg;
1362a394cbbSZane Shelley     pdbg_targets_init(nullptr);
1372a394cbbSZane Shelley 
1382a394cbbSZane Shelley     auto procChip = getTrgt("/proc0");
1392a394cbbSZane Shelley     auto omiUnit = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1");
1402a394cbbSZane Shelley     auto omiUnitPos = 5;
1412a394cbbSZane Shelley 
1422a394cbbSZane Shelley     // Get the unit and verify.
1432a394cbbSZane Shelley     EXPECT_EQ(omiUnit, getChipUnit(procChip, TYPE_OMI, omiUnitPos));
1442a394cbbSZane Shelley 
1452a394cbbSZane Shelley     // Expect an exception when passing a unit instead of a chip.
1462a394cbbSZane Shelley     EXPECT_THROW(getChipUnit(omiUnit, TYPE_OMI, omiUnitPos), std::logic_error);
1472a394cbbSZane Shelley 
1482a394cbbSZane Shelley     // Expect an exception when passing a chip type.
1492a394cbbSZane Shelley     EXPECT_THROW(getChipUnit(procChip, TYPE_PROC, omiUnitPos),
1502a394cbbSZane Shelley                  std::out_of_range);
1512a394cbbSZane Shelley 
1522a394cbbSZane Shelley     // Expect an exception when passing a unit type not on the target chip.
1532a394cbbSZane Shelley     EXPECT_THROW(getChipUnit(procChip, TYPE_MEM_PORT, omiUnitPos),
1542a394cbbSZane Shelley                  std::out_of_range);
1552a394cbbSZane Shelley 
1562a394cbbSZane Shelley     // Expect a nullptr if the target is not found.
1572a394cbbSZane Shelley     EXPECT_EQ(nullptr, getChipUnit(procChip, TYPE_OMI, 100));
1582a394cbbSZane Shelley 
1592a394cbbSZane Shelley     auto ocmbChip = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0");
1602a394cbbSZane Shelley     auto memPortUnit =
1612a394cbbSZane Shelley         getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0/mem_port0");
1622a394cbbSZane Shelley     auto memPortUnitPos = 0;
1632a394cbbSZane Shelley 
1642a394cbbSZane Shelley     // Get the unit and verify.
1652a394cbbSZane Shelley     EXPECT_EQ(memPortUnit,
1662a394cbbSZane Shelley               getChipUnit(ocmbChip, TYPE_MEM_PORT, memPortUnitPos));
1672a394cbbSZane Shelley }
168c7026261SZane Shelley 
TEST(util_pdbg,getScom)169c7026261SZane Shelley TEST(util_pdbg, getScom)
170c7026261SZane Shelley {
171c7026261SZane Shelley     using namespace util::pdbg;
172c7026261SZane Shelley     pdbg_targets_init(nullptr);
173c7026261SZane Shelley 
174c7026261SZane Shelley     auto procChip = getTrgt("/proc0");
175c7026261SZane Shelley     auto ocmbChip = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0");
176c7026261SZane Shelley     auto omiUnit = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1");
177c7026261SZane Shelley 
178c7026261SZane Shelley     sim::ScomAccess& scom = sim::ScomAccess::getSingleton();
179c7026261SZane Shelley     scom.flush();
180c7026261SZane Shelley     scom.add(procChip, 0x11111111, 0x0011223344556677);
181c7026261SZane Shelley     scom.error(ocmbChip, 0x22222222);
182c7026261SZane Shelley 
183c7026261SZane Shelley     int rc = 0;
184c7026261SZane Shelley     uint64_t val = 0;
185c7026261SZane Shelley 
186c7026261SZane Shelley     // Test good path.
187c7026261SZane Shelley     rc = getScom(procChip, 0x11111111, val);
188c7026261SZane Shelley     EXPECT_EQ(0, rc);
189c7026261SZane Shelley     EXPECT_EQ(0x0011223344556677, val);
190c7026261SZane Shelley 
191c7026261SZane Shelley     // Test address that has not been added to ScomAccess.
192c7026261SZane Shelley     rc = getScom(procChip, 0x33333333, val);
193c7026261SZane Shelley     EXPECT_EQ(0, rc);
194c7026261SZane Shelley     EXPECT_EQ(0, val);
195c7026261SZane Shelley 
196c7026261SZane Shelley     // Test SCOM error.
197c7026261SZane Shelley     rc = getScom(ocmbChip, 0x22222222, val);
198c7026261SZane Shelley     EXPECT_EQ(1, rc);
199c7026261SZane Shelley 
200c7026261SZane Shelley     // Test non-chip target.
201c7026261SZane Shelley     EXPECT_DEATH({ getScom(omiUnit, 0x11111111, val); }, "");
202c7026261SZane Shelley }
203c7026261SZane Shelley 
TEST(util_pdbg,getCfam)204c7026261SZane Shelley TEST(util_pdbg, getCfam)
205c7026261SZane Shelley {
206c7026261SZane Shelley     using namespace util::pdbg;
207c7026261SZane Shelley     pdbg_targets_init(nullptr);
208c7026261SZane Shelley 
209c7026261SZane Shelley     auto procChip = getTrgt("/proc0");
210c7026261SZane Shelley     auto omiUnit = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1");
211c7026261SZane Shelley 
212c7026261SZane Shelley     sim::CfamAccess& cfam = sim::CfamAccess::getSingleton();
213c7026261SZane Shelley     cfam.flush();
214c7026261SZane Shelley     cfam.add(procChip, 0x11111111, 0x00112233);
215c7026261SZane Shelley     cfam.error(procChip, 0x22222222);
216c7026261SZane Shelley 
217c7026261SZane Shelley     int rc = 0;
218c7026261SZane Shelley     uint32_t val = 0;
219c7026261SZane Shelley 
220c7026261SZane Shelley     // Test good path.
221c7026261SZane Shelley     rc = getCfam(procChip, 0x11111111, val);
222c7026261SZane Shelley     EXPECT_EQ(0, rc);
223c7026261SZane Shelley     EXPECT_EQ(0x00112233, val);
224c7026261SZane Shelley 
225c7026261SZane Shelley     // Test address that has not been added to CfamAccess.
226c7026261SZane Shelley     rc = getCfam(procChip, 0x33333333, val);
227c7026261SZane Shelley     EXPECT_EQ(0, rc);
228c7026261SZane Shelley     EXPECT_EQ(0, val);
229c7026261SZane Shelley 
230c7026261SZane Shelley     // Test CFAM error.
231c7026261SZane Shelley     rc = getCfam(procChip, 0x22222222, val);
232c7026261SZane Shelley     EXPECT_EQ(1, rc);
233c7026261SZane Shelley 
234c7026261SZane Shelley     // Test non-chip target.
235c7026261SZane Shelley     EXPECT_DEATH({ getCfam(omiUnit, 0x11111111, val); }, "");
236c7026261SZane Shelley }
237e81eb15dSaustinfcui 
TEST(util_pdbg,getActiveChips)238e81eb15dSaustinfcui TEST(util_pdbg, getActiveChips)
239e81eb15dSaustinfcui {
240e81eb15dSaustinfcui     using namespace util::pdbg;
241e81eb15dSaustinfcui     using namespace libhei;
242e81eb15dSaustinfcui     pdbg_targets_init(nullptr);
243e81eb15dSaustinfcui 
244e81eb15dSaustinfcui     std::vector<libhei::Chip> chips;
245e81eb15dSaustinfcui     getActiveChips(chips);
246e81eb15dSaustinfcui 
247e81eb15dSaustinfcui     trace::inf("chips size: %u", chips.size());
248e81eb15dSaustinfcui     EXPECT_EQ(2, chips.size());
249*cd6373d3SZane Shelley 
250*cd6373d3SZane Shelley     /* TODO: There is an issue with the getActiveChips() function that only
251*cd6373d3SZane Shelley      *       seems to exist in simulation. For some reason, the OCMBs do not
252*cd6373d3SZane Shelley      *       show up as PDBG_TARGET_ENABLED. If we remove that check, this test
253*cd6373d3SZane Shelley      *       case works as expected. However, we don't want to do that in
254*cd6373d3SZane Shelley      *       production code.  Instead, we'll need to determine why the OCMBs
255*cd6373d3SZane Shelley      *       are not enabled in CI test and then reenable this test case.
256*cd6373d3SZane Shelley     auto proc0 = getTrgt("/proc0");
257*cd6373d3SZane Shelley     auto proc1 = getTrgt("/proc1");
258*cd6373d3SZane Shelley 
259*cd6373d3SZane Shelley     sim::ScomAccess& scom = sim::ScomAccess::getSingleton();
260*cd6373d3SZane Shelley     scom.flush();
261*cd6373d3SZane Shelley 
262*cd6373d3SZane Shelley     // Mask off proc0 mcc0 channel 1. The connected OCMB should be removed from
263*cd6373d3SZane Shelley     // the list.
264*cd6373d3SZane Shelley     scom.add(proc0, 0x0C010D03, 0x0f00000000000000);
265*cd6373d3SZane Shelley 
266*cd6373d3SZane Shelley     // Mask off one or two attentions, but not all, on proc0 mcc2. None of the
267*cd6373d3SZane Shelley     // connected OCMBs should be removed from the list.
268*cd6373d3SZane Shelley     scom.add(proc0, 0x0D010D03, 0xA500000000000000);
269*cd6373d3SZane Shelley 
270*cd6373d3SZane Shelley     // Mask off proc1 mcc7 channel 0. The connected OCMB should be removed from
271*cd6373d3SZane Shelley     // the list.
272*cd6373d3SZane Shelley     scom.add(proc1, 0x0F010D43, 0xf000000000000000);
273*cd6373d3SZane Shelley 
274*cd6373d3SZane Shelley     // Mask off proc1 mcc5 channels 0 and 1. Both the connected OCMBs should be
275*cd6373d3SZane Shelley     // removed from the list.
276*cd6373d3SZane Shelley     scom.add(proc1, 0x0E010D43, 0xff00000000000000);
277*cd6373d3SZane Shelley 
278*cd6373d3SZane Shelley     std::vector<libhei::Chip> chips;
279*cd6373d3SZane Shelley     getActiveChips(chips);
280*cd6373d3SZane Shelley 
281*cd6373d3SZane Shelley     // In total there should be 14 chips with 2 processors, 7 OCMBs on proc0,
282*cd6373d3SZane Shelley     // and 5 OCMBs on proc1.
283*cd6373d3SZane Shelley 
284*cd6373d3SZane Shelley     trace::inf("chips size: %u", chips.size());
285*cd6373d3SZane Shelley     EXPECT_EQ(14, chips.size());
286*cd6373d3SZane Shelley     */
287e81eb15dSaustinfcui }
288