Debian Codegraph @

madrisan-nagios-plugins-linux/nagios-plugins-linux/tests/tstemperature.c

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 /*
3 * License: GPLv3+
4 * Copyright (c) 2017 Davide Madrisan <[email protected]>
5 *
6 * Unit test for check_temperature.c
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include "testutils.h"
24
25 /* silence the compiler's warning 'function defined but not used' */
26 static _Noreturn void print_version (void) __attribute__ ((unused));
27 static _Noreturn void usage (FILE * out) __attribute__ ((unused));
28
29 #define NPL_TESTING
30 #include "../plugins/check_temperature.c"
31 #undef NPL_TESTING
32
33 typedef struct test_data
34 {
35 int unit;
36 double expect_value;
37 } test_data;
38
39 static int
40 test_temperature_unit_conversion (const void *tdata)
41 {
42 char *scale;
43 const struct test_data *data = tdata;
44 const unsigned long chk_temp = 1000UL*25; /* 25C */
45 int ret = 0;
46
47 TEST_ASSERT_EQUAL_NUMERIC (data->expect_value,
48 get_real_temp (chk_temp, &scale, data->unit));
49 return ret;
50 }
51
52 static int
53 mymain (void)
54 {
55 int ret = 0;
56
57 #define DO_TEST(MSG, UNIT, EXPECT_VALUE) \
58 do \
59 { \
60 test_data data = { \
61 .unit = UNIT, \
62 .expect_value = EXPECT_VALUE, \
63 }; \
64 if (test_run(MSG, test_temperature_unit_conversion, &data) < 0) \
65 ret = -1; \
66 } \
67 while (0)
68
69 DO_TEST ("check get_real_temp with temp_units eq TEMP_CELSIUS",
70 TEMP_CELSIUS, 25);
71 DO_TEST ("check get_real_temp with temp_units eq TEMP_FAHRENHEIT",
72 TEMP_FAHRENHEIT, 77);
73 DO_TEST ("check get_real_temp with temp_units eq TEMP_KELVIN",
74 TEMP_KELVIN, 298.1);
75
76 /* FIXME: we should test here /sys/class/thermal/ related stuff
77 /sys/class/thermal/thermal_zone[0-*]/{type,temp,trip_point_*}
78 see: ./lib/sysfsparser.c */
79
80 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
81 }
82
83 TEST_MAIN (mymain)