blob: f8f5a8a1474f0629115e8d5ec2da79927db71fd3 [file] [log] [blame]
Tomáš Pecka339bc672020-11-11 15:59:03 +01001#include "trompeloeil_doctest.h"
2#include <iterator>
3#include "ietf-hardware/IETFHardware.h"
Tomáš Pecka98ad18d2020-11-13 15:39:55 +01004#include "ietf-hardware/sysrepo/Sysrepo.h"
Tomáš Pecka339bc672020-11-11 15:59:03 +01005#include "mock/ietf_hardware.h"
6#include "pretty_printers.h"
7#include "test_log_setup.h"
Tomáš Pecka98ad18d2020-11-13 15:39:55 +01008#include "test_sysrepo_helpers.h"
Tomáš Pecka339bc672020-11-11 15:59:03 +01009#include "tests/configure.cmake.h"
10
11using namespace std::literals;
12
13TEST_CASE("HardwareState")
14{
15 TEST_INIT_LOGS;
Tomáš Pecka83b62e12020-12-16 14:50:49 +010016 static const auto modulePrefix = "/ietf-hardware:hardware"s;
Tomáš Pecka339bc672020-11-11 15:59:03 +010017
18 trompeloeil::sequence seq1;
Tomáš Pecka83b62e12020-12-16 14:50:49 +010019 auto ietfHardware = std::make_shared<velia::ietf_hardware::IETFHardware>();
Tomáš Pecka339bc672020-11-11 15:59:03 +010020
21 auto fans = std::make_shared<FakeHWMon>();
22 auto sysfsTempCpu = std::make_shared<FakeHWMon>();
23 auto sysfsTempFront = std::make_shared<FakeHWMon>();
24 auto sysfsTempMII0 = std::make_shared<FakeHWMon>();
25 auto sysfsTempMII1 = std::make_shared<FakeHWMon>();
26 auto emmc = std::make_shared<FakeEMMC>();
27
28 std::map<std::string, std::string> attributesEMMC;
29 std::map<std::string, int64_t> attributesHWMon;
30
31 // initialize all mocks
32 attributesEMMC = {
33 // FIXME passing initializer_list to macro is hell
34 {"date"s, "02/2017"s},
35 {"serial"s, "0x00a8808d"s},
36 {"name"s, "8GME4R"s},
37 };
38 FAKE_EMMC(emmc, attributesEMMC);
39
40 attributesHWMon = {
41 {"fan1_input"s, 253},
42 {"fan2_input"s, 0},
43 {"fan3_input"s, 1280},
44 {"fan4_input"s, 666},
45 };
46 FAKE_HWMON(fans, attributesHWMon);
47
48 attributesHWMon = {{"temp1_input", 30800}};
49 FAKE_HWMON(sysfsTempFront, attributesHWMon);
50 attributesHWMon = {{"temp1_input", 41800}};
51 FAKE_HWMON(sysfsTempCpu, attributesHWMon);
52 attributesHWMon = {{"temp1_input", 39000}};
53 FAKE_HWMON(sysfsTempMII0, attributesHWMon);
54 attributesHWMon = {{"temp1_input", 36000}};
55 FAKE_HWMON(sysfsTempMII1, attributesHWMon);
56
57 attributesEMMC = {{"life_time"s, "40"s}};
58 FAKE_EMMC(emmc, attributesEMMC);
59
60 // register components into hw state
Tomáš Pecka83b62e12020-12-16 14:50:49 +010061 ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::StaticData("ne", std::nullopt, {{"class", "iana-hardware:chassis"}, {"mfg-name", "CESNET"s}}));
62 ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::StaticData("ne:ctrl", "ne", {{"class", "iana-hardware:module"}}));
63 ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::Fans("ne:fans", "ne", fans, 4));
64 ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-front", "ne:ctrl", sysfsTempFront, 1));
65 ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-cpu", "ne:ctrl", sysfsTempCpu, 1));
66 ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-internal-0", "ne:ctrl", sysfsTempMII0, 1));
67 ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::SysfsTemperature("ne:ctrl:temperature-internal-1", "ne:ctrl", sysfsTempMII1, 1));
68 ietfHardware->registerDataReader(velia::ietf_hardware::data_reader::EMMC("ne:ctrl:emmc", "ne:ctrl", emmc));
Tomáš Pecka339bc672020-11-11 15:59:03 +010069
70 SECTION("Test HardwareState without sysrepo")
71 {
72 std::map<std::string, std::string> expected = {
Tomáš Pecka83b62e12020-12-16 14:50:49 +010073 {"/ietf-hardware:hardware/component[name='ne']/class", "iana-hardware:chassis"},
74 {"/ietf-hardware:hardware/component[name='ne']/mfg-name", "CESNET"},
Tomáš Pecka339bc672020-11-11 15:59:03 +010075
Tomáš Pecka83b62e12020-12-16 14:50:49 +010076 {"/ietf-hardware:hardware/component[name='ne:fans']/class", "iana-hardware:module"},
77 {"/ietf-hardware:hardware/component[name='ne:fans']/parent", "ne"},
78 {"/ietf-hardware:hardware/component[name='ne:fans:fan1']/class", "iana-hardware:fan"},
79 {"/ietf-hardware:hardware/component[name='ne:fans:fan1']/parent", "ne:fans"},
80 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/class", "iana-hardware:sensor"},
81 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/parent", "ne:fans:fan1"},
82 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/oper-status", "ok"},
83 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value", "253"},
84 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value-precision", "0"},
85 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value-scale", "units"},
86 {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value-type", "rpm"},
87 {"/ietf-hardware:hardware/component[name='ne:fans:fan2']/class", "iana-hardware:fan"},
88 {"/ietf-hardware:hardware/component[name='ne:fans:fan2']/parent", "ne:fans"},
89 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/class", "iana-hardware:sensor"},
90 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/parent", "ne:fans:fan2"},
91 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/oper-status", "ok"},
92 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value", "0"},
93 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value-precision", "0"},
94 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value-scale", "units"},
95 {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value-type", "rpm"},
96 {"/ietf-hardware:hardware/component[name='ne:fans:fan3']/class", "iana-hardware:fan"},
97 {"/ietf-hardware:hardware/component[name='ne:fans:fan3']/parent", "ne:fans"},
98 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/class", "iana-hardware:sensor"},
99 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/parent", "ne:fans:fan3"},
100 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/oper-status", "ok"},
101 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value", "1280"},
102 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value-precision", "0"},
103 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value-scale", "units"},
104 {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value-type", "rpm"},
105 {"/ietf-hardware:hardware/component[name='ne:fans:fan4']/class", "iana-hardware:fan"},
106 {"/ietf-hardware:hardware/component[name='ne:fans:fan4']/parent", "ne:fans"},
107 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/class", "iana-hardware:sensor"},
108 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/parent", "ne:fans:fan4"},
109 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/oper-status", "ok"},
110 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value", "666"},
111 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value-precision", "0"},
112 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value-scale", "units"},
113 {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value-type", "rpm"},
Tomáš Pecka339bc672020-11-11 15:59:03 +0100114
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100115 {"/ietf-hardware:hardware/component[name='ne:ctrl']/parent", "ne"},
116 {"/ietf-hardware:hardware/component[name='ne:ctrl']/class", "iana-hardware:module"},
Tomáš Pecka339bc672020-11-11 15:59:03 +0100117
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100118 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/class", "iana-hardware:sensor"},
119 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/parent", "ne:ctrl"},
120 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/oper-status", "ok"},
121 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value", "41800"},
122 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value-precision", "0"},
123 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value-scale", "milli"},
124 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value-type", "celsius"},
125 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-front']/class", "iana-hardware:sensor"},
126 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-front']/parent", "ne:ctrl"},
127 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-front']/sensor-data/oper-status", "ok"},
128 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-front']/sensor-data/value", "30800"},
129 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-front']/sensor-data/value-precision", "0"},
130 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-front']/sensor-data/value-scale", "milli"},
131 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-front']/sensor-data/value-type", "celsius"},
132 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-0']/class", "iana-hardware:sensor"},
133 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-0']/parent", "ne:ctrl"},
134 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-0']/sensor-data/oper-status", "ok"},
135 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-0']/sensor-data/value", "39000"},
136 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-0']/sensor-data/value-precision", "0"},
137 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-0']/sensor-data/value-scale", "milli"},
138 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-0']/sensor-data/value-type", "celsius"},
139 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-1']/class", "iana-hardware:sensor"},
140 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-1']/parent", "ne:ctrl"},
141 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-1']/sensor-data/oper-status", "ok"},
142 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-1']/sensor-data/value", "36000"},
143 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-1']/sensor-data/value-precision", "0"},
144 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-1']/sensor-data/value-scale", "milli"},
145 {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-internal-1']/sensor-data/value-type", "celsius"},
Tomáš Pecka339bc672020-11-11 15:59:03 +0100146
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100147 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/parent", "ne:ctrl"},
148 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/class", "iana-hardware:module"},
149 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/serial-num", "0x00a8808d"},
150 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/mfg-date", "2017-02-01T00:00:00Z"},
151 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/model-name", "8GME4R"},
152 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/class", "iana-hardware:sensor"},
153 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/parent", "ne:ctrl:emmc"},
154 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/oper-status", "ok"},
155 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value", "40"},
156 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value-precision", "0"},
157 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value-scale", "units"},
158 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value-type", "other"},
159 {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/units-display", "percent"},
Tomáš Pecka339bc672020-11-11 15:59:03 +0100160 };
161
162 // exclude last-change node
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100163 auto result = ietfHardware->process();
Tomáš Pecka339bc672020-11-11 15:59:03 +0100164 result.erase(modulePrefix + "/last-change");
165 REQUIRE(result == expected);
166 }
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100167
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100168 SECTION("Test IETF Hardware from sysrepo's view")
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100169 {
170 TEST_SYSREPO_INIT_LOGS;
171
172 auto srConn = std::make_shared<sysrepo::Connection>();
173 auto srSess = std::make_shared<sysrepo::Session>(srConn);
174 auto srSubs = std::make_shared<sysrepo::Subscribe>(srSess);
Tomáš Pecka83b62e12020-12-16 14:50:49 +0100175 auto ietfHardwareSysrepo = std::make_shared<velia::ietf_hardware::sysrepo::Sysrepo>(srSubs, ietfHardware);
Tomáš Pecka98ad18d2020-11-13 15:39:55 +0100176
177 SECTION("test last-change")
178 {
179 // at least check that there is some timestamp
180 srSess->session_switch_ds(SR_DS_OPERATIONAL);
181 REQUIRE(dataFromSysrepo(srSess, modulePrefix).count("/last-change") > 0);
182 srSess->session_switch_ds(SR_DS_RUNNING);
183 }
184
185 SECTION("test components")
186 {
187 std::map<std::string, std::string> expected = {
188 {"[name='ne']/name", "ne"},
189 {"[name='ne']/class", "iana-hardware:chassis"},
190 {"[name='ne']/mfg-name", "CESNET"},
191 {"[name='ne']/sensor-data", ""},
192
193 {"[name='ne:fans']/class", "iana-hardware:module"},
194 {"[name='ne:fans']/name", "ne:fans"},
195 {"[name='ne:fans']/parent", "ne"},
196 {"[name='ne:fans']/sensor-data", ""},
197 {"[name='ne:fans:fan1']/class", "iana-hardware:fan"},
198 {"[name='ne:fans:fan1']/name", "ne:fans:fan1"},
199 {"[name='ne:fans:fan1']/parent", "ne:fans"},
200 {"[name='ne:fans:fan1']/sensor-data", ""},
201 {"[name='ne:fans:fan1:rpm']/class", "iana-hardware:sensor"},
202 {"[name='ne:fans:fan1:rpm']/name", "ne:fans:fan1:rpm"},
203 {"[name='ne:fans:fan1:rpm']/parent", "ne:fans:fan1"},
204 {"[name='ne:fans:fan1:rpm']/sensor-data", ""},
205 {"[name='ne:fans:fan1:rpm']/sensor-data/oper-status", "ok"},
206 {"[name='ne:fans:fan1:rpm']/sensor-data/value", "253"},
207 {"[name='ne:fans:fan1:rpm']/sensor-data/value-precision", "0"},
208 {"[name='ne:fans:fan1:rpm']/sensor-data/value-scale", "units"},
209 {"[name='ne:fans:fan1:rpm']/sensor-data/value-type", "rpm"},
210 {"[name='ne:fans:fan2']/class", "iana-hardware:fan"},
211 {"[name='ne:fans:fan2']/name", "ne:fans:fan2"},
212 {"[name='ne:fans:fan2']/parent", "ne:fans"},
213 {"[name='ne:fans:fan2']/sensor-data", ""},
214 {"[name='ne:fans:fan2:rpm']/class", "iana-hardware:sensor"},
215 {"[name='ne:fans:fan2:rpm']/name", "ne:fans:fan2:rpm"},
216 {"[name='ne:fans:fan2:rpm']/parent", "ne:fans:fan2"},
217 {"[name='ne:fans:fan2:rpm']/sensor-data", ""},
218 {"[name='ne:fans:fan2:rpm']/sensor-data/oper-status", "ok"},
219 {"[name='ne:fans:fan2:rpm']/sensor-data/value", "0"},
220 {"[name='ne:fans:fan2:rpm']/sensor-data/value-precision", "0"},
221 {"[name='ne:fans:fan2:rpm']/sensor-data/value-scale", "units"},
222 {"[name='ne:fans:fan2:rpm']/sensor-data/value-type", "rpm"},
223 {"[name='ne:fans:fan3']/class", "iana-hardware:fan"},
224 {"[name='ne:fans:fan3']/name", "ne:fans:fan3"},
225 {"[name='ne:fans:fan3']/parent", "ne:fans"},
226 {"[name='ne:fans:fan3']/sensor-data", ""},
227 {"[name='ne:fans:fan3:rpm']/class", "iana-hardware:sensor"},
228 {"[name='ne:fans:fan3:rpm']/name", "ne:fans:fan3:rpm"},
229 {"[name='ne:fans:fan3:rpm']/parent", "ne:fans:fan3"},
230 {"[name='ne:fans:fan3:rpm']/sensor-data", ""},
231 {"[name='ne:fans:fan3:rpm']/sensor-data/oper-status", "ok"},
232 {"[name='ne:fans:fan3:rpm']/sensor-data/value", "1280"},
233 {"[name='ne:fans:fan3:rpm']/sensor-data/value-precision", "0"},
234 {"[name='ne:fans:fan3:rpm']/sensor-data/value-scale", "units"},
235 {"[name='ne:fans:fan3:rpm']/sensor-data/value-type", "rpm"},
236 {"[name='ne:fans:fan4']/class", "iana-hardware:fan"},
237 {"[name='ne:fans:fan4']/name", "ne:fans:fan4"},
238 {"[name='ne:fans:fan4']/parent", "ne:fans"},
239 {"[name='ne:fans:fan4']/sensor-data", ""},
240 {"[name='ne:fans:fan4:rpm']/class", "iana-hardware:sensor"},
241 {"[name='ne:fans:fan4:rpm']/name", "ne:fans:fan4:rpm"},
242 {"[name='ne:fans:fan4:rpm']/parent", "ne:fans:fan4"},
243 {"[name='ne:fans:fan4:rpm']/sensor-data", ""},
244 {"[name='ne:fans:fan4:rpm']/sensor-data/oper-status", "ok"},
245 {"[name='ne:fans:fan4:rpm']/sensor-data/value", "666"},
246 {"[name='ne:fans:fan4:rpm']/sensor-data/value-precision", "0"},
247 {"[name='ne:fans:fan4:rpm']/sensor-data/value-scale", "units"},
248 {"[name='ne:fans:fan4:rpm']/sensor-data/value-type", "rpm"},
249
250 {"[name='ne:ctrl']/name", "ne:ctrl"},
251 {"[name='ne:ctrl']/parent", "ne"},
252 {"[name='ne:ctrl']/class", "iana-hardware:module"},
253 {"[name='ne:ctrl']/sensor-data", ""},
254
255 {"[name='ne:ctrl:temperature-cpu']/name", "ne:ctrl:temperature-cpu"},
256 {"[name='ne:ctrl:temperature-cpu']/class", "iana-hardware:sensor"},
257 {"[name='ne:ctrl:temperature-cpu']/parent", "ne:ctrl"},
258 {"[name='ne:ctrl:temperature-cpu']/sensor-data", ""},
259 {"[name='ne:ctrl:temperature-cpu']/sensor-data/oper-status", "ok"},
260 {"[name='ne:ctrl:temperature-cpu']/sensor-data/value", "41800"},
261 {"[name='ne:ctrl:temperature-cpu']/sensor-data/value-precision", "0"},
262 {"[name='ne:ctrl:temperature-cpu']/sensor-data/value-scale", "milli"},
263 {"[name='ne:ctrl:temperature-cpu']/sensor-data/value-type", "celsius"},
264 {"[name='ne:ctrl:temperature-front']/name", "ne:ctrl:temperature-front"},
265 {"[name='ne:ctrl:temperature-front']/class", "iana-hardware:sensor"},
266 {"[name='ne:ctrl:temperature-front']/parent", "ne:ctrl"},
267 {"[name='ne:ctrl:temperature-front']/sensor-data", ""},
268 {"[name='ne:ctrl:temperature-front']/sensor-data/oper-status", "ok"},
269 {"[name='ne:ctrl:temperature-front']/sensor-data/value", "30800"},
270 {"[name='ne:ctrl:temperature-front']/sensor-data/value-precision", "0"},
271 {"[name='ne:ctrl:temperature-front']/sensor-data/value-scale", "milli"},
272 {"[name='ne:ctrl:temperature-front']/sensor-data/value-type", "celsius"},
273 {"[name='ne:ctrl:temperature-internal-0']/name", "ne:ctrl:temperature-internal-0"},
274 {"[name='ne:ctrl:temperature-internal-0']/class", "iana-hardware:sensor"},
275 {"[name='ne:ctrl:temperature-internal-0']/parent", "ne:ctrl"},
276 {"[name='ne:ctrl:temperature-internal-0']/sensor-data", ""},
277 {"[name='ne:ctrl:temperature-internal-0']/sensor-data/oper-status", "ok"},
278 {"[name='ne:ctrl:temperature-internal-0']/sensor-data/value", "39000"},
279 {"[name='ne:ctrl:temperature-internal-0']/sensor-data/value-precision", "0"},
280 {"[name='ne:ctrl:temperature-internal-0']/sensor-data/value-scale", "milli"},
281 {"[name='ne:ctrl:temperature-internal-0']/sensor-data/value-type", "celsius"},
282 {"[name='ne:ctrl:temperature-internal-1']/name", "ne:ctrl:temperature-internal-1"},
283 {"[name='ne:ctrl:temperature-internal-1']/class", "iana-hardware:sensor"},
284 {"[name='ne:ctrl:temperature-internal-1']/parent", "ne:ctrl"},
285 {"[name='ne:ctrl:temperature-internal-1']/sensor-data", ""},
286 {"[name='ne:ctrl:temperature-internal-1']/sensor-data/oper-status", "ok"},
287 {"[name='ne:ctrl:temperature-internal-1']/sensor-data/value", "36000"},
288 {"[name='ne:ctrl:temperature-internal-1']/sensor-data/value-precision", "0"},
289 {"[name='ne:ctrl:temperature-internal-1']/sensor-data/value-scale", "milli"},
290 {"[name='ne:ctrl:temperature-internal-1']/sensor-data/value-type", "celsius"},
291
292 {"[name='ne:ctrl:emmc']/name", "ne:ctrl:emmc"},
293 {"[name='ne:ctrl:emmc']/parent", "ne:ctrl"},
294 {"[name='ne:ctrl:emmc']/class", "iana-hardware:module"},
295 {"[name='ne:ctrl:emmc']/serial-num", "0x00a8808d"},
296 {"[name='ne:ctrl:emmc']/mfg-date", "2017-02-01T00:00:00Z"},
297 {"[name='ne:ctrl:emmc']/model-name", "8GME4R"},
298 {"[name='ne:ctrl:emmc']/sensor-data", ""},
299 {"[name='ne:ctrl:emmc:lifetime']/name", "ne:ctrl:emmc:lifetime"},
300 {"[name='ne:ctrl:emmc:lifetime']/class", "iana-hardware:sensor"},
301 {"[name='ne:ctrl:emmc:lifetime']/parent", "ne:ctrl:emmc"},
302 {"[name='ne:ctrl:emmc:lifetime']/sensor-data", ""},
303 {"[name='ne:ctrl:emmc:lifetime']/sensor-data/oper-status", "ok"},
304 {"[name='ne:ctrl:emmc:lifetime']/sensor-data/value", "40"},
305 {"[name='ne:ctrl:emmc:lifetime']/sensor-data/value-precision", "0"},
306 {"[name='ne:ctrl:emmc:lifetime']/sensor-data/value-scale", "units"},
307 {"[name='ne:ctrl:emmc:lifetime']/sensor-data/value-type", "other"},
308 {"[name='ne:ctrl:emmc:lifetime']/sensor-data/units-display", "percent"},
309 };
310
311 srSess->session_switch_ds(SR_DS_OPERATIONAL);
312 REQUIRE(dataFromSysrepo(srSess, modulePrefix + "/component") == expected);
313 srSess->session_switch_ds(SR_DS_RUNNING);
314 }
315
316 SECTION("test leafnode query")
317 {
318 const auto xpath = modulePrefix + "/component[name='ne:ctrl:emmc:lifetime']/class";
319 srSess->session_switch_ds(SR_DS_OPERATIONAL);
320 auto val = srSess->get_item(xpath.c_str());
321 srSess->session_switch_ds(SR_DS_RUNNING);
322 REQUIRE(!!val);
323 REQUIRE(val->data()->get_identityref() == "iana-hardware:sensor"s);
324 }
325 }
Tomáš Pecka339bc672020-11-11 15:59:03 +0100326}