aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--tests/testcases301
-rwxr-xr-xtests/tester.sh104
3 files changed, 409 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index c28e621c2..c3c0f7119 100644
--- a/Makefile
+++ b/Makefile
@@ -317,7 +317,10 @@ loop.h: mk_loop_h.sh
317 @ $(SHELL) $< > $@ 317 @ $(SHELL) $< > $@
318 318
319test tests: 319test tests:
320 cd tests && $(MAKE) all 320 # old way of doing it
321 #cd tests && $(MAKE) all
322 # new way of doing it
323 cd tests && ./tester.sh
321 324
322clean: 325clean:
323 - cd tests && $(MAKE) clean 326 - cd tests && $(MAKE) clean
diff --git a/tests/testcases b/tests/testcases
new file mode 100644
index 000000000..1838fa0fc
--- /dev/null
+++ b/tests/testcases
@@ -0,0 +1,301 @@
1# testcases
2#
3# This file should be filled with test cases to test applets that:
4#
5# - can somehow produce output (we can't test sync or sleep)
6# - have a GNU (or other) counterpart
7# - are not interactive (don't require a ^C or anything)
8# - don't require extensive setup or cleanup (a litte setup is fine)
9# - don't have huge and possibly damaging effects (fsck, swapoff)
10#
11# If possible, a test case should be made that tests each option the applet
12# supports. When a new option is added, a new test case should be written for
13# it. When somebody reports a bug with a testcase, that testcase should be
14# added here as well.
15#
16# Some other guidelines to follow:
17#
18# - please try to keep applets alphabetized, it will make life easier
19# - use the file tester.sh or testcases when you need to do a non-destructive
20# test on a file (i.e. cat, md5sum)
21# - try to make the applet you're testing the first thing on the line (this
22# not always possible)
23# - (???) if you have to create a temporary file, call it TMPFILE
24
25
26# ar
27
28# basename
29basename `pwd`
30
31# cat
32cat tester.sh
33
34# chmod
35# chown
36# chgrp
37# chroot
38# chvt - can't be tested here
39# clear - can't be tested here
40# cmp
41# cp
42# mv
43
44# cut
45echo "1234" | cut -c1
46echo "f1 f2" | cut -f2
47
48# date
49date
50date -R
51date -u
52date +%d/%m/%y
53
54# dc - needs an input file
55# dd
56# deallocvt
57
58# df
59df
60df .
61df -k
62df -h
63df -m
64
65# dirname
66dirname `pwd`
67
68# dmesg (XXX: change the silly cmd business in the source)
69dmesg
70dmesg -n 8
71dmesg -s 512
72# I really don't want to do this next one
73#dmesg -c
74
75# dos2unix - needs an input file
76# dpkg
77# dpkg_deb
78
79# du
80du
81du -s
82du -l
83du -k
84du -h
85du -m
86
87# dumpkmap - no counterprt?
88# dutmp - no counterprt?
89
90# echo
91echo "foo bar baz"
92echo -n "no newline"
93
94
95# expr
96expr 1 \| 1
97expr 1 \| 0
98expr 0 \| 1
99expr 0 \| 0
100
101expr 1 \& 1
102expr 1 \& 0
103expr 0 \& 1
104expr 0 \& 0
105
106expr 0 \< 1
107expr 1 \< 0
108
109expr 1 \> 0
110expr 0 \> 1
111
112expr 0 \<= 1
113expr 1 \<= 0
114expr 1 \<= 1
115
116expr 1 \>= 0
117expr 0 \>= 1
118expr 1 \>= 1
119
120expr 1 + 2
121expr 2 - 1
122expr 2 \* 3
123expr 12 / 2
124expr 12 % 5
125
126# somebody else can do all the string stuff
127
128
129# fbset - can't be tested here
130# fdflush
131# find
132find .
133
134# free
135free
136
137# freeramdisk
138# fsck.minix - won't test
139# getopt
140# grep
141# gunzip
142# gzip
143# halt
144
145# head
146head tester.sh
147head -n 2 tester.sh
148
149# hostid
150hostid
151
152# hostname
153hostname
154hostname -s
155hostname -i
156hostname -d
157# not going to do this next one
158#hostname -F
159
160# id
161id
162id -u
163id -g
164id -ur
165id -un
166
167
168# ifconfig
169#ifconfig
170#ifconfig eth0
171#ifconfig lo
172
173# init - won't test
174# insmod - won't test
175
176# kill
177#kill -l
178# not going to do any more
179
180# length
181# ln
182# loadacm
183# loadfont
184# loadkmap
185# logger
186# logname
187# ls
188ls
189ls -l
190ls -s
191ls -h
192ls -1
193
194# lsmod
195lsmod
196
197# makedevs
198
199# md5sum
200md5sum tester.sh
201
202# mkdir
203# mkfifo
204# mkfs.minix - won't test
205# mknod
206# mkswap - won't test
207# mktemp
208# more - can't test: interactive
209
210# mount
211mount
212# not going to test any more
213
214# mt
215# nc
216# nfsmount
217# nslookup
218# ping - can't test: interactive (needs ^C)
219# pivot_root
220# poweroff - won't test
221# printf
222# ps - there's lotsa differences between busybox ps and any other ps
223
224# pwd
225pwd
226
227# rdate - won't test
228
229# readlink
230ln -sf tester.sh LINKFILE
231readlink LINKFILE
232rm -f LINKFILE
233
234# reboot - won't test
235# renice - won't test
236# reset - can't test: no output
237# rm
238# rmdir
239# rmmod - won't test: dangerous
240# route
241# rpmunpack
242# sed - we can do some one-liners here; probably needs it's own input file
243# setkeycodes
244# sh - this should probably have it's own testcase or input file
245# sleep - can't test: produces no output
246# sort
247# stty
248# swapon - won't test: dangerous
249# swapoff - won't test: dangerous
250# sync - can't test: no output
251# syslogd
252
253# tail
254tail tester.sh
255tail -n 2 tester.sh
256
257# tar
258# tee
259# telnet
260# test
261# tftp
262# touch
263# tr
264true ; echo $?
265false ; echo $?
266# tty
267# umount
268# uname
269# uniq
270# unix2dos
271# update
272
273uptime
274
275# usleep
276# uudecode
277# uuencode
278# watchdog
279
280# wc
281wc tester.sh
282wc -c tester.sh
283wc -w tester.sh
284wc -l tester.sh
285wc -L tester.sh
286
287# wget
288
289# which
290which ls
291
292# whoami
293whoami
294
295# xargs
296# (for some reason, the > redirection isn't working)
297#ls -1 > TMPFILE
298#xargs md5sum < TMPFILE
299#rm -f TMPFILE
300
301# yes - can't test: interactive (needs ^C)
diff --git a/tests/tester.sh b/tests/tester.sh
new file mode 100755
index 000000000..bb49609c3
--- /dev/null
+++ b/tests/tester.sh
@@ -0,0 +1,104 @@
1#!/bin/bash
2#
3# tester.sh - reads testcases from file and tests busybox applets vs GNU
4# counterparts
5#
6
7# set up defaults (can be changed with cmd-line options)
8BUSYBOX=../busybox
9TESTCASES=testcases
10LOGFILE=tester.log
11BB_OUT=bb.out
12GNU_OUT=gnu.out
13SETUP=""
14CLEANUP=""
15
16# internal-use vars
17fail_only=0
18
19
20while getopts 'p:t:l:b:g:s:c:f' opt
21do
22 case $opt in
23 p) BUSYBOX=$OPTARG; ;;
24 t) TESTCASES=$OPTARG; ;;
25 l) LOGFILE=$OPTARG; ;;
26 b) BB_OUT=$OPTARG; ;;
27 g) GNU_OUT=$OPTARG; ;;
28 s) SETUP=$OPTARG; ;;
29 c) CLEANUP=$OPTARG; ;;
30 f) fail_only=1; ;;
31 *)
32 echo "usage: $0 [-ptlbgsc]"
33 echo " -p PATH path to busybox executable"
34 echo " -t FILE run testcases in FILE"
35 echo " -l FILE log test results in FILE"
36 echo " -b FILE store temporary busybox output in FILE"
37 echo " -g FILE store temporary GNU output in FILE"
38 echo " -s FILE (setup) run commands in FILE before testcases"
39 echo " -c FILE (cleanup) run commands in FILE after testcases"
40 echo " -f display only testcases that fail"
41 exit 1
42 ;;
43 esac
44done
45#shift `expr $OPTIND - 1`
46
47
48# do normal setup
49[ -e $LOGFILE ] && rm $LOGFILE
50unalias -a # gets rid of aliases that might create different output
51
52# do extra setup (if any)
53if [ ! -z $SETUP ]
54then
55 echo "running setup commands in $SETUP"
56 sh $SETUP
57 # XXX: Would 'eval' or 'source' work better instead of 'sh'?
58fi
59
60
61# go through each line in the testcase file
62cat $TESTCASES | while read line
63do
64 #echo $line
65 # only process non-blank lines and non-comment lines
66 if [ "$line" ]
67 then
68 if [ `echo "$line" | cut -c1` != "#" ]
69 then
70 [ $fail_only -eq 0 ] && echo "testing: $line" | tee -a $LOGFILE
71
72 # test if the applet was compiled into busybox
73 applet=`echo $line | cut -d' ' -f1`
74 $BUSYBOX 2>&1 | grep -qw $applet
75 if [ $? -eq 1 ]
76 then
77 echo "WHOOPS: $applet not compiled into busybox" | tee -a $LOGFILE
78 else
79 $BUSYBOX $line > $BB_OUT
80 $line > $GNU_OUT
81 diff -q $BB_OUT $GNU_OUT > /dev/null
82 if [ $? -eq 1 ]
83 then
84 echo "FAILED: $line" | tee -a $LOGFILE
85 diff -u $BB_OUT $GNU_OUT >> $LOGFILE
86 fi
87 fi
88 fi
89 fi
90done
91
92echo "Finished. Results are in $LOGFILE"
93
94
95# do normal cleanup
96rm -f $BB_OUT $GNU_OUT
97
98# do extra cleanup (if any)
99if [ ! -z $CLEANUP ]
100then
101 echo "running cleanup commands in $CLEANUP"
102 sh $CLEANUP
103 # XXX: Would 'eval' or 'source' work better instead of 'sh'?
104fi