parallel-tests-extra-programs.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. # Parallel test harness: check that $(TESTS) can lazily depend on
  17. # (or even be) $(EXTRA_PROGRAMS).
  18. required='cc native'
  19. . test-init.sh
  20. cat >> configure.ac << 'END'
  21. AC_PROG_CC
  22. AC_OUTPUT
  23. END
  24. # Will be extended later.
  25. cat > Makefile.am << 'END'
  26. TEST_EXTENSIONS = .bin .test
  27. EXTRA_PROGRAMS =
  28. TESTS =
  29. END
  30. #
  31. # Now try various kinds of test dependencies ...
  32. #
  33. # 1. A program that is also a test, and whose source files
  34. # already exist.
  35. cat >> Makefile.am <<'END'
  36. EXTRA_PROGRAMS += foo.bin
  37. TESTS += foo.bin
  38. foo_bin_SOURCES = foo.c
  39. END
  40. cat > foo.c <<'END'
  41. #include <stdio.h>
  42. int main (void)
  43. {
  44. printf ("foofoofoo\n");
  45. return 0;
  46. }
  47. END
  48. # 2. A program that is also a test, and whose source files
  49. # are buildable by make.
  50. cat >> Makefile.am <<'END'
  51. EXTRA_PROGRAMS += bar.bin
  52. TESTS += bar.bin
  53. bar_bin_SOURCES = bar.c
  54. bar.c: foo.c
  55. sed -e 's/foofoofoo/barbarbar/' foo.c > $@
  56. END
  57. # 3. A test script that already exists, whose execution depends
  58. # on a program whose source files already exist and which is
  59. # not itself a test.
  60. cat >> Makefile.am <<'END'
  61. EXTRA_PROGRAMS += y
  62. TESTS += baz.test
  63. baz.log: y$(EXEEXT)
  64. END
  65. cat > baz.test <<'END'
  66. #!/bin/sh
  67. $srcdir/y "$@" | sed 's/.*/&ep&ep&ep/'
  68. END
  69. chmod a+x baz.test
  70. cat > y.c <<'END'
  71. #include <stdio.h>
  72. int main (void)
  73. {
  74. printf ("y\n");
  75. return 0;
  76. }
  77. END
  78. # 4. A program that is also a test, but whose source files
  79. # do not exit and are not buildable by make.
  80. cat >> Makefile.am <<'END'
  81. EXTRA_PROGRAMS += none.bin
  82. TESTS += none.bin
  83. none_bin_SOURCES = none.c
  84. END
  85. #
  86. # Setup done, go with the tests.
  87. #
  88. $ACLOCAL
  89. $AUTOCONF
  90. $AUTOMAKE -a
  91. ./configure
  92. # What we check now:
  93. # 1. even if we cannot build the 'none.bin' program, all the other
  94. # test programs should be built, and all the other tests should
  95. # be run;
  96. # 2. still, since we cannot create the 'none.log' file, the
  97. # 'test-suite.log' file shouldn't be created (as it depends
  98. # on *all* the test logs).
  99. run_make -E -O -e IGNORE -- -k check
  100. ls -l
  101. if using_gmake; then
  102. test $am_make_rc -gt 0 || exit 1
  103. else
  104. # Don't trust exit status of "make -k" for non-GNU make.
  105. $MAKE check && exit 1
  106. : For shells with busted 'set -e'.
  107. fi
  108. # Files that should have been created, with the expected content.
  109. cat bar.c
  110. grep foofoofoo foo.log
  111. grep barbarbar bar.log
  112. grep yepyepyep baz.log
  113. # Files that shouldn't have been created.
  114. test ! -e none.log
  115. test ! -e test-suite.log
  116. # Expected testsuite progress output.
  117. grep '^PASS: baz\.test$' stdout
  118. # Don't anchor the end of the next two patterns, to allow for non-empty
  119. # $(EXEEXT).
  120. grep '^PASS: foo\.bin' stdout
  121. grep '^PASS: bar\.bin' stdout
  122. # Expected error messages from make. Some make implementations (e.g.,
  123. # FreeBSD make) seem to print the error on stdout instead, so check for
  124. # it there as well.
  125. $EGREP 'none\.(bin|o|c)' stderr stdout
  126. # What we check now:
  127. # 1. if we make the last EXTRA_PROGRAM buildable, the failed tests
  128. # pass;
  129. # 2. on a lazy re-run, the passed tests are not re-run, and
  130. # 3. their log files are not updated or touched.
  131. : > stamp
  132. $sleep
  133. echo 'int main (void) { return 0; }' > none.c
  134. run_make -O -e IGNORE check RECHECK_LOGS=
  135. ls -l # For debugging.
  136. test $am_make_rc -eq 0 || exit 1
  137. # For debugging.
  138. stat stamp foo.log bar.log baz.log || :
  139. # Files that shouldn't have been updated or otherwise touched.
  140. is_newest stamp foo.log bar.log baz.log
  141. # Files that should have been created now.
  142. test -f none.log
  143. test -f test-suite.log
  144. # Tests that shouldn't have been re-run.
  145. $EGREP '(foo|bar)\.bin|baz\.test$' stdout && exit 1
  146. # Tests that should have been run. Again, we don't anchor the end
  147. # of the next pattern, to allow for non-empty $(EXEEXT).
  148. grep '^PASS: none\.bin' stdout
  149. :