Updated to hostap_2_6
[mech_eap.git] / libeap / tests / hwsim / vm / vm-run.sh
1 #!/bin/bash
2
3 cd "$(dirname $0)"
4
5 if [ -z "$TESTDIR" ] ; then
6         TESTDIR=$(pwd)/../
7 fi
8
9 if [ -n "$HWSIM_TEST_LOG_DIR" ] ; then
10         LOGS="$HWSIM_TEST_LOG_DIR"
11 else
12         LOGS=/tmp/hwsim-test-logs
13 fi
14
15 # increase the memory size if you want to run with valgrind, 512 MB works
16 MEMORY=192
17
18 # Some ubuntu systems (notably 12.04) have issues with this - since the guest
19 # mounts as read-only it should be safe to not specify ,readonly. Override in
20 # vm-config if needed (see below)
21 ROTAG=,readonly
22
23 # set this to ttyS0 to see kvm messages (if something doesn't work)
24 KVMOUT=ttyS1
25
26 # you can set EPATH if you need anything extra in $PATH inside the VM
27 #EPATH=/some/dir
28
29 # extra KVM arguments, e.g., -s for gdbserver
30 #KVMARGS=-s
31
32 # number of channels each hwsim device supports
33 CHANNELS=1
34
35 test -f vm-config && . vm-config
36 test -f ~/.wpas-vm-config && . ~/.wpas-vm-config
37
38 if [ -z "$KERNEL" ] && [ -z "$KERNELDIR" ] ; then
39         echo "You need to set a KERNEL or KERNELDIR (in the environment or vm-config)"
40         exit 2
41 fi
42 if [ -z "$KERNEL" ] ; then
43         KERNEL=$KERNELDIR/arch/x86_64/boot/bzImage
44 fi
45
46
47 CMD=$TESTDIR/vm/inside.sh
48
49 unset RUN_TEST_ARGS
50 TIMESTAMP=$(date +%s)
51 DATE=$TIMESTAMP
52 CODECOV=no
53 TIMEWARP=0
54 DELAY=0
55 CODECOV_DIR=
56 while [ "$1" != "" ]; do
57         case $1 in
58                 --timestamp ) shift
59                         TIMESTAMP=$1
60                         shift
61                         ;;
62                 --ext ) shift
63                         DATE=$TIMESTAMP.$1
64                         shift
65                         ;;
66                 --codecov ) shift
67                         CODECOV=yes
68                         ;;
69                 --codecov_dir ) shift
70                         CODECOV_DIR=$1
71                         shift
72                         ;;
73                 --timewrap ) shift
74                         TIMEWARP=1
75                         ;;
76                 --delay ) shift
77                         DELAY=$1
78                         shift
79                         ;;
80                 * )
81                         RUN_TEST_ARGS="$RUN_TEST_ARGS$1 "
82                         shift
83                         ;;
84         esac
85 done
86
87 LOGDIR=$LOGS/$DATE
88 mkdir -p $LOGDIR
89
90 if [ -n "$CODECOV_DIR" ]; then
91     cp -a $CODECOV_DIR/alt-wpa_supplicant $LOGDIR
92     cp -a $CODECOV_DIR/alt-hostapd $LOGDIR
93     cp -a $CODECOV_DIR/alt-hostapd-as $LOGDIR
94     cp -a $CODECOV_DIR/alt-hlr_auc_gw $LOGDIR
95 elif [ $CODECOV = "yes" ]; then
96     ./build-codecov.sh $LOGDIR || exit 1
97 else
98     CODECOV=no
99 fi
100
101 if [ $DELAY -gt 0 ]; then
102     echo "Wait $DELAY seconds before starting VM"
103     sleep $DELAY
104 fi
105
106 echo "Starting test run in a virtual machine"
107
108 KVM=kvm
109 for kvmprog in kvm qemu-kvm; do
110     if $kvmprog --version &> /dev/null; then
111         KVM=$kvmprog
112         break
113     fi
114 done
115
116 argsfile=$(mktemp)
117 if [ $? -ne 0 ] ; then
118         exit 2
119 fi
120 function finish {
121         rm -f $argsfile
122 }
123 trap finish EXIT
124
125 echo "$RUN_TEST_ARGS" > $argsfile
126
127 $KVM \
128         -kernel $KERNEL -smp 4 \
129         $KVMARGS -m $MEMORY -nographic \
130         -fsdev local,security_model=none,id=fsdev-root,path=/$ROTAG \
131         -device virtio-9p-pci,id=fs-root,fsdev=fsdev-root,mount_tag=/dev/root \
132         -fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \
133         -device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
134         -monitor null -serial stdio -serial file:$LOGDIR/console \
135         -append "mac80211_hwsim.support_p2p_device=0 mac80211_hwsim.channels=$CHANNELS mac80211_hwsim.radios=7 init=$CMD testdir=$TESTDIR timewarp=$TIMEWARP console=$KVMOUT root=/dev/root rootflags=trans=virtio,version=9p2000.u ro rootfstype=9p EPATH=$EPATH ARGS=$argsfile"
136
137 if [ $CODECOV = "yes" ]; then
138     echo "Preparing code coverage reports"
139     ./process-codecov.sh $LOGDIR "" restore
140     ./combine-codecov.sh $LOGDIR lcov
141 fi
142
143 echo
144 echo "Test run completed"
145 echo "Logfiles are at $LOGDIR"
146 if [ $CODECOV = "yes" ]; then
147     echo "Code coverage report:"
148     echo "file://$LOGDIR/lcov/index.html"
149 fi