]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/vm/vm-run.sh
tests: Assume --long for UML
[thirdparty/hostap.git] / 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=256
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 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
51 fi
52 if [ ! -e $KERNEL ]; then
53 echo "Kernel image not found: $KERNEL"
54 exit 2
55 fi
56
57
58 CMD=$TESTDIR/vm/inside.sh
59
60 unset RUN_TEST_ARGS
61 TIMESTAMP=$(date +%s)
62 DATE=$TIMESTAMP
63 CODECOV=no
64 TIMEWARP=0
65 TELNET_QEMU=
66 TELNET_ARG=0
67 CODECOV_DIR=
68 while [ "$1" != "" ]; do
69 case $1 in
70 --timestamp ) shift
71 TIMESTAMP=$1
72 shift
73 ;;
74 --ext ) shift
75 DATE=$TIMESTAMP.$1
76 shift
77 ;;
78 --codecov ) shift
79 CODECOV=yes
80 ;;
81 --codecov_dir ) shift
82 CODECOV_DIR=$1
83 shift
84 ;;
85 --timewrap ) shift
86 TIMEWARP=1
87 ;;
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 ;;
93 * )
94 RUN_TEST_ARGS="$RUN_TEST_ARGS$1 "
95 shift
96 ;;
97 esac
98 done
99
100 LOGDIR=$LOGS/$DATE
101 mkdir -p $LOGDIR
102 rm -f $LOGS/latest
103 ln -s $LOGDIR $LOGS/latest
104
105 if [ -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
110 elif [ $CODECOV = "yes" ]; then
111 ./build-codecov.sh $LOGDIR || exit 1
112 else
113 CODECOV=no
114 fi
115
116 echo "Starting test run in a virtual machine"
117
118 if [ -x $KERNEL ]; then
119 unset KVM
120 else
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
128 fi
129
130 argsfile=$(mktemp)
131 if [ $? -ne 0 ] ; then
132 exit 2
133 fi
134 function finish {
135 rm -f $argsfile
136 }
137 trap finish EXIT
138
139 if [ -z $KVM ]; then
140 RUN_TEST_ARGS="--long $RUN_TEST_ARGS"
141 fi
142 echo "$RUN_TEST_ARGS" > $argsfile
143
144 A="mac80211_hwsim.support_p2p_device=0 "
145 A+="mac80211_hwsim.channels=$CHANNELS "
146 A+="mac80211_hwsim.radios=7 "
147 A+="cfg80211.dyndbg=+p "
148 A+="mac80211.dyndbg=+p "
149 A+="mac80211_hwsim.dyndbg=+p "
150 A+="init=$CMD "
151 A+="testdir=$TESTDIR "
152 A+="timewarp=$TIMEWARP "
153 A+="TELNET=$TELNET_ARG "
154 A+="EPATH=$EPATH "
155 A+="ARGS=$argsfile "
156 A+="console=$KVMOUT "
157 A+="ro"
158
159 if [ -z $KVM ]; then
160 $KERNEL \
161 mem=${MEMORY}M \
162 LOGDIR=$LOGDIR \
163 time-travel=inf-cpu \
164 $A \
165 root=none hostfs=/ rootfstype=hostfs rootflags=/ \
166 ssl0=fd:0,fd:1 \
167 ssl1=fd:100 \
168 ssl-non-raw \
169 100<>$LOGDIR/console 2>&1 | \
170 sed -u '0,/VM has started up/d'
171 else
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'
188 fi
189
190 if [ $CODECOV = "yes" ]; then
191 echo "Preparing code coverage reports"
192 ./process-codecov.sh $LOGDIR "" restore
193 ./combine-codecov.sh $LOGDIR lcov
194 fi
195
196 echo
197 echo "Test run completed"
198 echo "Logfiles are at $LOGDIR ($LOGS/latest)"
199 if [ $CODECOV = "yes" ]; then
200 echo "Code coverage report:"
201 echo "file://$LOGDIR/lcov/index.html"
202 fi