test-driver 4.0 KB

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