+2008-06-17 Eric Blake <ebb9@byu.net>
+
+ 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.
+
2008-06-16 Eric Blake <ebb9@byu.net>
Use raise module consistently.
# define STDERR_FILENO 2
#endif
-#if DEBUG
-# include <stdio.h>
-#endif
-
#include "c-stack.h"
#include "exitfail.h"
}
#endif
-
-\f
-
-#if DEBUG
-
-int volatile exit_failure;
-
-static long
-recurse (char *p)
-{
- char array[500];
- array[0] = 1;
- return *p + recurse (array);
-}
-
-char *program_name;
-
-int
-main (int argc __attribute__ ((unused)), char **argv)
-{
- program_name = argv[0];
- fprintf (stderr,
- "The last output line should contain \"stack overflow\".\n");
- if (c_stack_action (0) == 0)
- return recurse ("\1");
- perror ("c_stack_action");
- return 1;
-}
-
-#endif /* DEBUG */
-\f
-/*
-Local Variables:
-compile-command: "gcc -DDEBUG -g -O -Wall -W c-stack.c"
-End:
-*/
--- /dev/null
+/* Test of c-stack module.
+ Copyright (C) 2002, 2004, 2006, 2008 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "c-stack.h"
+
+#include "exitfail.h"
+#include <stdio.h>
+#include <stdlib.h>
+#if HAVE_SETRLIMIT
+# include <sys/resource.h>
+#endif
+
+#define ASSERT(expr) \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+ fflush (stderr); \
+ abort (); \
+ } \
+ } \
+ while (0)
+
+static long
+recurse (char *p)
+{
+ char array[500];
+ array[0] = 1;
+ return *p + recurse (array);
+}
+
+char *program_name;
+
+int
+main (int argc, char **argv)
+{
+ program_name = argv[0];
+#if HAVE_SETRLIMIT && defined RLIMIT_STACK
+ /* Before starting the endless recursion, try to be friendly to the
+ user's machine. On some Linux 2.2.x systems, there is no stack
+ limit for user processes at all. We don't want to kill such
+ systems. */
+ struct rlimit rl;
+ rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */
+ setrlimit (RLIMIT_STACK, &rl);
+#endif
+
+ if (c_stack_action (0) == 0)
+ return recurse ("\1");
+ perror ("c_stack_action");
+ return 77;
+}