release: bump the release to 3.14
[module-init-tools.git] / tests / runtests
blobf1bf983c4bd6012c5363afe681ea1a9468df9ce8
1 #! /bin/bash
2 # Shell script to run test suite.
4 set -e
6 usage()
8 echo "Usage: tests/runtests [-v] [-v] [--valgrind] [test]"
9 echo " -v (or --verbose) prints each test as it is run"
10 echo " -vv (very verbose) traces test execution"
11 echo " --valgrind runs the test programs using the valgrind memory checker"
12 echo "The TEST_ENDIAN and TEST_BITS variables can be used to limit which"
13 echo "endianess (le, be) and bitness (32, 64) will be tested"
14 exit
17 while [ $# != 0 ]; do
18 case "$1" in
19 -v)
20 if [ -z "$VERBOSE" ]; then
21 VERBOSE=1
22 else
23 EXTRA_ARGS=-x
26 -vv)
27 VERBOSE=1
28 EXTRA_ARGS=-x
30 --valgrind)
31 VALGRIND=1
33 -h|--help|-*)
34 usage
37 [ -n "$TEST" ] && usage
38 TEST="$1"
40 esac
41 shift
42 done
44 # Creates a temporary file and exports the name of the file to
45 # the provided argument. Exits on error.
47 # Usage: create_tempfile TEMPFILE
49 create_tempfile()
51 if test $# = 0
52 then
53 echo "No argument passed to create_tempfile()"
54 exit 1
57 if [ -x /bin/tempfile ]
58 then
59 # Debian
60 export $1="`tempfile`"
61 elif [ -x /bin/mktemp ]
62 then
63 # RedHat et. al.
64 export $1="`mktemp /tmp/modtest.XXXXXX`"
65 else
66 echo "Don't know how to make a temporary file on this "
67 echo "system, sorry."
68 exit 1
71 if [ $? -ne 0 ]
72 then
73 echo "Can't create temporary file."
74 exit 1
77 export -f create_tempfile
79 if [ ! -e "tests/build" ]; then
80 echo Making build directory for tests
81 mkdir tests/build
83 if [ ! -e "tests/tmp" ]; then
84 echo Making temporary directory for tests
85 mkdir tests/tmp
88 : ${TEST_ENDIAN:=-be -le}
89 _tmp=
90 for e in $TEST_ENDIAN; do
91 case $e in
92 -be | -le)
93 _tmp="$_tmp $e"
95 be | le)
96 _tmp="$_tmp -$e"
99 echo "Unknown endian: $e, valid values are \"be\" and \"le\"" >&2
100 exit 1
101 esac
102 done
103 TEST_ENDIAN="$_tmp"
104 export TEST_ENDIAN
106 : ${TEST_BITS:=32 64}
107 for b in $TEST_BITS; do
108 case $b in
109 32 | 64)
112 echo "Unknown word size: $b, valid values are 32 and 64" >&2
113 exit 1
114 esac
115 done
116 export TEST_BITS
118 for config in --enable-zlib --disable-zlib; do
119 echo Building with $config...
121 cd tests/build
122 ../../configure $config CFLAGS="-DJUST_TESTING -g -Wall" >/dev/null
123 make clean >/dev/null
124 # ismod.static doesn't build with -DJUST_TESTING and --enable-zlib
125 make insmod.static >/dev/null 2>&1 || touch insmod.static
126 make all >/dev/null
127 cd ../..
129 echo Testing with $config...
130 if grep -q CONFIG_USE_ZLIB=1 tests/build/Makefile; then
131 CONFIG_HAVE_ZLIB=1
132 export CONFIG_HAVE_ZLIB
133 else
134 unset CONFIG_HAVE_ZLIB
137 # Create endianness links
138 case `file tests/build/modprobe` in
139 *MSB*) ENDIAN=be;;
140 *LSB*) ENDIAN=le;;
141 *) echo Unknown endian! >&2; exit 1;;
142 esac
143 ln -sfn 64-$ENDIAN tests/data/64
144 ln -sfn 32-$ENDIAN tests/data/32
146 # Make them run the valgrind wrappers if requested.
147 if [ -n "$VALGRIND" ]; then
148 PATH=`pwd`/tests/valgrind:$PATH
149 else
150 PATH=`pwd`/tests/build:$PATH
153 # By default, we want to look like a new kernel.
154 MODTEST_UNAME=2.6.27
155 export MODTEST_UNAME
157 MODTEST_OVERRIDE_ROOT=tests/tmp
158 export MODTEST_OVERRIDE_ROOT
160 if [ -n "$TEST" ]; then DOING=0; else DOING=1; fi
162 for dir in `find tests/test-* -type d | sort`
165 if [ -z "$VERBOSE" ]; then
166 echo -n Running tests for $dir.
167 else
168 echo Running tests for $dir.
170 shopt -s nullglob
171 for f in $dir/[0-9]*.sh; do
172 if [ $DOING -eq 0 ]; then
173 case "$f" in *$TEST*) DOING=1;; *) continue;; esac
176 rm -rf tests/tmp/*
177 if sh -e $EXTRA_ARGS $f; then
178 if [ -z "$VERBOSE" ]; then
179 echo -n .
180 else
181 echo Tests $f succeeded.
183 else
184 echo Test for $f failed.
185 exit 1
187 done
188 if [ -z "$VERBOSE" ]; then echo; fi
189 done
190 done
192 exit 0