15 #include "../../../tests/catch2/catch.hpp"
16 #include "../../tests/testMacrosINDI.hpp"
18 #include "../sysMonitor.hpp"
22 SCENARIO(
"System monitor is constructed and CPU temperature results are passed in",
"[sysMonitor]" )
24 GIVEN(
"A default constructed system monitor object and an empty vector for temperatures")
32 WHEN(
"Correct line is given")
39 WHEN(
"Correct line is given")
46 WHEN(
"Correct line is given")
53 WHEN(
"Blank line is given")
60 WHEN(
"Incorrect line is given")
67 WHEN(
"Corrupted line is given")
74 WHEN(
"Corrupted line is given")
83 SCENARIO(
"System monitor is constructed and CPU load results are passed in",
"[sysMonitor]" )
85 GIVEN(
"A default constructed system monitor object and an empty vector for loads")
93 WHEN(
"Correct line is given")
95 rv = sm.
parseCPULoads(loads,
"02:35:43 PM 0 6.57 0.02 1.32 0.24 0.00 0.00 0.00 0.00 0.00 91.85");
97 REQUIRE((loads - 0.0815) < 0.0005);
100 WHEN(
"Correct line is given")
102 rv = sm.
parseCPULoads(loads,
"10:32:28 AM 1 6.54 0.21 2.75 24.64 0.00 0.06 0.00 0.00 0.00 65.81");
104 REQUIRE((loads - 0.3419) < 0.0005);
107 WHEN(
"Correct line is given")
109 rv = sm.
parseCPULoads(loads,
"10:32:28 AM 3 4.24 0.03 1.97 5.52 0.00 0.00 0.00 0.00 0.00 88.24");
111 REQUIRE((loads - 0.1176) < 0.0005);
114 WHEN(
"Blank line is given")
121 WHEN(
"Incorrect line is given")
123 rv = sm.
parseCPULoads(loads,
"02:35:43 PM CPU %%usr %%nice %%sys %%iowait %%irq %%soft %%steal %%guest %%gnice %%idle");
128 WHEN(
"Corrupted line is given")
130 rv = sm.
parseCPULoads(loads,
"10:32:28AM 2 5.24 0.14 2.70_1.41 0.00 0.00 0.00 0.00 0.00 80.50 ncawd vexing");
137 SCENARIO(
"System monitor is constructed and disk temperature result is passed in",
"[sysMonitor]" )
139 GIVEN(
"A default constructed system monitor object and an empty float for temperature")
148 WHEN(
"Correct line is given for hard drive")
156 WHEN(
"Correct line is given for ssd")
164 WHEN(
"Correct line is given for ssd")
172 WHEN(
"Blank line is given")
180 WHEN(
"Incorrect line is given")
188 WHEN(
"Corrupted line is given")
198 SCENARIO(
"System monitor is constructed and disk usage result is passed in",
"[sysMonitor]" )
200 GIVEN(
"A default constructed system monitor object and an empty float for usage")
204 float rootUsage = -1;
205 float dataUsage = -1;
206 float bootUsage = -1;
210 WHEN(
"Correct line is given for root")
212 rv = sm.
parseDiskUsage(
"/dev/mapper/cl-root 52403200 12321848 40081352 24% /", rootUsage, dataUsage, bootUsage);
214 REQUIRE((rootUsage - 0.24f) < 0.0005);
217 WHEN(
"Correct line for /data is given")
219 rv = sm.
parseDiskUsage(
"/dev/md124 1952297568 81552 1952216016 1% /data", rootUsage, dataUsage, bootUsage);
221 REQUIRE((dataUsage - 0.01f) < 0.0005);
224 WHEN(
"Correct line for /boot is given")
226 rv = sm.
parseDiskUsage(
"/dev/md126 484004 289264 194740 60% /boot", rootUsage, dataUsage, bootUsage);
228 REQUIRE((bootUsage - 0.6f) < 0.0005);
231 WHEN(
"Blank line is given")
240 WHEN(
"Incorrect line is given")
242 rv = sm.
parseDiskUsage(
"/dev/mapper/cl-root2403200 12321848 40081352 24% / 23e32 dwwe", rootUsage, dataUsage, bootUsage);
249 WHEN(
"Corrupted line is given")
251 rv = sm.
parseDiskUsage(
"/dev/mapper/cl-root 52403200 12321848 40081352 aa% /", rootUsage, dataUsage, bootUsage);
260 SCENARIO(
"System monitor is constructed and ram usage result is passed in",
"[sysMonitor]" )
262 GIVEN(
"A default constructed system monitor object and an float for usage")
270 WHEN(
"Correct line is given")
272 rv = sm.
parseRamUsage(
"Mem: 7714 1308 4550 288 1855 5807", ramUsage);
274 REQUIRE(ramUsage == (
float) 1308/7714);
277 WHEN(
"Correct line is given")
279 rv = sm.
parseRamUsage(
"Mem: 7777 7700 4550 288 1855 5807", ramUsage);
281 REQUIRE(ramUsage == (
float)7700/7777);
284 WHEN(
"Blank line is given")
291 WHEN(
"Incorrect line is given")
299 WHEN(
"Corrupted line is given")
301 rv = sm.
parseRamUsage(
"Mem: 1308 7714 4550 288 1855 5807", ramUsage);
317 m_configName = device;
int parseDiskTemperature(std::string &driveName, float &temp, const std::string &line)
Parses string from system call to find drive temperatures.
int parseCPUTemperatures(float &temp, const std::string &line)
Parses string from system call to find CPU temperatures.
int parseCPULoads(float &, const std::string &)
Parses string from system call to find CPU usage loads.
int parseDiskUsage(std::string, float &, float &, float &)
Parses string from system call to find drive usage space.
int parseRamUsage(std::string, float &)
Parses string from system call to find RAM usage.
sysMonitor_test(const std::string device)
#define XWCTEST_INDI_NEW_CALLBACK(testclass, propname)
Catch-2 tests for whether a NEW callback properly validates the input property properly.
SCENARIO("System monitor is constructed and CPU temperature results are passed in", "[sysMonitor]")
#define XWCTEST_SETUP_INDI_NEW_PROP(propname)