Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[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 LOGS=/tmp/hwsim-test-logs
10
11 # increase the memory size if you want to run with valgrind, 512 MB works
12 MEMORY=192
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
45 unset RUN_TEST_ARGS
46 TIMESTAMP=$(date +%s)
47 DATE=$TIMESTAMP
48 CODECOV=no
49 TIMEWARP=0
50 DELAY=0
51 CODECOV_DIR=
52 while [ "$1" != "" ]; do
53         case $1 in
54                 --timestamp ) shift
55                         TIMESTAMP=$1
56                         shift
57                         ;;
58                 --ext ) shift
59                         DATE=$TIMESTAMP.$1
60                         shift
61                         ;;
62                 --codecov ) shift
63                         CODECOV=yes
64                         ;;
65                 --codecov_dir ) shift
66                         CODECOV_DIR=$1
67                         shift
68                         ;;
69                 --timewrap ) shift
70                         TIMEWARP=1
71                         ;;
72                 --delay ) shift
73                         DELAY=$1
74                         shift
75                         ;;
76                 * )
77                         RUN_TEST_ARGS="$RUN_TEST_ARGS$1 "
78                         shift
79                         ;;
80         esac
81 done
82
83 LOGDIR=$LOGS/$DATE
84 mkdir -p $LOGDIR
85
86 if [ -n "$CODECOV_DIR" ]; then
87     cp -a $CODECOV_DIR/alt-wpa_supplicant $LOGDIR
88     cp -a $CODECOV_DIR/alt-hostapd $LOGDIR
89     cp -a $CODECOV_DIR/alt-hostapd-as $LOGDIR
90     cp -a $CODECOV_DIR/alt-hlr_auc_gw $LOGDIR
91 elif [ $CODECOV = "yes" ]; then
92     ./build-codecov.sh $LOGDIR || exit 1
93 else
94     CODECOV=no
95 fi
96
97 if [ $DELAY -gt 0 ]; then
98     echo "Wait $DELAY seconds before starting VM"
99     sleep $DELAY
100 fi
101
102 echo "Starting test run in a virtual machine"
103
104 kvm \
105         -kernel $KERNEL -smp 4 \
106         $KVMARGS -m $MEMORY -nographic \
107         -fsdev local,security_model=none,id=fsdev-root,path=/$ROTAG \
108         -device virtio-9p-pci,id=fs-root,fsdev=fsdev-root,mount_tag=/dev/root \
109         -fsdev local,security_model=none,id=fsdev-logs,path="$LOGDIR",writeout=immediate \
110         -device virtio-9p-pci,id=fs-logs,fsdev=fsdev-logs,mount_tag=logshare \
111         -monitor null -serial stdio -serial file:$LOGDIR/console \
112         -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=$RUN_TEST_ARGS"
113
114 if [ $CODECOV = "yes" ]; then
115     echo "Preparing code coverage reports"
116     ./process-codecov.sh $LOGDIR "" restore
117     ./combine-codecov.sh $LOGDIR lcov
118 fi
119
120 echo
121 echo "Test run completed"
122 echo "Logfiles are at $LOGDIR"
123 if [ $CODECOV = "yes" ]; then
124     echo "Code coverage report:"
125     echo "file://$LOGDIR/lcov/index.html"
126 fi