123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. # ffoo test harness
  3. # See LICENSE file for copyright and license details.
  4. . $TF_DIR/include/common.sh
  5. #
  6. # Default path to header generator
  7. #
  8. __TF_HDRCMD="$TF_SUITE/TF_HEADER"
  9. __tf_collect_if_needed() {
  10. #
  11. # Collect artifact if exit status suggests it
  12. #
  13. # Use test exit status $1 to help decide if artifacts are
  14. # needed, and collect them if so.
  15. #
  16. # If TF_COLLECT is set to "always", collect regardless of
  17. # the status. Otherwise, collect unless status is 0 or 1
  18. # (pass or bailout); in that case do nothing.
  19. #
  20. local tes=$1 # test exit status
  21. local will # should we collect artifacts?
  22. case "$TF_COLLECT:$tes" in
  23. always:*) will=true ;;
  24. *:0) will=false ;;
  25. *:2) will=false ;;
  26. *) will=true ;;
  27. esac
  28. $will || return 0
  29. mkdir -p "$artifact_dir/$stamp"
  30. cp -r $tmpdir/* "$artifact_dir/$stamp"
  31. }
  32. __tf_default_header() {
  33. #
  34. # Create default header
  35. #
  36. echo "(add $__TF_HDRCMD executable for own header)"
  37. }
  38. __tf_header() {
  39. #
  40. # create header to add to output before test
  41. #
  42. local field
  43. local hdrcmd="$__TF_HDRCMD"
  44. test -x "$hdrcmd" || hdrcmd="__tf_default_header"
  45. $hdrcmd \
  46. | while read field;
  47. do
  48. test -n "$field" || break
  49. tf_think "# $field"
  50. done
  51. tf_think ""
  52. }
  53. tf_enum_tests() {
  54. #
  55. # List what looks like test; relative to $TF_SUITE
  56. #
  57. tf_debug "TF_SUITE='$TF_SUITE'"
  58. test -d $TF_SUITE || return 0
  59. find -L \
  60. $TF_SUITE \
  61. -mindepth 2 \
  62. -maxdepth 2 \
  63. -type f \
  64. -perm /111 \
  65. -name TF_RUN \
  66. | cut -d/ -f2
  67. }
  68. tf_run_tests() {
  69. #
  70. # Discover and run tests
  71. #
  72. local artifact_dir="$PWD/tfkit-artifacts"
  73. local es=0 # overall exit status
  74. local tmpdir="" # test temporary dir
  75. local tname="" # test name
  76. local tes=0 # test result
  77. local stamp="" # test stamp to use as artifact name
  78. local tf_dir tf_suite # to keep absolute paths for TF_RUN
  79. __tf_header
  80. tf_dir="$(readlink -f "$TF_DIR")"
  81. tf_suite="$(readlink -f "$TF_SUITE")"
  82. es=0
  83. for tname in $(tf_enum_tests | grep -e "$TF_FILTER_TEST");
  84. do
  85. tf_think "... $tname"
  86. tmpdir=$(mktemp -d)
  87. stamp=$(date +artifacts-$tname-%Y%m%d-%H%M%S)
  88. cp -r "$TF_SUITE/$tname/"* "$tmpdir"
  89. pushd $tmpdir >/dev/null
  90. TF_DIR="$tf_dir" TF_SUITE=$tf_suite TF_TNAME="$tname" \
  91. ./TF_RUN
  92. tes=$?
  93. __tf_collect_if_needed $tes
  94. test $tes -gt $es && es=$tes
  95. popd >/dev/null
  96. rm -rf $tmpdir
  97. if test $tes -eq 0;
  98. then
  99. tf_think "''' $tname ($tes)"
  100. else
  101. tf_warn "??? $tname ($tes)"
  102. fi
  103. done
  104. return $es
  105. }