bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

c-stack tests


From: Eric Blake
Subject: c-stack tests
Date: Tue, 17 Jun 2008 15:37:24 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

I'm committing this to give c-stack better testsuite exposure.  It skips on 
cygwin (no sigaltstack) and mingw (no SA_SIGINFO), but passes on Linux, 
OpenBSD, and Solaris.  It does not check for false positives on declaring stack 
overflow (otherwise, both Linux and OpenBSD would fail, leaving only Solaris 
passing, since of those three, only Solaris provides siginfo_t semantics that 
can avoid false positives).  I still haven't gotten a response from the Austin 
group as whether it was intended to make Solaris' semantics standardized.

The hope is that once I get libsigsegv hooks in place, then I can make this 
test pass on cygwin and mingw and avoid false positives on Linux when compiled 
with libsigsegv.

>From c0dfc033aad9449b6470c34d7d251a43bd0bd975 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Tue, 17 Jun 2008 08:43:38 -0600
Subject: [PATCH] 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 <address@hidden>
---
 ChangeLog             |    9 ++++++
 lib/c-stack.c         |   36 --------------------------
 modules/c-stack-tests |   15 +++++++++++
 tests/test-c-stack.c  |   68 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/test-c-stack.sh |   21 +++++++++++++++
 5 files changed, 113 insertions(+), 36 deletions(-)
 create mode 100644 modules/c-stack-tests
 create mode 100644 tests/test-c-stack.c
 create mode 100755 tests/test-c-stack.sh

diff --git a/ChangeLog b/ChangeLog
index 0976ec3..80c51b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-06-17  Eric Blake  <address@hidden>
+
+       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  <address@hidden>
 
        Use raise module consistently.
diff --git a/lib/c-stack.c b/lib/c-stack.c
index a7ebafa..2d5ac31 100644
--- a/lib/c-stack.c
+++ b/lib/c-stack.c
@@ -265,39 +265,3 @@ c_stack_action (void (*action) (int)  __attribute__ 
((unused)))
 }
 
 #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:
-*/
diff --git a/modules/c-stack-tests b/modules/c-stack-tests
new file mode 100644
index 0000000..291f58d
--- /dev/null
+++ b/modules/c-stack-tests
@@ -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
diff --git a/tests/test-c-stack.c b/tests/test-c-stack.c
new file mode 100644
index 0000000..5c6c773
--- /dev/null
+++ b/tests/test-c-stack.c
@@ -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;
+}
diff --git a/tests/test-c-stack.sh b/tests/test-c-stack.sh
new file mode 100755
index 0000000..f979065
--- /dev/null
+++ b/tests/test-c-stack.sh
@@ -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
-- 
1.5.5.1







reply via email to

[Prev in Thread] Current Thread [Next in Thread]