3
0

runtest 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/sh
  2. [ -n "$srcdir" ] || srcdir=$(pwd)
  3. [ -n "$bindir" ] || bindir=$(dirname $(pwd))
  4. PATH=$bindir:$PATH
  5. # Run old-style test.
  6. 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. implemented=$($bindir/busybox 2>&1 |
  75. while read line
  76. do
  77. if test x"$line" = x"Currently defined functions:"
  78. then
  79. xargs | sed 's/,//g'
  80. break
  81. fi
  82. done
  83. )
  84. rm -rf "$LINKSDIR" 2>/dev/null
  85. mkdir "$LINKSDIR"
  86. for i in $implemented
  87. do
  88. ln -s $bindir/busybox "$LINKSDIR"/$i
  89. done
  90. # Set up option flags so tests can be selective.
  91. configfile=${bindir:-../../}/.config
  92. export OPTIONFLAGS=:$(echo $(sed -nr 's/^CONFIG_(.*)=.*/\1/p' $configfile) | sed 's/ /:/g')
  93. for applet in $applets; do
  94. if [ "$applet" = "links" ]; then continue; fi
  95. if [ "$applet" != "CVS" -a -d "$srcdir/$applet" ]; then
  96. if run_applet_tests $applet; then
  97. :
  98. else
  99. status=1
  100. fi
  101. fi
  102. # Is this a new-style test?
  103. applet=$(echo "$applet" | sed -n 's/\.tests$//p')
  104. if [ ${#applet} -ne 0 ]
  105. then
  106. if [ ! -h "$LINKSDIR/$applet" ] && [ "${applet:0:4}" != "all_" ]
  107. then
  108. echo "SKIPPED: $applet (not built)"
  109. continue
  110. fi
  111. if PATH="$LINKSDIR":$srcdir:$bindir:$PATH \
  112. "${srcdir:-.}/$applet".tests
  113. then
  114. :
  115. else
  116. status=1
  117. fi
  118. fi
  119. done
  120. rm -rf "$LINKSDIR"
  121. exit $status