summaryrefslogtreecommitdiff
path: root/common/scripts/kvm/test-kvm.sh
blob: b53de5b11c08f05f4e0654721deb3847a45bee89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/bin/sh
#
# Copyright (C) 2010 - 2014, Linaro Limited.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Maintainer: Riku Voipio <riku.voipio@linaro.org>

tamper_guest()
{
    guest=$1
    prefix=$2
    PREFIX_KVM_BOOT=${prefix}-$KVM_BOOT
    PREFIX_KVM_GUEST_NET=${prefix}-$KVM_GUEST_NET

    if [ ! -r $guest ]; then
        echo "$PREFIX_KVM_BOOT 0 pc skip"
        echo "$PREFIX_KVM_GUEST_NET 0 pc skip"
        exit 0
    fi

    qemu-nbd -c /dev/nbd0 $guest
    sleep 2
    mount /dev/nbd0p2 /mnt/

    if [ -x /mnt/lib/systemd/systemd ]
    then
        cp common/scripts/kvm/kvm-lava.service /mnt/etc/systemd/system/kvm-lava.service
        chroot /mnt systemctl enable kvm-lava.service
    else
        cp common/scripts/kvm/kvm-lava.conf  /mnt/etc/init/kvm-lava.conf
    fi

    # Build up file test-guest.sh
    if [ "x$1" = "xbenchmark" ]; then
        cp /usr/bin/lat_ctx /mnt/usr/bin/lat_ctx
        cp common/scripts/lmbench.sh /mnt/root/lmbench.sh
        TEST_SCRIPT=/root/lmbench.sh
    else
        cp hackbench-${prefix} /mnt/usr/bin/hackbench
        cp common/scripts/kvm/test-rt-tests.sh /mnt/root/test-rt-tests.sh
        TEST_SCRIPT="/root/test-rt-tests.sh ${prefix}-guest"
    fi

    cat >> /mnt/usr/bin/test-guest.sh <<EOF
#!/bin/sh
    exec > /root/guest.log 2>&1
    echo "$PREFIX_KVM_BOOT 0 pc pass"
    ping -w 20 -c 10 10.0.0.1 && echo "$PREFIX_KVM_GUEST_NET 0 pc pass" || echo "$PREFIX_KVM_GUEST_NET 0 pc fail"
    sh $TEST_SCRIPT
EOF
    chmod a+x /mnt/usr/bin/test-guest.sh

    umount /mnt
    mount /dev/nbd0p1 /mnt/
    case $prefix in
        aarch64)
            cp Image /mnt
            echo 'FS0:\Image root=/dev/vda2 rw rootwait mem=1024M earlyprintk=pl011,0x9000000 console=ttyAMA0,38400n8' > /mnt/startup.nsh
            ;;
        armv7l)
            cp zImage-vexpress /mnt/zImage
            echo 'FS0:\zImage root=/dev/vda2 rw rootwait mem=1024M console=ttyAMA0,38400n8' > /mnt/startup.nsh
            ;;
    esac
    umount /mnt
    sync
    qemu-nbd -d /dev/nbd0

}

