From e1920b4f221c42ebcf3335a855a8024eadf41617 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Fri, 19 May 2017 11:34:19 +0100 Subject: [PATCH] tests: Add a test for running qemu in a container The qemu backend defaults to running against a locally installed qemu but falls back to running in a container if qemu is not installed. This test explicitly tests that the containerised qemu backend works only if there is a locally installed qemu. Signed-off-by: Rolf Neugebauer --- .../000_qemu/100_container/test.sh | 35 +++++++++++++++++++ .../000_qemu/100_container/test.yml | 16 +++++++++ 2 files changed, 51 insertions(+) create mode 100644 test/cases/010_platforms/000_qemu/100_container/test.sh create mode 100644 test/cases/010_platforms/000_qemu/100_container/test.yml diff --git a/test/cases/010_platforms/000_qemu/100_container/test.sh b/test/cases/010_platforms/000_qemu/100_container/test.sh new file mode 100644 index 000000000..dc2c091cf --- /dev/null +++ b/test/cases/010_platforms/000_qemu/100_container/test.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# SUMMARY: Check that qemu runs containerised +# LABELS: +# AUTHOR: Rolf Neugebauer + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +NAME=qemu-kernel + +clean_up() { + # remove any files, containers, images etc + rm -rf ${NAME}* || true +} + +trap clean_up EXIT + +# check if qemu is installed locally +QEMU=$(command -v qemu-system-x86_64 || true) +if [ -z "${QEMU}" ]; then + # No qemu installed so don't bother to test as all the other + # qemu tests would have been run containerised + echo "No locally installed qemu" + exit $RT_CANCEL +fi + +moby build -name "${NAME}" test.yml +[ -f "${NAME}-kernel" ] || exit 1 +[ -f "${NAME}-initrd.img" ] || exit 1 +[ -f "${NAME}-cmdline" ]|| exit 1 +linuxkit run qemu -containerized "${NAME}" | grep -q "Welcome to LinuxKit" +exit 0 diff --git a/test/cases/010_platforms/000_qemu/100_container/test.yml b/test/cases/010_platforms/000_qemu/100_container/test.yml new file mode 100644 index 000000000..5f5a5da05 --- /dev/null +++ b/test/cases/010_platforms/000_qemu/100_container/test.yml @@ -0,0 +1,16 @@ +kernel: + image: "linuxkit/kernel:4.9.x" + cmdline: "console=ttyS0 console=tty0 page_poison=1" +init: + - linuxkit/init:cbd7ae748f0a082516501a3e914fa0c924ee941e + - linuxkit/runc:24dfe632ed3ff53a026ee3fac046fd544434e2d6 + - linuxkit/containerd:f1130450206d4f64f0ddc13d15bb68435aa1ff61 +onboot: + - name: poweroff + image: "linuxkit/poweroff:a8f1e4ad8d459f1fdaad9e4b007512cb3b504ae8" + command: ["/bin/sh", "/poweroff.sh", "3"] +trust: + image: + - linuxkit/kernel +outputs: + - format: kernel+initrd