]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/vm/vm-run.sh
tests: Assume --long for UML
[thirdparty/hostap.git] / tests / hwsim / vm / vm-run.sh
CommitLineData
970d3b09
JB
1#!/bin/bash
2
3cd "$(dirname $0)"
4
5if [ -z "$TESTDIR" ] ; then
6 TESTDIR=$(pwd)/../
7fi
8
680ce356
JB
9if [ -n "$HWSIM_TEST_LOG_DIR" ] ; then
10 LOGS="$HWSIM_TEST_LOG_DIR"
11else
12 LOGS=/tmp/hwsim-test-logs
13fi
970d3b09
JB
14
15# increase the memory size if you want to run with valgrind, 512 MB works
255f3846 16MEMORY=256
970d3b09
JB
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)
21ROTAG=,readonly
22
23# set this to ttyS0 to see kvm messages (if something doesn't work)
24KVMOUT=ttyS1
25
26# you can set EPATH if you need anything extra in $PATH inside the VM
27#EPATH=/some/dir
28
1cd3eae3
JB
29# extra KVM arguments, e.g., -s for gdbserver
30#KVMARGS=-s
31
4ecf11c5
JB
32# number of channels each hwsim device supports
33CHANNELS=1
34
970d3b09 35test -f vm-config && . vm-config
fd77e594 36test -f ~/.wpas-vm-config && . ~/.wpas-vm-config
970d3b09 37
1cd3eae3
JB
38if [ -z "$KERNEL" ] && [ -z "$KERNELDIR" ] ; then
39 echo "You need to set a KERNEL or KERNELDIR (in the environment or vm-config)"
970d3b09
JB
40 exit 2
41fi
1cd3eae3 42if [ -z "$KERNEL" ] ; then
1cefd89b
JM
43 if [ -e $KERNELDIR/arch/x86_64/boot/bzImage ]; then
44 KERNEL=$KERNELDIR/arch/x86_64/boot/bzImage
45 elif [ -e $KERNELDIR/linux ]; then
46 KERNEL=$KERNELDIR/linux
47 else
48 echo "No suitable kernel image found from KERNELDIR"
49 exit 2
50 fi
51fi
52if [ ! -e $KERNEL ]; then
53 echo "Kernel image not found: $KERNEL"
54 exit 2
1cd3eae3 55fi
970d3b09
JB
56
57
58CMD=$TESTDIR/vm/inside.sh
006a1c4d
IP
59
60unset RUN_TEST_ARGS
7e694225
JM
61TIMESTAMP=$(date +%s)
62DATE=$TIMESTAMP
006a1c4d
IP
63CODECOV=no
64TIMEWARP=0
e3395110
JB
65TELNET_QEMU=
66TELNET_ARG=0
e0cccf26 67CODECOV_DIR=
006a1c4d
IP
68while [ "$1" != "" ]; do
69 case $1 in
7e694225
JM
70 --timestamp ) shift
71 TIMESTAMP=$1
72 shift
73 ;;
006a1c4d 74 --ext ) shift
7e694225 75 DATE=$TIMESTAMP.$1
006a1c4d
IP
76 shift
77 ;;
78 --codecov ) shift
79 CODECOV=yes
80 ;;
e0cccf26
JM
81 --codecov_dir ) shift
82 CODECOV_DIR=$1
83 shift
84 ;;
006a1c4d
IP
85 --timewrap ) shift
86 TIMEWARP=1
87 ;;
e3395110
JB
88 --telnet ) shift
89 TELNET_ARG=1
90 TELNET_QEMU="-net nic,model=virtio -net user,id=telnet,restrict=on,net=172.16.0.0/24,hostfwd=tcp:127.0.0.1:$1-:23"
91 shift
92 ;;
006a1c4d
IP
93 * )
94 RUN_TEST_ARGS="$RUN_TEST_ARGS$1 "
95 shift
96 ;;
97 esac
98done
99
3f33b3ad 100LOGDIR=$LOGS/$DATE
970d3b09 101mkdir -p $LOGDIR
8bdefe51
JB
102rm -f $LOGS/latest
103ln -s $LOGDIR $LOGS/latest
970d3b09 104
e0cccf26
JM
105if [ -n "$CODECOV_DIR" ]; then
106 cp -a $CODECOV_DIR/alt-wpa_supplicant $LOGDIR
107 cp -a $CODECOV_DIR/alt-hostapd $LOGDIR
108 cp -a $CODECOV_DIR/alt-hostapd-as $LOGDIR
109 cp -a $CODECOV_DIR/alt-hlr_auc_gw $LOGDIR
110elif [ $CODECOV = "yes" ]; then
111 ./build-codecov.sh $LOGDIR || exit 1
3f33b3ad
JM
112else
113 CODECOV=no
114fi
115
116echo "Starting test run in a virtual machine"
117
1cefd89b
JM
118if [ -x $KERNEL ]; then
119 unset KVM
120else
121 KVM=kvm
122 for kvmprog in kvm qemu-kvm; do
123 if $kvmprog --version &> /dev/null; then
124 KVM=$kvmprog
125 break
126 fi
127 done
128fi
d7273180 129
23fcfd60
JB
130argsfile=$(mktemp)
131if [ $? -ne 0 ] ; then
132 exit 2
133fi
134function finish {
135 rm -f $argsfile
136}
137trap finish EXIT
138
478bc00b
JB
139if [ -z $KVM ]; then
140 RUN_TEST_ARGS="--long $RUN_TEST_ARGS"
141fi
23fcfd60
JB
142echo "$RUN_TEST_ARGS" > $argsfile
143
1cefd89b
JM
144A="mac80211_hwsim.support_p2p_device=0 "
145A+="mac80211_hwsim.channels=$CHANNELS "
146A+="mac80211_hwsim.radios=7 "
147A+="cfg80211.dyndbg=+p "
148A+="mac80211.dyndbg=+p "
149A+="mac80211_hwsim.dyndbg=+p "
150A+="init=$CMD "
151A+="testdir=$TESTDIR "
152A+="timewarp=$TIMEWARP "
153A+="TELNET=$TELNET_ARG "
154A+="EPATH=$EPATH "
155A+="ARGS=$argsfile "
156A+="console=$KVMOUT "
157A+="ro"
158
159if [ -z $KVM ]; then
160 $KERNEL \
161 mem=${MEMORY}M \
162 LOGDIR=$LOGDIR \
d55035c9 163 time-travel=inf-cpu \
1cefd89b
JM
164 $A \
165 root=none hostfs=/ rootfstype=hostfs rootflags=/ \
166 ssl0=fd:0,fd:1 \
167 ssl1=fd:100 \
2080f4c7 168 ssl-non-raw \
1cefd89b
JM
169 100<>$LOGDIR/console 2>&1 | \
170 sed -u '0,/VM has started up/d'
171else
172 $KVM \
173 -kernel $KERNEL \
174 -smp 4 \
175 $KVMARGS \
176 -m $MEMORY \
177 -nographic \
178 -fsdev local,security_model=none,id=fsdev-root,path=/$ROTAG \
179 -device virtio-9p-pci,id=fs-root,fsdev=fsdev-root,mount_tag=/dev/root \
180 -fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \
181 -device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
182 -monitor null \
183 -serial stdio \
184 -serial file:$LOGDIR/console \
185 $TELNET_QEMU \
186 -append "$A root=/dev/root rootflags=trans=virtio,version=9p2000.u rootfstype=9p" | \
187 sed -u '0,/VM has started up/d'
188fi
f4bfa2d2 189
3f33b3ad 190if [ $CODECOV = "yes" ]; then
f24489d9
JM
191 echo "Preparing code coverage reports"
192 ./process-codecov.sh $LOGDIR "" restore
193 ./combine-codecov.sh $LOGDIR lcov
3f33b3ad 194fi
f4bfa2d2 195
3f33b3ad
JM
196echo
197echo "Test run completed"
8bdefe51 198echo "Logfiles are at $LOGDIR ($LOGS/latest)"
3f33b3ad 199if [ $CODECOV = "yes" ]; then
f24489d9
JM
200 echo "Code coverage report:"
201 echo "file://$LOGDIR/lcov/index.html"
f4bfa2d2 202fi