Skip to contentSkip to conversation

raisin: introduce tests

PATCH Superseded Stefano Stabellini 2 participants 8 messages Apr 29, 2015 – Apr 30, 2015 Library code

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover raisin: introduce tests

Hi all,

this patch series introduces a framework to execute simple unit and functional tests in raisin. It can be used by developers to validate their changes before submitting a patch series to xen-devel. It can also be used by OSSTest to test for regressions on one particular functionality. This patch series only introduces two tests: a PV guest creation test and an HVM guest creation test. They are both based on busybox. More tests will follow.

Stefano Stabellini (3):
raisin: introduce tests
raisin: add an hvm test
raisin: improve output

 README                      |   14 ++++
 components/grub             |    4 +-
 components/libvirt          |    4 +-
 components/linux            |    2 +-
 components/ovmf             |    6 +-
 components/qemu             |    2 +-
 components/qemu_traditional |    2 +-
 components/seabios          |    6 +-
 components/xen              |    8 +-
 defconfig                   |    5 ++
 lib/commands.sh             |   22 +++---
 lib/common-functions.sh     |  138 +++++++++++++++++++++++++++++-----
 lib/common-tests.sh         |  174 +++++++++++++++++++++++++++++++++++++++++++
 raise                       |    8 +-
 scripts/lopartsetup         |   67 +++++++++++++++++
 tests/busybox-hvm           |   44 +++++++++++
 tests/busybox-pv            |   38 ++++++++++
 tests/series                |    2 +
 18 files changed, 499 insertions(+), 47 deletions(-)
 create mode 100644 lib/common-tests.sh
 create mode 100755 scripts/lopartsetup
 create mode 100755 tests/busybox-hvm
 create mode 100755 tests/busybox-pv
 create mode 100644 tests/series

Cheers,

Stefano

#1 lore raw

PATCH 1/3 raisin: introduce tests

Introduce a new command to run functional tests and unit tests. Introduce a generic infrastrucutre to run tests on the local machine. Add a library of common functions that can be used by the test scripts to setup guest VMs.

Add a simple test script that boots a single busybox based PV guest.

---
 README                  |   14 ++++++
 defconfig               |    5 +++
 lib/commands.sh         |    4 ++
 lib/common-functions.sh |   74 +++++++++++++++++++++++++++++++
 lib/common-tests.sh     |  112 +++++++++++++++++++++++++++++++++++++++++++++++
 raise                   |    8 ++--
 tests/busybox-pv        |   38 ++++++++++++++++
 tests/series            |    1 +
 8 files changed, 253 insertions(+), 3 deletions(-)
 create mode 100644 lib/common-tests.sh
 create mode 100755 tests/busybox-pv
 create mode 100644 tests/series
README +14 -0
index b7832da..42c0f4d 100644
@@ -102,3 +102,17 @@ check-package
 
 If your component comes with additional data, maybe a config script or
 anything else, place it under "data".
+
+
+= Testing =
+
+Raisin can also be used for testing. Make sure to have Xen already up
+and running (raise build, raise install and host reboot).
+Ask Raisin to run tests like this:
+
+./raise test
+
+You can specify a subset of tests to run with ENABLED_TESTS in the
+config file, or the TESTS environmental variable:
+
+TESTS="busybox-pv" ./raise test
defconfig +5 -0
index b4ed94d..e88f3d3 100644
@@ -39,3 +39,8 @@ GRUB_REVISION="master"
 LIBVIRT_REVISION="master"
 OVMF_REVISION="master"
 LINUX_REVISION="master"
+
+# Tests
+## All tests: busybox-pv
+## ENABLED_TESTS is the list of test run by raise test
+ENABLED_TESTS="busybox-pv"
lib/commands.sh +4 -0
index 801341b..ffbadb4 100755
@@ -103,3 +103,7 @@ function configure() {
     for_each_component configure
 }
 
+function test() {
+    init_tests
+    run_tests
+}
lib/common-functions.sh +74 -0

92 lines not on this page · raw message

lib/common-tests.sh new file +112 -0

112 lines not on this page · raw message

raise +5 -3
index 68dbfd8..dd275ad 100755
@@ -3,7 +3,7 @@
 set -e
 
 _help() {
-    echo "Usage: ./build.sh <options> <command>"
+    echo "Usage: ./raise <options> <command>"
     echo "where options are:"
     echo "    -v | --verbose       Verbose"
     echo "    -y | --yes           Do not ask questions and continue"
@@ -14,6 +14,7 @@ _help() {
     echo "    install              Install binaries under /  (requires sudo)"
     echo "    configure            Configure the system  (requires sudo)"
     echo "    unraise              Uninstall and unconfigure the system  (requires sudo)"
+    echo "    test                 Runs tests on the system (requires sudo, Xen must be running)"
 }
 
 # Include your defaults
@@ -25,10 +26,11 @@ fi
 source ./config
 
 # To use this as a library, set RAISIN_PATH appropriately
-[[ -z "$RAISIN_PATH" ]] && RAISIN_PATH="$PWD/lib"
+[[ -z "$RAISIN_PATH" ]] && export RAISIN_PATH="$PWD/lib"
 
 # Then as many as the sub-libraries as you need
 source ${RAISIN_PATH}/common-functions.sh
+source ${RAISIN_PATH}/common-tests.sh
 source ${RAISIN_PATH}/git-checkout.sh
 source ${RAISIN_PATH}/commands.sh
 
@@ -59,7 +61,7 @@ do
 done
 
 case "$1" in
-    "install-builddep" | "build" | "install" | "configure" | "unraise" )
+    "install-builddep" | "build" | "install" | "configure" | "unraise" | "test" )
         COMMAND=$1
         ;;
     *)
