Mercurial > hg > octave-kai > gnulib-hg
annotate tests/test-c-stack.c @ 17082:62741e75b7c5
poll/select: document portability problems not fixed by Gnulib.
* doc/posix-functions/poll.texi: poll does not work well on
pipes under Windows. It has the same limitations as select on
BeOS.
* doc/posix-functions/select.texi: select does not work well
on pipes under Windows.
author | Paolo Bonzini <pbonzini@redhat.com> |
---|---|
date | Thu, 13 Sep 2012 08:51:16 +0200 |
parents | 8250f2777afc |
children | e542fd46ad6f |
rev | line source |
---|---|
10213 | 1 /* Test of c-stack module. |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
14184
diff
changeset
|
2 Copyright (C) 2002, 2004, 2006, 2008-2012 Free Software Foundation, Inc. |
10213 | 3 |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program 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 | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | |
17 #include <config.h> | |
18 | |
19 #include "c-stack.h" | |
20 | |
21 #include "exitfail.h" | |
22 #include <stdio.h> | |
23 #if HAVE_SETRLIMIT | |
10346
1d6d83874993
test-c-stack: fix compilation failure on FreeBSD 5.0
Eric Blake <ebb9@byu.net>
parents:
10316
diff
changeset
|
24 /* At least FreeBSD 5.0 needs extra headers before <sys/resource.h> |
1d6d83874993
test-c-stack: fix compilation failure on FreeBSD 5.0
Eric Blake <ebb9@byu.net>
parents:
10316
diff
changeset
|
25 will compile. */ |
1d6d83874993
test-c-stack: fix compilation failure on FreeBSD 5.0
Eric Blake <ebb9@byu.net>
parents:
10316
diff
changeset
|
26 # include <sys/types.h> |
1d6d83874993
test-c-stack: fix compilation failure on FreeBSD 5.0
Eric Blake <ebb9@byu.net>
parents:
10316
diff
changeset
|
27 # include <sys/time.h> |
10213 | 28 # include <sys/resource.h> |
29 #endif | |
30 | |
12496
a48d3d749ca5
Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents:
12421
diff
changeset
|
31 #include "macros.h" |
10213 | 32 |
10471
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
33 char *program_name; |
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
34 |
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
35 static volatile int * |
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
36 recurse_1 (volatile int n, volatile int *p) |
10213 | 37 { |
10471
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
38 if (n >= 0) |
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
39 *recurse_1 (n + 1, p) += n; |
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
40 return p; |
10213 | 41 } |
42 | |
10471
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
43 static int |
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
44 recurse (volatile int n) |
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
45 { |
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
46 int sum = 0; |
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
47 return *recurse_1 (n, &sum); |
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
48 } |
10213 | 49 |
50 int | |
51 main (int argc, char **argv) | |
52 { | |
53 #if HAVE_SETRLIMIT && defined RLIMIT_STACK | |
10316 | 54 /* Before starting the endless recursion, try to be friendly to the |
55 user's machine. On some Linux 2.2.x systems, there is no stack | |
56 limit for user processes at all. We don't want to kill such | |
57 systems. */ | |
58 struct rlimit rl; | |
59 rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */ | |
60 setrlimit (RLIMIT_STACK, &rl); | |
10213 | 61 #endif |
62 | |
10316 | 63 program_name = argv[0]; |
14184
3cb76305b3e9
c-stack: assume stack overflow if SA_SIGINFO unsupported
Eric Blake <eblake@redhat.com>
parents:
14079
diff
changeset
|
64 if (c_stack_action (NULL) == 0) |
10275
4c08c1b6678e
c-stack: Expose false positives when not using libsigsegv.
Eric Blake <ebb9@byu.net>
parents:
10213
diff
changeset
|
65 { |
4c08c1b6678e
c-stack: Expose false positives when not using libsigsegv.
Eric Blake <ebb9@byu.net>
parents:
10213
diff
changeset
|
66 if (1 < argc) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10471
diff
changeset
|
67 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10471
diff
changeset
|
68 exit_failure = 77; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10471
diff
changeset
|
69 ++*argv[argc]; /* Intentionally dereference NULL. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10471
diff
changeset
|
70 } |
10471
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
71 return recurse (0); |
10275
4c08c1b6678e
c-stack: Expose false positives when not using libsigsegv.
Eric Blake <ebb9@byu.net>
parents:
10213
diff
changeset
|
72 } |
10471
f318366f3bc7
c-stack: avoid compiler optimizations when provoking overflow
Eric Blake <ebb9@byu.net>
parents:
10346
diff
changeset
|
73 fputs ("skipping test: ", stderr); |
10213 | 74 perror ("c_stack_action"); |
75 return 77; | |
76 } |