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"
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
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 <<EOF
+set default="0"
+set timeout=0
+
+menuentry 'Xen Guest' {
+ set root=hd0,1
+ linux `get_host_kernel` root=/dev/xvda1 console=ttyS0
+EOF
+ if [[ -e `get_host_initrd` ]]
+ then
+ echo "initrd `get_host_initrd`" >> $tmpdir/boot/grub/grub.cfg
+ fi
+ echo "}" >> $tmpdir/boot/grub/grub.cfg
+
+ cat >$tmpdir/boot/grub/device.map <<EOF
+(hd0) $dev
+(hd0,1) $devp
+EOF
+
+ if [[ $DISTRO = "Debian" ]]
+ then
+ $SUDO grub-install --no-floppy \
+ --grub-mkdevicemap=$tmpdir/boot/grub/device.map \
+ --root-directory=$tmpdir $dev
+ elif [[ $DISTRO = "Fedora" ]]
+ then
+ $SUDO grub2-install --no-floppy \
+ --grub-mkdevicemap=$tmpdir/boot/grub/device.map \
+ --root-directory=$tmpdir $dev
+ else
+ echo "I don't know how to install grub on $DISTRO"
+ fi
+
+ $SUDO umount $tmpdir
+ rmdir $tmpdir
+}
+
function check_guest_alive() {
local i
i=0
--- /dev/null
+#!/usr/bin/env bash
+#
+# Need root privileges
+#
+# Create loop devices corresponding to partitions within an existing
+# file.
+
+set -e
+
+function _help() {
+ echo "Usage: lopartsetup file"
+}
+
+function _create_loop_device() {
+ local devnode
+ local filename
+ local offset
+ local index
+
+ filename="$1"
+ index="$2"
+ offset="$3"
+
+ devnode="`losetup -f 2>/dev/null`"
+ if [[ -z "$devnode" ]]
+ then
+ echo "no loop devices available"
+ exit 1
+ fi
+
+ echo "$devnode: partition $index of $filename"
+ losetup "$devnode" "$filename" -o "$offset"
+}
+
+if [[ $# -lt 1 ]]
+then
+ _help
+ exit 1
+fi
+
+if [[ -f "$1" && -r "$1" ]]
+then
+ filename="$1"
+ shift
+else
+ echo invalid image file
+ exit 1
+fi
+
+if [[ ! "`file -b $filename`" = *"boot sector"* ]]
+then
+ echo "$filename does not have a partition table"
+ exit 1
+fi
+
+unit="`fdisk -lu $filename 2>/dev/null | grep -e "^Units = " | cut -d " " -f 9`"
+index=0
+for i in "`fdisk -lu $filename 2>/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
--- /dev/null
+#!/usr/bin/env bash
+
+set -e
+
+function busybox-hvm-cleanup() {
+ $SUDO xl destroy raisin-test || true
+ umount $LOOP_P0 || true
+ cd "$BASEDIR"
+ $SUDO losetup -d $LOOP_P0 $LOOP
+ rm -rf $TMPDIR
+}
+
+function busybox-hvm-test() {
+ if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]]
+ then
+ echo busybox hvm test only valid on x86
+ exit 0
+ fi
+
+ 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 <<EOF
+builder = "hvm"
+memory = 512
+name = "raisin-test"
+vcpus = 2
+disk = [ '$LOOP,raw,hda,w' ]
+serial="pty"
+boot="c"
+vif=['bridge=xenbr1']
+EOF
+
+ $SUDO xl create busybox-hvm
+ check_guest_alive
+}