subtest.sh 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_name2cmd() {
  11. #
  12. # Stub: expand test name to test command
  13. #
  14. tf_warn "implement tf_name2cmd()!"
  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 tcmd="" # test command
  24. local setup=true # setup command
  25. local cleanup=true # cleanup command
  26. test -f TF_SETUP && setup=". TF_SETUP"
  27. test -f TF_CLEANUP && cleanup=". TF_CLEANUP"
  28. if $setup;
  29. then
  30. tcmd="$(tf_name2cmd $subtname)"
  31. tf_debug "tcmd='$tcmd'"
  32. $tcmd; ses=$?
  33. else
  34. tf_warn "setup phase failed, skipping: $subtname"
  35. ses=$TF_ES_ERROR
  36. fi
  37. if ! $cleanup;
  38. then
  39. tf_warn "cleanup phase failed: $subtname"
  40. ses=$TF_ES_PANIC
  41. fi
  42. return $ses
  43. }
  44. tf_do_subtests() {
  45. #
  46. # Run all subtests and return highest status
  47. #
  48. local es=0 # final exit status ("worst" of subtests)
  49. local subtname="" # one subtest name
  50. local tes="" # one subtest exit status
  51. local enumd=TF_ENUMERATED_SUBTESTS
  52. local fltrd=TF_FILTERED_SUBTESTS
  53. tf_enum_subtests >$enumd || { tf_warn "error enumerating subtests"; return $TF_ES_BAILOUT; }
  54. test -s $enumd || { tf_warn "no subtests enumerated"; return $TF_ES_BAILOUT; }
  55. grep -e "$TF_FILTER_SUBTEST" $enumd > $fltrd
  56. test -s $fltrd || tf_debug "TF_FILTER_SUBTEST ate everything: $TF_FILTER_SUBTEST"
  57. for subtname in $(<$fltrd);
  58. do
  59. export TF_SUBTNAME=$subtname
  60. tf_think "::: $TF_TNAME::$TF_SUBTNAME"
  61. tf_do_subtest "$TF_SUBTNAME";
  62. tes=$?
  63. test $tes -gt $es && es=$tes
  64. test $tes -gt $TF_ES_OK && tf_warn "!!! $TF_TNAME::$TF_SUBTNAME ($tes)"
  65. test $tes -gt $TF_ES_BAILOUT && break
  66. done
  67. return $es
  68. }