runtest 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/sh
  2. [ -n "$srcdir" ] || srcdir=$(pwd)
  3. [ -n "$bindir" ] || bindir=$(dirname $(pwd))
  4. PATH=$bindir:$PATH
  5. # Run old-style test.
  6. function run_applet_testcase
  7. {
  8. local applet=$1
  9. local testcase=$2
  10. local status=0
  11. local RES=
  12. local uc_applet=$(echo $applet | tr a-z A-Z)
  13. local testname=$(basename $testcase)
  14. if grep -q "^# CONFIG_${uc_applet} is not set$" $bindir/.config; then
  15. echo UNTESTED: $testname
  16. return 0
  17. fi
  18. if grep -q "^# FEATURE: " $testcase; then
  19. local feature=`sed -ne 's/^# FEATURE: //p' $testcase`
  20. if grep -q "^# ${feature} is not set$" $bindir/.config; then
  21. echo UNTESTED: $testname
  22. return 0
  23. fi
  24. fi
  25. rm -rf tmp
  26. mkdir -p tmp
  27. pushd tmp > /dev/null
  28. d=$srcdir sh -x -e $testcase >.logfile.txt 2>&1 || status=$?
  29. if [ $status -ne 0 ] ; then
  30. echo FAIL: $testname
  31. if [ $verbose -gt 0 ]; then
  32. cat .logfile.txt
  33. fi
  34. status=$?
  35. else
  36. echo PASS: $testname
  37. rm -f .logfile.txt
  38. status=$?
  39. fi
  40. popd > /dev/null
  41. rm -rf tmp
  42. return $status
  43. }
  44. run_applet_tests ()
  45. {
  46. local applet=$1
  47. local status=0
  48. for testcase in $srcdir/$applet/*; do
  49. if [ "$testcase" = "$srcdir/$applet/CVS" ]; then
  50. continue
  51. fi
  52. if run_applet_testcase $applet $testcase; then
  53. :
  54. else
  55. status=1
  56. fi
  57. done
  58. return $status
  59. }
  60. status=0
  61. verbose=0
  62. if [ x"$1" = x"-v" ]; then
  63. verbose=1
  64. export VERBOSE=$verbose
  65. shift
  66. fi
  67. if [ $# -ne 0 ]; then
  68. applets=$(cd $srcdir ; for i in $@; do ls ${i}* ; done)
  69. else
  70. applets=$(ls $srcdir)
  71. fi
  72. # Populate a directory with links to all busybox applets
  73. LINKSDIR="${bindir}/runtest-tempdir-links"
  74. rm -rf "$LINKSDIR" 2>/dev/null
  75. mkdir "$LINKSDIR"
  76. for i in $(sed 's@/[a-z0-9/\[]*/@@' $bindir/busybox.links 2>/dev/null)
  77. do
  78. ln -s $bindir/busybox "$LINKSDIR"/$i
  79. done
  80. # Set up option flags so tests can be selective.
  81. configfile=${bindir:-../../}/.config
  82. export OPTIONFLAGS=:$(echo $(sed -nr 's/^CONFIG_(.*)=.*/\1/p' $configfile) | sed 's/ /:/g')
  83. for applet in $applets; do
  84. if [ "$applet" = "links" ]; then continue; fi
  85. if [ "$applet" != "CVS" -a -d "$srcdir/$applet" ]; then
  86. if run_applet_tests $applet; then
  87. :
  88. else
  89. status=1
  90. fi
  91. fi
  92. # Is this a new-style test?
  93. applet=$(echo "$applet" | sed -n 's/\.tests$//p')
  94. if [ ${#applet} -ne 0 ]
  95. then
  96. if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ]
  97. then
  98. echo "SKIPPED: $applet (not built)"
  99. continue
  100. fi
  101. if PATH="$LINKSDIR":$srcdir:$bindir:$PATH \
  102. "${srcdir:-.}/$applet".tests
  103. then
  104. :
  105. else
  106. status=1
  107. fi
  108. fi
  109. done
  110. rm -rf "$LINKSDIR"
  111. exit $status