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