aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--common.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/common.h b/common.h
new file mode 100644
index 0000000..3e34f3b
--- /dev/null
+++ b/common.h
@@ -0,0 +1,86 @@
+/* See LICENSE file for copyright and license details. */
+#include "libabort.h"
+
+#if defined(__GNUC__)
+# define CONST __attribute__((__const__))
+#else
+# define CONST
+#endif
+
+#ifdef TEST
+# ifdef __linux__
+# include <sys/prctl.h>
+# endif
+# include <sys/resource.h>
+# include <sys/types.h>
+# include <sys/wait.h>
+# include <signal.h>
+# include <string.h>
+# include <unistd.h>
+
+
+# if defined(PR_SET_DUMPABLE)
+# define INIT_TEST_ABORT()\
+ do {\
+ struct rlimit rl__;\
+ rl__.rlim_cur = 0;\
+ rl__.rlim_max = 0;\
+ (void) setrlimit(RLIMIT_CORE, &rl__);\
+ (void) prctl(PR_SET_DUMPABLE, 0);\
+ EXPECT_ABORT(abort());\
+ } while (0)
+# else
+# define INIT_TEST_ABORT()\
+ do {\
+ struct rlimit rl__;\
+ rl__.rlim_cur = 0;\
+ rl__.rlim_max = 0;\
+ (void) setrlimit(RLIMIT_CORE, &rl__);\
+ EXPECT_ABORT(abort());\
+ } while (0)
+# endif
+
+# define EXPECT__(EXPR, HOW, RETEXTRACT, RETEXPECT)\
+ do {\
+ pid_t pid__;\
+ int status__;\
+ pid__ = fork();\
+ EXPECT(pid__ != -1);\
+ if (pid__ == 0) {\
+ (EXPR);\
+ _exit(0);\
+ }\
+ EXPECT(waitpid(pid__, &status__, 0) == pid__);\
+ EXPECT(HOW(status__));\
+ EXPECT(RETEXTRACT(status__) == RETEXPECT);\
+ } while (0)
+
+# define EXPECT_ABORT(EXPR)\
+ do {\
+ EXPECT__(EXPR, WIFSIGNALED, WTERMSIG, SIGABRT);\
+ } while (0)
+
+# define EXPECT_NO_ABORT(EXPR)\
+ do {\
+ EXPECT__(EXPR, WIFEXITED, WEXITSTATUS, 0);\
+ (EXPR);\
+ } while (0)
+
+# define EXPECT(EXPR)\
+ do {\
+ if (!(EXPR)) {\
+ fprintf(stderr, "Failure at %s:%d: %s\n", __FILE__, __LINE__, #EXPR);\
+ exit(1);\
+ }\
+ } while (0)
+
+# define TESTED\
+ CONST int\
+ main(void)\
+ {\
+ return 0;\
+ }
+
+extern volatile size_t test_size_t_discard;
+
+#endif