From: Stefano Stabellini Subject: [PATCH v2 2/4] raisin: add an hvm test Date: Fri, 1 May 2015 16:48:49 +0100 Message-ID: <1430495331-8169-2-git-send-email-stefano.stabellini@eu.citrix.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xensource.com Cc: george.dunlap@eu.citrix.com, Stefano Stabellini List-Id: xen-devel@lists.xenproject.org Add a few functions to create partitions, install and configure grub in the VM disk. Introduce a script to loopmount a partition within a VM disk. Add a new test that creates a local HVM guest, boots it and check the network. Signed-off-by: Stefano Stabellini --- defconfig | 4 +-- lib/common-tests.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/lopartsetup | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/busybox-hvm | 44 +++++++++++++++++++++++++++++++++ tests/series | 1 + 5 files changed, 176 insertions(+), 2 deletions(-) create mode 100755 scripts/lopartsetup create mode 100755 tests/busybox-hvm diff --git a/defconfig b/defconfig index e88f3d3..664aee6 100644 --- a/defconfig +++ b/defconfig @@ -41,6 +41,6 @@ OVMF_REVISION="master" LINUX_REVISION="master" # Tests -## All tests: busybox-pv +## All tests: busybox-pv busybox-hvm ## ENABLED_TESTS is the list of test run by raise test -ENABLED_TESTS="busybox-pv" +ENABLED_TESTS="busybox-pv busybox-hvm" diff --git a/lib/common-tests.sh b/lib/common-tests.sh index 8d2ee6b..abbc91a 100644 --- a/lib/common-tests.sh +++ b/lib/common-tests.sh @@ -31,6 +31,18 @@ function create_loop() { echo $loop } +# $1 disk name +# print loop device name of the partition +function create_one_partition() { + local disk + local dev + + disk=$1 + echo -e "o\nn\np\n1\n\n\nw" | $SUDO fdisk $disk &>/dev/null + dev=`$SUDO $BASEDIR/scripts/lopartsetup $disk | head -1 | cut -d ":" -f 1` + echo $dev +} + # $1 dev name function busybox_rootfs() { local dev @@ -78,6 +90,56 @@ EOF rmdir $tmpdir } +function bootloader_init() { + local dev + local devp + local tmpdir + + dev=$1 + devp=$2 + tmpdir=`mktemp -d` + + $SUDO mount $devp $tmpdir + mkdir -p $tmpdir/boot/grub + cp "`get_host_kernel`" $tmpdir/boot + cp "`get_host_initrd`" $tmpdir/boot || true + cat >$tmpdir/boot/grub/grub.cfg <> $tmpdir/boot/grub/grub.cfg + fi + echo "}" >> $tmpdir/boot/grub/grub.cfg + + cat >$tmpdir/boot/grub/device.map </dev/null | grep -e "^$filename"`" +do + index=$((index+1)) + offset=`echo $i | tr -s " " | cut -d " " -f 2` + offset=$((unit*offset)) + + _create_loop_device "$filename" "$index" "$offset" +done + +exit 0 diff --git a/tests/busybox-hvm b/tests/busybox-hvm new file mode 100755 index 0000000..b97ae34 --- /dev/null +++ b/tests/busybox-hvm @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +set -e + +source $BASEDIR/lib/common-tests.sh + +function cleanup() { + $SUDO xl destroy raisin-test || true + umount $LOOP_P0 || true + cd "$BASEDIR" + $SUDO losetup -d $LOOP_P0 $LOOP + rm -rf $TMPDIR +} + +if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]] +then + echo busybox hvm test only valid on x86 + exit 0 +fi + +trap cleanup EXIT +TMPDIR=`mktemp -d` +cd $TMPDIR + +allocate_disk busybox-vm-disk $((20*1024*1024)) +LOOP=`create_loop busybox-vm-disk` +LOOP_P0=`create_one_partition busybox-vm-disk` +busybox_rootfs $LOOP_P0 +busybox_network_init $LOOP_P0 +bootloader_init $LOOP $LOOP_P0 + +cat >busybox-hvm <