summaryrefslogtreecommitdiff
path: root/lava/scripts/test-guest.sh
blob: d6a46a7ed68e6e4447fc110cc0ce0c138cf61563 (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
#! /bin/bash
#
# Xen script to test that guest is booting
#
# Copyright (C) 2013, 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.
#
# Author: Julien Grall <julien.grall@linaro.org>
#

dir=`dirname "$0"`
root="$dir/../../"

source "$dir/include/sh-test-lib"

set -e 

ntpdate ntp.ubuntu.com||true

# check we're root
if ! check_root; then
    error_msg "Please run the test case as root"
fi

ROOTFS_BUILD_SUITE="trusty"

case `uname -m` in
    armv7l)

        ROOTFS_BUILD_NUMBER=`wget -q --no-check-certificate -O - https://ci.linaro.org/jenkins/job/ubuntu-armhf-hwpacks/hwpack=vexpress,label=build/lastSuccessfulBuild/buildNumber`
        ROOTFS_BUILD_DATE=`wget -q --no-check-certificate -O - https://ci.linaro.org/jenkins/job/ubuntu-armhf-hwpacks/hwpack=vexpress,label=build/lastSuccessfulBuild/buildTimestamp?format=yyyyMMdd`
        ROOTFS_BUILD_FILENAME="vexpress-${ROOTFS_BUILD_SUITE}_nano_$ROOTFS_BUILD_DATE-$ROOTFS_BUILD_NUMBER.img"
        ROOTFS_BUILD_URL="https://snapshots.linaro.org/ubuntu/pre-built/vexpress/$ROOTFS_BUILD_NUMBER/$ROOTFS_BUILD_FILENAME.gz"
        BACKUP_URL=https://snapshots.linaro.org/ubuntu/pre-built/vexpress/686/vexpress-trusty_nano_20140823-686.img.gz
        BACKUP_FILENAME=vexpress-trusty_nano_20140823-686.img
        ;;
    aarch64)
        ROOTFS_BUILD_NUMBER=`wget -q --no-check-certificate -O - https://ci.linaro.org/jenkins/job/ubuntu-arm64-rootfs/label=build,rootfs=nano/lastSuccessfulBuild/buildNumber`
        ROOTFS_BUILD_TIMESTAMP=`wget -q --no-check-certificate -O - https://ci.linaro.org/jenkins/job/ubuntu-arm64-rootfs/label=build,rootfs=nano/lastSuccessfulBuild/buildTimestamp?format=yyyyMMdd`
        ROOTFS_BUILD_FILENAME="linaro-${ROOTFS_BUILD_SUITE}-nano-${ROOTFS_BUILD_TIMESTAMP}-${ROOTFS_BUILD_NUMBER}.tar"
        ROOTFS_BUILD_URL="http://snapshots.linaro.org/ubuntu/images/nano-arm64/${ROOTFS_BUILD_NUMBER}/${ROOTFS_BUILD_FILENAME}.gz"
        wget -q --no-check-certificate https://snapshots.linaro.org/ubuntu/images/xen/latest/Image-xen-mustang
        mv Image-xen-mustang zImage
        ;;
    *)
        echo unsupported arch `uname -m`
        exit 1
        ;;
esac

rm -f $ROOTFS_BUILD_FILENAME $ROOTFS_BUILD_FILENAME.gz

set +e
wget --progress=dot -e dotbytes=1M --no-check-certificate $ROOTFS_BUILD_URL
if [ ! -r $ROOTFS_BUILD_FILENAME.gz ]
then
    set -e
    wget --progress=dot -e dotbytes=1M --no-check-certificate $BACKUP_URL
    ROOTFS_BUILD_FILENAME=$BACKUP_FILENAME
fi
set -e

case `uname -m` in
    armv7l)
        # Extract the image
        gunzip $ROOTFS_BUILD_FILENAME.gz
        IMGFILE=$ROOTFS_BUILD_FILENAME
        kpartx -a -v $IMGFILE
        # Extract the zImage from the image
        mount /dev/mapper/loop0p1 /media
        dd if=/media/uImage ibs=64 skip=1 of=zImage
        umount /media
        mount /dev/mapper/loop0p2 /media
        ;;
    aarch64)
        IMGFILE=guest.img
        dd if=/dev/zero of=$IMGFILE bs=1024 seek=1M count=0
        /sbin/parted --script $IMGFILE mklabel msdos
        /sbin/parted --script $IMGFILE mkpart p fat32 1 50
        /sbin/parted --script  -- $IMGFILE mkpart p ext4 51 -0
        kpartx -a -v $IMGFILE
        mkfs.ext4 /dev/mapper/loop0p1
        mkfs.ext4 /dev/mapper/loop0p2
        mount /dev/mapper/loop0p2 /media
        tar xaf $ROOTFS_BUILD_FILENAME.gz -C /media --strip-components=1
        ;;

esac

#  Prepare the image by copying usefull file

# Copy hvc0 initscript
cp $root/files/hvc0.conf /media/etc/init/hvc0.conf

# Copy hackbench
cp /usr/bin/hackbench /media/usr/bin/hackbench

# Copy tests
cp $root/files/test-rt-tests.sh /media/root/test-rt-tests.sh
cp $root/files/xen-lava.conf /media/etc/init/xen-lava.conf

# FIXME: Disable network for now
cp $root/files/interfaces /media/etc/network/interfaces

umount /media
kpartx -d $IMGFILE

# Create the guest
loop=`losetup -f --show $IMGFILE`

TEST="xl-create-guest"
xl -vvv create $root/files/guest1.xl
check_return_pass

# Disable exit on error during the waiting loop

# 20 minutes of timeout
timeout=20
pass=0
set +o errexit
while [ true ]; do
    xl list guest1 > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        pass=1
        break
    fi
    xl list -v
    sleep 60
    timeout=$((timeout - 1))
    if [ $timeout -eq 0 ]; then
        xl destroy guest1
        break
    fi
done

set -e

losetup -d $loop

# Test case: check if the guest has booted
TEST="xen-boot-1"

if ! grep -q "xen-boot-1:" /var/log/xen/console/guest-guest1.log; then
    fail_test "Guest didn't boot"
    exit 0
else
    pass_test
fi

# Test case: check if the guest didn't timeout
TEST="guest-hackbench"
if [ $pass -ne 1 ]; then
    fail_test "Hackbench timeout"
    exit 0
fi

pass_test

# clean exit so lava-test can trust the results
exit 0