]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/vm/vm-run.sh
tests: Build hlr_auc_gw separately for code coverage analysis
[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 LOGS=/tmp/hwsim-test-logs
10
11 # increase the memory size if you want to run with valgrind, 512 MB works
12 MEMORY=128
13
14 # Some ubuntu systems (notably 12.04) have issues with this - since the guest
15 # mounts as read-only it should be safe to not specify ,readonly. Override in
16 # vm-config if needed (see below)
17 ROTAG=,readonly
18
19 # set this to ttyS0 to see kvm messages (if something doesn't work)
20 KVMOUT=ttyS1
21
22 # you can set EPATH if you need anything extra in $PATH inside the VM
23 #EPATH=/some/dir
24
25 # extra KVM arguments, e.g., -s for gdbserver
26 #KVMARGS=-s
27
28 # number of channels each hwsim device supports
29 CHANNELS=1
30
31 test -f vm-config && . vm-config
32 test -f ~/.wpas-vm-config && . ~/.wpas-vm-config
33
34 if [ -z "$KERNEL" ] && [ -z "$KERNELDIR" ] ; then
35 echo "You need to set a KERNEL or KERNELDIR (in the environment or vm-config)"
36 exit 2
37 fi
38 if [ -z "$KERNEL" ] ; then
39 KERNEL=$KERNELDIR/arch/x86_64/boot/bzImage
40 fi
41
42
43 CMD=$TESTDIR/vm/inside.sh
44 DATE=$(date +%s)
45 LOGDIR=$LOGS/$DATE
46 mkdir -p $LOGDIR
47
48 if [ "$1" = "--codecov" ]; then
49 shift
50 CODECOV=yes
51 DIR=$PWD
52 if [ -e /tmp/logs ]; then
53 echo "/tmp/logs exists - cannot prepare build trees"
54 exit 1
55 fi
56 mkdir /tmp/logs
57 echo "Preparing separate build trees for hostapd/wpa_supplicant"
58 cd ../../..
59 git archive --format=tar --prefix=hostap/ HEAD > /tmp/logs/hostap.tar
60 cd $DIR
61 cat ../../../wpa_supplicant/.config > /tmp/logs/wpa_supplicant.config
62 echo "CONFIG_CODE_COVERAGE=y" >> /tmp/logs/wpa_supplicant.config
63 cat ../../../hostapd/.config > /tmp/logs/hostapd.config
64 echo "CONFIG_CODE_COVERAGE=y" >> /tmp/logs/hostapd.config
65
66 cd /tmp/logs
67 tar xf hostap.tar
68 mv hostap alt-wpa_supplicant
69 mv wpa_supplicant.config alt-wpa_supplicant/wpa_supplicant/.config
70 tar xf hostap.tar
71 mv hostap alt-hostapd
72 cp hostapd.config alt-hostapd/hostapd/.config
73 tar xf hostap.tar
74 mv hostap alt-hostapd-as
75 cp hostapd.config alt-hostapd-as/hostapd/.config
76 tar xf hostap.tar
77 mv hostap alt-hlr_auc_gw
78 mv hostapd.config alt-hlr_auc_gw/hostapd/.config
79 rm hostap.tar
80
81 cd /tmp/logs/alt-wpa_supplicant/wpa_supplicant
82 echo "Building wpa_supplicant"
83 make -j8 > /dev/null
84
85 cd /tmp/logs/alt-hostapd/hostapd
86 echo "Building hostapd"
87 make -j8 hostapd > /dev/null
88
89 cd /tmp/logs/alt-hostapd-as/hostapd
90 echo "Building hostapd (AS)"
91 make -j8 hostapd > /dev/null
92
93 cd /tmp/logs/alt-hlr_auc_gw/hostapd
94 echo "Building hlr_auc_gw"
95 make -j8 hlr_auc_gw > /dev/null
96
97 cd $DIR
98
99 mv /tmp/logs/alt-wpa_supplicant $LOGDIR
100 mv /tmp/logs/alt-hostapd $LOGDIR
101 mv /tmp/logs/alt-hostapd-as $LOGDIR
102 mv /tmp/logs/alt-hlr_auc_gw $LOGDIR
103 else
104 CODECOV=no
105 fi
106
107 if [ "$1" == "--timewarp" ] ; then
108 TIMEWARP=1
109 shift
110 else
111 TIMEWARP=0
112 fi
113
114 echo "Starting test run in a virtual machine"
115
116 kvm \
117 -kernel $KERNEL -smp 4 \
118 $KVMARGS -m $MEMORY -nographic \
119 -fsdev local,security_model=none,id=fsdev-root,path=/$ROTAG \
120 -device virtio-9p-pci,id=fs-root,fsdev=fsdev-root,mount_tag=/dev/root \
121 -fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \
122 -device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
123 -monitor null -serial stdio -serial file:$LOGDIR/console \
124 -append "mac80211_hwsim.channels=$CHANNELS mac80211_hwsim.radios=6 init=$CMD testdir=$TESTDIR timewarp=$TIMEWARP console=$KVMOUT root=/dev/root rootflags=trans=virtio,version=9p2000.u ro rootfstype=9p EPATH=$EPATH ARGS=$*"
125
126 if [ $CODECOV = "yes" ]; then
127 mv $LOGDIR/alt-wpa_supplicant /tmp/logs
128 mv $LOGDIR/alt-hostapd /tmp/logs
129 mv $LOGDIR/alt-hostapd-as /tmp/logs
130 mv $LOGDIR/alt-hlr_auc_gw /tmp/logs
131
132 echo "Generating code coverage report for wpa_supplicant"
133 cd /tmp/logs/alt-wpa_supplicant/wpa_supplicant
134 lcov -c -d .. > lcov.info 2> lcov.log
135 genhtml -t "wpa_supplicant hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-wpa_supplicant >> lcov.log 2>&1
136 mv lcov.info lcov.log $LOGDIR/lcov-wpa_supplicant
137
138 echo "Generating code coverage report for hostapd"
139 cd /tmp/logs/alt-hostapd/hostapd
140 lcov -c -d .. > lcov.info 2> lcov.log
141 genhtml -t "hostapd hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-hostapd >> lcov.log 2>&1
142 mv lcov.info lcov.log $LOGDIR/lcov-hostapd
143
144 echo "Generating code coverage report for hostapd (AS)"
145 cd /tmp/logs/alt-hostapd-as/hostapd
146 lcov -c -d .. > lcov.info 2> lcov.log
147 genhtml -t "hostapd (AS) hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-hostapd-as >> lcov.log 2>&1
148 mv lcov.info lcov.log $LOGDIR/lcov-hostapd-as
149
150 echo "Generating code coverage report for hlr_auc_gw"
151 cd /tmp/logs/alt-hlr_auc_gw/hostapd
152 lcov -c -d .. > lcov.info 2> lcov.log
153 genhtml -t "hlr_auc_gw hwsim test run $DATE" lcov.info --output-directory $LOGDIR/lcov-hlr_auc_gw >> lcov.log 2>&1
154 mv lcov.info lcov.log $LOGDIR/lcov-hlr_auc_gw
155
156 echo "Generating combined code coverage report"
157 mkdir $LOGDIR/lcov-combined
158 for i in wpa_supplicant hostapd hostapd-as hlr_auc_gw; do
159 sed s%SF:/tmp/logs/alt-[^/]*/%SF:/tmp/logs/alt-wpa_supplicant/% < $LOGDIR/lcov-$i/lcov.info > $LOGDIR/lcov-combined/$i.info
160 done
161 cd $LOGDIR/lcov-combined
162 lcov -a wpa_supplicant.info -a hostapd.info -a hostapd-as.info -a hlr_auc_gw.info -o combined.info > lcov.log 2>&1
163 genhtml -t "wpa_supplicant/hostapd combined for hwsim test run $DATE" combined.info --output-directory . >> lcov.log 2>&1
164
165 cd $DIR
166 rm -r /tmp/logs/alt-wpa_supplicant
167 rm -r /tmp/logs/alt-hostapd
168 rm -r /tmp/logs/alt-hostapd-as
169 rm -r /tmp/logs/alt-hlr_auc_gw
170 rmdir /tmp/logs
171 fi
172
173 echo
174 echo "Test run completed"
175 echo "Logfiles are at $LOGDIR"
176 if [ $CODECOV = "yes" ]; then
177 echo "Code coverage reports:"
178 echo "wpa_supplicant: file://$LOGDIR/lcov-wpa_supplicant/index.html"
179 echo "hostapd: file://$LOGDIR/lcov-hostapd/index.html"
180 echo "hostapd (AS): file://$LOGDIR/lcov-hostapd-as/index.html"
181 echo "hlr_auc_gw: file://$LOGDIR/lcov-hlr_auc_gw/index.html"
182 echo "combined: file://$LOGDIR/lcov-combined/index.html"
183 fi