| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "testutils.h" |
| 24 |
|
| 25 |
|
| 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_intr.c" |
| 31 |
#undef NPL_TESTING |
| 32 |
|
| 33 |
static bool |
| 34 |
test_intr_proc_stat_exists () |
| 35 |
{ |
| 36 |
FILE *fp; |
| 37 |
|
| 38 |
if ((fp = fopen (get_path_proc_stat (), "r")) == NULL) |
| 39 |
return false; |
| 40 |
|
| 41 |
fclose (fp); |
| 42 |
return true; |
| 43 |
} |
| 44 |
|
| 45 |
static int |
| 46 |
test_intr_monotonic (const void *tdata) |
| 47 |
{ |
| 48 |
unsigned int ncpus0 = 0, ncpus1 = 0; |
| 49 |
unsigned long *vintr[2] = { NULL, NULL }; |
| 50 |
|
| 51 |
long delta = get_intrdelta (&ncpus0, &ncpus1, &vintr, 1, 1, false); |
| 52 |
|
| 53 |
if (delta <= 0) |
| 54 |
return -1; |
| 55 |
|
| 56 |
return 0; |
| 57 |
} |
| 58 |
|
| 59 |
static int |
| 60 |
test_intr_proc_parsing () |
| 61 |
{ |
| 62 |
int ret = 0; |
| 63 |
const char *env_variable = "NPL_TEST_PATH_PROCSTAT"; |
| 64 |
|
| 65 |
ret = setenv (env_variable, NPL_TEST_PATH_PROCSTAT, 1); |
| 66 |
if (ret < 0) |
| 67 |
return EXIT_AM_HARDFAIL; |
| 68 |
|
| 69 |
|
| 70 |
if (cpu_stats_get_intr () != 4315363) |
| 71 |
ret = -1; |
| 72 |
|
| 73 |
unsetenv (env_variable); |
| 74 |
return ret; |
| 75 |
} |
| 76 |
|
| 77 |
static int |
| 78 |
mymain (void) |
| 79 |
{ |
| 80 |
int ret = 0; |
| 81 |
|
| 82 |
if (!test_intr_proc_stat_exists ()) |
| 83 |
return EXIT_AM_SKIP; |
| 84 |
|
| 85 |
#define DO_TEST(MSG, FUNC, DATA) \ |
| 86 |
do { if (test_run (MSG, FUNC, DATA) < 0) ret = -1; } while (0) |
| 87 |
|
| 88 |
DO_TEST ("check if get_intrdelta() is monotonic", |
| 89 |
test_intr_monotonic, NULL); |
| 90 |
DO_TEST ("check for parsing errors in cpu_stats_get_intr()", |
| 91 |
test_intr_proc_parsing, NULL); |
| 92 |
|
| 93 |
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
| 94 |
} |
| 95 |
|
| 96 |
TEST_MAIN (mymain) |