parallel-tests-fork-bomb.sh 4.1 KB

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