changeset 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 77b5668a1038
children 6fcac230dda4
files ChangeLog lib/c-stack.c modules/c-stack-tests tests/test-c-stack.c tests/test-c-stack.sh
diffstat 5 files changed, 113 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Jun 16 20:54:38 2008 -0600
+++ b/ChangeLog	Tue Jun 17 08:43:38 2008 -0600
@@ -1,3 +1,12 @@
+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.
--- a/lib/c-stack.c	Mon Jun 16 20:54:38 2008 -0600
+++ b/lib/c-stack.c	Tue Jun 17 08:43:38 2008 -0600
@@ -76,10 +76,6 @@
 # define STDERR_FILENO 2
 #endif
 
-#if DEBUG
-# include <stdio.h>
-#endif
-
 #include "c-stack.h"
 #include "exitfail.h"
 
@@ -265,39 +261,3 @@
 }
 
 #endif
-
-
-
-#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 */
-
-/*
-Local Variables:
-compile-command: "gcc -DDEBUG -g -O -Wall -W c-stack.c"
-End:
-*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/c-stack-tests	Tue Jun 17 08:43:38 2008 -0600
@@ -0,0 +1,15 @@
+Files:
+tests/test-c-stack.c
+tests/test-c-stack.sh
+
+Depends-on:
+exitfail
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-c-stack.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@'
+check_PROGRAMS += test-c-stack
+test_c_stack_LDADD = $(LDADD) @LIBINTL@
+MOSTLYCLEANFILES += t-c-stack.tmp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-c-stack.c	Tue Jun 17 08:43:38 2008 -0600
@@ -0,0 +1,68 @@
+/* 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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-c-stack.sh	Tue Jun 17 08:43:38 2008 -0600
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="t-c-stack.tmp"
+./test-c-stack${EXEEXT} 2> t-c-stack.tmp
+case $? in
+  77) cat t-c-stack.tmp >&2; (exit 77); exit 77 ;;
+  1) ;;
+  *) (exit 1); exit 1 ;;
+esac
+if grep 'stack overflow' t-c-stack.tmp >/dev/null ; then
+  :
+else
+  (exit 1); exit 1
+fi
+
+rm -fr $tmpfiles
+
+exit 0