runtest 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/sh
  2. # Usage:
  3. # runtest [applet1] [applet2...]
  4. # Run one old-style test.
  5. # Tests are stored in applet/testcase shell scripts.
  6. # They are run using "sh -x -e applet/testcase".
  7. # Option -e will make testcase stop on the first failed command.
  8. run_applet_testcase()
  9. {
  10. local applet=$1
  11. local testcase=$2
  12. local status
  13. local uc_applet=$(echo $applet | tr a-z A-Z)
  14. local testname=$(basename $testcase)
  15. if grep -q "^# CONFIG_${uc_applet} is not set$" $bindir/.config; then
  16. echo "UNTESTED: $testname"
  17. return 0
  18. fi
  19. if grep -q "^# FEATURE: " $testcase; then
  20. local feature=`sed -ne 's/^# FEATURE: //p' $testcase`
  21. if grep -q "^# ${feature} is not set$" $bindir/.config; then
  22. echo "UNTESTED: $testname"
  23. return 0
  24. fi
  25. fi
  26. rm -rf ".tmpdir.$applet"
  27. mkdir -p ".tmpdir.$applet"
  28. cd ".tmpdir.$applet" || return 1
  29. # echo "Running testcase $testcase"
  30. d="$tsdir" sh -x -e "$testcase" >"$testname.stdout.txt" 2>&1
  31. status=$?
  32. if [ $status != 0 ]; then
  33. echo "FAIL: $testname"
  34. if [ x"$VERBOSE" != x ]; then
  35. cat "$testname.stdout.txt"
  36. fi
  37. else
  38. echo "PASS: $testname"
  39. fi
  40. cd ..
  41. rm -rf ".tmpdir.$applet"
  42. return $status
  43. }
  44. # Run all old-style tests for given applet
  45. run_applet_tests()
  46. {
  47. local applet=$1
  48. local status=0
  49. for testcase in $tsdir/$applet/*; do
  50. if [ "$testcase" = "$tsdir/$applet/CVS" ]; then
  51. continue
  52. fi
  53. run_applet_testcase $applet $testcase
  54. test $? = 0 || status=1
  55. done
  56. return $status
  57. }
  58. [ -n "$tsdir" ] || tsdir=$(pwd)
  59. [ -n "$bindir" ] || bindir=$(dirname $(pwd))
  60. PATH="$bindir:$PATH"
  61. if [ x"$VERBOSE" = x ]; then
  62. export VERBOSE=
  63. fi
  64. if [ x"$1" = x"-v" ]; then
  65. export VERBOSE=1
  66. shift
  67. fi
  68. implemented=$(
  69. $bindir/busybox 2>&1 |
  70. while read line; do
  71. if [ x"$line" = x"Currently defined functions:" ]; then
  72. xargs | sed 's/,//g'
  73. break
  74. fi
  75. done
  76. )
  77. applets="$implemented"
  78. if [ $# -ne 0 ]; then
  79. applets="$@"
  80. fi
  81. # Populate a directory with links to all busybox applets
  82. LINKSDIR="$bindir/runtest-tempdir-links"
  83. rm -rf "$LINKSDIR" 2>/dev/null
  84. mkdir "$LINKSDIR"
  85. for i in $implemented; do
  86. ln -s $bindir/busybox "$LINKSDIR"/$i
  87. done
  88. # Set up option flags so tests can be selective.
  89. export OPTIONFLAGS=:$(sed -nr 's/^CONFIG_//p' $bindir/.config | sed 's/=.*//' | xargs | sed 's/ /:/g')
  90. status=0
  91. for applet in $applets; do
  92. if [ "$applet" = "links" ]; then continue; fi
  93. # Any old-style tests for this applet?
  94. if [ "$applet" != "CVS" -a -d "$tsdir/$applet" ]; then
  95. run_applet_tests "$applet"
  96. test $? = 0 || status=1
  97. fi
  98. # Is this a new-style test?
  99. if [ -f "${applet}.tests" ]; then
  100. if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ]; then
  101. echo "SKIPPED: $applet (not built)"
  102. continue
  103. fi
  104. # echo "Running test ${tsdir:-.}/${applet}.tests"
  105. PATH="$LINKSDIR:$tsdir:$bindir:$PATH" "${tsdir:-.}/${applet}.tests"
  106. test $? = 0 || status=1
  107. fi
  108. done
  109. # Leaving the dir makes it somewhat easier to run failed test by hand
  110. #rm -rf "$LINKSDIR"
  111. if [ $status != 0 -a x"$VERBOSE" = x ]; then
  112. echo "Failures detected, running with -v (verbose) will give more info"
  113. fi
  114. exit $status