summaryrefslogtreecommitdiff
path: root/common/scripts/kvm/test-kvm.sh
blob: 4e54659c3aedf594725e152d3657841155810c5c (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
#!/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>

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 --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`

case ${ARCH} in
    armv7l)
        $DOWNLOAD_FILE http://snapshots.linaro.org/ubuntu/images/kvm-guest/$BUILD_NUMBER_GUEST/kvm-arm32.qcow2.gz
        $DOWNLOAD_FILE http://snapshots.linaro.org/ubuntu/images/kvm-guest/$BUILD_NUMBER_GUEST/zImage-vexpress
        $DOWNLOAD_FILE http://snapshots.linaro.org/ubuntu/images/kvm-guest/$BUILD_NUMBER_GUEST/vexpress-v2p-ca15-tc1.dtb
        gunzip kvm-arm32.qcow2.gz
        mv kvm-arm32.qcow2 kvm.qcow2
        modprobe nbd max_part=16
        ;;
    aarch64)
        hwpack=`uname -r|sed -e's,.*-,,'`
        BUILD_NUMBER_HOST=`$(echo $EXTRACT_BUILD_NUMBER) https://ci.linaro.org/job/linux-kvm/hwpack=${hwpack},label=docker-utopic/lastSuccessfulBuild/buildNumber`
        $DOWNLOAD_FILE http://snapshots.linaro.org/ubuntu/images/kvm-guest/$BUILD_NUMBER_GUEST/kvm-arm64.qcow2.gz
        $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
        gunzip kvm-arm64.qcow2.gz
        mv kvm-arm64.qcow2 kvm.qcow2
        zcat nbd-${hwpack}.ko.gz > nbd.ko
        insmod nbd.ko max_part=16
        ;;
    *)
        echo unknown arch ${ARCH}
        exit 1
        ;;
esac

if [ ! -r kvm.qcow2 ]; then
    echo "$KVM_HOST_NET 0 pc skip"
    echo "$KVM_BOOT 0 pc skip"
    echo "$KVM_GUEST_NET 0 pc skip"
    exit 0
fi

qemu-nbd -c /dev/nbd0 kvm.qcow2
sleep 2
mount /dev/nbd0p2 /mnt/

cp common/scripts/kvm/kvm-lava.conf  /mnt/etc/init/kvm-lava.conf

# 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 /usr/bin/hackbench /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 guest'
fi

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

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

umount /mnt
sync
qemu-nbd -d /dev/nbd0

case ${ARCH} in
    armv7l)
        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
esac

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)
        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' \
        -drive if=none,id=image,file=kvm.qcow2 \
        -netdev tap,id=tap0,script=no,downscript=no,ifname="tap0" \
        -device virtio-net-device,netdev=tap0 \
        -device virtio-blk-device,drive=image \
        -nographic -enable-kvm 2>&1|tee kvm-log.txt
        ;;
    aarch64)
        qemu-system-aarch64 --version
        taskset -c 0,1,2,3 qemu-system-aarch64 -smp 2 -m 1024 -cpu host -M virt \
        -kernel ./Image-${hwpack} \
        -append 'root=/dev/vda2 rw rootwait mem=1024M earlyprintk=pl011,0x9000000 console=ttyAMA0,38400n8' \
        -drive if=none,id=image,file=kvm.qcow2 \
        -netdev user,id=user0 -device virtio-net-device,netdev=user0 \
        -device virtio-blk-device,drive=image \
        -nographic -enable-kvm 2>&1|tee kvm-log.txt
        ;;
    *)
        echo unknown arch ${ARCH}
        exit 1
        ;;
esac

qemu-nbd -c /dev/nbd0 kvm.qcow2
sleep 2
mount /dev/nbd0p2 /mnt/

if ! grep -q "kvm-boot-1:" /mnt/root/guest.log
then
    echo "$KVM_BOOT 0 pc fail"
fi

cat /mnt/root/guest.log
cp /mnt/*.txt .
cp /mnt/root/guest.log .

umount /mnt
sync
qemu-nbd -d /dev/nbd0