From 8db3a012ea1afe89a81a68cb18cb7bcafd194142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Thu, 10 Apr 2014 11:39:38 +0100 Subject: new: add qemu-system-test definition and expect scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As we need to send commands to the qemu console to shutdown cleanly and it is a pain to custom build a rootfs to just run a test we use an expect wrapper for controlling qemu. The whole thing is controlled by a wrapper so several TESTS can be run in one definition and the results kept together. Signed-off-by: Alex Bennée Change-Id: I82ae7305ce2cdd8d3cef05621f4e4eace7d35bb7 -- v2 - fix boot test message v3 - include the IMAGE name in the test result - add wget dep v4 - more updates --- ubuntu/qemu-system-test.yaml | 39 +++++++++++++++++++++++++++++++++++++ ubuntu/scripts/qemu-boot.expect | 29 +++++++++++++++++++++++++++ ubuntu/scripts/qemu-stress.expect | 38 ++++++++++++++++++++++++++++++++++++ ubuntu/scripts/qemu-system-tests.sh | 31 +++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 ubuntu/qemu-system-test.yaml create mode 100755 ubuntu/scripts/qemu-boot.expect create mode 100755 ubuntu/scripts/qemu-stress.expect create mode 100755 ubuntu/scripts/qemu-system-tests.sh (limited to 'ubuntu') diff --git a/ubuntu/qemu-system-test.yaml b/ubuntu/qemu-system-test.yaml new file mode 100644 index 0000000..f2afedd --- /dev/null +++ b/ubuntu/qemu-system-test.yaml @@ -0,0 +1,39 @@ +metadata: + name: qemu-system-test + format: "Lava-Test-Shell Test Definition 1.0" + description: "Setup and run a test on QEMU System Image" + maintainer: + - alex.bennee@linaro.org + os: + - ubuntu + scope: + - functional + devices: + - kvm + +params: + # This is a combined image and initrd/rootfs that qemu can boot + IMAGE: http://people.linaro.org/~alex.bennee/images/aarch64-linux-buildroot.img + # List of tests to run + TESTS: boot + # The QEMU executable + QEMU_BIN: /usr/local/bin/qemu-system-aarch64 + # The QEMU machine definitions + QEMU_MACHINE: virt + QEMU_ARGS: -cpu cortex-a57 -nographic -smp 1 -m 396 + # The arguments passed to the kernel + KERNEL_ARGS: console=ttyAMA0 + +install: + steps: + - cd /home + - wget -O image ${IMAGE} + + deps: + - wget + - expect + +run: + steps: + - export QEMU_BIN QEMU_MACHINE QEMU_ARGS KERNEL_ARGS IMAGE + - ubuntu/scripts/qemu-system-tests.sh ${TESTS} diff --git a/ubuntu/scripts/qemu-boot.expect b/ubuntu/scripts/qemu-boot.expect new file mode 100755 index 0000000..ad8cb13 --- /dev/null +++ b/ubuntu/scripts/qemu-boot.expect @@ -0,0 +1,29 @@ +#!/usr/bin/expect -- +# +# Run qemu-system and check we can boot and shutdown +# + +if {[llength $argv] == 0} { + send_user "Usage: boot.expect \n" + exit 1 +} + +set timeout 20 +spawn {*}$argv +expect { + "buildroot login: " { send -- "root\r" } + timeout { send "# boot failed"; exit 1 } +} + + +expect "# " +send -- "uname -a\r" +expect "# " +set timeout 10 +send -- "halt -d 5\r" +expect { + "reboot: System halted" { send -- "c"; expect "(qemu) "; send -- "quit\r" } + timeout { send "# shutdown failed"; exit 2 } +} +expect eof +exit 0 diff --git a/ubuntu/scripts/qemu-stress.expect b/ubuntu/scripts/qemu-stress.expect new file mode 100755 index 0000000..fdab3a2 --- /dev/null +++ b/ubuntu/scripts/qemu-stress.expect @@ -0,0 +1,38 @@ +#!/usr/bin/expect -- +# +# Run qemu-system and spawn the stress benchmark +# + +if {[llength $argv] == 0} { + send_user "Usage: stress.expect \n" + exit 1 +} + +set exit_status 0 +set timeout 20 +spawn {*}$argv +expect "buildroot login: " +send -- "root\r" +expect "# " +set timeout 40 +send -- "stress --cpu 4 --io 4 --vm 2 --vm-bytes 64M -d 2 --hdd-bytes 32M --timeout 30s\r" +expect { + "successful run completed in *s" { expect "# "; send "# found success\n" } + timeout { send "# time waiting for stress to finish\n"; set exit_status 1 } +} +expect "# " +set timeout 10 +send -- "echo \$?\r" +expect { + "0\r\r" { send "# found success\n" } + "1\r\r" { send "# found failure\n"; set exit_status 2 } + timeout { send "# time out looking for result\n"; set exit_status 3 } +} +expect "# " +send -- "halt -d 5\r" +expect "reboot: System halted" +send -- "c" +expect "(qemu) " +send -- "quit\r" +expect eof +exit $exit_status diff --git a/ubuntu/scripts/qemu-system-tests.sh b/ubuntu/scripts/qemu-system-tests.sh new file mode 100755 index 0000000..b681699 --- /dev/null +++ b/ubuntu/scripts/qemu-system-tests.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# A simple wrapper to run a series of expect based system tests +# +# This expects the follow environment variables to be set: +# QEMU_BIN - path to binary +# QEMU_ARGS - arguments to run +# QEMU_MACHINE - machine type +# KERNEL_ARGS - arguments to kernel +# IMAGE - URL to image +# +# It expects the system test image to be in /home/image +# +# The expect script that will control QEMU, prefix will be qemu- and suffix .expect +# + +pushd `dirname $0` > /dev/null +BASE=`pwd -P` +popd > /dev/null + +IMAGE_FILE=${IMAGE##*/} +IMAGE_NAME=${IMAGE_FILE%.*} + +: ${KERNEL_IMAGE}=/home/image + +for test in $@; do + lava-test-case qemu-${test}-${QEMU_MACHINE}-${IMAGE_NAME} \ + --shell ${BASE}/qemu-${test}.expect ${QEMU_BIN} ${QEMU_ARGS} -machine type=${QEMU_MACHINE} \ + -kernel ${KERNEL_IMAGE} -append "${KERNEL_ARGS}" +done + -- cgit v1.2.3