test-driver 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #! /bin/sh
  2. # test-driver - basic testsuite driver script.
  3. scriptversion=2018-03-07.03; # UTC
  4. # Copyright (C) 2011-2020 Free Software Foundation, Inc.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2, or (at your option)
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. # As a special exception to the GNU General Public License, if you
  19. # distribute this file as part of a program that contains a
  20. # configuration script generated by Autoconf, you may include it under
  21. # the same distribution terms that you use for the rest of that program.
  22. # This file is maintained in Automake, please report
  23. # bugs to <bug-automake@gnu.org> or send patches to
  24. # <automake-patches@gnu.org>.
  25. # Make unconditional expansion of undefined variables an error. This
  26. # helps a lot in preventing typo-related bugs.
  27. set -u
  28. usage_error ()
  29. {
  30. echo "$0: $*" >&2
  31. print_usage >&2
  32. exit 2
  33. }
  34. print_usage ()
  35. {
  36. cat <<END
  37. Usage:
  38. test-driver --test-name NAME --log-file PATH --trs-file PATH
  39. [--expect-failure {yes|no}] [--color-tests {yes|no}]
  40. [--enable-hard-errors {yes|no}] [--]
  41. TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
  42. The '--test-name', '--log-file' and '--trs-file' options are mandatory.
  43. See the GNU Automake documentation for information.
  44. END
  45. }
  46. test_name= # Used for reporting.
  47. log_file= # Where to save the output of the test script.
  48. trs_file= # Where to save the metadata of the test run.
  49. expect_failure=no
  50. color_tests=no
  51. enable_hard_errors=yes
  52. while test $# -gt 0; do
  53. case $1 in
  54. --help) print_usage; exit $?;;
  55. --version) echo "test-driver $scriptversion"; exit $?;;
  56. --test-name) test_name=$2; shift;;
  57. --log-file) log_file=$2; shift;;
  58. --trs-file) trs_file=$2; shift;;
  59. --color-tests) color_tests=$2; shift;;
  60. --expect-failure) expect_failure=$2; shift;;
  61. --enable-hard-errors) enable_hard_errors=$2; shift;;
  62. --) shift; break;;
  63. -*) usage_error "invalid option: '$1'";;
  64. *) break;;
  65. esac
  66. shift
  67. done
  68. missing_opts=
  69. test x"$test_name" = x && missing_opts="$missing_opts --test-name"
  70. test x"$log_file" = x && missing_opts="$missing_opts --log-file"
  71. test x"$trs_file" = x && missing_opts="$missing_opts --trs-file"
  72. if test x"$missing_opts" != x; then
  73. usage_error "the following mandatory options are missing:$missing_opts"
  74. fi
  75. if test $# -eq 0; then
  76. usage_error "missing argument"
  77. fi
  78. if test $color_tests = yes; then
  79. # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
  80. red='' # Red.
  81. grn='' # Green.
  82. lgn='' # Light green.
  83. blu='' # Blue.
  84. mgn='' # Magenta.
  85. std='' # No color.
  86. else
  87. red= grn= lgn= blu= mgn= std=
  88. fi
  89. do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
  90. trap "st=129; $do_exit" 1
  91. trap "st=130; $do_exit" 2
  92. trap "st=141; $do_exit" 13
  93. trap "st=143; $do_exit" 15
  94. # Test script is run here.
  95. "$@" >$log_file 2>&1
  96. estatus=$?
  97. if test $enable_hard_errors = no && test $estatus -eq 99; then
  98. tweaked_estatus=1
  99. else
  100. tweaked_estatus=$estatus
  101. fi
  102. case $tweaked_estatus:$expect_failure in
  103. 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
  104. 0:*) col=$grn res=PASS recheck=no gcopy=no;;
  105. 77:*) col=$blu res=SKIP recheck=no gcopy=yes;;
  106. 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;;
  107. *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;;
  108. *:*) col=$red res=FAIL recheck=yes gcopy=yes;;
  109. esac
  110. # Report the test outcome and exit status in the logs, so that one can
  111. # know whether the test passed or failed simply by looking at the '.log'
  112. # file, without the need of also peaking into the corresponding '.trs'
  113. # file (automake bug#11814).
  114. echo "$res $test_name (exit status: $estatus)" >>$log_file
  115. # Report outcome to console.
  116. echo "${col}${res}${std}: $test_name"
  117. # Register the test result, and other relevant metadata.
  118. echo ":test-result: $res" > $trs_file
  119. echo ":global-test-result: $res" >> $trs_file
  120. echo ":recheck: $recheck" >> $trs_file
  121. echo ":copy-in-global-log: $gcopy" >> $trs_file
  122. # Local Variables:
  123. # mode: shell-script
  124. # sh-indentation: 2
  125. # eval: (add-hook 'before-save-hook 'time-stamp)
  126. # time-stamp-start: "scriptversion="
  127. # time-stamp-format: "%:y-%02m-%02d.%02H"
  128. # time-stamp-time-zone: "UTC0"
  129. # time-stamp-end: "; # UTC"
  130. # End: