ceeeabee63d5fa3eac2d9374d9619609300713d5
[platform/upstream/automake.git] / t / parallel-tests-fork-bomb.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
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 2, or (at your option)
7 # 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 # Check parallel-tests features:
18 #  - If $(TEST_SUITE_LOG) is in $(TEST_LOGS), we get a diagnosed
19 #    error, not a make hang or a system freeze.
20
21 am_parallel_tests=yes
22 . ./defs || Exit 1
23
24 # We don't want localized error messages from make, since we'll have
25 # to grep them.  See automake bug#11452.
26 LANG=C LANGUAGE=C LC_ALL=C
27 export LANG LANGUAGE LC_ALL
28
29 # The tricky part of this test is to avoid that make hangs or even
30 # freezes the system in case infinite recursion (which is the bug we
31 # are testing against) is encountered.  The following hacky makefile
32 # should minimize the probability of that happening.
33 cat > Makefile.am << 'END'
34 TEST_LOG_COMPILER = true
35 TESTS =
36
37 errmsg = ::OOPS:: Recursion too deep
38
39 if IS_GNU_MAKE
40
41  is_too_deep := $(shell test $(MAKELEVEL) -lt 10 && echo no)
42
43 ## Indenteation here required to avoid confusing Automake.
44  ifeq ($(is_too_deep),no)
45  else
46  $(error $(errmsg), $(MAKELEVEL) levels)
47  endif
48
49 else !IS_GNU_MAKE
50
51 # We use mkdir to detect the level of recursion, since it is easy
52 # to use and assured to be portably atomical.  Also use an higher
53 # number than with GNU make above, since the level used here can
54 # be incremented by tow or more per recursion.
55 recursion-not-too-deep:
56         @ok=no; \
57         for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 \
58                  18 19 20 21 22 23 24 25 26 27 28 29; \
59         do \
60           echo " mkdir rec-$$i.d"; \
61           if mkdir rec-$$i.d; then \
62             ok=yes; break; \
63           else :; fi; \
64         done; \
65         test $$ok = yes || { echo '$(errmsg)' >&2; exit 1; }
66 .PHONY: recursion-not-too-deep
67 clean-local:
68         rmdir rec-[0-9].d
69
70 targets = all check recheck $(TESTS) $(TEST_LOGS) $(TEST_SUITE_LOG)
71 $(targets): recursion-not-too-deep
72
73 # For BSD make.
74 .BEGIN: recursion-not-too-deep
75
76 endif !IS_GNU_MAKE
77 END
78
79 if using_gmake; then
80   cond=:
81 else
82   cond=false
83 fi
84
85 cat >> configure.ac << END
86 AM_CONDITIONAL([IS_GNU_MAKE], [$cond])
87 AC_OUTPUT
88 END
89
90 # Another helpful idiom to avoid hanging on capable systems.  The subshell
91 # is needed since 'ulimit' might be a special shell builtin.
92 if (ulimit -t 8); then ulimit -t 8; fi
93
94 $ACLOCAL
95 $AUTOCONF
96 $AUTOMAKE -a -Wno-portability
97
98 ./configure
99
100 do_check ()
101 {
102   st=0
103   log=$1; shift
104   env "$@" $MAKE -e check >output 2>&1 || st=$?
105   cat output
106   $FGREP '::OOPS::' output && Exit 1 # Possible infinite recursion.
107   # Check that at least we don't create a botched global log file.
108   test ! -f "$log"
109   if using_gmake; then
110     grep "[Cc]ircular.*dependency" output | $FGREP "$log"
111     test $st -gt 0
112   else
113     # Look for possible error messages about circular dependencies from
114     # either make or our own recipes.  At least one such a message must
115     # be present.  OTOH, some make implementations (e.g., NetBSD's), while
116     # smartly detecting the circular dependency early and diagnosing it,
117     # still exit with a successful exit status (yikes!).  So don't check
118     # the exit status of non-GNU make, to avoid spurious failures.
119     # this case.
120     err_seen=no
121     for err_rx in \
122       'circular.* depend' \
123       'depend.* circular' \
124       'graph cycle' \
125       'infinite (loop|recursion)' \
126       'depend.* on itself' \
127     ; do
128       $EGREP -i "$err_rx" output | $FGREP "$log" || continue
129       err_seen=yes
130       break
131     done
132     test $err_seen = yes || Exit 1
133   fi
134 }
135
136 : > test-suite.test
137 do_check test-suite.log TESTS=test-suite.test
138 rm -f *.log *.test
139
140 : > 0.test
141 : > 1.test
142 : > 2.test
143 : > 3.test
144 : > foobar.test
145 do_check foobar.log TEST_LOGS='0.log 1.log foobar.log 2.log 3.log' \
146                     TEST_SUITE_LOG=foobar.log
147 rm -f *.log *.test
148
149 :