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 | |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 13 | #define COMPONENT(RESOURCE) "/ietf-hardware:hardware/component[name='" RESOURCE "']" |
| 14 | |
| 15 | #define THRESHOLD_STATE(RESOURCE, STATE) {COMPONENT(RESOURCE) "/sensor-data/value", STATE} |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 16 | |
| 17 | using velia::ietf_hardware::State; |
| 18 | |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 19 | TEST_CASE("HardwareState") |
| 20 | { |
| 21 | TEST_INIT_LOGS; |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 22 | |
| 23 | trompeloeil::sequence seq1; |
Tomáš Pecka | 83b62e1 | 2020-12-16 14:50:49 +0100 | [diff] [blame] | 24 | auto ietfHardware = std::make_shared<velia::ietf_hardware::IETFHardware>(); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 25 | |
| 26 | auto fans = std::make_shared<FakeHWMon>(); |
| 27 | auto sysfsTempCpu = std::make_shared<FakeHWMon>(); |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 28 | auto sysfsVoltageAc = std::make_shared<FakeHWMon>(); |
| 29 | auto sysfsVoltageDc = std::make_shared<FakeHWMon>(); |
| 30 | auto sysfsPower = std::make_shared<FakeHWMon>(); |
| 31 | auto sysfsCurrent = std::make_shared<FakeHWMon>(); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 32 | auto emmc = std::make_shared<FakeEMMC>(); |
| 33 | |
| 34 | std::map<std::string, std::string> attributesEMMC; |
| 35 | std::map<std::string, int64_t> attributesHWMon; |
| 36 | |
| 37 | // initialize all mocks |
| 38 | attributesEMMC = { |
| 39 | // FIXME passing initializer_list to macro is hell |
| 40 | {"date"s, "02/2017"s}, |
| 41 | {"serial"s, "0x00a8808d"s}, |
| 42 | {"name"s, "8GME4R"s}, |
| 43 | }; |
| 44 | FAKE_EMMC(emmc, attributesEMMC); |
| 45 | |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 46 | std::array<int64_t, 4> fanValues = {777, 0, 1280, 666}; |
Tomáš Pecka | cd7f9cc | 2023-12-11 15:52:48 +0100 | [diff] [blame] | 47 | REQUIRE_CALL(*fans, attribute("fan1_input"s)).LR_RETURN(fanValues[0]).TIMES(5); |
| 48 | REQUIRE_CALL(*fans, attribute("fan2_input"s)).LR_RETURN(fanValues[1]).TIMES(5); |
| 49 | REQUIRE_CALL(*fans, attribute("fan3_input"s)).LR_RETURN(fanValues[2]).TIMES(5); |
| 50 | REQUIRE_CALL(*fans, attribute("fan4_input"s)).LR_RETURN(fanValues[3]).TIMES(5); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 51 | |
Tomáš Pecka | cd7f9cc | 2023-12-11 15:52:48 +0100 | [diff] [blame] | 52 | REQUIRE_CALL(*sysfsTempCpu, attribute("temp1_input")).RETURN(41800).TIMES(5); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 53 | |
Tomáš Pecka | cd7f9cc | 2023-12-11 15:52:48 +0100 | [diff] [blame] | 54 | REQUIRE_CALL(*sysfsVoltageAc, attribute("in1_input")).RETURN(220000).TIMES(5); |
| 55 | REQUIRE_CALL(*sysfsVoltageDc, attribute("in1_input")).RETURN(12000).TIMES(5); |
| 56 | REQUIRE_CALL(*sysfsPower, attribute("power1_input")).RETURN(14000000).TIMES(5); |
| 57 | REQUIRE_CALL(*sysfsCurrent, attribute("curr1_input")).RETURN(200).TIMES(5); |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 58 | |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 59 | attributesEMMC = {{"life_time"s, "40"s}}; |
Tomáš Pecka | cd7f9cc | 2023-12-11 15:52:48 +0100 | [diff] [blame] | 60 | FAKE_EMMC(emmc, attributesEMMC).TIMES(5); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 61 | |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 62 | using velia::ietf_hardware::OneThreshold; |
| 63 | using velia::ietf_hardware::Thresholds; |
Tomáš Pecka | 63c3c3c | 2023-04-13 18:20:22 +0200 | [diff] [blame] | 64 | using velia::ietf_hardware::data_reader::EMMC; |
| 65 | using velia::ietf_hardware::data_reader::Fans; |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 66 | using velia::ietf_hardware::data_reader::SensorType; |
| 67 | using velia::ietf_hardware::data_reader::StaticData; |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 68 | using velia::ietf_hardware::data_reader::SysfsValue; |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 69 | |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 70 | // register components into hw state |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 71 | ietfHardware->registerDataReader(StaticData("ne", std::nullopt, {{"class", "iana-hardware:chassis"}, {"mfg-name", "CESNET"s}})); |
| 72 | ietfHardware->registerDataReader(StaticData("ne:ctrl", "ne", {{"class", "iana-hardware:module"}})); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 73 | ietfHardware->registerDataReader(Fans("ne:fans", "ne", fans, 4, Thresholds<int64_t>{ |
| 74 | .criticalLow = OneThreshold<int64_t>{300, 200}, |
| 75 | .warningLow = OneThreshold<int64_t>{600, 200}, |
| 76 | .warningHigh = std::nullopt, |
| 77 | .criticalHigh =std::nullopt, |
| 78 | })); |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 79 | 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] | 80 | ietfHardware->registerDataReader(SysfsValue<SensorType::VoltageAC>("ne:ctrl:voltage-in", "ne:ctrl", sysfsVoltageAc, 1)); |
| 81 | ietfHardware->registerDataReader(SysfsValue<SensorType::VoltageDC>("ne:ctrl:voltage-out", "ne:ctrl", sysfsVoltageDc, 1)); |
| 82 | ietfHardware->registerDataReader(SysfsValue<SensorType::Power>("ne:ctrl:power", "ne:ctrl", sysfsPower, 1)); |
| 83 | ietfHardware->registerDataReader(SysfsValue<SensorType::Current>("ne:ctrl:current", "ne:ctrl", sysfsCurrent, 1)); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 84 | ietfHardware->registerDataReader(EMMC("ne:ctrl:emmc", "ne:ctrl", emmc, Thresholds<int64_t>{ |
| 85 | .criticalLow = OneThreshold<int64_t>{20, 0}, |
| 86 | .warningLow = OneThreshold<int64_t>{50, 0}, |
| 87 | .warningHigh = std::nullopt, |
| 88 | .criticalHigh = std::nullopt, |
| 89 | })); |
| 90 | |
| 91 | /* 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. |
| 92 | * 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). |
| 93 | * 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. |
| 94 | */ |
| 95 | struct PsuDataReader { |
| 96 | const bool& active; |
| 97 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 98 | velia::ietf_hardware::SensorPollData operator()() |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 99 | { |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 100 | velia::ietf_hardware::ThresholdsBySensorPath thr; |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 101 | velia::ietf_hardware::DataTree res = { |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 102 | {COMPONENT("ne:psu") "/class", "iana-hardware:power-supply"}, |
| 103 | {COMPONENT("ne:psu") "/parent", "ne"}, |
| 104 | {COMPONENT("ne:psu") "/state/oper-state", "disabled"}, |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | if (active) { |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 108 | res[COMPONENT("ne:psu") "/state/oper-state"] = "enabled"; |
| 109 | res[COMPONENT("ne:psu:child") "/class"] = "iana-hardware:sensor"; |
| 110 | res[COMPONENT("ne:psu:child") "/parent"] = "ne:psu"; |
| 111 | res[COMPONENT("ne:psu:child") "/state/oper-state"] = "enabled"; |
| 112 | res[COMPONENT("ne:psu:child") "/sensor-data/oper-status"] = "ok"; |
| 113 | res[COMPONENT("ne:psu:child") "/sensor-data/value"] = "20000"; |
| 114 | res[COMPONENT("ne:psu:child") "/sensor-data/value-precision"] = "0"; |
| 115 | res[COMPONENT("ne:psu:child") "/sensor-data/value-scale"] = "milli"; |
| 116 | res[COMPONENT("ne:psu:child") "/sensor-data/value-type"] = "volts-DC"; |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 117 | |
| 118 | thr[COMPONENT("ne:psu:child") "/sensor-data/value"] = Thresholds<int64_t>{ |
| 119 | .criticalLow = std::nullopt, |
| 120 | .warningLow = OneThreshold<int64_t>{10000, 2000}, |
| 121 | .warningHigh = OneThreshold<int64_t>{15000, 2000}, |
| 122 | .criticalHigh = std::nullopt, |
| 123 | }; |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 124 | } |
| 125 | |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 126 | return {res, thr}; |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 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 = { |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 133 | {COMPONENT("ne") "/class", "iana-hardware:chassis"}, |
| 134 | {COMPONENT("ne") "/mfg-name", "CESNET"}, |
| 135 | {COMPONENT("ne") "/state/oper-state", "enabled"}, |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 136 | |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 137 | {COMPONENT("ne:fans") "/class", "iana-hardware:module"}, |
| 138 | {COMPONENT("ne:fans") "/parent", "ne"}, |
| 139 | {COMPONENT("ne:fans") "/state/oper-state", "enabled"}, |
| 140 | {COMPONENT("ne:fans:fan1") "/class", "iana-hardware:fan"}, |
| 141 | {COMPONENT("ne:fans:fan1") "/parent", "ne:fans"}, |
| 142 | {COMPONENT("ne:fans:fan1") "/state/oper-state", "enabled"}, |
| 143 | {COMPONENT("ne:fans:fan1:rpm") "/class", "iana-hardware:sensor"}, |
| 144 | {COMPONENT("ne:fans:fan1:rpm") "/parent", "ne:fans:fan1"}, |
| 145 | {COMPONENT("ne:fans:fan1:rpm") "/sensor-data/oper-status", "ok"}, |
| 146 | THRESHOLD_STATE("ne:fans:fan1:rpm", "777"), |
| 147 | {COMPONENT("ne:fans:fan1:rpm") "/sensor-data/value-precision", "0"}, |
| 148 | {COMPONENT("ne:fans:fan1:rpm") "/sensor-data/value-scale", "units"}, |
| 149 | {COMPONENT("ne:fans:fan1:rpm") "/sensor-data/value-type", "rpm"}, |
| 150 | {COMPONENT("ne:fans:fan1:rpm") "/state/oper-state", "enabled"}, |
| 151 | {COMPONENT("ne:fans:fan2") "/class", "iana-hardware:fan"}, |
| 152 | {COMPONENT("ne:fans:fan2") "/parent", "ne:fans"}, |
| 153 | {COMPONENT("ne:fans:fan2") "/state/oper-state", "enabled"}, |
| 154 | {COMPONENT("ne:fans:fan2:rpm") "/class", "iana-hardware:sensor"}, |
| 155 | {COMPONENT("ne:fans:fan2:rpm") "/parent", "ne:fans:fan2"}, |
| 156 | {COMPONENT("ne:fans:fan2:rpm") "/sensor-data/oper-status", "ok"}, |
| 157 | THRESHOLD_STATE("ne:fans:fan2:rpm", "0"), |
| 158 | {COMPONENT("ne:fans:fan2:rpm") "/sensor-data/value-precision", "0"}, |
| 159 | {COMPONENT("ne:fans:fan2:rpm") "/sensor-data/value-scale", "units"}, |
| 160 | {COMPONENT("ne:fans:fan2:rpm") "/sensor-data/value-type", "rpm"}, |
| 161 | {COMPONENT("ne:fans:fan2:rpm") "/state/oper-state", "enabled"}, |
| 162 | {COMPONENT("ne:fans:fan3") "/class", "iana-hardware:fan"}, |
| 163 | {COMPONENT("ne:fans:fan3") "/parent", "ne:fans"}, |
| 164 | {COMPONENT("ne:fans:fan3") "/state/oper-state", "enabled"}, |
| 165 | {COMPONENT("ne:fans:fan3:rpm") "/class", "iana-hardware:sensor"}, |
| 166 | {COMPONENT("ne:fans:fan3:rpm") "/parent", "ne:fans:fan3"}, |
| 167 | {COMPONENT("ne:fans:fan3:rpm") "/sensor-data/oper-status", "ok"}, |
| 168 | THRESHOLD_STATE("ne:fans:fan3:rpm", "1280"), |
| 169 | {COMPONENT("ne:fans:fan3:rpm") "/sensor-data/value-precision", "0"}, |
| 170 | {COMPONENT("ne:fans:fan3:rpm") "/sensor-data/value-scale", "units"}, |
| 171 | {COMPONENT("ne:fans:fan3:rpm") "/sensor-data/value-type", "rpm"}, |
| 172 | {COMPONENT("ne:fans:fan3:rpm") "/state/oper-state", "enabled"}, |
| 173 | {COMPONENT("ne:fans:fan4") "/class", "iana-hardware:fan"}, |
| 174 | {COMPONENT("ne:fans:fan4") "/parent", "ne:fans"}, |
| 175 | {COMPONENT("ne:fans:fan4") "/state/oper-state", "enabled"}, |
| 176 | {COMPONENT("ne:fans:fan4:rpm") "/class", "iana-hardware:sensor"}, |
| 177 | {COMPONENT("ne:fans:fan4:rpm") "/parent", "ne:fans:fan4"}, |
| 178 | {COMPONENT("ne:fans:fan4:rpm") "/sensor-data/oper-status", "ok"}, |
| 179 | THRESHOLD_STATE("ne:fans:fan4:rpm", "666"), |
| 180 | {COMPONENT("ne:fans:fan4:rpm") "/sensor-data/value-precision", "0"}, |
| 181 | {COMPONENT("ne:fans:fan4:rpm") "/sensor-data/value-scale", "units"}, |
| 182 | {COMPONENT("ne:fans:fan4:rpm") "/sensor-data/value-type", "rpm"}, |
| 183 | {COMPONENT("ne:fans:fan4:rpm") "/state/oper-state", "enabled"}, |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 184 | |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 185 | {COMPONENT("ne:ctrl") "/parent", "ne"}, |
| 186 | {COMPONENT("ne:ctrl") "/class", "iana-hardware:module"}, |
| 187 | {COMPONENT("ne:ctrl") "/state/oper-state", "enabled"}, |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 188 | |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 189 | {COMPONENT("ne:ctrl:temperature-cpu") "/class", "iana-hardware:sensor"}, |
| 190 | {COMPONENT("ne:ctrl:temperature-cpu") "/parent", "ne:ctrl"}, |
| 191 | {COMPONENT("ne:ctrl:temperature-cpu") "/sensor-data/oper-status", "ok"}, |
| 192 | THRESHOLD_STATE("ne:ctrl:temperature-cpu", "41800"), |
| 193 | {COMPONENT("ne:ctrl:temperature-cpu") "/sensor-data/value-precision", "0"}, |
| 194 | {COMPONENT("ne:ctrl:temperature-cpu") "/sensor-data/value-scale", "milli"}, |
| 195 | {COMPONENT("ne:ctrl:temperature-cpu") "/sensor-data/value-type", "celsius"}, |
| 196 | {COMPONENT("ne:ctrl:temperature-cpu") "/state/oper-state", "enabled"}, |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 197 | |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 198 | {COMPONENT("ne:ctrl:power") "/class", "iana-hardware:sensor"}, |
| 199 | {COMPONENT("ne:ctrl:power") "/parent", "ne:ctrl"}, |
| 200 | {COMPONENT("ne:ctrl:power") "/sensor-data/oper-status", "ok"}, |
| 201 | THRESHOLD_STATE("ne:ctrl:power", "14000000"), |
| 202 | {COMPONENT("ne:ctrl:power") "/sensor-data/value-precision", "0"}, |
| 203 | {COMPONENT("ne:ctrl:power") "/sensor-data/value-scale", "micro"}, |
| 204 | {COMPONENT("ne:ctrl:power") "/sensor-data/value-type", "watts"}, |
| 205 | {COMPONENT("ne:ctrl:power") "/state/oper-state", "enabled"}, |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 206 | |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 207 | {COMPONENT("ne:ctrl:voltage-in") "/class", "iana-hardware:sensor"}, |
| 208 | {COMPONENT("ne:ctrl:voltage-in") "/parent", "ne:ctrl"}, |
| 209 | {COMPONENT("ne:ctrl:voltage-in") "/sensor-data/oper-status", "ok"}, |
| 210 | THRESHOLD_STATE("ne:ctrl:voltage-in", "220000"), |
| 211 | {COMPONENT("ne:ctrl:voltage-in") "/sensor-data/value-precision", "0"}, |
| 212 | {COMPONENT("ne:ctrl:voltage-in") "/sensor-data/value-scale", "milli"}, |
| 213 | {COMPONENT("ne:ctrl:voltage-in") "/sensor-data/value-type", "volts-AC"}, |
| 214 | {COMPONENT("ne:ctrl:voltage-in") "/state/oper-state", "enabled"}, |
| 215 | {COMPONENT("ne:ctrl:voltage-out") "/class", "iana-hardware:sensor"}, |
| 216 | {COMPONENT("ne:ctrl:voltage-out") "/parent", "ne:ctrl"}, |
| 217 | {COMPONENT("ne:ctrl:voltage-out") "/sensor-data/oper-status", "ok"}, |
| 218 | THRESHOLD_STATE("ne:ctrl:voltage-out", "12000"), |
| 219 | {COMPONENT("ne:ctrl:voltage-out") "/sensor-data/value-precision", "0"}, |
| 220 | {COMPONENT("ne:ctrl:voltage-out") "/sensor-data/value-scale", "milli"}, |
| 221 | {COMPONENT("ne:ctrl:voltage-out") "/sensor-data/value-type", "volts-DC"}, |
| 222 | {COMPONENT("ne:ctrl:voltage-out") "/state/oper-state", "enabled"}, |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 223 | |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 224 | {COMPONENT("ne:ctrl:current") "/class", "iana-hardware:sensor"}, |
| 225 | {COMPONENT("ne:ctrl:current") "/parent", "ne:ctrl"}, |
| 226 | {COMPONENT("ne:ctrl:current") "/sensor-data/oper-status", "ok"}, |
| 227 | THRESHOLD_STATE("ne:ctrl:current", "200"), |
| 228 | {COMPONENT("ne:ctrl:current") "/sensor-data/value-precision", "0"}, |
| 229 | {COMPONENT("ne:ctrl:current") "/sensor-data/value-scale", "milli"}, |
| 230 | {COMPONENT("ne:ctrl:current") "/sensor-data/value-type", "amperes"}, |
| 231 | {COMPONENT("ne:ctrl:current") "/state/oper-state", "enabled"}, |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 232 | |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 233 | {COMPONENT("ne:ctrl:emmc") "/parent", "ne:ctrl"}, |
| 234 | {COMPONENT("ne:ctrl:emmc") "/class", "iana-hardware:module"}, |
| 235 | {COMPONENT("ne:ctrl:emmc") "/serial-num", "0x00a8808d"}, |
| 236 | {COMPONENT("ne:ctrl:emmc") "/mfg-date", "2017-02-01T00:00:00-00:00"}, |
| 237 | {COMPONENT("ne:ctrl:emmc") "/model-name", "8GME4R"}, |
| 238 | {COMPONENT("ne:ctrl:emmc") "/state/oper-state", "enabled"}, |
| 239 | {COMPONENT("ne:ctrl:emmc:lifetime") "/class", "iana-hardware:sensor"}, |
| 240 | {COMPONENT("ne:ctrl:emmc:lifetime") "/parent", "ne:ctrl:emmc"}, |
| 241 | {COMPONENT("ne:ctrl:emmc:lifetime") "/sensor-data/oper-status", "ok"}, |
| 242 | THRESHOLD_STATE("ne:ctrl:emmc:lifetime", "40"), |
| 243 | {COMPONENT("ne:ctrl:emmc:lifetime") "/sensor-data/value-precision", "0"}, |
| 244 | {COMPONENT("ne:ctrl:emmc:lifetime") "/sensor-data/value-scale", "units"}, |
| 245 | {COMPONENT("ne:ctrl:emmc:lifetime") "/sensor-data/value-type", "other"}, |
| 246 | {COMPONENT("ne:ctrl:emmc:lifetime") "/sensor-data/units-display", "percent"}, |
| 247 | {COMPONENT("ne:ctrl:emmc:lifetime") "/state/oper-state", "enabled"}, |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 248 | |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 249 | {COMPONENT("ne:psu") "/class", "iana-hardware:power-supply"}, |
| 250 | {COMPONENT("ne:psu") "/parent", "ne"}, |
| 251 | {COMPONENT("ne:psu") "/state/oper-state", "enabled"}, |
| 252 | {COMPONENT("ne:psu:child") "/class", "iana-hardware:sensor"}, |
| 253 | {COMPONENT("ne:psu:child") "/parent", "ne:psu"}, |
| 254 | {COMPONENT("ne:psu:child") "/state/oper-state", "enabled"}, |
| 255 | {COMPONENT("ne:psu:child") "/sensor-data/oper-status", "ok"}, |
| 256 | THRESHOLD_STATE("ne:psu:child", "20000"), |
| 257 | {COMPONENT("ne:psu:child") "/sensor-data/value-precision", "0"}, |
| 258 | {COMPONENT("ne:psu:child") "/sensor-data/value-scale", "milli"}, |
| 259 | {COMPONENT("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 | { |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 263 | auto [data, alarms, activeSensors] = ietfHardware->process(); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 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 | }); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 279 | REQUIRE(activeSensors == std::set<std::string>{ |
| 280 | COMPONENT("ne:ctrl:current") "/sensor-data/value", |
| 281 | COMPONENT("ne:ctrl:emmc:lifetime") "/sensor-data/value", |
| 282 | COMPONENT("ne:ctrl:power") "/sensor-data/value", |
| 283 | COMPONENT("ne:ctrl:temperature-cpu") "/sensor-data/value", |
| 284 | COMPONENT("ne:ctrl:voltage-in") "/sensor-data/value", |
| 285 | COMPONENT("ne:ctrl:voltage-out") "/sensor-data/value", |
| 286 | COMPONENT("ne:fans:fan1:rpm") "/sensor-data/value", |
| 287 | COMPONENT("ne:fans:fan2:rpm") "/sensor-data/value", |
| 288 | COMPONENT("ne:fans:fan3:rpm") "/sensor-data/value", |
| 289 | COMPONENT("ne:fans:fan4:rpm") "/sensor-data/value", |
| 290 | COMPONENT("ne:psu:child") "/sensor-data/value", |
| 291 | }); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | fanValues[1] = 500; |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 295 | expected[COMPONENT("ne:fans:fan2:rpm") "/sensor-data/value"] = "500"; |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 296 | { |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 297 | auto [data, alarms, activeSensors] = ietfHardware->process(); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 298 | NUKE_LAST_CHANGE(data); |
| 299 | REQUIRE(data == expected); |
| 300 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 301 | THRESHOLD_STATE("ne:fans:fan2:rpm", State::WarningLow), |
| 302 | }); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 303 | REQUIRE(activeSensors == std::set<std::string>{ |
| 304 | COMPONENT("ne:ctrl:current") "/sensor-data/value", |
| 305 | COMPONENT("ne:ctrl:emmc:lifetime") "/sensor-data/value", |
| 306 | COMPONENT("ne:ctrl:power") "/sensor-data/value", |
| 307 | COMPONENT("ne:ctrl:temperature-cpu") "/sensor-data/value", |
| 308 | COMPONENT("ne:ctrl:voltage-in") "/sensor-data/value", |
| 309 | COMPONENT("ne:ctrl:voltage-out") "/sensor-data/value", |
| 310 | COMPONENT("ne:fans:fan1:rpm") "/sensor-data/value", |
| 311 | COMPONENT("ne:fans:fan2:rpm") "/sensor-data/value", |
| 312 | COMPONENT("ne:fans:fan3:rpm") "/sensor-data/value", |
| 313 | COMPONENT("ne:fans:fan4:rpm") "/sensor-data/value", |
| 314 | COMPONENT("ne:psu:child") "/sensor-data/value", |
| 315 | }); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | psuActive = false; |
| 319 | fanValues[1] = 1; |
| 320 | fanValues[2] = 5000; |
| 321 | |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 322 | expected.erase(COMPONENT("ne:psu:child") "/class"); |
| 323 | expected.erase(COMPONENT("ne:psu:child") "/parent"); |
| 324 | expected.erase(COMPONENT("ne:psu:child") "/state/oper-state"); |
| 325 | expected.erase(COMPONENT("ne:psu:child") "/sensor-data/oper-status"); |
| 326 | expected.erase(COMPONENT("ne:psu:child") "/sensor-data/value"); |
| 327 | expected.erase(COMPONENT("ne:psu:child") "/sensor-data/value-precision"); |
| 328 | expected.erase(COMPONENT("ne:psu:child") "/sensor-data/value-scale"); |
| 329 | expected.erase(COMPONENT("ne:psu:child") "/sensor-data/value-type"); |
| 330 | expected[COMPONENT("ne:psu") "/state/oper-state"] = "disabled"; |
| 331 | expected[COMPONENT("ne:fans:fan2:rpm") "/sensor-data/value"] = "1"; |
| 332 | expected[COMPONENT("ne:fans:fan3:rpm") "/sensor-data/value"] = "5000"; |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 333 | |
| 334 | { |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 335 | auto [data, alarms, activeSensors] = ietfHardware->process(); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 336 | NUKE_LAST_CHANGE(data); |
| 337 | |
| 338 | REQUIRE(data == expected); |
| 339 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 340 | THRESHOLD_STATE("ne:fans:fan2:rpm", State::CriticalLow), |
| 341 | THRESHOLD_STATE("ne:psu:child", State::NoValue), |
| 342 | }); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 343 | REQUIRE(activeSensors == std::set<std::string>{ |
| 344 | COMPONENT("ne:ctrl:current") "/sensor-data/value", |
| 345 | COMPONENT("ne:ctrl:emmc:lifetime") "/sensor-data/value", |
| 346 | COMPONENT("ne:ctrl:power") "/sensor-data/value", |
| 347 | COMPONENT("ne:ctrl:temperature-cpu") "/sensor-data/value", |
| 348 | COMPONENT("ne:ctrl:voltage-in") "/sensor-data/value", |
| 349 | COMPONENT("ne:ctrl:voltage-out") "/sensor-data/value", |
| 350 | COMPONENT("ne:fans:fan1:rpm") "/sensor-data/value", |
| 351 | COMPONENT("ne:fans:fan2:rpm") "/sensor-data/value", |
| 352 | COMPONENT("ne:fans:fan3:rpm") "/sensor-data/value", |
| 353 | COMPONENT("ne:fans:fan4:rpm") "/sensor-data/value", |
| 354 | }); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | psuActive = true; |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 358 | expected[COMPONENT("ne:psu") "/class"] = "iana-hardware:power-supply"; |
| 359 | expected[COMPONENT("ne:psu") "/parent"] = "ne"; |
| 360 | expected[COMPONENT("ne:psu") "/state/oper-state"] = "enabled"; |
| 361 | expected[COMPONENT("ne:psu:child") "/class"] = "iana-hardware:sensor"; |
| 362 | expected[COMPONENT("ne:psu:child") "/parent"] = "ne:psu"; |
| 363 | expected[COMPONENT("ne:psu:child") "/state/oper-state"] = "enabled"; |
| 364 | expected[COMPONENT("ne:psu:child") "/sensor-data/oper-status"] = "ok"; |
| 365 | expected[COMPONENT("ne:psu:child") "/sensor-data/value"] = "20000"; |
| 366 | expected[COMPONENT("ne:psu:child") "/sensor-data/value-precision"] = "0"; |
| 367 | expected[COMPONENT("ne:psu:child") "/sensor-data/value-scale"] = "milli"; |
| 368 | expected[COMPONENT("ne:psu:child") "/sensor-data/value-type"] = "volts-DC"; |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 369 | |
| 370 | { |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 371 | auto [data, alarms, activeSensors] = ietfHardware->process(); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 372 | NUKE_LAST_CHANGE(data); |
| 373 | |
| 374 | REQUIRE(data == expected); |
| 375 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 376 | THRESHOLD_STATE("ne:psu:child", State::WarningHigh), |
| 377 | }); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 378 | REQUIRE(activeSensors == std::set<std::string>{ |
| 379 | COMPONENT("ne:ctrl:current") "/sensor-data/value", |
| 380 | COMPONENT("ne:ctrl:emmc:lifetime") "/sensor-data/value", |
| 381 | COMPONENT("ne:ctrl:power") "/sensor-data/value", |
| 382 | COMPONENT("ne:ctrl:temperature-cpu") "/sensor-data/value", |
| 383 | COMPONENT("ne:ctrl:voltage-in") "/sensor-data/value", |
| 384 | COMPONENT("ne:ctrl:voltage-out") "/sensor-data/value", |
| 385 | COMPONENT("ne:fans:fan1:rpm") "/sensor-data/value", |
| 386 | COMPONENT("ne:fans:fan2:rpm") "/sensor-data/value", |
| 387 | COMPONENT("ne:fans:fan3:rpm") "/sensor-data/value", |
| 388 | COMPONENT("ne:fans:fan4:rpm") "/sensor-data/value", |
| 389 | COMPONENT("ne:psu:child") "/sensor-data/value", |
| 390 | }); |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 391 | } |
Tomáš Pecka | cd7f9cc | 2023-12-11 15:52:48 +0100 | [diff] [blame] | 392 | |
| 393 | |
| 394 | fanValues[0] = -1'000'000'001; |
| 395 | fanValues[1] = 1'000'000'001; |
Jan Kundrát | bf39bcb | 2024-01-10 17:46:59 +0100 | [diff] [blame] | 396 | expected[COMPONENT("ne:fans:fan1:rpm") "/sensor-data/value"] = "-1000000000"; |
| 397 | expected[COMPONENT("ne:fans:fan1:rpm") "/sensor-data/oper-status"] = "nonoperational"; |
| 398 | expected[COMPONENT("ne:fans:fan2:rpm") "/sensor-data/value"] = "1000000000"; |
| 399 | expected[COMPONENT("ne:fans:fan2:rpm") "/sensor-data/oper-status"] = "nonoperational"; |
Tomáš Pecka | cd7f9cc | 2023-12-11 15:52:48 +0100 | [diff] [blame] | 400 | |
| 401 | { |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 402 | auto [data, alarms, activeSensors] = ietfHardware->process(); |
Tomáš Pecka | cd7f9cc | 2023-12-11 15:52:48 +0100 | [diff] [blame] | 403 | NUKE_LAST_CHANGE(data); |
| 404 | |
| 405 | REQUIRE(data == expected); |
| 406 | REQUIRE(alarms == std::map<std::string, velia::ietf_hardware::State>{ |
| 407 | THRESHOLD_STATE("ne:fans:fan1:rpm", State::CriticalLow), |
| 408 | THRESHOLD_STATE("ne:fans:fan2:rpm", State::Normal), |
| 409 | }); |
Tomáš Pecka | c0991ce | 2023-12-20 15:46:03 +0100 | [diff] [blame] | 410 | REQUIRE(activeSensors == std::set<std::string>{ |
| 411 | COMPONENT("ne:ctrl:current") "/sensor-data/value", |
| 412 | COMPONENT("ne:ctrl:emmc:lifetime") "/sensor-data/value", |
| 413 | COMPONENT("ne:ctrl:power") "/sensor-data/value", |
| 414 | COMPONENT("ne:ctrl:temperature-cpu") "/sensor-data/value", |
| 415 | COMPONENT("ne:ctrl:voltage-in") "/sensor-data/value", |
| 416 | COMPONENT("ne:ctrl:voltage-out") "/sensor-data/value", |
| 417 | COMPONENT("ne:fans:fan1:rpm") "/sensor-data/value", |
| 418 | COMPONENT("ne:fans:fan2:rpm") "/sensor-data/value", |
| 419 | COMPONENT("ne:fans:fan3:rpm") "/sensor-data/value", |
| 420 | COMPONENT("ne:fans:fan4:rpm") "/sensor-data/value", |
| 421 | COMPONENT("ne:psu:child") "/sensor-data/value", |
| 422 | }); |
Tomáš Pecka | cd7f9cc | 2023-12-11 15:52:48 +0100 | [diff] [blame] | 423 | } |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 424 | } |