subtest.sh 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. . "$TF_DIR/include/common.sh"
  3. tf_enum_subtests() {
  4. #
  5. # Stub: enumerate subtests
  6. #
  7. tf_warn "implement tf_enum_subtests()!"
  8. return "$TF_ES_ERROR"
  9. }
  10. tf_do_subtest() {
  11. #
  12. # Stub: perform test named $1
  13. #
  14. tf_warn "implement tf_do_subtest()!"
  15. return "$TF_ES_ERROR"
  16. }
  17. _tf_do_subtest() {
  18. #
  19. # Run single subtest inc. setup/cleanup if present
  20. #
  21. local subtname="$1" # this subtest name
  22. local ses=0 # subtest exit status
  23. local setup=true # setup command
  24. local cleanup=true # cleanup command
  25. if test -f TF_SETUP;
  26. then
  27. setup=". TF_SETUP"
  28. bash -n TF_SETUP || {
  29. tf_warn "synax errors in TF_SETUP, skipping"
  30. return "$TF_ES_ERROR"
  31. }
  32. fi
  33. if test -f TF_CLEANUP;
  34. then
  35. setup=". TF_CLEANUP"
  36. bash -n TF_CLEANUP || {
  37. tf_warn "synax errors in TF_CLEANUP, skipping"
  38. return "$TF_ES_ERROR"
  39. }
  40. fi
  41. if $setup;
  42. then
  43. tf_do_subtest "$subtname"; ses=$?
  44. else
  45. tf_warn "setup phase failed, skipping: $subtname"
  46. ses=$TF_ES_ERROR
  47. fi
  48. if ! $cleanup;
  49. then
  50. tf_warn "cleanup phase failed: $subtname"
  51. ses=$TF_ES_PANIC
  52. fi
  53. return "$ses"
  54. }
  55. tf_do_subtests() {
  56. #
  57. # Run all subtests and return highest status
  58. #
  59. local es=0 # final exit status ("worst" of subtests)
  60. local subtname="" # one subtest name
  61. local tes="" # one subtest exit status
  62. local enumd=TF_ENUMERATED_SUBTESTS
  63. local fltrd=TF_FILTERED_SUBTESTS
  64. tf_enum_subtests >$enumd || { tf_warn "error enumerating subtests"; return "$TF_ES_BAILOUT"; }
  65. test -s $enumd || { tf_warn "no subtests enumerated"; return "$TF_ES_BAILOUT"; }
  66. grep -e "$TF_FILTER_SUBTEST" $enumd > $fltrd
  67. test -s $fltrd || tf_debug "TF_FILTER_SUBTEST ate everything: $TF_FILTER_SUBTEST"
  68. for subtname in $(<$fltrd);
  69. do
  70. export TF_SUBTNAME=$subtname
  71. tf_think "::: $TF_TNAME::$TF_SUBTNAME"
  72. _tf_do_subtest "$TF_SUBTNAME";
  73. tes=$?
  74. test $tes -gt $es && es=$tes
  75. test $tes -gt "$TF_ES_OK" && tf_warn "!!! $TF_TNAME::$TF_SUBTNAME ($tes)"
  76. test $tes -gt "$TF_ES_BAILOUT" && break
  77. done
  78. return $es
  79. }