blob: 83727f6d3259eec3d304846e731b2b0c8915d124 [file] [log] [blame]
Rob Landley16890752005-09-02 00:41:53 +00001# Simple test harness infrastructurei for BusyBox
2#
3# Copyright 2005 by Rob Landley
4#
5# License is GPLv2, see LICENSE in the busybox tarball for full license text.
6
7# The "testing" function uses one environment variable:
8# COMMAND = command to execute
9#
10# The function takes five arguments:
11# $1) Description to display when running command
12# $2) Command line arguments to command"
13# $3) Expected result (on stdout)"
14# $4) Data written to file "input"
15# $5) Data written to stdin
16#
17# The exit value of testing is the exit value of the command it ran.
18#
19# The environment variable "FAILCOUNT" contains a cumulative total of the
20#
21
Mike Frysinger3f91d7a2005-09-24 00:52:58 +000022verbose=0
23debug=0
24force=0
25for x in "$@" ; do
26 case "$x" in
27 -v|--verbose) verbose=1; shift;;
28 -d|--debug) debug=1; shift;;
29 -f|--force) force=1; shift;;
30 --) break;;
31 -*) echo "Unknown option '$x'"; exit 1;;
32 *) break;;
33 esac
34done
Rob Landley16890752005-09-02 00:41:53 +000035
Mike Frysinger3f91d7a2005-09-24 00:52:58 +000036if [ -n "$VERBOSE" ] ; then
37 verbose=1
38fi
39if [ -n "$DEBUG" ] ; then
40 debug=1
Rob Landley16890752005-09-02 00:41:53 +000041fi
42
43export FAILCOUNT=0
44
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +000045# Helper functions
46
47config_is_set ()
48{
49 local uc_what=$(echo ${1?} | tr a-z A-Z)
50 grep -q "^[ ]*CONFIG_${uc_what}" ${bindir:-..}/.config || \
51 grep -q "^[ ]*BB_CONFIG_${uc_what}" ${bindir:-..}/.config
52 return $?
53}
54
Rob Landley16890752005-09-02 00:41:53 +000055# The testing function
56
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000057testing ()
Rob Landley16890752005-09-02 00:41:53 +000058{
59 if [ $# -ne 5 ]
60 then
61 echo "Test $1 has the wrong number of arguments" >&2
62 exit
63 fi
64
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000065 if [ $debug -eq 1 ] ; then
Mike Frysinger3f91d7a2005-09-24 00:52:58 +000066 set -x
67 fi
68
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000069 if [ -n "$_BB_CONFIG_DEP" ] && [ ${force} -eq 0 ]
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +000070 then
71 if ! config_is_set "$_BB_CONFIG_DEP"
72 then
Mike Frysinger3f91d7a2005-09-24 00:52:58 +000073 echo "SKIPPED: $1"
Bernhard Reutner-Fischerb47a74f2005-09-23 15:44:46 +000074 return 0
75 fi
76 fi
77
Rob Landley16890752005-09-02 00:41:53 +000078 echo -ne "$3" > expected
79 echo -ne "$4" > input
80 echo -n -e "$5" | eval "$COMMAND $2" > actual
81 RETVAL=$?
82
83 cmp expected actual > /dev/null
84 if [ $? -ne 0 ]
85 then
Mike Frysinger3f91d7a2005-09-24 00:52:58 +000086 ((FAILCOUNT++))
Rob Landleyb766c392005-09-04 11:10:37 +000087 echo "FAIL: $1"
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000088 if [ $verbose -eq 1 ]
Rob Landley16890752005-09-02 00:41:53 +000089 then
90 diff -u expected actual
91 fi
92 else
Rob Landleyb766c392005-09-04 11:10:37 +000093 echo "PASS: $1"
Rob Landley16890752005-09-02 00:41:53 +000094 fi
95 rm -f input expected actual
96
Bernhard Reutner-Fischere34e8782005-10-06 12:48:03 +000097 if [ $debug -eq 1 ] ; then
Mike Frysinger3f91d7a2005-09-24 00:52:58 +000098 set +x
99 fi
100
Rob Landley16890752005-09-02 00:41:53 +0000101 return $RETVAL
102}