Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 1 | #include "trompeloeil_doctest.h" |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 2 | #include <cstdint> |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 3 | #include "ietf-hardware/IETFHardware.h" |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 4 | #include "ietf-hardware/thresholds.h" |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 5 | #include "mock/ietf_hardware.h" |
| 6 | #include "pretty_printers.h" |
| 7 | #include "test_log_setup.h" |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 8 | |
| 9 | using namespace std::literals; |
| 10 | |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 11 | #define NUKE_LAST_CHANGE(DATA) DATA.erase("/ietf-hardware:hardware/last-change") |
| 12 | |
| 13 | #define THRESHOLD_STATE(RESOURCE, STATE) {"/ietf-hardware:hardware/component[name='" RESOURCE "']/sensor-data/value", STATE} |
| 14 | |
| 15 | using velia::ietf_hardware::State; |
| 16 | |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 17 | TEST_CASE("HardwareState") |
| 18 | { |
| 19 | TEST_INIT_LOGS; |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 20 | |
| 21 | trompeloeil::sequence seq1; |
Tomáš Pecka | 83b62e1 | 2020-12-16 14:50:49 +0100 | [diff] [blame] | 22 | auto ietfHardware = std::make_shared<velia::ietf_hardware::IETFHardware>(); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 23 | |
| 24 | auto fans = std::make_shared<FakeHWMon>(); |
| 25 | auto sysfsTempCpu = std::make_shared<FakeHWMon>(); |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 26 | auto sysfsVoltageAc = std::make_shared<FakeHWMon>(); |
| 27 | auto sysfsVoltageDc = std::make_shared<FakeHWMon>(); |
| 28 | auto sysfsPower = std::make_shared<FakeHWMon>(); |
| 29 | auto sysfsCurrent = std::make_shared<FakeHWMon>(); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 30 | auto emmc = std::make_shared<FakeEMMC>(); |
| 31 | |
| 32 | std::map<std::string, std::string> attributesEMMC; |
| 33 | std::map<std::string, int64_t> attributesHWMon; |
| 34 | |
| 35 | // initialize all mocks |
| 36 | attributesEMMC = { |
| 37 | // FIXME passing initializer_list to macro is hell |
| 38 | {"date"s, "02/2017"s}, |
| 39 | {"serial"s, "0x00a8808d"s}, |
| 40 | {"name"s, "8GME4R"s}, |
| 41 | }; |
| 42 | FAKE_EMMC(emmc, attributesEMMC); |
| 43 | |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 44 | std::array<int64_t, 4> fanValues = {777, 0, 1280, 666}; |
| 45 | REQUIRE_CALL(*fans, attribute("fan1_input"s)).LR_RETURN(fanValues[0]).TIMES(4); |
| 46 | REQUIRE_CALL(*fans, attribute("fan2_input"s)).LR_RETURN(fanValues[1]).TIMES(4); |
| 47 | REQUIRE_CALL(*fans, attribute("fan3_input"s)).LR_RETURN(fanValues[2]).TIMES(4); |
| 48 | REQUIRE_CALL(*fans, attribute("fan4_input"s)).LR_RETURN(fanValues[3]).TIMES(4); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 49 | |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 50 | REQUIRE_CALL(*sysfsTempCpu, attribute("temp1_input")).RETURN(41800).TIMES(4); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 51 | |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 52 | REQUIRE_CALL(*sysfsVoltageAc, attribute("in1_input")).RETURN(220000).TIMES(4); |
| 53 | REQUIRE_CALL(*sysfsVoltageDc, attribute("in1_input")).RETURN(12000).TIMES(4); |
| 54 | REQUIRE_CALL(*sysfsPower, attribute("power1_input")).RETURN(14000000).TIMES(4); |
| 55 | REQUIRE_CALL(*sysfsCurrent, attribute("curr1_input")).RETURN(200).TIMES(4); |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 56 | |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 57 | attributesEMMC = {{"life_time"s, "40"s}}; |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 58 | FAKE_EMMC(emmc, attributesEMMC).TIMES(4); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 59 | |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 60 | using velia::ietf_hardware::OneThreshold; |
| 61 | using velia::ietf_hardware::Thresholds; |
Tomáš Pecka | 63c3c3c | 2023-04-13 18:20:22 +0200 | [diff] [blame] | 62 | using velia::ietf_hardware::data_reader::EMMC; |
| 63 | using velia::ietf_hardware::data_reader::Fans; |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 64 | using velia::ietf_hardware::data_reader::SensorType; |
| 65 | using velia::ietf_hardware::data_reader::StaticData; |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 66 | using velia::ietf_hardware::data_reader::SysfsValue; |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 67 | |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 68 | // register components into hw state |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 69 | ietfHardware->registerDataReader(StaticData("ne", std::nullopt, {{"class", "iana-hardware:chassis"}, {"mfg-name", "CESNET"s}})); |
| 70 | ietfHardware->registerDataReader(StaticData("ne:ctrl", "ne", {{"class", "iana-hardware:module"}})); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 71 | ietfHardware->registerDataReader(Fans("ne:fans", "ne", fans, 4, Thresholds<int64_t>{ |
| 72 | .criticalLow = OneThreshold<int64_t>{300, 200}, |
| 73 | .warningLow = OneThreshold<int64_t>{600, 200}, |
| 74 | .warningHigh = std::nullopt, |
| 75 | .criticalHigh =std::nullopt, |
| 76 | })); |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 77 | ietfHardware->registerDataReader(SysfsValue<SensorType::Temperature>("ne:ctrl:temperature-cpu", "ne:ctrl", sysfsTempCpu, 1)); |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 78 | ietfHardware->registerDataReader(SysfsValue<SensorType::VoltageAC>("ne:ctrl:voltage-in", "ne:ctrl", sysfsVoltageAc, 1)); |
| 79 | ietfHardware->registerDataReader(SysfsValue<SensorType::VoltageDC>("ne:ctrl:voltage-out", "ne:ctrl", sysfsVoltageDc, 1)); |
| 80 | ietfHardware->registerDataReader(SysfsValue<SensorType::Power>("ne:ctrl:power", "ne:ctrl", sysfsPower, 1)); |
| 81 | ietfHardware->registerDataReader(SysfsValue<SensorType::Current>("ne:ctrl:current", "ne:ctrl", sysfsCurrent, 1)); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 82 | ietfHardware->registerDataReader(EMMC("ne:ctrl:emmc", "ne:ctrl", emmc, Thresholds<int64_t>{ |
| 83 | .criticalLow = OneThreshold<int64_t>{20, 0}, |
| 84 | .warningLow = OneThreshold<int64_t>{50, 0}, |
| 85 | .warningHigh = std::nullopt, |
| 86 | .criticalHigh = std::nullopt, |
| 87 | })); |
| 88 | |
| 89 | /* Some data readers (like our PSU reader, see the FspYhPsu test) may set oper-state to enabled/disabled depending on whether the device is present. |
| 90 | * If the device is not present we also don't want to report some elements of the data tree that contain a sensor (ne:psu:child in this case). |
| 91 | * This should also trigger the alarm reporting that the sensor is missing so we should test that the State::NoValue is reported when the sensor disappears. |
| 92 | */ |
| 93 | struct PsuDataReader { |
| 94 | const bool& active; |
| 95 | |
| 96 | velia::ietf_hardware::DataTree operator()() |
| 97 | { |
| 98 | velia::ietf_hardware::DataTree res = { |
| 99 | {"/ietf-hardware:hardware/component[name='ne:psu']/class", "iana-hardware:power-supply"}, |
| 100 | {"/ietf-hardware:hardware/component[name='ne:psu']/parent", "ne"}, |
| 101 | {"/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state", "disabled"}, |
| 102 | }; |
| 103 | |
| 104 | if (active) { |
| 105 | res["/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state"] = "enabled"; |
| 106 | res["/ietf-hardware:hardware/component[name='ne:psu:child']/class"] = "iana-hardware:sensor"; |
| 107 | res["/ietf-hardware:hardware/component[name='ne:psu:child']/parent"] = "ne:psu"; |
| 108 | res["/ietf-hardware:hardware/component[name='ne:psu:child']/state/oper-state"] = "enabled"; |
| 109 | res["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/oper-status"] = "ok"; |
| 110 | res["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value"] = "20000"; |
| 111 | res["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-precision"] = "0"; |
| 112 | res["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-scale"] = "milli"; |
| 113 | res["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-type"] = "volts-DC"; |
| 114 | } |
| 115 | |
| 116 | return res; |
| 117 | } |
| 118 | |
| 119 | velia::ietf_hardware::ThresholdsBySensorPath thresholds() const |
| 120 | { |
| 121 | return {{"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value", Thresholds<int64_t>{ |
| 122 | .criticalLow = std::nullopt, |
| 123 | .warningLow = OneThreshold<int64_t>{10000, 2000}, |
| 124 | .warningHigh = OneThreshold<int64_t>{15000, 2000}, |
| 125 | .criticalHigh = std::nullopt, |
| 126 | }}}; |
| 127 | } |
| 128 | }; |
| 129 | bool psuActive = true; |
| 130 | ietfHardware->registerDataReader(PsuDataReader{psuActive}); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 131 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 132 | std::map<std::string, std::string> expected = { |
| 133 | {"/ietf-hardware:hardware/component[name='ne']/class", "iana-hardware:chassis"}, |
| 134 | {"/ietf-hardware:hardware/component[name='ne']/mfg-name", "CESNET"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 135 | {"/ietf-hardware:hardware/component[name='ne']/state/oper-state", "enabled"}, |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 136 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 137 | {"/ietf-hardware:hardware/component[name='ne:fans']/class", "iana-hardware:module"}, |
| 138 | {"/ietf-hardware:hardware/component[name='ne:fans']/parent", "ne"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 139 | {"/ietf-hardware:hardware/component[name='ne:fans']/state/oper-state", "enabled"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 140 | {"/ietf-hardware:hardware/component[name='ne:fans:fan1']/class", "iana-hardware:fan"}, |
| 141 | {"/ietf-hardware:hardware/component[name='ne:fans:fan1']/parent", "ne:fans"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 142 | {"/ietf-hardware:hardware/component[name='ne:fans:fan1']/state/oper-state", "enabled"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 143 | {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/class", "iana-hardware:sensor"}, |
| 144 | {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/parent", "ne:fans:fan1"}, |
| 145 | {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/oper-status", "ok"}, |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 146 | {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value", "777"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 147 | {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value-precision", "0"}, |
| 148 | {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value-scale", "units"}, |
| 149 | {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value-type", "rpm"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 150 | {"/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/state/oper-state", "enabled"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 151 | {"/ietf-hardware:hardware/component[name='ne:fans:fan2']/class", "iana-hardware:fan"}, |
| 152 | {"/ietf-hardware:hardware/component[name='ne:fans:fan2']/parent", "ne:fans"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 153 | {"/ietf-hardware:hardware/component[name='ne:fans:fan2']/state/oper-state", "enabled"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 154 | {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/class", "iana-hardware:sensor"}, |
| 155 | {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/parent", "ne:fans:fan2"}, |
| 156 | {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/oper-status", "ok"}, |
| 157 | {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value", "0"}, |
| 158 | {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value-precision", "0"}, |
| 159 | {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value-scale", "units"}, |
| 160 | {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value-type", "rpm"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 161 | {"/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/state/oper-state", "enabled"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 162 | {"/ietf-hardware:hardware/component[name='ne:fans:fan3']/class", "iana-hardware:fan"}, |
| 163 | {"/ietf-hardware:hardware/component[name='ne:fans:fan3']/parent", "ne:fans"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 164 | {"/ietf-hardware:hardware/component[name='ne:fans:fan3']/state/oper-state", "enabled"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 165 | {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/class", "iana-hardware:sensor"}, |
| 166 | {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/parent", "ne:fans:fan3"}, |
| 167 | {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/oper-status", "ok"}, |
| 168 | {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value", "1280"}, |
| 169 | {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value-precision", "0"}, |
| 170 | {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value-scale", "units"}, |
| 171 | {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value-type", "rpm"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 172 | {"/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/state/oper-state", "enabled"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 173 | {"/ietf-hardware:hardware/component[name='ne:fans:fan4']/class", "iana-hardware:fan"}, |
| 174 | {"/ietf-hardware:hardware/component[name='ne:fans:fan4']/parent", "ne:fans"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 175 | {"/ietf-hardware:hardware/component[name='ne:fans:fan4']/state/oper-state", "enabled"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 176 | {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/class", "iana-hardware:sensor"}, |
| 177 | {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/parent", "ne:fans:fan4"}, |
| 178 | {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/oper-status", "ok"}, |
| 179 | {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value", "666"}, |
| 180 | {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value-precision", "0"}, |
| 181 | {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value-scale", "units"}, |
| 182 | {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value-type", "rpm"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 183 | {"/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/state/oper-state", "enabled"}, |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 184 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 185 | {"/ietf-hardware:hardware/component[name='ne:ctrl']/parent", "ne"}, |
| 186 | {"/ietf-hardware:hardware/component[name='ne:ctrl']/class", "iana-hardware:module"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 187 | {"/ietf-hardware:hardware/component[name='ne:ctrl']/state/oper-state", "enabled"}, |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 188 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 189 | {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/class", "iana-hardware:sensor"}, |
| 190 | {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/parent", "ne:ctrl"}, |
| 191 | {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/oper-status", "ok"}, |
| 192 | {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value", "41800"}, |
| 193 | {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value-precision", "0"}, |
| 194 | {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value-scale", "milli"}, |
| 195 | {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value-type", "celsius"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 196 | {"/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/state/oper-state", "enabled"}, |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 197 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 198 | {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/class", "iana-hardware:sensor"}, |
| 199 | {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/parent", "ne:ctrl"}, |
| 200 | {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/sensor-data/oper-status", "ok"}, |
| 201 | {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/sensor-data/value", "14000000"}, |
| 202 | {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/sensor-data/value-precision", "0"}, |
| 203 | {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/sensor-data/value-scale", "micro"}, |
| 204 | {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/sensor-data/value-type", "watts"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 205 | {"/ietf-hardware:hardware/component[name='ne:ctrl:power']/state/oper-state", "enabled"}, |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 206 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 207 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/class", "iana-hardware:sensor"}, |
| 208 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/parent", "ne:ctrl"}, |
| 209 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/sensor-data/oper-status", "ok"}, |
| 210 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/sensor-data/value", "220000"}, |
| 211 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/sensor-data/value-precision", "0"}, |
| 212 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/sensor-data/value-scale", "milli"}, |
| 213 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/sensor-data/value-type", "volts-AC"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 214 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/state/oper-state", "enabled"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 215 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/class", "iana-hardware:sensor"}, |
| 216 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/parent", "ne:ctrl"}, |
| 217 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/sensor-data/oper-status", "ok"}, |
| 218 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/sensor-data/value", "12000"}, |
| 219 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/sensor-data/value-precision", "0"}, |
| 220 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/sensor-data/value-scale", "milli"}, |
| 221 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/sensor-data/value-type", "volts-DC"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 222 | {"/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/state/oper-state", "enabled"}, |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 223 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 224 | {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/class", "iana-hardware:sensor"}, |
| 225 | {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/parent", "ne:ctrl"}, |
| 226 | {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/sensor-data/oper-status", "ok"}, |
| 227 | {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/sensor-data/value", "200"}, |
| 228 | {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/sensor-data/value-precision", "0"}, |
| 229 | {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/sensor-data/value-scale", "milli"}, |
| 230 | {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/sensor-data/value-type", "amperes"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 231 | {"/ietf-hardware:hardware/component[name='ne:ctrl:current']/state/oper-state", "enabled"}, |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 232 | |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 233 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/parent", "ne:ctrl"}, |
| 234 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/class", "iana-hardware:module"}, |
| 235 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/serial-num", "0x00a8808d"}, |
| 236 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/mfg-date", "2017-02-01T00:00:00-00:00"}, |
| 237 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/model-name", "8GME4R"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 238 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc']/state/oper-state", "enabled"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 239 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/class", "iana-hardware:sensor"}, |
| 240 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/parent", "ne:ctrl:emmc"}, |
| 241 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/oper-status", "ok"}, |
| 242 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value", "40"}, |
| 243 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value-precision", "0"}, |
| 244 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value-scale", "units"}, |
| 245 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value-type", "other"}, |
| 246 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/units-display", "percent"}, |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 247 | {"/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/state/oper-state", "enabled"}, |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 248 | |
| 249 | {"/ietf-hardware:hardware/component[name='ne:psu']/class", "iana-hardware:power-supply"}, |
| 250 | {"/ietf-hardware:hardware/component[name='ne:psu']/parent", "ne"}, |
| 251 | {"/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state", "enabled"}, |
| 252 | {"/ietf-hardware:hardware/component[name='ne:psu:child']/class", "iana-hardware:sensor"}, |
| 253 | {"/ietf-hardware:hardware/component[name='ne:psu:child']/parent", "ne:psu"}, |
| 254 | {"/ietf-hardware:hardware/component[name='ne:psu:child']/state/oper-state", "enabled"}, |
| 255 | {"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/oper-status", "ok"}, |
| 256 | {"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value", "20000"}, |
| 257 | {"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-precision", "0"}, |
| 258 | {"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-scale", "milli"}, |
| 259 | {"/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-type", "volts-DC"}, |
Tomáš Pecka | 3f81196 | 2023-04-14 10:54:32 +0200 | [diff] [blame] | 260 | }; |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 261 | |
Tomáš Pecka | d2322ad | 2023-05-11 16:20:38 +0200 | [diff] [blame] | 262 | REQUIRE(ietfHardware->sensorsXPaths() == std::vector<std::string>{ |
| 263 | "/ietf-hardware:hardware/component[name='ne:ctrl:current']/sensor-data/value", |
| 264 | "/ietf-hardware:hardware/component[name='ne:ctrl:emmc:lifetime']/sensor-data/value", |
| 265 | "/ietf-hardware:hardware/component[name='ne:ctrl:power']/sensor-data/value", |
| 266 | "/ietf-hardware:hardware/component[name='ne:ctrl:temperature-cpu']/sensor-data/value", |
| 267 | "/ietf-hardware:hardware/component[name='ne:ctrl:voltage-in']/sensor-data/value", |
| 268 | "/ietf-hardware:hardware/component[name='ne:ctrl:voltage-out']/sensor-data/value", |
| 269 | "/ietf-hardware:hardware/component[name='ne:fans:fan1:rpm']/sensor-data/value", |
| 270 | "/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value", |
| 271 | "/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value", |
| 272 | "/ietf-hardware:hardware/component[name='ne:fans:fan4:rpm']/sensor-data/value", |
| 273 | "/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value", |
| 274 | }); |
| 275 | |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 276 | { |
| 277 | auto [data, alarms] = ietfHardware->process(); |
| 278 | NUKE_LAST_CHANGE(data); |
| 279 | REQUIRE(data == expected); |
| 280 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 281 | THRESHOLD_STATE("ne:ctrl:current", State::Disabled), |
| 282 | THRESHOLD_STATE("ne:ctrl:power", State::Disabled), |
| 283 | THRESHOLD_STATE("ne:ctrl:temperature-cpu", State::Disabled), |
| 284 | THRESHOLD_STATE("ne:ctrl:voltage-in", State::Disabled), |
| 285 | THRESHOLD_STATE("ne:ctrl:voltage-out", State::Disabled), |
| 286 | THRESHOLD_STATE("ne:ctrl:emmc:lifetime", State::WarningLow), |
| 287 | THRESHOLD_STATE("ne:fans:fan1:rpm", State::Normal), |
| 288 | THRESHOLD_STATE("ne:fans:fan2:rpm", State::CriticalLow), |
| 289 | THRESHOLD_STATE("ne:fans:fan3:rpm", State::Normal), |
| 290 | THRESHOLD_STATE("ne:fans:fan4:rpm", State::Normal), |
| 291 | THRESHOLD_STATE("ne:psu:child", State::WarningHigh), |
| 292 | }); |
| 293 | } |
| 294 | |
| 295 | fanValues[1] = 500; |
| 296 | expected["/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value"] = "500"; |
| 297 | { |
| 298 | auto [data, alarms] = ietfHardware->process(); |
| 299 | NUKE_LAST_CHANGE(data); |
| 300 | REQUIRE(data == expected); |
| 301 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 302 | THRESHOLD_STATE("ne:fans:fan2:rpm", State::WarningLow), |
| 303 | }); |
| 304 | } |
| 305 | |
| 306 | psuActive = false; |
| 307 | fanValues[1] = 1; |
| 308 | fanValues[2] = 5000; |
| 309 | |
| 310 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/class"); |
| 311 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/parent"); |
| 312 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/state/oper-state"); |
| 313 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/oper-status"); |
| 314 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value"); |
| 315 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-precision"); |
| 316 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-scale"); |
| 317 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-type"); |
| 318 | expected["/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state"] = "disabled"; |
| 319 | expected["/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value"] = "1"; |
| 320 | expected["/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value"] = "5000"; |
| 321 | |
| 322 | { |
| 323 | auto [data, alarms] = ietfHardware->process(); |
| 324 | NUKE_LAST_CHANGE(data); |
| 325 | |
| 326 | REQUIRE(data == expected); |
| 327 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 328 | THRESHOLD_STATE("ne:fans:fan2:rpm", State::CriticalLow), |
| 329 | THRESHOLD_STATE("ne:psu:child", State::NoValue), |
| 330 | }); |
| 331 | } |
| 332 | |
| 333 | psuActive = true; |
| 334 | expected["/ietf-hardware:hardware/component[name='ne:psu']/class"] = "iana-hardware:power-supply"; |
| 335 | expected["/ietf-hardware:hardware/component[name='ne:psu']/parent"] = "ne"; |
| 336 | expected["/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state"] = "enabled"; |
| 337 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/class"] = "iana-hardware:sensor"; |
| 338 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/parent"] = "ne:psu"; |
| 339 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/state/oper-state"] = "enabled"; |
| 340 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/oper-status"] = "ok"; |
| 341 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value"] = "20000"; |
| 342 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-precision"] = "0"; |
| 343 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-scale"] = "milli"; |
| 344 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-type"] = "volts-DC"; |
| 345 | |
| 346 | { |
| 347 | auto [data, alarms] = ietfHardware->process(); |
| 348 | NUKE_LAST_CHANGE(data); |
| 349 | |
| 350 | REQUIRE(data == expected); |
| 351 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 352 | THRESHOLD_STATE("ne:psu:child", State::WarningHigh), |
| 353 | }); |
| 354 | } |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 355 | } |