runtest 3.6 KB

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