blob: a4fa38d348ee5c2f313b05da3fe40c4869079b7f [file] [log] [blame]
Mark Whitleyd2117e92001-03-10 00:51:29 +00001#!/bin/bash
2#
3# tester.sh - reads testcases from file and tests busybox applets vs GNU
4# counterparts
5#
Mark Whitleyc75f83d2001-03-13 23:30:18 +00006# 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.
Mark Whitleyd2117e92001-03-10 00:51:29 +00008
9# set up defaults (can be changed with cmd-line options)
10BUSYBOX=../busybox
11TESTCASES=testcases
12LOGFILE=tester.log
13BB_OUT=bb.out
14GNU_OUT=gnu.out
15SETUP=""
16CLEANUP=""
Mark Whitleyc75f83d2001-03-13 23:30:18 +000017KEEPTMPFILES="no"
18DEBUG=2
Mark Whitleyd2117e92001-03-10 00:51:29 +000019
20
Mark Whitleyc75f83d2001-03-13 23:30:18 +000021#while getopts 'p:t:l:b:g:s:c:kd:' opt
22while getopts 'p:t:l:s:c:kd:' opt
Mark Whitleyd2117e92001-03-10 00:51:29 +000023do
24 case $opt in
25 p) BUSYBOX=$OPTARG; ;;
26 t) TESTCASES=$OPTARG; ;;
27 l) LOGFILE=$OPTARG; ;;
Mark Whitleyc75f83d2001-03-13 23:30:18 +000028# b) BB_OUT=$OPTARG; ;;
29# g) GNU_OUT=$OPTARG; ;;
Mark Whitleyd2117e92001-03-10 00:51:29 +000030 s) SETUP=$OPTARG; ;;
31 c) CLEANUP=$OPTARG; ;;
Mark Whitleyc75f83d2001-03-13 23:30:18 +000032 k) KEEPTMPFILES="yes"; ;;
33 d) DEBUG=$OPTARG; ;;
Mark Whitleyd2117e92001-03-10 00:51:29 +000034 *)
35 echo "usage: $0 [-ptlbgsc]"
Mark Whitleyc75f83d2001-03-13 23:30:18 +000036 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"
Mark Whitleyd2117e92001-03-10 00:51:29 +000041 echo " -s FILE (setup) run commands in FILE before testcases"
42 echo " -c FILE (cleanup) run commands in FILE after testcases"
Mark Whitleyc75f83d2001-03-13 23:30:18 +000043 echo " -k keep temporary output files (don't delete them)"
44 echo " -d NUM set level of debugging output"
45 echo " 0 = no 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)"
Mark Whitleyd2117e92001-03-10 00:51:29 +000049 exit 1
50 ;;
51 esac
52done
53#shift `expr $OPTIND - 1`
54
55
Mark Whitleyc75f83d2001-03-13 23:30:18 +000056# maybe print some debug output
57if [ $DEBUG -ge 3 ]
58then
59 echo "BUSYBOX=$BUSYBOX"
60 echo "TESTCASES=$TESTCASES"
61 echo "LOGFILE=$LOGFILE"
62 echo "BB_OUT=$BB_OUT"
63 echo "GNU_OUT=$GNU_OUT"
64 echo "SETUP=$SETUP"
65 echo "CLEANUP=$CLEANUP"
66 echo "DEBUG=$DEBUG"
67fi
68
69
70# do sanity checks
71if [ ! -e $BUSYBOX ]
72then
73 echo "Busybox executable: $BUSYBOX not found!"
74 exit 1
75fi
76
77if [ ! -e $TESTCASES ]
78then
79 echo "Testcases file: $TESTCASES not found!"
80 exit 1
81fi
82
83
Mark Whitleyd2117e92001-03-10 00:51:29 +000084# do normal setup
85[ -e $LOGFILE ] && rm $LOGFILE
86unalias -a # gets rid of aliases that might create different output
87
Mark Whitleyc75f83d2001-03-13 23:30:18 +000088
Mark Whitleyd2117e92001-03-10 00:51:29 +000089# do extra setup (if any)
90if [ ! -z $SETUP ]
91then
Mark Whitleyc75f83d2001-03-13 23:30:18 +000092 [ $DEBUG -ge 2 ] && echo "running setup commands in $SETUP"
93 source $SETUP
Mark Whitleyd2117e92001-03-10 00:51:29 +000094fi
95
96
97# go through each line in the testcase file
98cat $TESTCASES | while read line
99do
100 #echo $line
101 # only process non-blank lines and non-comment lines
102 if [ "$line" ]
103 then
104 if [ `echo "$line" | cut -c1` != "#" ]
105 then
Mark Whitleyd2117e92001-03-10 00:51:29 +0000106
107 # test if the applet was compiled into busybox
Mark Whitleyc75f83d2001-03-13 23:30:18 +0000108 # (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/'`
Mark Whitleyd2117e92001-03-10 00:51:29 +0000111 $BUSYBOX 2>&1 | grep -qw $applet
112 if [ $? -eq 1 ]
113 then
114 echo "WHOOPS: $applet not compiled into busybox" | tee -a $LOGFILE
115 else
Mark Whitleyc75f83d2001-03-13 23:30:18 +0000116
117 # execute line using gnu / system programs
118 [ $DEBUG -ge 2 ] && echo "testing: $line" | tee -a $LOGFILE
119 sh -c "$line" > $GNU_OUT
120
121 # change line to include "busybox" before every statement
122 line="$BUSYBOX $line"
123 line=${line//;/; $BUSYBOX }
124 line=${line//|/| $BUSYBOX }
125
126 # execute line using busybox programs
127 [ $DEBUG -ge 2 ] && echo "testing: $line" | tee -a $LOGFILE
128 sh -c "$line" > $BB_OUT
129
130 # see if they match
Mark Whitleyd2117e92001-03-10 00:51:29 +0000131 diff -q $BB_OUT $GNU_OUT > /dev/null
132 if [ $? -eq 1 ]
133 then
Mark Whitleyc75f83d2001-03-13 23:30:18 +0000134 [ $DEBUG -ge 1 ] && echo "FAILED: $line" | tee -a $LOGFILE
Mark Whitleyd2117e92001-03-10 00:51:29 +0000135 diff -u $BB_OUT $GNU_OUT >> $LOGFILE
136 fi
137 fi
138 fi
139 fi
140done
141
Mark Whitleyc75f83d2001-03-13 23:30:18 +0000142[ $DEBUG -gt 0 ] && echo "Finished. Results are in $LOGFILE"
Mark Whitleyd2117e92001-03-10 00:51:29 +0000143
144
145# do normal cleanup
Mark Whitleyc75f83d2001-03-13 23:30:18 +0000146[ $KEEPTMPFILES == "no" ] && rm -f $BB_OUT $GNU_OUT
147
Mark Whitleyd2117e92001-03-10 00:51:29 +0000148
149# do extra cleanup (if any)
150if [ ! -z $CLEANUP ]
151then
Mark Whitleyc75f83d2001-03-13 23:30:18 +0000152 [ $DEBUG -ge 2 ] && echo "running cleanup commands in $CLEANUP"
153 source $CLEANUP
Mark Whitleyd2117e92001-03-10 00:51:29 +0000154fi