tests/busybox-pv new file +38 -0
new file mode 100755
index 0000000..941c739
@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+
+set -e
+
+source $BASEDIR/lib/common-tests.sh
+
+function cleanup() {
+    $SUDO xl destroy raisin-test || true
+    umount $LOOP || true
+    cd "$BASEDIR"
+    $SUDO losetup -d $LOOP
+    rm -rf $TMPDIR
+}
+
+trap cleanup EXIT
+TMPDIR=`mktemp -d`
+cd $TMPDIR
+
+allocate_disk busybox-vm-disk $((20*1024*1024))
+LOOP=`create_loop busybox-vm-disk`
+busybox_rootfs $LOOP
+busybox_network_init $LOOP
+
+cat >busybox-pv <<EOF
+kernel = "`get_host_kernel`"
+ramdisk = "`get_host_initrd`"
+extra = "root=/dev/xvda console=hvc0"
+memory = 512
+name = "raisin-test"
+vcpus = 2
+disk = [ '$LOOP,raw,xvda,w' ]
+serial="pty"
+boot="c"
+vif=['bridge=xenbr1']
+EOF
+
+$SUDO xl create busybox-pv
+check_guest_alive
tests/series new file +1 -0
new file mode 100644
index 0000000..a5ec626
@@ -0,0 +1 @@
+busybox-pv
Signature · 1 line
1.7.10.4
#2 lore raw
Quoted 108 lines · Stefano Stabellini

Introduce a new command to run functional tests and unit tests. Introduce a generic infrastrucutre to run tests on the local machine. Add a library of common functions that can be used by the test scripts to setup guest VMs.

Add a simple test script that boots a single busybox based PV guest.

---
 README                  |   14 ++++++
 defconfig               |    5 +++
 lib/commands.sh         |    4 ++
 lib/common-functions.sh |   74 +++++++++++++++++++++++++++++++
 lib/common-tests.sh     |  112 +++++++++++++++++++++++++++++++++++++++++++++++
 raise                   |    8 ++--
 tests/busybox-pv        |   38 ++++++++++++++++
 tests/series            |    1 +
 8 files changed, 253 insertions(+), 3 deletions(-)
 create mode 100644 lib/common-tests.sh
 create mode 100755 tests/busybox-pv
 create mode 100644 tests/series
README +14 -0
index b7832da..42c0f4d 100644
@@ -102,3 +102,17 @@ check-package
 
 If your component comes with additional data, maybe a config script or
 anything else, place it under "data".
+
+
+= Testing =
+
+Raisin can also be used for testing. Make sure to have Xen already up
+and running (raise build, raise install and host reboot).
+Ask Raisin to run tests like this:
+
+./raise test
+
+You can specify a subset of tests to run with ENABLED_TESTS in the
+config file, or the TESTS environmental variable:
+
+TESTS="busybox-pv" ./raise test
defconfig +5 -0
index b4ed94d..e88f3d3 100644
@@ -39,3 +39,8 @@ GRUB_REVISION="master"
 LIBVIRT_REVISION="master"
 OVMF_REVISION="master"
 LINUX_REVISION="master"
+
+# Tests
+## All tests: busybox-pv
+## ENABLED_TESTS is the list of test run by raise test
+ENABLED_TESTS="busybox-pv"
lib/commands.sh +4 -0
index 801341b..ffbadb4 100755
@@ -103,3 +103,7 @@ function configure() {
     for_each_component configure
 }
 
