| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "system.h" |
| 24 |
#include "testutils.h" |
| 25 |
|
| 26 |
|
| 27 |
static _Noreturn void print_version (void) __attribute__((unused)); |
| 28 |
static _Noreturn void usage (FILE * out) __attribute__((unused)); |
| 29 |
static unsigned long long get_ctxtdelta (unsigned int, unsigned int, bool) |
| 30 |
__attribute__((unused)); |
| 31 |
|
| 32 |
#define NPL_TESTING |
| 33 |
# include "../plugins/check_cswch.c" |
| 34 |
#undef NPL_TESTING |
| 35 |
|
| 36 |
static bool |
| 37 |
test_cswch_proc_stat_exists () |
| 38 |
{ |
| 39 |
FILE *fp; |
| 40 |
|
| 41 |
if ((fp = fopen (get_path_proc_stat (), "r")) == NULL) |
| 42 |
return false; |
| 43 |
|
| 44 |
fclose (fp); |
| 45 |
return true; |
| 46 |
} |
| 47 |
|
| 48 |
static int |
| 49 |
test_cswch_proc_parsing () |
| 50 |
{ |
| 51 |
int ret = 0; |
| 52 |
const char *env_variable = "NPL_TEST_PATH_PROCSTAT"; |
| 53 |
|
| 54 |
ret = setenv (env_variable, NPL_TEST_PATH_PROCSTAT, 1); |
| 55 |
if (ret < 0) |
| 56 |
return EXIT_AM_HARDFAIL; |
| 57 |
|
| 58 |
|
| 59 |
if (cpu_stats_get_cswch () != 13817032) |
| 60 |
ret = -1; |
| 61 |
|
| 62 |
unsetenv (env_variable); |
| 63 |
return ret; |
| 64 |
} |
| 65 |
|
| 66 |
static int |
| 67 |
mymain (void) |
| 68 |
{ |
| 69 |
int ret = 0; |
| 70 |
|
| 71 |
if (!test_cswch_proc_stat_exists ()) |
| 72 |
return EXIT_AM_SKIP; |
| 73 |
|
| 74 |
#define DO_TEST(MSG, FUNC, DATA) \ |
| 75 |
do { if (test_run (MSG, FUNC, DATA) < 0) ret = -1; } while (0) |
| 76 |
|
| 77 |
DO_TEST ("check for parsing errors in cpu_stats_get_cswch()", |
| 78 |
test_cswch_proc_parsing, NULL); |
| 79 |
|
| 80 |
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
| 81 |
} |
| 82 |
|
| 83 |
TEST_MAIN (mymain) |