get_results()
{
    guest=$1
    prefix=$2
    qemu-nbd -c /dev/nbd0 $guest
    sleep 2
    mount /dev/nbd0p2 /mnt/

    if ! grep -q "kvm-boot-1:" /mnt/root/guest.log
    then
        echo "${prefix}-${KVM_BOOT} 0 pc fail"
    fi
    echo ${prefix}-guest logs:
    cp /mnt/*.txt .
    cp /mnt/root/guest.log ./${prefix}-guest.log
    cat ./${prefix}-guest.log
    umount /mnt
    sync
    qemu-nbd -d /dev/nbd0
}

deadline() {
    timeout=$1
    binary=$2
    set +o errexit
    while [ true ]; do
        pid=`pidof $binary`
        if [ $? -ne 0 ]; then
            break
        fi
        sleep 60
        timeout=$((timeout - 1))
        if [ $timeout -eq 0 ]; then
            kill $pid
            sleep 10
            kill -9 $pid
        break
        fi
    done
}

KVM_HOST_NET="kvm-host-net-1:"
KVM_GUEST_NET="kvm-guest-net-1:"
KVM_INIT="kvm-init-1:"
KVM_BOOT="kvm-boot-1:"
if [ "x$1" = "xbenchmark" ]; then
    KVM_HOST_NET="$KVM_HOST_NET 0 none"
    KVM_GUEST_NET="$KVM_GUEST_NET 0 none"
    KVM_INIT="$KVM_INIT 0 none"
    KVM_BOOT="$KVM_BOOT 0 none"
fi

ARCH=`uname -m`

dmesg|grep 'Hyp mode initialized successfully' && echo "$KVM_INIT 0 pc pass" || \
{
    echo "$KVM_INIT 0 pc fail"
    echo "$KVM_HOST_NET 0 pc skip"
    echo "$KVM_BOOT 0 pc skip"
    echo "$KVM_GUEST_NET 0 pc skip"
    exit 0
}

curl 2>/dev/null
if [ $? = 2 ]; then
    EXTRACT_BUILD_NUMBER="curl -sk"
    DOWNLOAD_FILE="curl -SOk"
else
    EXTRACT_BUILD_NUMBER="wget -q --no-check-certificate -O -"
    DOWNLOAD_FILE="wget --no-clobber --progress=dot -e dotbytes=2M --no-check-certificate"
fi

BUILD_NUMBER_GUEST=`$(echo $EXTRACT_BUILD_NUMBER) https://ci.linaro.org/job/kvm-guest-image/lastSuccessfulBuild/buildNumber`
BUILD_NUMBER_HOST=`$(echo $EXTRACT_BUILD_NUMBER) https://ci.linaro.org/job/linux-kvm/lastSuccessfulBuild/buildNumber`

$DOWNLOAD_FILE http://snapshots.linaro.org/ubuntu/images/kvm-guest/$BUILD_NUMBER_GUEST/armhf/kvm-armhf.qcow2.xz
$DOWNLOAD_FILE http://snapshots.linaro.org/ubuntu/images/kvm/$BUILD_NUMBER_HOST/zImage-armv7
mv zImage-armv7 zImage-vexpress
$DOWNLOAD_FILE http://snapshots.linaro.org/ubuntu/images/kvm/$BUILD_NUMBER_HOST/vexpress-v2p-ca15-tc1.dtb

xz -d kvm-armhf.qcow2.xz

case ${ARCH} in
    armv7l)
        modprobe nbd max_part=16
        ;;
    aarch64)
        hwpack=`uname -r|sed -e's,.*-,,'`
        $DOWNLOAD_FILE http://snapshots.linaro.org/ubuntu/images/kvm-guest/$BUILD_NUMBER_GUEST/arm64/kvm-arm64.qcow2.xz
        $DOWNLOAD_FILE http://snapshots.linaro.org/ubuntu/images/kvm/$BUILD_NUMBER_HOST/Image-${hwpack}
        $DOWNLOAD_FILE http://snapshots.linaro.org/ubuntu/images/kvm/$BUILD_NUMBER_HOST/nbd-${hwpack}.ko.gz
        $DOWNLOAD_FILE http://releases.linaro.org/15.01/components/kernel/uefi-linaro/release/qemu64-intelbds/QEMU_EFI.fd
        xz -d kvm-arm64.qcow2.xz
        zcat nbd-${hwpack}.ko.gz > nbd.ko
        insmod nbd.ko max_part=16
        mv Image-${hwpack} Image
        tamper_guest kvm-arm64.qcow2 aarch64
        ;;
    *)
        echo unknown arch ${ARCH}
        exit 1
        ;;
esac


echo 0 2000000 > /proc/sys/net/ipv4/ping_group_range

tamper_guest kvm-armhf.qcow2 armv7l

if ! grep -q root=/dev/nfs /proc/cmdline
then
        echo "setting up and testing networking bridge for guest"
        brctl addbr br0
        tunctl -u root
        ifconfig eth0 0.0.0.0 up
        ifconfig tap0 0.0.0.0 up
        brctl addif br0 eth0
        brctl addif br0 tap0
        udhcpc -t 10 -i br0
        netparams="-device virtio-net-device,netdev=tap0 -netdev tap,id=tap0,script=no,downscript=no,ifname=tap0"
else
        netparams="-netdev user,id=user0 -device virtio-net-device,netdev=user0"
fi

ping -W 4 -c 10 10.0.0.1 && echo "$KVM_HOST_NET 0 pc pass" || echo "$KVM_HOST_NET 0 pc fail"

case ${ARCH} in
    armv7l)
        deadline 60 qemu-system-arm &
        qemu-system-arm --version
        qemu-system-arm -smp 2 -m 1024 -cpu cortex-a15 -M vexpress-a15 \
        -kernel ./zImage-vexpress -dtb ./vexpress-v2p-ca15-tc1.dtb \
        -append 'root=/dev/vda2 rw rootwait mem=1024M console=ttyAMA0,38400n8' \
        $netparams \
        -drive if=none,id=image,file=kvm-armhf.qcow2 \
        -device virtio-blk-device,drive=image \
        -nographic -enable-kvm 2>&1|tee kvm-arm32.log
        ;;
    aarch64)
        # handle big.LITTLE
        hwloc-ls
        case ${hwpack} in
            juno)
                # run on a53 cluster
                echo run on a53
                bind="hwloc-bind socket:0"
                ;;
            *)
                bind=""
                ;;
        esac
        deadline 120 qemu-system-aarch64 &
        qemu-system-aarch64 --version
        echo "64bit guest test"
        $bind qemu-system-aarch64 -smp 2 -m 1024 -cpu host -M virt \
        -bios QEMU_EFI.fd \
        -device virtio-blk-device,drive=image \
        -drive if=none,id=image,file=kvm-arm64.qcow2 \
        $netparams \
        -nographic -enable-kvm 2>&1|tee kvm-arm64.log
        echo "32bit guest test"
        $bind qemu-system-aarch64 -smp 2 -m 1024 -cpu host,aarch64=off -M virt \
        -kernel ./zImage-vexpress \
        -append 'root=/dev/vda2 rw rootwait mem=1024M console=ttyAMA0,38400n8' \
        -device virtio-blk-device,drive=image \
        -drive if=none,id=image,file=kvm-armhf.qcow2 \
        $netparams \
        -nographic -enable-kvm 2>&1|tee kvm-arm32.log
        get_results kvm-arm64.qcow2 aarch64
        ;;
    *)
        echo unknown arch ${ARCH}
        exit 1
        ;;
esac

get_results kvm-armhf.qcow2 armv7l

ls *log *txt
rm -f md5sum.txt