parallel-tests-concurrency.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #! /bin/sh
  2. # Copyright (C) 2009-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. # - concurrent parallel execution
  18. # FIXME: we should factor out (into am-test-lib.sh?) the code to determine
  19. # how to run make in parallel mode ...
  20. . test-init.sh
  21. case $MAKE in
  22. *\ -j*) skip_ "\$MAKE contains '-j'";;
  23. esac
  24. if using_gmake; then
  25. j=-j
  26. else
  27. unindent > Makefile <<END
  28. all: one two
  29. one:
  30. $sleep && test -f two
  31. two:
  32. echo ok > \$@
  33. END
  34. for j in "-j" "-j " NONE; do
  35. if test x"$j" = xNONE; then
  36. skip_ "can't run make in parallel mode"
  37. fi
  38. run_make -M -- ${j}2 all || continue
  39. $EGREP -i "(warning|error):|-j[\"\'\` ]" output && continue
  40. break
  41. done
  42. rm -f one output Makefile
  43. fi
  44. cat >> configure.ac << 'END'
  45. AC_OUTPUT
  46. END
  47. cat > Makefile.am << 'END'
  48. TESTS =
  49. END
  50. cat > x <<'END'
  51. #! /bin/sh
  52. echo "this is $0"
  53. # Creative quoting below to please maintainer-check.
  54. sleep '1'
  55. exit 0
  56. END
  57. chmod a+x ./x
  58. mkdir sub
  59. for i in 1 2 3; do
  60. echo "TESTS += foo$i.test" >> Makefile.am
  61. cp x foo$i.test
  62. echo "TESTS += zap$i" >> Makefile.am
  63. cp x zap$i
  64. echo "TESTS += sub/bar$i.test" >> Makefile.am
  65. cp x sub/bar$i.test
  66. echo "TESTS += sub/mu$i" >> Makefile.am
  67. cp x sub/mu$i
  68. done
  69. $ACLOCAL
  70. $AUTOCONF
  71. $AUTOMAKE -a
  72. for build in serial parallel; do
  73. mkdir $build
  74. cd $build
  75. ../configure
  76. $MAKE
  77. cd ..
  78. done
  79. cd serial
  80. # Do *not* use "make -j1" here; apparently, some make implementations
  81. # (e.g., AIX 7.1) interpret it as a synonym of "make -j" :-(
  82. $MAKE check &
  83. cd ..
  84. cd parallel
  85. $sleep
  86. run_make -O -- ${j}4 check
  87. cd ..
  88. # Ensure the tests are really being run in parallel mode: if this is
  89. # the case, the serial run of the dummy testsuite started above should
  90. # still be ongoing when the parallel one has terminated.
  91. kill -0 $!
  92. cat parallel/stdout
  93. test $(grep -c '^PASS:' parallel/stdout) -eq 12
  94. # Wait long enough so that there are no open files any more when the
  95. # post-test cleanup runs. But exit after we've waited for two minutes
  96. # or more, to avoid testsuite hangs in unusual situations (this has
  97. # already happened).
  98. i=1
  99. while test ! -f serial/test-suite.log && test $i -le 120; do
  100. i=$(($i + 1))
  101. sleep '1' # Extra quoting to please maintainer-check.
  102. done
  103. $sleep
  104. :