summaryrefslogtreecommitdiff
path: root/tests/common.h
diff options
context:
space:
mode:
authorjvoisin2023-03-18 13:29:22 +0100
committerjvoisin2023-04-13 23:49:02 +0200
commit4f1380a48da7cb0375810f70e68ca6282486dec1 (patch)
tree2f98c995017e7f52b30b71ca35990f036f56cc19 /tests/common.h
parent3e6704d0be707487d7a9dccfdc75203c7261e11b (diff)
Add a basic testsuite
Diffstat (limited to 'tests/common.h')
-rw-r--r--tests/common.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/common.h b/tests/common.h
new file mode 100644
index 0000000..4bd5a4e
--- /dev/null
+++ b/tests/common.h
@@ -0,0 +1,62 @@
1/* Copyright (C) 2004-2020 Free Software Foundation, Inc.
2 This snippet is taken from debug/tst-chk1 in the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18#include <setjmp.h>
19#include <unistd.h>
20#include <signal.h>
21#include <stdio.h>
22
23volatile int chk_fail_ok;
24volatile int ret;
25jmp_buf chk_fail_buf;
26
27static void
28handler (int sig)
29{
30 if (chk_fail_ok)
31 {
32 chk_fail_ok = 0;
33 longjmp (chk_fail_buf, 1);
34 }
35 else
36 _exit (127);
37}
38
39void
40__attribute__((constructor))
41set_fortify_handler (void)
42{
43 struct sigaction sa;
44
45 sa.sa_handler = handler;
46 sa.sa_flags = 0;
47 sigemptyset (&sa.sa_mask);
48
49 sigaction (SIGILL, &sa, NULL);
50}
51
52#define FAIL() \
53 do { fprintf (stderr, "Failure on line %d\n", __LINE__); ret = 1; } while (0)
54#define CHK_FAIL_START \
55 chk_fail_ok = 1; \
56 if (! setjmp (chk_fail_buf)) \
57 {
58#define CHK_FAIL_END \
59 chk_fail_ok = 0; \
60 FAIL (); \
61 }
62