blob: 19ffc2841f03ba00b837fe2426c80d5135f82d03 [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}