Debian Codegraph @

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

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 /*
3 * License: GPLv3+
4 * Copyright (c) 2016,2017 Davide Madrisan <[email protected]>
5 *
6 * Unit test for check_paging.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_paging.c"
31 #undef NPL_TESTING
32
33 static int
34 test_paging_summary (const void *tdata)
35 {
36 int ret = 0;
37 const char *env_variable = "NPL_TEST_PATH_PROCVMSTAT";
38 paging_data_t paging;
39
40 if (setenv (env_variable, NPL_TEST_PATH_PROCVMSTAT, 1) < 0)
41 return EXIT_AM_HARDFAIL;
42
43 #define CHECK_SUMMARY(SWAPPING_ONLY) \
44 do \
45 { \
46 get_paging_status (true, SWAPPING_ONLY, &paging); \
47 unsigned long summary = \
48 SWAPPING_ONLY ? (paging.dpswpin + \
49 paging.dpswpout) : paging.dpgmajfault; \
50 if (summary != paging.summary) \
51 ret = -1; \
52 } \
53 while (0)
54
55 CHECK_SUMMARY (true);
56 CHECK_SUMMARY (false);
57
58 return ret;
59 }
60
61 static int
62 mymain (void)
63 {
64 int ret = 0;
65
66 #define DO_TEST(MSG, FUNC, DATA) \
67 do { if (test_run (MSG, FUNC, DATA) < 0) ret = -1; } while (0)
68
69 DO_TEST ("check for get_paging_status() paging.summary",
70 test_paging_summary, NULL);
71
72 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
73 }
74
75 TEST_MAIN (mymain)