+function test() {
+    init_tests
+    run_tests
+}
lib/common-functions.sh +19 -0
index d38788b..2edb168 100644
@@ -39,6 +39,7 @@ function common_init() {
     get_distro
     get_arch
     get_components
+    get_tests
 
     verbose_echo "Distro: $DISTRO"
     verbose_echo "Arch: $RAISIN_ARCH"
@@ -73,6 +74,24 @@ function get_components() {
     export COMPONENTS
 }
 
+function get_tests() {
+    if [[ -z "$TESTS" ]]
+    then
+        TESTS="$ENABLED_TESTS"
+    fi
+
+    if [[ -z "$TESTS" ]] 
+    then
+        local t
+        for t in `cat "$BASEDIR"/tests/series`
+        do
+            TESTS="$TESTS $t"
+            verbose_echo "Found test $t"
+        done
+    fi
+    export TESTS
+}
+
 function get_distro() {
     if [[ -x "`which lsb_release 2>/dev/null`" ]]
     then
@@ -278,6 +297,61 @@ function for_each_component () {
     done

lib/common-functions.sh function for_each_component () { · line 307

Quoted 10 lines
lib/common-functions.sh +8 -0
 }
 
+function run_tests() {
+    local t
+    local enabled
+    local found
+
+    for t in `cat "$BASEDIR"/tests/series`
+    do
+        found=0

found=false

lib/common-functions.sh function for_each_component () { · line 312

Quoted 5 lines
lib/common-functions.sh +5 -0
+        for enabled in $TESTS
+        do
+            if [[ $enabled = $t ]]
+            then
+                found=1

found=true

lib/common-functions.sh function for_each_component () { · line 316

Quoted 4 lines
lib/common-functions.sh +4 -0
+                break
+            fi
+        done
+        if [[ $found -eq 0 ]]

if $found
;)

Quoted 12 lines
lib/common-functions.sh +12 -0
+        then
+            verbose_echo "$t" is disabled
+            continue
+        fi
+
+        verbose_echo running test "$t"
+        "$BASEDIR"/tests/$t
+        verbose_echo "test "$t" done"
+    done
+}
+
+function init_tests() {

lib/common-functions.sh function for_each_component () { · line 338

Quoted 10 lines
lib/common-functions.sh +10 -0
+    local -a missing
+
+    check-package bridge-utils
+    if [[ $DISTRO = "Debian" ]]
+    then
+        check-package busybox-static
+    elif [[ $DISTRO = "Fedora" ]]
+    then
+        check-package busybox grub2 which
+    else

Wouldn't it be easier to read with "case" instead of "if" ?

lib/common-functions.sh function for_each_component () { · line 342

Quoted 4 lines
lib/common-functions.sh +4 -0
+        echo "I don't know distro $DISTRO. It might be missing packages."
+    fi
+    
+    if [[ -n "${missing[@]}" ]]

missing looks empty to me.

Quoted 120 lines
lib/common-functions.sh +12 -0
+    then
+        verbose_echo "Installing ${missing[@]}"
+        install-package "${missing[@]}"
+    fi
+
+    if ! ifconfig xenbr1 &>/dev/null
+    then
+        $SUDO brctl addbr xenbr1
+        $SUDO ifconfig xenbr1 169.254.0.1 up
+    fi
+}
+
 function _build_package_deb() {
     fakeroot bash ./scripts/mkdeb "$1"
 }
lib/common-tests.sh new file +99 -0
new file mode 100644
index 0000000..be1c720
@@ -0,0 +1,112 @@
+#!/usr/bin/env bash
+
+source ${RAISIN_PATH}/common-functions.sh
+
+# $1 disk name
+# $2 disk size
+function allocate_disk() {
+    local disk
+    local size
+
+    disk=$1
+    size=$2
+
+    size=$((size+511))
+    size=$((size/512))
+
+    dd if=/dev/zero of=$disk bs=512 count=$size
+    sync
+}
+
+# $1 disk name
+# print loop device name
+function create_loop() {
+    local disk
+    local loop
+
+    disk=`readlink -f $1`
+
+    $SUDO losetup -f $disk
+    loop=`$SUDO losetup -a | grep $disk | cut -d : -f 1`
+    echo $loop
+}
+
+# $1 dev name
+function busybox_rootfs() {
+    local dev
+    local tmpdir
+
+    dev=$1
+
+    $SUDO mkfs.ext3 $dev
+
+    tmpdir=`mktemp -d`
+    $SUDO mount $dev $tmpdir
+    mkdir -p $tmpdir/bin
+    mkdir -p $tmpdir/sbin
+    mkdir -p $tmpdir/dev
+    mkdir -p $tmpdir/proc
+    mkdir -p $tmpdir/sys
+    mkdir -p $tmpdir/lib
+    mkdir -p $tmpdir/var
+    cp `which busybox` $tmpdir/bin
+    $tmpdir/bin/busybox --install $tmpdir/bin
+
+    $SUDO umount $tmpdir
+    rmdir $tmpdir
+}
+
+function busybox_network_init() {
+    local dev
+    local tmpdir
+
+    dev=$1
+    tmpdir=`mktemp -d`
+
+    $SUDO mount $dev $tmpdir
+    rm -f $tmpdir/bin/init
+    cat >$tmpdir/bin/init <<EOF
+#!/bin/sh
+mount -t proc proc /proc
+mount -t sysfs sysfs /sys
+ifconfig eth0 169.254.0.2 up
+/bin/sh
+EOF
+    chmod +x $tmpdir/bin/init
+
+    $SUDO umount $tmpdir
+    rmdir $tmpdir
+}
+
+function check_guest_alive() {
+    local i
+    i=0
+    while ! ping -c 1 169.254.0.2 &> /dev/null
+    do
+        sleep 1
+        i=$((i+1))
+        if [[ $i -gt 60 ]]
+        then
+            echo Timeout connecting to guest
+            return 1
+        fi
+    done
+    return 0
+}
+
+function get_host_kernel() {
+    echo "/boot/vmlinuz-`uname -r`"
+}

lib/common-tests.sh line 109

Quoted 10 lines
lib/common-tests.sh new file +10 -0
+
+function get_host_initrd() {
+    if [[ $DISTRO = "Debian" ]]
+    then
+        echo "/boot/initrd.img-`uname -r`"
+    elif [[ $DISTRO = "Fedora" ]]
+    then
+        echo "/boot/initramfs-`uname -r`".img
+    else
+        echo "I don't know how to find the initrd"

echo >&2 since it's an error message?

lib/common-tests.sh line 112

Quoted 3 lines
lib/common-tests.sh new file +3 -0
+        exit 1
+    fi
+}

Also, in general, it might be better to use quotes around variables in case an argument of a function is missing, or a path contain a space.

Signature · 1 line
Anthony PERARD
#3 lore raw
Quoted 130 lines · Anthony PERARD
Quoted 108 lines · Stefano Stabellini

Introduce a new command to run functional tests and unit tests. Introduce a generic infrastrucutre to run tests on the local machine. Add a library of common functions that can be used by the test scripts to setup guest VMs.

Add a simple test script that boots a single busybox based PV guest.

---
 README                  |   14 ++++++
 defconfig               |    5 +++
 lib/commands.sh         |    4 ++
 lib/common-functions.sh |   74 +++++++++++++++++++++++++++++++
 lib/common-tests.sh     |  112 +++++++++++++++++++++++++++++++++++++++++++++++
 raise                   |    8 ++--
 tests/busybox-pv        |   38 ++++++++++++++++
 tests/series            |    1 +
 8 files changed, 253 insertions(+), 3 deletions(-)
 create mode 100644 lib/common-tests.sh
 create mode 100755 tests/busybox-pv
 create mode 100644 tests/series
README +14 -0
index b7832da..42c0f4d 100644
@@ -102,3 +102,17 @@ check-package
 
 If your component comes with additional data, maybe a config script or
 anything else, place it under "data".
+
+
+= Testing =
+
+Raisin can also be used for testing. Make sure to have Xen already up
+and running (raise build, raise install and host reboot).
+Ask Raisin to run tests like this:
+
+./raise test
+
+You can specify a subset of tests to run with ENABLED_TESTS in the
+config file, or the TESTS environmental variable:
+
+TESTS="busybox-pv" ./raise test
defconfig +5 -0
index b4ed94d..e88f3d3 100644
@@ -39,3 +39,8 @@ GRUB_REVISION="master"
 LIBVIRT_REVISION="master"
 OVMF_REVISION="master"
 LINUX_REVISION="master"
+
+# Tests
+## All tests: busybox-pv
+## ENABLED_TESTS is the list of test run by raise test
+ENABLED_TESTS="busybox-pv"
lib/commands.sh +4 -0
index 801341b..ffbadb4 100755
@@ -103,3 +103,7 @@ function configure() {
     for_each_component configure
 }
 
+function test() {
+    init_tests
+    run_tests
+}
lib/common-functions.sh +19 -0
index d38788b..2edb168 100644
@@ -39,6 +39,7 @@ function common_init() {
     get_distro
     get_arch
     get_components
+    get_tests
 
     verbose_echo "Distro: $DISTRO"
     verbose_echo "Arch: $RAISIN_ARCH"
@@ -73,6 +74,24 @@ function get_components() {
     export COMPONENTS
 }
 
+function get_tests() {
+    if [[ -z "$TESTS" ]]
+    then
+        TESTS="$ENABLED_TESTS"
+    fi
+
+    if [[ -z "$TESTS" ]] 
+    then
+        local t
+        for t in `cat "$BASEDIR"/tests/series`
+        do
+            TESTS="$TESTS $t"
+            verbose_echo "Found test $t"
+        done
+    fi
+    export TESTS
+}
+
 function get_distro() {
     if [[ -x "`which lsb_release 2>/dev/null`" ]]
     then
@@ -278,6 +297,61 @@ function for_each_component () {
     done

lib/common-functions.sh function for_each_component () { · line 307

Quoted 10 lines
lib/common-functions.sh +8 -0
 }
 
+function run_tests() {
+    local t
+    local enabled
+    local found
+
+    for t in `cat "$BASEDIR"/tests/series`
+    do
+        found=0

found=false

lib/common-functions.sh function for_each_component () { · line 312

Quoted 5 lines
lib/common-functions.sh +5 -0
+        for enabled in $TESTS
+        do
+            if [[ $enabled = $t ]]
+            then
+                found=1

found=true

Quoted 7 lines

lib/common-functions.sh function for_each_component () { · line 316

Quoted 4 lines
lib/common-functions.sh +4 -0
+                break
+            fi
+        done
+        if [[ $found -eq 0 ]]

if $found
;)

good suggestion, I'll make the change

Quoted 16 lines
Quoted 16 lines
lib/common-functions.sh +16 -0
+        then
+            verbose_echo "$t" is disabled
+            continue
+        fi
+
+        verbose_echo running test "$t"
+        "$BASEDIR"/tests/$t
+        verbose_echo "test "$t" done"
+    done
+}
+
+function init_tests() {
+    local -a missing
+
+    check-package bridge-utils
+    if [[ $DISTRO = "Debian" ]]
Quoted 8 lines

lib/common-functions.sh function for_each_component () { · line 338

Quoted 6 lines
lib/common-functions.sh +6 -0
+    then
+        check-package busybox-static
+    elif [[ $DISTRO = "Fedora" ]]
+    then
+        check-package busybox grub2 which
+    else

Wouldn't it be easier to read with "case" instead of "if" ?

Maybe, I don't really have a preference, but we have the same pair of ifs in many other places.

Quoted 6 lines

lib/common-functions.sh function for_each_component () { · line 342

Quoted 4 lines
lib/common-functions.sh +4 -0
+        echo "I don't know distro $DISTRO. It might be missing packages."
+    fi
+    
+    if [[ -n "${missing[@]}" ]]

missing looks empty to me.

It is filled by the check-package calls above

Quoted 124 lines
Quoted 124 lines
lib/common-functions.sh +12 -0
+    then
+        verbose_echo "Installing ${missing[@]}"
+        install-package "${missing[@]}"
+    fi
+
+    if ! ifconfig xenbr1 &>/dev/null
+    then
+        $SUDO brctl addbr xenbr1
+        $SUDO ifconfig xenbr1 169.254.0.1 up
+    fi
+}
+
 function _build_package_deb() {
     fakeroot bash ./scripts/mkdeb "$1"
 }
lib/common-tests.sh new file +103 -0
new file mode 100644
index 0000000..be1c720
@@ -0,0 +1,112 @@
+#!/usr/bin/env bash
+
+source ${RAISIN_PATH}/common-functions.sh
+
+# $1 disk name
+# $2 disk size
+function allocate_disk() {
+    local disk
+    local size
+
+    disk=$1
+    size=$2
+
+    size=$((size+511))
+    size=$((size/512))
+
+    dd if=/dev/zero of=$disk bs=512 count=$size
+    sync
+}
+
+# $1 disk name
+# print loop device name
+function create_loop() {
+    local disk
+    local loop
+
+    disk=`readlink -f $1`
+
+    $SUDO losetup -f $disk
+    loop=`$SUDO losetup -a | grep $disk | cut -d : -f 1`
+    echo $loop
+}
+
+# $1 dev name
+function busybox_rootfs() {
+    local dev
+    local tmpdir
+
+    dev=$1
+
+    $SUDO mkfs.ext3 $dev
+
+    tmpdir=`mktemp -d`
+    $SUDO mount $dev $tmpdir
+    mkdir -p $tmpdir/bin
+    mkdir -p $tmpdir/sbin
+    mkdir -p $tmpdir/dev
+    mkdir -p $tmpdir/proc
+    mkdir -p $tmpdir/sys
+    mkdir -p $tmpdir/lib
+    mkdir -p $tmpdir/var
+    cp `which busybox` $tmpdir/bin
+    $tmpdir/bin/busybox --install $tmpdir/bin
+
+    $SUDO umount $tmpdir
+    rmdir $tmpdir
+}
+
+function busybox_network_init() {
+    local dev
+    local tmpdir
+
+    dev=$1
+    tmpdir=`mktemp -d`
+
+    $SUDO mount $dev $tmpdir
+    rm -f $tmpdir/bin/init
+    cat >$tmpdir/bin/init <<EOF
+#!/bin/sh
+mount -t proc proc /proc
+mount -t sysfs sysfs /sys
+ifconfig eth0 169.254.0.2 up
+/bin/sh
+EOF
+    chmod +x $tmpdir/bin/init
+
+    $SUDO umount $tmpdir
+    rmdir $tmpdir
+}
+
+function check_guest_alive() {
+    local i
+    i=0
+    while ! ping -c 1 169.254.0.2 &> /dev/null
+    do
+        sleep 1
+        i=$((i+1))
+        if [[ $i -gt 60 ]]
+        then
+            echo Timeout connecting to guest
+            return 1
+        fi
+    done
+    return 0
+}
+
+function get_host_kernel() {
+    echo "/boot/vmlinuz-`uname -r`"
+}
+
+function get_host_initrd() {
+    if [[ $DISTRO = "Debian" ]]
+    then
Quoted 8 lines

lib/common-tests.sh line 109

Quoted 6 lines
lib/common-tests.sh new file +6 -0
+        echo "/boot/initrd.img-`uname -r`"
+    elif [[ $DISTRO = "Fedora" ]]
+    then
+        echo "/boot/initramfs-`uname -r`".img
+    else
+        echo "I don't know how to find the initrd"

echo >&2 since it's an error message?

Good point

Quoted 6 lines

lib/common-tests.sh line 112

Quoted 3 lines
lib/common-tests.sh new file +3 -0
+        exit 1
+    fi
+}

Also, in general, it might be better to use quotes around variables in case an argument of a function is missing, or a path contain a space.

Yes, you are right. I am trying to avoid quotes only on variables we know must be populated, see README for a list. DISTRO is one of them.

#4 lore raw

PATCH 2/3 raisin: add an hvm test

In reply to Stefano Stabellini

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.

---
 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
defconfig +2 -2
index e88f3d3..664aee6 100644
@@ -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"
lib/common-tests.sh +62 -0

74 lines not on this page · raw message

scripts/lopartsetup new file +67 -0

67 lines not on this page · raw message

tests/busybox-hvm new file +44 -0

44 lines not on this page · raw message

tests/series +1 -0
index a5ec626..1f5f5c6 100644
@@ -1 +1,2 @@
 busybox-pv
+busybox-hvm
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 3/3 raisin: improve output

In reply to Stefano Stabellini

Introduce an error_echo function that prints to stderr. Call error_echo or verbose_echo, instead of echo, when possible and appropriate.
Redirect build and tests output to /dev/null unless VERBOSE==1. Redirect apt-get and yum output to /dev/null.
Fix echo arguments in check-package-deb.

---
 components/grub             |    4 +--
 components/libvirt          |    4 +--
 components/linux            |    2 +-
 components/ovmf             |    6 ++--
 components/qemu             |    2 +-
 components/qemu_traditional |    2 +-
 components/seabios          |    6 ++--
 components/xen              |    8 ++---
 lib/commands.sh             |   18 +++++------
 lib/common-functions.sh     |   72 ++++++++++++++++++++++++++++++-------------
 lib/common-tests.sh         |    6 ++--
 tests/busybox-hvm           |    2 +-
 12 files changed, 80 insertions(+), 52 deletions(-)
components/grub +2 -2
index fa72b99..3bb5254 100644
@@ -19,10 +19,10 @@ function grub_check_package() {
 
     if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]]
     then
-        echo grub is only supported on x86_32 and x86_64
+        verbose_echo grub is only supported on x86_32 and x86_64
         return
     fi
-    echo Checking Grub dependencies
+    verbose_echo Checking Grub dependencies
     eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
 }
 
components/libvirt +2 -2
index a554643..20405ae 100644
@@ -22,7 +22,7 @@ function libvirt_check_package() {
     local DEP_CentOS_x86_32="$DEP_Fedora_x86_32"
     local DEP_CentOS_x86_64="$DEP_Fedora_x86_64"
 
-    echo Checking Libvirt dependencies
+    verbose_echo Checking Libvirt dependencies
     eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
 }
 
@@ -52,7 +52,7 @@ function libvirt_build() {
         cp daemon/libvirtd.init "$INST_DIR"/etc/rc.d/init.d/libvirtd
         chmod +x "$INST_DIR"/etc/rc.d/init.d/libvirtd
     else
-        echo "I don't know how write an init script for Libvirt on $DISTRO"
+        error_echo "I don't know how write an init script for Libvirt on $DISTRO"
     fi
     cd ..
 }
components/linux +1 -1
index f90a894..9ae6955 100644
@@ -15,7 +15,7 @@ function linux_check_package() {
     local DEP_CentOS_x86_32="$DEP_Fedora_x86_32"
     local DEP_CentOS_x86_64="$DEP_Fedora_x86_64"
 
-    echo Checking Linux dependencies
+    verbose_echo Checking Linux dependencies
     eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
 }
 
components/ovmf +3 -3
index a59a771..387044a 100644
@@ -14,10 +14,10 @@ function ovmf_check_package() {
 
     if [[ $RAISIN_ARCH != "x86_64" ]]
     then
-        echo ovmf is only supported on x86_64
+        verbose_echo ovmf is only supported on x86_64
         return
     fi
-    echo Checking OVMF dependencies
+    verbose_echo Checking OVMF dependencies
     eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
 }
 
@@ -25,7 +25,7 @@ function ovmf_check_package() {
 function ovmf_build() {
     if [[ $RAISIN_ARCH != "x86_64" ]]
     then
-        echo ovmf is only supported on x86_64
+        verbose_echo ovmf is only supported on x86_64
         return
     fi
 
components/qemu +1 -1
index 72cfec1..dce4ce0 100644
@@ -11,7 +11,7 @@ function qemu_check_package() {
     local DEP_Fedora_x86_32="$DEP_Fedora_common"
     local DEP_Fedora_x86_64="$DEP_Fedora_common"
 
-    echo Checking QEMU dependencies
+    verbose_echo Checking QEMU dependencies
     eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
 }
 
components/qemu_traditional +1 -1
index b338007..a9609b1 100644
@@ -12,7 +12,7 @@ function qemu_traditional_check_package() {
     local DEP_Fedora_x86_32="$DEP_Fedora_common"
     local DEP_Fedora_x86_64="$DEP_Fedora_common"
 
-    echo Checking QEMU dependencies
+    verbose_echo Checking QEMU dependencies
     eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
 }
 
components/seabios +3 -3
index ed2c7d2..8fea193 100644
@@ -14,10 +14,10 @@ function seabios_check_package() {
 
     if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]]
     then
-        echo seabios is only supported on x86_32 and x86_64
+        verbose_echo seabios is only supported on x86_32 and x86_64
         return
     fi
-    echo Checking SeaBIOS dependencies
+    verbose_echo Checking SeaBIOS dependencies
     eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
 }
 
@@ -25,7 +25,7 @@ function seabios_check_package() {
 function seabios_build() {
     if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]]
     then
-        echo seabios is only supported on x86_32 and x86_64
+        verbose_echo seabios is only supported on x86_32 and x86_64
         return
     fi
 
components/xen +4 -4
index add8136..6b700e5 100644
@@ -19,7 +19,7 @@ function xen_check_package() {
     local DEP_CentOS_x86_32="$DEP_CentOS_common dev86 texinfo iasl"
     local DEP_CentOS_x86_64="$DEP_CentOS_x86_32 glibc-devel.i686"
 
-    echo Checking Xen dependencies
+    verbose_echo Checking Xen dependencies
     eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
 }
 
@@ -62,13 +62,13 @@ function _xen_create_bridge_Debian() {
 
     if [[ -z "$IFACE" ]]
     then
-        echo "Please refer to the following page to setup networking:"
-        echo "http://wiki.xenproject.org/wiki/Network_Configuration_Examples_(Xen_4.1%2B)"
+        error_echo "Please refer to the following page to setup networking:"
+        error_echo "http://wiki.xenproject.org/wiki/Network_Configuration_Examples_(Xen_4.1%2B)"
         return 1
     fi
     if [[ "`grep $BRIDGE /etc/network/interfaces`" ]]
     then
-        echo "a network bridge seems to be already setup"
+        verbose_echo "a network bridge seems to be already setup"
         return 0
     fi
 
lib/commands.sh +9 -9
index ffbadb4..a79611e 100755
@@ -17,29 +17,29 @@ function check-builddep() {
 
     if [[ -n "${missing[@]}" ]]
     then
-        echo "Missing packages: ${missing[@]}"
+        echo "$PREPEND Missing packages: ${missing[@]}"
         if [[ "$YES" = "n" ]]
         then
             return
         elif [[ "$YES" != "y" ]]
         then
-            echo "Do you want Raisin to automatically install them for you? (y/n)"
+            echo "$PREPEND Do you want Raisin to automatically install them for you? (y/n)"
             while read answer
             do
                 if [[ "$answer" = "n" ]]
                 then
-                    echo "Please install, or run ./raise install-builddep"
+                    echo "$PREPEND Please install, or run ./raise install-builddep"
                     exit 1
                 elif [[ "$answer" = "y" ]]
                 then
                     break
                 else
-                    echo "Reply y or n"
+                    echo "$PREPEND Reply y or n"
                 fi
             done
         fi
 
-        echo "Installing..."
+        echo "$PREPEND Installing..."
         install-package "${missing[@]}"
     fi
 }
@@ -72,7 +72,7 @@ function install() {
     # need single braces for filename matching expansion
     if [ ! -f xen-sytem*rpm ] && [ ! -f xen-system*deb ]
     then
-        echo You need to raise build first.
+        error_echo You need to raise build first.
         exit 1
     fi
     install_package xen-system
@@ -84,8 +84,8 @@ function configure() {
         return
     elif [[ "$YES" != "y" ]]
     then
-        echo "Proceeding we'll make changes to the running system,"
-        echo "are you sure that you want to continue? (y/n)"
+        echo "$PREPEND Proceeding we'll make changes to the running system,"
+        echo "$PREPEND are you sure that you want to continue? (y/n)"
         while read answer
         do
             if [[ "$answer" = "n" ]]
@@ -95,7 +95,7 @@ function configure() {
             then
                 break
             else
-                echo "Reply y or n"
+                echo "$PREPEND Reply y or n"
             fi
         done
     fi
lib/common-functions.sh +50 -22

172 lines not on this page · raw message

lib/common-tests.sh +3 -3
index aa1daa4..02bca1c 100644
@@ -133,7 +133,7 @@ EOF
             --grub-mkdevicemap=$tmpdir/boot/grub/device.map \
             --root-directory=$tmpdir $dev
     else
-        echo "I don't know how to install grub on $DISTRO"
+        echo "$PREPEND I don't know how to install grub on $DISTRO"
     fi
 
     $SUDO umount $tmpdir
@@ -149,7 +149,7 @@ function check_guest_alive() {
         i=$((i+1))
         if [[ $i -gt 60 ]]
         then
-            echo Timeout connecting to guest
+            echo $PREPEND Timeout connecting to guest
             return 1
         fi
     done
@@ -168,7 +168,7 @@ function get_host_initrd() {
     then
         echo "/boot/initramfs-`uname -r`".img
     else
-        echo "I don't know how to find the initrd"
+        echo "$PREPEND I don't know how to find the initrd"
         exit 1
     fi
 }
tests/busybox-hvm +1 -1
index b97ae34..c8024e5 100755
@@ -14,7 +14,7 @@ function cleanup() {
 
 if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]]
 then
-    echo busybox hvm test only valid on x86
+    echo $PREPEND busybox hvm test only valid on x86
     exit 0
 fi
 
Signature · 1 line
1.7.10.4
#6 lore raw

Re: [PATCH 3/3] raisin: improve output

Quoted 23 lines · Stefano Stabellini

Introduce an error_echo function that prints to stderr. Call error_echo or verbose_echo, instead of echo, when possible and appropriate.
Redirect build and tests output to /dev/null unless VERBOSE==1. Redirect apt-get and yum output to /dev/null.
Fix echo arguments in check-package-deb.

---
 components/grub             |    4 +--
 components/libvirt          |    4 +--
 components/linux            |    2 +-
 components/ovmf             |    6 ++--
 components/qemu             |    2 +-
 components/qemu_traditional |    2 +-
 components/seabios          |    6 ++--
 components/xen              |    8 ++---
 lib/commands.sh             |   18 +++++------
 lib/common-functions.sh     |   72 ++++++++++++++++++++++++++++++-------------
 lib/common-tests.sh         |    6 ++--
 tests/busybox-hvm           |    2 +-
 12 files changed, 80 insertions(+), 52 deletions(-)

[...]

Quoted 5 lines
lib/common-functions.sh +0 -0
index 2edb168..f293ff4 100644

lib/common-functions.sh line 11

Quoted 10 lines
lib/common-functions.sh +3 -1
@@ -3,10 +3,14 @@
 function verbose_echo() {
     if [[ $VERBOSE -eq 1 ]]
     then
-        echo $*
+        echo "$PREPEND" $*
     fi
 }
 
+function error_echo() {
+    echo "$PREPEND" $* >&2

I think using "$@" (with the quote) instead of $* would be better. The quotes will keep any space that you want to echo and using $@ instead of $* will keep parameters separated. So calling error_echo would have the same beavior as calling echo (well almost).

Same thing for verbose_echo.

Quoted 2 lines
lib/common-functions.sh +2 -0
+}
+
Signature · 1 line
Anthony PERARD
#7 lore raw

Re: [PATCH 3/3] raisin: improve output

Quoted 48 lines · Anthony PERARD
Quoted 23 lines · Stefano Stabellini

Introduce an error_echo function that prints to stderr. Call error_echo or verbose_echo, instead of echo, when possible and appropriate.
Redirect build and tests output to /dev/null unless VERBOSE==1. Redirect apt-get and yum output to /dev/null.
Fix echo arguments in check-package-deb.

---
 components/grub             |    4 +--
 components/libvirt          |    4 +--
 components/linux            |    2 +-
 components/ovmf             |    6 ++--
 components/qemu             |    2 +-
 components/qemu_traditional |    2 +-
 components/seabios          |    6 ++--
 components/xen              |    8 ++---
 lib/commands.sh             |   18 +++++------
 lib/common-functions.sh     |   72 ++++++++++++++++++++++++++++++-------------
 lib/common-tests.sh         |    6 ++--
 tests/busybox-hvm           |    2 +-
 12 files changed, 80 insertions(+), 52 deletions(-)

[...]

Quoted 5 lines
lib/common-functions.sh +0 -0
index 2edb168..f293ff4 100644

lib/common-functions.sh line 11

Quoted 10 lines
lib/common-functions.sh +3 -1
@@ -3,10 +3,14 @@
 function verbose_echo() {
     if [[ $VERBOSE -eq 1 ]]
     then
-        echo $*
+        echo "$PREPEND" $*
     fi
 }
 
+function error_echo() {
+    echo "$PREPEND" $* >&2

I think using "$@" (with the quote) instead of $* would be better. The quotes will keep any space that you want to echo and using $@ instead of $* will keep parameters separated. So calling error_echo would have the same beavior as calling echo (well almost).

Quoted 1 line

Same thing for verbose_echo.

You are right, good suggestion.