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 | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame^] | 262 | { |
| 263 | auto [data, alarms] = ietfHardware->process(); |
| 264 | NUKE_LAST_CHANGE(data); |
| 265 | REQUIRE(data == expected); |
| 266 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 267 | THRESHOLD_STATE("ne:ctrl:current", State::Disabled), |
| 268 | THRESHOLD_STATE("ne:ctrl:power", State::Disabled), |
| 269 | THRESHOLD_STATE("ne:ctrl:temperature-cpu", State::Disabled), |
| 270 | THRESHOLD_STATE("ne:ctrl:voltage-in", State::Disabled), |
| 271 | THRESHOLD_STATE("ne:ctrl:voltage-out", State::Disabled), |
| 272 | THRESHOLD_STATE("ne:ctrl:emmc:lifetime", State::WarningLow), |
| 273 | THRESHOLD_STATE("ne:fans:fan1:rpm", State::Normal), |
| 274 | THRESHOLD_STATE("ne:fans:fan2:rpm", State::CriticalLow), |
| 275 | THRESHOLD_STATE("ne:fans:fan3:rpm", State::Normal), |
| 276 | THRESHOLD_STATE("ne:fans:fan4:rpm", State::Normal), |
| 277 | THRESHOLD_STATE("ne:psu:child", State::WarningHigh), |
| 278 | }); |
| 279 | } |
| 280 | |
| 281 | fanValues[1] = 500; |
| 282 | expected["/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value"] = "500"; |
| 283 | { |
| 284 | auto [data, alarms] = ietfHardware->process(); |
| 285 | NUKE_LAST_CHANGE(data); |
| 286 | REQUIRE(data == expected); |
| 287 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 288 | THRESHOLD_STATE("ne:fans:fan2:rpm", State::WarningLow), |
| 289 | }); |
| 290 | } |
| 291 | |
| 292 | psuActive = false; |
| 293 | fanValues[1] = 1; |
| 294 | fanValues[2] = 5000; |
| 295 | |
| 296 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/class"); |
| 297 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/parent"); |
| 298 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/state/oper-state"); |
| 299 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/oper-status"); |
| 300 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value"); |
| 301 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-precision"); |
| 302 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-scale"); |
| 303 | expected.erase("/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-type"); |
| 304 | expected["/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state"] = "disabled"; |
| 305 | expected["/ietf-hardware:hardware/component[name='ne:fans:fan2:rpm']/sensor-data/value"] = "1"; |
| 306 | expected["/ietf-hardware:hardware/component[name='ne:fans:fan3:rpm']/sensor-data/value"] = "5000"; |
| 307 | |
| 308 | { |
| 309 | auto [data, alarms] = ietfHardware->process(); |
| 310 | NUKE_LAST_CHANGE(data); |
| 311 | |
| 312 | REQUIRE(data == expected); |
| 313 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 314 | THRESHOLD_STATE("ne:fans:fan2:rpm", State::CriticalLow), |
| 315 | THRESHOLD_STATE("ne:psu:child", State::NoValue), |
| 316 | }); |
| 317 | } |
| 318 | |
| 319 | psuActive = true; |
| 320 | expected["/ietf-hardware:hardware/component[name='ne:psu']/class"] = "iana-hardware:power-supply"; |
| 321 | expected["/ietf-hardware:hardware/component[name='ne:psu']/parent"] = "ne"; |
| 322 | expected["/ietf-hardware:hardware/component[name='ne:psu']/state/oper-state"] = "enabled"; |
| 323 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/class"] = "iana-hardware:sensor"; |
| 324 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/parent"] = "ne:psu"; |
| 325 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/state/oper-state"] = "enabled"; |
| 326 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/oper-status"] = "ok"; |
| 327 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value"] = "20000"; |
| 328 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-precision"] = "0"; |
| 329 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-scale"] = "milli"; |
| 330 | expected["/ietf-hardware:hardware/component[name='ne:psu:child']/sensor-data/value-type"] = "volts-DC"; |
| 331 | |
| 332 | { |
| 333 | auto [data, alarms] = ietfHardware->process(); |
| 334 | NUKE_LAST_CHANGE(data); |
| 335 | |
| 336 | REQUIRE(data == expected); |
| 337 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 338 | THRESHOLD_STATE("ne:psu:child", State::WarningHigh), |
| 339 | }); |
| 340 | } |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 341 | } |