]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/vm/vm-run.sh
tests: uml: Request non-raw serial ports
[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
5554fbef 67DELAY=0
e0cccf26 68CODECOV_DIR=
006a1c4d
IP
69while [ "$1" != "" ]; do
70 case $1 in
7e694225
JM
71 --timestamp ) shift
72 TIMESTAMP=$1
73 shift
74 ;;
006a1c4d 75 --ext ) shift
7e694225 76 DATE=$TIMESTAMP.$1
006a1c4d
IP
77 shift
78 ;;
79 --codecov ) shift
80 CODECOV=yes
81 ;;
e0cccf26
JM
82 --codecov_dir ) shift
83 CODECOV_DIR=$1
84 shift
85 ;;
006a1c4d
IP
86 --timewrap ) shift
87 TIMEWARP=1
88 ;;
e3395110
JB
89 --telnet ) shift
90 TELNET_ARG=1
91 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"
92 shift
93 ;;
5554fbef
JM
94 --delay ) shift
95 DELAY=$1
96 shift
97 ;;
006a1c4d
IP
98 * )
99 RUN_TEST_ARGS="$RUN_TEST_ARGS$1 "
100 shift
101 ;;
102 esac
103done
104
3f33b3ad 105LOGDIR=$LOGS/$DATE
970d3b09 106mkdir -p $LOGDIR
8bdefe51
JB
107rm -f $LOGS/latest
108ln -s $LOGDIR $LOGS/latest
970d3b09 109
e0cccf26
JM
110if [ -n "$CODECOV_DIR" ]; then
111 cp -a $CODECOV_DIR/alt-wpa_supplicant $LOGDIR
112 cp -a $CODECOV_DIR/alt-hostapd $LOGDIR
113 cp -a $CODECOV_DIR/alt-hostapd-as $LOGDIR
114 cp -a $CODECOV_DIR/alt-hlr_auc_gw $LOGDIR
115elif [ $CODECOV = "yes" ]; then
116 ./build-codecov.sh $LOGDIR || exit 1
3f33b3ad
JM
117else
118 CODECOV=no
119fi
120
5554fbef
JM
121if [ $DELAY -gt 0 ]; then
122 echo "Wait $DELAY seconds before starting VM"
123 sleep $DELAY
124fi
125
3f33b3ad
JM
126echo "Starting test run in a virtual machine"
127
1cefd89b
JM
128if [ -x $KERNEL ]; then
129 unset KVM
130else
131 KVM=kvm
132 for kvmprog in kvm qemu-kvm; do
133 if $kvmprog --version &> /dev/null; then
134 KVM=$kvmprog
135 break
136 fi
137 done
138fi
d7273180 139
23fcfd60
JB
140argsfile=$(mktemp)
141if [ $? -ne 0 ] ; then
142 exit 2
143fi
144function finish {
145 rm -f $argsfile
146}
147trap finish EXIT
148
149echo "$RUN_TEST_ARGS" > $argsfile
150
1cefd89b
JM
151A="mac80211_hwsim.support_p2p_device=0 "
152A+="mac80211_hwsim.channels=$CHANNELS "
153A+="mac80211_hwsim.radios=7 "
154A+="cfg80211.dyndbg=+p "
155A+="mac80211.dyndbg=+p "
156A+="mac80211_hwsim.dyndbg=+p "
157A+="init=$CMD "
158A+="testdir=$TESTDIR "
159A+="timewarp=$TIMEWARP "
160A+="TELNET=$TELNET_ARG "
161A+="EPATH=$EPATH "
162A+="ARGS=$argsfile "
163A+="console=$KVMOUT "
164A+="ro"
165
166if [ -z $KVM ]; then
167 $KERNEL \
168 mem=${MEMORY}M \
169 LOGDIR=$LOGDIR \
d55035c9 170 time-travel=inf-cpu \
1cefd89b
JM
171 $A \
172 root=none hostfs=/ rootfstype=hostfs rootflags=/ \
173 ssl0=fd:0,fd:1 \
174 ssl1=fd:100 \
2080f4c7 175 ssl-non-raw \
1cefd89b
JM
176 100<>$LOGDIR/console 2>&1 | \
177 sed -u '0,/VM has started up/d'
178else
179 $KVM \
180 -kernel $KERNEL \
181 -smp 4 \
182 $KVMARGS \
183 -m $MEMORY \
184 -nographic \
185 -fsdev local,security_model=none,id=fsdev-root,path=/$ROTAG \
186 -device virtio-9p-pci,id=fs-root,fsdev=fsdev-root,mount_tag=/dev/root \
187 -fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \
188 -device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
189 -monitor null \
190 -serial stdio \
191 -serial file:$LOGDIR/console \
192 $TELNET_QEMU \
193 -append "$A root=/dev/root rootflags=trans=virtio,version=9p2000.u rootfstype=9p" | \
194 sed -u '0,/VM has started up/d'
195fi
f4bfa2d2 196
3f33b3ad 197if [ $CODECOV = "yes" ]; then
f24489d9
JM
198 echo "Preparing code coverage reports"
199 ./process-codecov.sh $LOGDIR "" restore
200 ./combine-codecov.sh $LOGDIR lcov
3f33b3ad 201fi
f4bfa2d2 202
3f33b3ad
JM
203echo
204echo "Test run completed"
8bdefe51 205echo "Logfiles are at $LOGDIR ($LOGS/latest)"
3f33b3ad 206if [ $CODECOV = "yes" ]; then
f24489d9
JM
207 echo "Code coverage report:"
208 echo "file://$LOGDIR/lcov/index.html"
f4bfa2d2 209fi