test-driver 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #! /bin/sh
  2. # test-driver - basic driver script for the 'parallel-tests' mode.
  3. scriptversion=2012-06-27.10; # UTC
  4. # Copyright (C) 2011-2012 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 <http://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}] [--] TEST-SCRIPT
  41. The '--test-name', '--log-file' and '--trs-file' options are mandatory.
  42. END
  43. }
  44. # TODO: better error handling in option parsing (in particular, ensure
  45. # TODO: $log_file, $trs_file and $test_name are defined).
  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. esac
  65. shift
  66. done
  67. if test $color_tests = yes; then
  68. # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
  69. red='' # Red.
  70. grn='' # Green.
  71. lgn='' # Light green.
  72. blu='' # Blue.
  73. mgn='' # Magenta.
  74. std='' # No color.
  75. else
  76. red= grn= lgn= blu= mgn= std=
  77. fi
  78. do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
  79. trap "st=129; $do_exit" 1
  80. trap "st=130; $do_exit" 2
  81. trap "st=141; $do_exit" 13
  82. trap "st=143; $do_exit" 15
  83. # Test script is run here.
  84. "$@" >$log_file 2>&1
  85. estatus=$?
  86. if test $enable_hard_errors = no && test $estatus -eq 99; then
  87. estatus=1
  88. fi
  89. case $estatus:$expect_failure in
  90. 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
  91. 0:*) col=$grn res=PASS recheck=no gcopy=no;;
  92. 77:*) col=$blu res=SKIP recheck=no gcopy=yes;;
  93. 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;;
  94. *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;;
  95. *:*) col=$red res=FAIL recheck=yes gcopy=yes;;
  96. esac
  97. # Report outcome to console.
  98. echo "${col}${res}${std}: $test_name"
  99. # Register the test result, and other relevant metadata.
  100. echo ":test-result: $res" > $trs_file
  101. echo ":global-test-result: $res" >> $trs_file
  102. echo ":recheck: $recheck" >> $trs_file
  103. echo ":copy-in-global-log: $gcopy" >> $trs_file
  104. # Local Variables:
  105. # mode: shell-script
  106. # sh-indentation: 2
  107. # eval: (add-hook 'write-file-hooks 'time-stamp)
  108. # time-stamp-start: "scriptversion="
  109. # time-stamp-format: "%:y-%02m-%02d.%02H"
  110. # time-stamp-time-zone: "UTC"
  111. # time-stamp-end: "; # UTC"
  112. # End: