annotate tests/test-c-stack.c @ 10213:d8fca1d0aba3

Move c-stack test into testsuite. * modules/c-stack-tests: New file. * lib/c-stack.c [DEBUG]: Move test program... * tests/test-c-stack.c: ...into this new file. Skip rather than fail test if sigaltstack is lacking. * tests/test-c-stack.sh: New driver file. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Tue, 17 Jun 2008 08:43:38 -0600
parents
children 4c08c1b6678e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10213
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* Test of c-stack module.
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
2 Copyright (C) 2002, 2004, 2006, 2008 Free Software Foundation, Inc.
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 (at your option) any later version.
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 #include <config.h>
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 #include "c-stack.h"
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21 #include "exitfail.h"
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22 #include <stdio.h>
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
23 #include <stdlib.h>
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
24 #if HAVE_SETRLIMIT
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
25 # include <sys/resource.h>
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26 #endif
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
28 #define ASSERT(expr) \
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29 do \
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30 { \
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31 if (!(expr)) \
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32 { \
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
33 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
34 fflush (stderr); \
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
35 abort (); \
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
36 } \
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
37 } \
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38 while (0)
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40 static long
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41 recurse (char *p)
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 {
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43 char array[500];
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 array[0] = 1;
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 return *p + recurse (array);
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
46 }
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
47
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
48 char *program_name;
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
49
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
50 int
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51 main (int argc, char **argv)
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
52 {
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 program_name = argv[0];
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54 #if HAVE_SETRLIMIT && defined RLIMIT_STACK
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
55 /* Before starting the endless recursion, try to be friendly to the
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 user's machine. On some Linux 2.2.x systems, there is no stack
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57 limit for user processes at all. We don't want to kill such
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 systems. */
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
59 struct rlimit rl;
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 setrlimit (RLIMIT_STACK, &rl);
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 #endif
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
63
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
64 if (c_stack_action (0) == 0)
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
65 return recurse ("\1");
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66 perror ("c_stack_action");
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
67 return 77;
d8fca1d0aba3 Move c-stack test into testsuite.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
68 }