3 # tester.sh - reads testcases from file and tests busybox applets vs GNU
6 # This should be run from within the tests/ directory. Before you run it, you
7 # should compile up a busybox that has all applets and all features turned on.
9 # set up defaults (can be changed with cmd-line options)
21 #while getopts 'p:t:l:b:g:s:c:kd:' opt
22 while getopts 'p:t:l:s:c:kd:' opt
25 p) BUSYBOX=$OPTARG; ;;
26 t) TESTCASES=$OPTARG; ;;
27 l) LOGFILE=$OPTARG; ;;
28 # b) BB_OUT=$OPTARG; ;;
29 # g) GNU_OUT=$OPTARG; ;;
31 c) CLEANUP=$OPTARG; ;;
32 k) KEEPTMPFILES="yes"; ;;
35 echo "usage: $0 [-ptlbgsc]"
36 echo " -p PATH path to busybox executable (default=$BUSYBOX)"
37 echo " -t FILE run testcases in FILE (default=$TESTCASES)"
38 echo " -l FILE log test results in FILE (default=$LOGFILE)"
39 # echo " -b FILE store temporary busybox output in FILE"
40 # echo " -g FILE store temporary GNU output in FILE"
41 echo " -s FILE (setup) run commands in FILE before testcases"
42 echo " -c FILE (cleanup) run commands in FILE after testcases"
43 echo " -k keep temporary output files (don't delete them)"
44 echo " -d NUM set level of debugging output"
46 echo " 1 = output failures / whoops lines only"
47 echo " 2 = (default) output setup / cleanup msgs and testcase lines"
48 echo " 3+= other debug noise (internal stuff)"
53 #shift `expr $OPTIND - 1`
56 # maybe print some debug output
59 echo "BUSYBOX=$BUSYBOX"
60 echo "TESTCASES=$TESTCASES"
61 echo "LOGFILE=$LOGFILE"
63 echo "GNU_OUT=$GNU_OUT"
65 echo "CLEANUP=$CLEANUP"
73 echo "Busybox executable: $BUSYBOX not found!"
77 if [ ! -e $TESTCASES ]
79 echo "Testcases file: $TESTCASES not found!"
85 [ -e $LOGFILE ] && rm $LOGFILE
86 unalias -a # gets rid of aliases that might create different output
89 # do extra setup (if any)
92 [ $DEBUG -ge 2 ] && echo "running setup commands in $SETUP"
97 # go through each line in the testcase file
98 cat $TESTCASES | while read line
101 # only process non-blank lines and non-comment lines
104 if [ `echo "$line" | cut -c1` != "#" ]
107 # test if the applet was compiled into busybox
108 # (this only tests the applet at the beginning of the line)
109 #applet=`echo $line | cut -d' ' -f1`
110 applet=`echo $line | sed 's/\(^[^ ;]*\)[ ;].*/\1/'`
111 $BUSYBOX 2>&1 | grep -qw $applet
114 echo "WHOOPS: $applet not compiled into busybox" | tee -a $LOGFILE
117 # execute line using gnu / system programs
118 [ $DEBUG -ge 2 ] && echo "testing: $line" | tee -a $LOGFILE
119 sh -c "$line" > $GNU_OUT
121 # change line to include "busybox" before every statement
122 line="$BUSYBOX $line"
123 line=${line//;/; $BUSYBOX }
124 line=${line//|/| $BUSYBOX }
126 # execute line using busybox programs
127 [ $DEBUG -ge 2 ] && echo "testing: $line" | tee -a $LOGFILE
128 sh -c "$line" > $BB_OUT
131 diff -q $BB_OUT $GNU_OUT > /dev/null
134 [ $DEBUG -ge 1 ] && echo "FAILED: $line" | tee -a $LOGFILE
135 diff -u $BB_OUT $GNU_OUT >> $LOGFILE
142 [ $DEBUG -gt 0 ] && echo "Finished. Results are in $LOGFILE"
146 [ $KEEPTMPFILES == "no" ] && rm -f $BB_OUT $GNU_OUT
149 # do extra cleanup (if any)
152 [ $DEBUG -ge 2 ] && echo "running cleanup commands in $CLEANUP"