blob: 1e5075c429695697801d80fe1d08de4e61e3053e [file] [log] [blame]
austinfcui35257fd2021-12-09 17:56:00 -06001#include <fcntl.h>
2
3#include <util/pdbg.hpp>
4#include <util/trace.hpp>
5
6#include <limits>
7
8#include "gtest/gtest.h"
9
10TEST(PDBG, PdbgDtsTest1)
11{
12 const char* perv1_fapi_pos_path = "/proc0/pib/perv1";
13 const char* perv12_fapi_pos_path = "/proc0/pib/perv12";
14 const uint32_t perv1_fapi_pos = 1;
15 const uint32_t perv12_fapi_pos = 12;
16
17 pdbg_targets_init(nullptr);
18
19 trace::inf("retrieving fapi pos.");
20 uint32_t attr = std::numeric_limits<uint32_t>::max();
21 pdbg_target* trgt = pdbg_target_from_path(nullptr, perv1_fapi_pos_path);
22 pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
23 trace::inf("perv1 fapi pos in DTS: %u", attr);
24 EXPECT_EQ(attr, perv1_fapi_pos);
25
26 attr = std::numeric_limits<uint32_t>::max();
27 trgt = pdbg_target_from_path(nullptr, perv12_fapi_pos_path);
28 pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
29 trace::inf("perv12 fapi pos in DTS: %u", attr);
30 EXPECT_EQ(attr, perv12_fapi_pos);
31}
32
33TEST(PDBG, PdbgDtsTest2)
34{
35 const char* dimm0_path =
36 "/proc0/pib/perv12/mc0/mi0/mcc0/omi0/ocmb0/mem_port0/dimm0";
37 const uint32_t index = 0;
38 const uint32_t fapi_pos = 0;
39
40 pdbg_targets_init(nullptr);
41
42 trace::inf("retrieving fapi pos.");
43 uint32_t attr = std::numeric_limits<uint32_t>::max();
44 pdbg_target* trgt = pdbg_target_from_path(nullptr, dimm0_path);
45 pdbg_target_get_attribute(trgt, "index", 4, 1, &attr);
46 trace::inf("index in DTS: %u", attr);
47 EXPECT_EQ(attr, index);
48
49 attr = std::numeric_limits<uint32_t>::max();
50 pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
51 trace::inf("fapi pos in DTS: %u", attr);
52 EXPECT_EQ(attr, fapi_pos);
53}
54
55TEST(PDBG, PdbgDtsTest3)
56{
57 const uint32_t chipId = 0; // ID for proc0.
58 const uint32_t fapiPos = 0; // FAPI Position for proc0.
59
60 pdbg_targets_init(nullptr);
61
62 // Iterate each processor.
63 pdbg_target* procTrgt;
64 pdbg_for_each_class_target("/proc0", procTrgt)
65 {
66 // Active processors only.
67 if (PDBG_TARGET_ENABLED !=
68 pdbg_target_probe(util::pdbg::getPibTrgt(procTrgt)))
69 continue;
70
71 // Process the PROC target.
72 uint32_t attr = std::numeric_limits<uint32_t>::max();
73 pdbg_target_get_attribute(procTrgt, "ATTR_CHIP_ID", 4, 1, &attr);
74 trace::inf("Chip ID: %u", attr);
75 EXPECT_EQ(attr, chipId);
76
77 attr = std::numeric_limits<uint32_t>::max();
78 pdbg_target_get_attribute(procTrgt, "ATTR_FAPI_POS", 4, 1, &attr);
79 trace::inf("ATTR_FAPI_POS: %u", attr);
80 EXPECT_EQ(attr, fapiPos);
81 }
82}
83
84TEST(PDBG, PdbgDtsTest4)
85{
86 const uint32_t index = 1;
87 const uint32_t fapi_pos = 1;
88 const char* perv1_path = "/proc0/pib/perv1";
89
90 pdbg_targets_init(nullptr);
91
92 // Iterate each processor.
93 pdbg_target* trgt;
94 uint32_t attr;
95
96 pdbg_for_each_class_target(perv1_path, trgt)
97 {
98 attr = std::numeric_limits<uint32_t>::max();
99 pdbg_target_get_attribute(trgt, "index", 4, 1, &attr);
100 trace::inf("index in DTS: %u", attr);
101 EXPECT_EQ(attr, index);
102
103 attr = std::numeric_limits<uint32_t>::max();
104 pdbg_target_get_attribute(trgt, "ATTR_FAPI_POS", 4, 1, &attr);
105 trace::inf("fapi pos in DTS: %u", attr);
106 EXPECT_EQ(attr, fapi_pos);
107 }
108}
Zane Shelley2a394cb2022-02-17 22:01:39 -0600109
110TEST(util_pdbg, getParentChip)
111{
112 using namespace util::pdbg;
113 pdbg_targets_init(nullptr);
114
115 auto procChip = getTrgt("/proc0");
116 auto omiUnit = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1");
117
118 EXPECT_EQ(procChip, getParentChip(procChip)); // get self
119 EXPECT_EQ(procChip, getParentChip(omiUnit)); // get unit
120
121 auto ocmbChip = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0");
122 auto memPortUnit =
123 getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0/mem_port0");
124
125 EXPECT_EQ(ocmbChip, getParentChip(ocmbChip)); // get self
126 EXPECT_EQ(ocmbChip, getParentChip(memPortUnit)); // get unit
127}
128
129TEST(util_pdbg, getChipUnit)
130{
131 using namespace util::pdbg;
132 pdbg_targets_init(nullptr);
133
134 auto procChip = getTrgt("/proc0");
135 auto omiUnit = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1");
136 auto omiUnitPos = 5;
137
138 // Get the unit and verify.
139 EXPECT_EQ(omiUnit, getChipUnit(procChip, TYPE_OMI, omiUnitPos));
140
141 // Expect an exception when passing a unit instead of a chip.
142 EXPECT_THROW(getChipUnit(omiUnit, TYPE_OMI, omiUnitPos), std::logic_error);
143
144 // Expect an exception when passing a chip type.
145 EXPECT_THROW(getChipUnit(procChip, TYPE_PROC, omiUnitPos),
146 std::out_of_range);
147
148 // Expect an exception when passing a unit type not on the target chip.
149 EXPECT_THROW(getChipUnit(procChip, TYPE_MEM_PORT, omiUnitPos),
150 std::out_of_range);
151
152 // Expect a nullptr if the target is not found.
153 EXPECT_EQ(nullptr, getChipUnit(procChip, TYPE_OMI, 100));
154
155 auto ocmbChip = getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0");
156 auto memPortUnit =
157 getTrgt("/proc0/pib/perv13/mc1/mi0/mcc0/omi1/ocmb0/mem_port0");
158 auto memPortUnitPos = 0;
159
160 // Get the unit and verify.
161 EXPECT_EQ(memPortUnit,
162 getChipUnit(ocmbChip, TYPE_MEM_PORT, memPortUnitPos));
163}