2001-03-10 06:21:29 +05:30
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# tester.sh - reads testcases from file and tests busybox applets vs GNU
|
|
|
|
# counterparts
|
|
|
|
#
|
2001-03-14 05:00:18 +05:30
|
|
|
# This should be run from within the tests/ directory. Before you run it, you
|
|
|
|
# should compile up a busybox that has all applets and all features turned on.
|
2001-03-10 06:21:29 +05:30
|
|
|
|
|
|
|
# set up defaults (can be changed with cmd-line options)
|
|
|
|
BUSYBOX=../busybox
|
|
|
|
TESTCASES=testcases
|
|
|
|
LOGFILE=tester.log
|
2001-10-24 10:30:29 +05:30
|
|
|
CONFIG_OUT=bb.out
|
2001-03-10 06:21:29 +05:30
|
|
|
GNU_OUT=gnu.out
|
|
|
|
SETUP=""
|
|
|
|
CLEANUP=""
|
2001-03-14 05:00:18 +05:30
|
|
|
KEEPTMPFILES="no"
|
|
|
|
DEBUG=2
|
2001-03-10 06:21:29 +05:30
|
|
|
|
|
|
|
|
2001-03-14 05:00:18 +05:30
|
|
|
#while getopts 'p:t:l:b:g:s:c:kd:' opt
|
|
|
|
while getopts 'p:t:l:s:c:kd:' opt
|
2001-03-10 06:21:29 +05:30
|
|
|
do
|
|
|
|
case $opt in
|
|
|
|
p) BUSYBOX=$OPTARG; ;;
|
|
|
|
t) TESTCASES=$OPTARG; ;;
|
|
|
|
l) LOGFILE=$OPTARG; ;;
|
2001-10-24 10:30:29 +05:30
|
|
|
# b) CONFIG_OUT=$OPTARG; ;;
|
2001-03-14 05:00:18 +05:30
|
|
|
# g) GNU_OUT=$OPTARG; ;;
|
2001-03-10 06:21:29 +05:30
|
|
|
s) SETUP=$OPTARG; ;;
|
|
|
|
c) CLEANUP=$OPTARG; ;;
|
2001-03-14 05:00:18 +05:30
|
|
|
k) KEEPTMPFILES="yes"; ;;
|
|
|
|
d) DEBUG=$OPTARG; ;;
|
2001-03-10 06:21:29 +05:30
|
|
|
*)
|
|
|
|
echo "usage: $0 [-ptlbgsc]"
|
2001-03-14 05:00:18 +05:30
|
|
|
echo " -p PATH path to busybox executable (default=$BUSYBOX)"
|
|
|
|
echo " -t FILE run testcases in FILE (default=$TESTCASES)"
|
|
|
|
echo " -l FILE log test results in FILE (default=$LOGFILE)"
|
|
|
|
# echo " -b FILE store temporary busybox output in FILE"
|
|
|
|
# echo " -g FILE store temporary GNU output in FILE"
|
2001-03-10 06:21:29 +05:30
|
|
|
echo " -s FILE (setup) run commands in FILE before testcases"
|
|
|
|
echo " -c FILE (cleanup) run commands in FILE after testcases"
|
2001-03-14 05:00:18 +05:30
|
|
|
echo " -k keep temporary output files (don't delete them)"
|
|
|
|
echo " -d NUM set level of debugging output"
|
|
|
|
echo " 0 = no output"
|
|
|
|
echo " 1 = output failures / whoops lines only"
|
|
|
|
echo " 2 = (default) output setup / cleanup msgs and testcase lines"
|
|
|
|
echo " 3+= other debug noise (internal stuff)"
|
2001-03-10 06:21:29 +05:30
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
#shift `expr $OPTIND - 1`
|
|
|
|
|
|
|
|
|
2001-03-14 05:00:18 +05:30
|
|
|
# maybe print some debug output
|
|
|
|
if [ $DEBUG -ge 3 ]
|
|
|
|
then
|
|
|
|
echo "BUSYBOX=$BUSYBOX"
|
|
|
|
echo "TESTCASES=$TESTCASES"
|
|
|
|
echo "LOGFILE=$LOGFILE"
|
2001-10-24 10:30:29 +05:30
|
|
|
echo "CONFIG_OUT=$CONFIG_OUT"
|
2001-03-14 05:00:18 +05:30
|
|
|
echo "GNU_OUT=$GNU_OUT"
|
|
|
|
echo "SETUP=$SETUP"
|
|
|
|
echo "CLEANUP=$CLEANUP"
|
|
|
|
echo "DEBUG=$DEBUG"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# do sanity checks
|
|
|
|
if [ ! -e $BUSYBOX ]
|
|
|
|
then
|
|
|
|
echo "Busybox executable: $BUSYBOX not found!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -e $TESTCASES ]
|
|
|
|
then
|
|
|
|
echo "Testcases file: $TESTCASES not found!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2001-03-10 06:21:29 +05:30
|
|
|
# do normal setup
|
|
|
|
[ -e $LOGFILE ] && rm $LOGFILE
|
|
|
|
unalias -a # gets rid of aliases that might create different output
|
|
|
|
|
2001-03-14 05:00:18 +05:30
|
|
|
|
2001-03-10 06:21:29 +05:30
|
|
|
# do extra setup (if any)
|
2001-05-24 22:45:33 +05:30
|
|
|
if [ ! -z "$SETUP" ]
|
2001-03-10 06:21:29 +05:30
|
|
|
then
|
2001-03-14 05:00:18 +05:30
|
|
|
[ $DEBUG -ge 2 ] && echo "running setup commands in $SETUP"
|
|
|
|
source $SETUP
|
2001-03-10 06:21:29 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# go through each line in the testcase file
|
|
|
|
cat $TESTCASES | while read line
|
|
|
|
do
|
|
|
|
#echo $line
|
|
|
|
# only process non-blank lines and non-comment lines
|
|
|
|
if [ "$line" ]
|
|
|
|
then
|
|
|
|
if [ `echo "$line" | cut -c1` != "#" ]
|
|
|
|
then
|
|
|
|
|
|
|
|
# test if the applet was compiled into busybox
|
2001-03-14 05:00:18 +05:30
|
|
|
# (this only tests the applet at the beginning of the line)
|
|
|
|
#applet=`echo $line | cut -d' ' -f1`
|
|
|
|
applet=`echo $line | sed 's/\(^[^ ;]*\)[ ;].*/\1/'`
|
2001-03-10 06:21:29 +05:30
|
|
|
$BUSYBOX 2>&1 | grep -qw $applet
|
|
|
|
if [ $? -eq 1 ]
|
|
|
|
then
|
|
|
|
echo "WHOOPS: $applet not compiled into busybox" | tee -a $LOGFILE
|
|
|
|
else
|
2001-03-14 05:00:18 +05:30
|
|
|
|
|
|
|
# execute line using gnu / system programs
|
|
|
|
[ $DEBUG -ge 2 ] && echo "testing: $line" | tee -a $LOGFILE
|
|
|
|
sh -c "$line" > $GNU_OUT
|
|
|
|
|
|
|
|
# change line to include "busybox" before every statement
|
|
|
|
line="$BUSYBOX $line"
|
2001-05-24 22:45:33 +05:30
|
|
|
# is this a bash-2-ism?
|
|
|
|
# line=${line//;/; $BUSYBOX }
|
|
|
|
# line=${line//|/| $BUSYBOX }
|
|
|
|
# assume $BUSYBOX has no commas
|
2001-05-25 02:54:39 +05:30
|
|
|
line=`echo "$line" | sed -e 's,;,; '$BUSYBOX, \
|
|
|
|
-e 's, |, | '$BUSYBOX,`
|
2001-03-14 05:00:18 +05:30
|
|
|
|
|
|
|
# execute line using busybox programs
|
|
|
|
[ $DEBUG -ge 2 ] && echo "testing: $line" | tee -a $LOGFILE
|
2001-10-24 10:30:29 +05:30
|
|
|
sh -c "$line" > $CONFIG_OUT
|
2001-03-14 05:00:18 +05:30
|
|
|
|
|
|
|
# see if they match
|
2001-10-24 10:30:29 +05:30
|
|
|
diff -q $CONFIG_OUT $GNU_OUT > /dev/null
|
2001-03-10 06:21:29 +05:30
|
|
|
if [ $? -eq 1 ]
|
|
|
|
then
|
2001-03-14 05:00:18 +05:30
|
|
|
[ $DEBUG -ge 1 ] && echo "FAILED: $line" | tee -a $LOGFILE
|
2001-10-24 10:30:29 +05:30
|
|
|
diff -u $CONFIG_OUT $GNU_OUT >> $LOGFILE
|
2001-03-10 06:21:29 +05:30
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2001-03-14 05:00:18 +05:30
|
|
|
[ $DEBUG -gt 0 ] && echo "Finished. Results are in $LOGFILE"
|
2001-03-10 06:21:29 +05:30
|
|
|
|
|
|
|
|
|
|
|
# do normal cleanup
|
2001-10-24 10:30:29 +05:30
|
|
|
[ "$KEEPTMPFILES" = "no" ] && rm -f $CONFIG_OUT $GNU_OUT
|
2001-03-14 05:00:18 +05:30
|
|
|
|
2001-03-10 06:21:29 +05:30
|
|
|
|
|
|
|
# do extra cleanup (if any)
|
2001-05-24 22:45:33 +05:30
|
|
|
if [ ! -z "$CLEANUP" ]
|
2001-03-10 06:21:29 +05:30
|
|
|
then
|
2001-03-14 05:00:18 +05:30
|
|
|
[ $DEBUG -ge 2 ] && echo "running cleanup commands in $CLEANUP"
|
|
|
|
source $CLEANUP
|
2001-03-10 06:21:29 +05:30
|
|
|
fi
|