# HG changeset patch # User Eric Blake # Date 1213713818 21600 # Node ID d8fca1d0aba388277d444d44efffb9dbe8852a7a # Parent 77b5668a1038fdf3073d089893890fe0e6fdb757 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 diff -r 77b5668a1038 -r d8fca1d0aba3 ChangeLog --- 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 + + 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 Use raise module consistently. diff -r 77b5668a1038 -r d8fca1d0aba3 lib/c-stack.c --- 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 -#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: -*/ diff -r 77b5668a1038 -r d8fca1d0aba3 modules/c-stack-tests --- /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 diff -r 77b5668a1038 -r d8fca1d0aba3 tests/test-c-stack.c --- /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 . */ + +#include + +#include "c-stack.h" + +#include "exitfail.h" +#include +#include +#if HAVE_SETRLIMIT +# include +#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 -r 77b5668a1038 -r d8fca1d0aba3 tests/test-c-stack.sh --- /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