| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef _TESTUTILS_H |
| 18 |
#define _TESTUTILS_H |
| 19 |
|
| 20 |
#include <stddef.h> |
| 21 |
#include <stdio.h> |
| 22 |
#include <stdlib.h> |
| 23 |
#include <string.h> |
| 24 |
#include <unistd.h> |
| 25 |
|
| 26 |
#include "getenv.h" |
| 27 |
#include "string-macros.h" |
| 28 |
|
| 29 |
#define EXIT_AM_SKIP 77 |
| 30 |
#define EXIT_AM_HARDFAIL 99 |
| 31 |
|
| 32 |
#define TEST_KERNEL_VERSION_MAJOR 2 |
| 33 |
#define TEST_KERNEL_VERSION_MINOR 6 |
| 34 |
#define TEST_KERNEL_VERSION_PATCH 27 |
| 35 |
#define TEST_KERNEL_VERSION "2.6.27" |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
#define NPL_TEST_PATH_PROCSTAT abs_srcdir "/ts_procstat.data" |
| 42 |
#define NPL_TEST_PATH_PROCMEMINFO abs_srcdir "/ts_procmeminfo.data" |
| 43 |
#define NPL_TEST_PATH_PROCVMSTAT abs_srcdir "/ts_procvmstat.data" |
| 44 |
#define NPL_TEST_PATH_PROCPRESSURE_CPU abs_srcdir "/ts_procpressurecpu.data" |
| 45 |
#define NPL_TEST_PATH_PROCPRESSURE_IO abs_srcdir "/ts_procpressureio.data" |
| 46 |
|
| 47 |
|
| 48 |
#define NPL_TEST_PATH_CONTAINER_JSON abs_srcdir "/ts_container_docker.data" |
| 49 |
|
| 50 |
|
| 51 |
#define NPL_TEST_PATH_PODMAN_GETCONTAINERSBYSTATUS_JSON \ |
| 52 |
abs_srcdir "/ts_container_podman_GetContainersByStatus.data" |
| 53 |
#define NPL_TEST_PATH_PODMAN_GETCONTAINERSTATS_JSON \ |
| 54 |
abs_srcdir "/ts_container_podman_GetContainerStats.data" |
| 55 |
#define NPL_TEST_PATH_PODMAN_LISTCONTAINERS_JSON \ |
| 56 |
abs_srcdir "/ts_container_podman_ListContainers.data" |
| 57 |
|
| 58 |
#define TEST_ASSERT_EQUAL_NUMERIC(A, B) \ |
| 59 |
do { if ((A) != (B)) ret = -1; } while (0) |
| 60 |
|
| 61 |
#define TEST_ASSERT_EQUAL_STRING(A, B) \ |
| 62 |
do { if (STRNEQ (A, B)) ret = -1; } while (0) |
| 63 |
|
| 64 |
#ifdef __cplusplus |
| 65 |
extern "C" |
| 66 |
{ |
| 67 |
#endif |
| 68 |
|
| 69 |
char * test_fstringify (const char * filename); |
| 70 |
int test_main (int argc, char **argv, int (*func) (void), ...); |
| 71 |
|
| 72 |
# define TEST_MAIN(func) \ |
| 73 |
int main (int argc, char **argv) \ |
| 74 |
{ \ |
| 75 |
return test_main (argc, argv, func, NULL); \ |
| 76 |
} |
| 77 |
|
| 78 |
# define TEST_PRELOAD(lib) \ |
| 79 |
do \ |
| 80 |
{ \ |
| 81 |
const char *preload = secure_getenv ("LD_PRELOAD"); \ |
| 82 |
if (preload == NULL || strstr (preload, lib) == NULL) \ |
| 83 |
{ \ |
| 84 |
char *newenv; \ |
| 85 |
if (!test_file_is_executable (lib)) \ |
| 86 |
{ \ |
| 87 |
perror (lib); \ |
| 88 |
return EXIT_FAILURE; \ |
| 89 |
} \ |
| 90 |
if (!preload) \ |
| 91 |
{ \ |
| 92 |
newenv = (char *) lib; \ |
| 93 |
} \ |
| 94 |
else if (asprintf (&newenv, "%s:%s", lib, preload) < 0) \ |
| 95 |
{ \ |
| 96 |
perror ("asprintf"); \ |
| 97 |
return EXIT_FAILURE; \ |
| 98 |
} \ |
| 99 |
if (setenv ("LD_PRELOAD", newenv, 1) < 0) \ |
| 100 |
{ \ |
| 101 |
perror ("setenv"); \ |
| 102 |
return EXIT_FAILURE; \ |
| 103 |
} \ |
| 104 |
char *argv0 = realpath (argv[0], NULL); \ |
| 105 |
if (!argv0) \ |
| 106 |
{ \ |
| 107 |
perror ("realpath"); \ |
| 108 |
return EXIT_FAILURE; \ |
| 109 |
} \ |
| 110 |
execv (argv0, argv); \ |
| 111 |
free (argv0); \ |
| 112 |
} \ |
| 113 |
} \ |
| 114 |
while (0) |
| 115 |
|
| 116 |
# define TEST_MAIN_PRELOAD(func, ...) \ |
| 117 |
int main (int argc, char **argv) \ |
| 118 |
{ \ |
| 119 |
return test_main (argc, argv, func, __VA_ARGS__, NULL); \ |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
int test_run (const char *title, |
| 125 |
int (*body) (const void *data), const void *data); |
| 126 |
|
| 127 |
#ifdef __cplusplus |
| 128 |
} |
| 129 |
#endif |
| 130 |
|
| 131 |
#endif |