Fix openflow.h compilation with GCC 2.95.
[sliver-openvswitch.git] / datapath / run-unit-tests
1 #! /bin/sh -ex
2
3 fail () {
4     echo "$@"
5     exit 1
6 }
7
8 test -n "$VMDIR" || fail "must pass --with-vm to configure to run unit tests"
9
10 rm -rf tmp
11 mkdir tmp
12 cd tmp
13
14 ln -s $KSRC/arch/i386/boot/bzImage kernel.bin
15 ln -s $VMDIR/hda.dsk hda.dsk
16
17 cat > unit.conf <<EOF
18 MEM=128         # Avoids kmalloc failures that clutter output.
19 SWITCHES=
20 VMS="unit"
21 unit_NETS=""
22 EOF
23
24 unit_tests="table_t crc_t forward_t"
25 unit_tests_comma=`echo $unit_tests | sed 's/ /,/g'`
26 if test "$KVERSION" = 2.6; then
27     prereq_modules="openflow_mod.ko"
28     unit_mod="unit_mod.ko"
29 elif test "$KVERSION" = 2.4; then
30     prereq_modules="compat24_mod.o openflow_mod.o"
31     unit_mod="unit_mod.o"
32 else
33     fail "\$KVERSION not set"
34 fi
35
36 load_prereqs=
37 for d in $prereq_modules; do
38     load_prereqs="$load_prereqs
39 insmod $d"
40 done
41
42 mkdir unit.cd
43 ln -s $KSRC/System.map $KSRC/vmlinux unit.cd
44 for d in $prereq_modules $unit_mod; do
45     ln -s $builddir/$d unit.cd
46 done
47 cat > unit.cd/runme <<EOF
48 #! /bin/sh -x
49 $load_prereqs
50 insmod $unit_mod 'run="$unit_tests_comma"' || true
51 poweroff
52 EOF
53 chmod a+x unit.cd/runme
54
55 $top_srcdir/switch/utilities/start-test-vm -f unit unit.conf
56
57 grep -3 FAIL unit.log && fail "Unit test failed (see tmp/unit.log)"
58 for d in $unit_tests; do
59     grep -F -q "$d: PASS" unit.log || fail "$d didn't pass (see tmp/unit.log)"
60 done
61
62 rm -rf tmp
63
64 echo "Unit tests passed"