Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/testsuite/testing.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 4  Line 4 
4  #  #
5  # License is GPLv2, see LICENSE in the busybox tarball for full license text.  # License is GPLv2, see LICENSE in the busybox tarball for full license text.
6    
7  # This file defines two functions, "testing" and "optionflag"  # This file defines two functions, "testing" and "optional"
8    # and a couple more...
9    
10  # The following environment variables may be set to enable optional behavior  # The following environment variables may be set to enable optional behavior
11  # in "testing":  # in "testing":
12  #    VERBOSE - Print the diff -u of each failed test case.  #    VERBOSE - Print the diff -u of each failed test case.
13  #    DEBUG - Enable command tracing.  #    DEBUG - Enable command tracing.
14  #    SKIP - do not perform this test (this is set by "optionflag")  #    SKIP - do not perform this test (this is set by "optional")
15  #  #
16  # The "testing" function takes five arguments:  # The "testing" function takes five arguments:
17  # $1) Description to display when running command  # $1) Test description
18  # $2) Command line arguments to command  # $2) Command(s) to run. May have pipes, redirects, etc
19  # $3) Expected result (on stdout)  # $3) Expected result on stdout
20  # $4) Data written to file "input"  # $4) Data to be written to file "input"
21  # $5) Data written to stdin  # $5) Data to be written to stdin
22  #  #
23  # The exit value of testing is the exit value of the command it ran.  # The exit value of testing is the exit value of $2 it ran.
24  #  #
25  # The environment variable "FAILCOUNT" contains a cumulative total of the  # The environment variable "FAILCOUNT" contains a cumulative total of the
26  # number of failed tests.  # number of failed tests.
27    
28  # The "optional" function is used to skip certain tests, ala:  # The "optional" function is used to skip certain tests, ala:
29  #   optionflag CONFIG_FEATURE_THINGY  #   optional CONFIG_FEATURE_THINGY
30  #  #
31  # The "optional" function checks the environment variable "OPTIONFLAGS",  # The "optional" function checks the environment variable "OPTIONFLAGS",
32  # which is either empty (in which case it always clears SKIP) or  # which is either empty (in which case it always clears SKIP) or
# Line 39  export SKIP= Line 40  export SKIP=
40    
41  optional()  optional()
42  {  {
43    option=`echo "$OPTIONFLAGS" | egrep "(^|:)$1(:|\$)"`    option=`echo ":$OPTIONFLAGS:" | grep ":$1:"`
44    # Not set?    # Not set?
45    if [ -z "$1" ] || [ -z "$OPTIONFLAGS" ] || [ ${#option} -ne 0 ]    if [ -z "$1" ] || [ -z "$OPTIONFLAGS" ] || [ ${#option} -ne 0 ]
46    then    then
47      SKIP=""      SKIP=
48      return      return
49    fi    fi
50    SKIP=1    SKIP=1
# Line 51  optional() Line 52  optional()
52    
53  # The testing function  # The testing function
54    
55  testing ()  testing()
56  {  {
57    NAME="$1"    NAME="$1"
58    [ -z "$1" ] && NAME=$2    [ -n "$1" ] || NAME="$2"
59    
60    if [ $# -ne 5 ]    if [ $# -ne 5 ]
61    then    then
62      echo "Test $NAME has the wrong number of arguments ($# $*)" >&2      echo "Test $NAME has wrong number of arguments (must be 5) ($# $*)" >&2
63      exit      exit 1
64    fi    fi
65    
66    [ -n "$DEBUG" ] && set -x    [ -z "$DEBUG" ] || set -x
67    
68    if [ -n "$SKIP" ]    if [ -n "$SKIP" ]
69    then    then
# Line 70  testing () Line 71  testing ()
71      return 0      return 0
72    fi    fi
73    
74    echo -ne "$3" > expected    $ECHO -ne "$3" > expected
75    echo -ne "$4" > input    $ECHO -ne "$4" > input
76    [ -z "$VERBOSE" ] || echo "echo '$5' | $2"    [ -z "$VERBOSE" ] || echo "echo '$5' | $2"
77    echo -ne "$5" | eval "$2" > actual    $ECHO -ne "$5" | eval "$2" > actual
78    RETVAL=$?    RETVAL=$?
79    
80    cmp expected actual > /dev/null    if cmp expected actual >/dev/null 2>/dev/null
   if [ $? -ne 0 ]  
81    then    then
     FAILCOUNT=$[$FAILCOUNT+1]  
     echo "FAIL: $NAME"  
     [ -n "$VERBOSE" ] && diff -u expected actual  
   else  
82      echo "PASS: $NAME"      echo "PASS: $NAME"
83      else
84        FAILCOUNT=$(($FAILCOUNT + 1))
85        echo "FAIL: $NAME"
86        [ -z "$VERBOSE" ] || diff -u expected actual
87    fi    fi
88    rm -f input expected actual    rm -f input expected actual
89    
90    [ -n "$DEBUG" ] && set +x    [ -z "$DEBUG" ] || set +x
91    
92    return $RETVAL    return $RETVAL
93  }  }
# Line 97  testing () Line 97  testing ()
97  # the file is assumed to already be there and only its library dependencies  # the file is assumed to already be there and only its library dependencies
98  # are copied.  # are copied.
99    
100  function mkchroot  mkchroot()
101  {  {
102    [ $# -lt 2 ] && return    [ $# -lt 2 ] && return
103    
104    echo -n .    $ECHO -n .
105    
106    dest=$1    dest=$1
107    shift    shift
108    for i in "$@"    for i in "$@"
109    do    do
110      [ "${i:0:1}" == "/" ] || i=$(which $i)      #bashism: [ "${i:0:1}" == "/" ] || i=$(which $i)
111        i=$(which $i) # no-op for /bin/prog
112      [ -f "$dest/$i" ] && continue      [ -f "$dest/$i" ] && continue
113      if [ -e "$i" ]      if [ -e "$i" ]
114      then      then
# Line 126  function mkchroot Line 127  function mkchroot
127  # Needed commands listed on command line  # Needed commands listed on command line
128  # Script fed to stdin.  # Script fed to stdin.
129    
130  function dochroot  dochroot()
131  {  {
132    mkdir tmpdir4chroot    mkdir tmpdir4chroot
133    mount -t ramfs tmpdir4chroot tmpdir4chroot    mount -t ramfs tmpdir4chroot tmpdir4chroot
# Line 135  function dochroot Line 136  function dochroot
136    
137    # Copy utilities from command line arguments    # Copy utilities from command line arguments
138    
139    echo -n "Setup chroot"    $ECHO -n "Setup chroot"
140    mkchroot tmpdir4chroot $*    mkchroot tmpdir4chroot $*
141    echo    echo
142    
# Line 151  function dochroot Line 152  function dochroot
152    umount -l tmpdir4chroot    umount -l tmpdir4chroot
153    rmdir tmpdir4chroot    rmdir tmpdir4chroot
154  }  }
   

Legend:
Removed from v.532  
changed lines
  Added in v.816