test-driver 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #! /bin/sh
  2. # test-driver - basic testsuite driver script.
  3. scriptversion=2013-07-13.22; # UTC
  4. # Copyright (C) 2011-2013 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}] [--]
  41. TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
  42. The '--test-name', '--log-file' and '--trs-file' options are mandatory.
  43. END
  44. }
  45. test_name= # Used for reporting.
  46. log_file= # Where to save the output of the test script.
  47. trs_file= # Where to save the metadata of the test run.
  48. expect_failure=no
  49. color_tests=no
  50. enable_hard_errors=yes
  51. while test $# -gt 0; do
  52. case $1 in
  53. --help) print_usage; exit $?;;
  54. --version) echo "test-driver $scriptversion"; exit $?;;
  55. --test-name) test_name=$2; shift;;
  56. --log-file) log_file=$2; shift;;
  57. --trs-file) trs_file=$2; shift;;
  58. --color-tests) color_tests=$2; shift;;
  59. --expect-failure) expect_failure=$2; shift;;
  60. --enable-hard-errors) enable_hard_errors=$2; shift;;
  61. --) shift; break;;
  62. -*) usage_error "invalid option: '$1'";;
  63. *) break;;
  64. esac
  65. shift
  66. done
  67. missing_opts=
  68. test x"$test_name" = x && missing_opts="$missing_opts --test-name"
  69. test x"$log_file" = x && missing_opts="$missing_opts --log-file"
  70. test x"$trs_file" = x && missing_opts="$missing_opts --trs-file"
  71. if test x"$missing_opts" != x; then
  72. usage_error "the following mandatory options are missing:$missing_opts"
  73. fi
  74. if test $# -eq 0; then
  75. usage_error "missing argument"
  76. fi
  77. if test $color_tests = yes; then
  78. # Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
  79. red='' # Red.
  80. grn='' # Green.
  81. lgn='' # Light green.
  82. blu='' # Blue.
  83. mgn='' # Magenta.
  84. std='' # No color.
  85. else
  86. red= grn= lgn= blu= mgn= std=
  87. fi
  88. do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
  89. trap "st=129; $do_exit" 1
  90. trap "st=130; $do_exit" 2
  91. trap "st=141; $do_exit" 13
  92. trap "st=143; $do_exit" 15
  93. # Test script is run here.
  94. "$@" >$log_file 2>&1
  95. estatus=$?
  96. if test $enable_hard_errors = no && test $estatus -eq 99; then
  97. estatus=1
  98. fi
  99. case $estatus:$expect_failure in
  100. 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
  101. 0:*) col=$grn res=PASS recheck=no gcopy=no;;
  102. 77:*) col=$blu res=SKIP recheck=no gcopy=yes;;
  103. 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;;
  104. *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;;
  105. *:*) col=$red res=FAIL recheck=yes gcopy=yes;;
  106. esac
  107. # Report outcome to console.
  108. echo "${col}${res}${std}: $test_name"
  109. # Register the test result, and other relevant metadata.
  110. echo ":test-result: $res" > $trs_file
  111. echo ":global-test-result: $res" >> $trs_file
  112. echo ":recheck: $recheck" >> $trs_file
  113. echo ":copy-in-global-log: $gcopy" >> $trs_file
  114. # Local Variables:
  115. # mode: shell-script
  116. # sh-indentation: 2
  117. # eval: (add-hook 'write-file-hooks 'time-stamp)
  118. # time-stamp-start: "scriptversion="
  119. # time-stamp-format: "%:y-%02m-%02d.%02H"
  120. # time-stamp-time-zone: "UTC"
  121. # time-stamp-end: "; # UTC"
  122. # End: