From ce2bdea399db11af0fedd6755eaa59deea88fbfb Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 2 May 2017 09:57:34 +0100 Subject: [PATCH] =?UTF-8?q?Add=20a=20test=20suite=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds a test suite to be executed using `linuxkit/rtf`. This is installed in the top-level Makefile The tests are written in shell script and cover the following cases: - Kernel Config is OK! - Kernel Modules can be built and loaded - QEMU can build and run kernel+initrd, iso-bios and iso-uefi - That we can build for all other supported output formats - That all of the examples in `./examples` can be built - The LTP tests can be run (if `-l slow` is provided) The virtsock and docker-bench tests were migrated but no test has been written as yet as AFAICT they are still a WIP Signed-off-by: Dave Tucker --- .gitignore | 2 +- Makefile | 12 +++- README.md | 29 ++++++++- test/.gitignore | 2 + test/Makefile | 65 +++++++------------ test/README.md | 19 ++++++ .../000_kernel}/test-kernel-config.yml | 4 -- test/cases/000_config/000_kernel/test.sh | 23 +++++++ .../000_config/010_kmod}/Dockerfile | 0 .../000_config/010_kmod}/check.sh | 0 .../000_config/010_kmod}/kmod.yml | 7 ++ .../000_config/010_kmod}/src/Makefile | 0 .../000_config/010_kmod}/src/hello_world.c | 0 test/cases/000_config/010_kmod/test.sh | 28 ++++++++ test/cases/000_config/group.sh | 37 +++++++++++ .../010_platforms/000_qemu/000_build/test.sh | 28 ++++++++ .../010_platforms/000_qemu/000_build/test.yml | 31 +++++++++ .../010_platforms/000_qemu/001_run/test.sh | 24 +++++++ .../000_qemu/010_build_iso/test.sh | 26 ++++++++ .../000_qemu/010_build_iso/test.yml | 31 +++++++++ .../000_qemu/011_run_iso/test.sh | 24 +++++++ .../000_qemu/020_build_efi/test.sh | 25 +++++++ .../000_qemu/020_build_efi/test.yml | 31 +++++++++ .../000_qemu/021_run_efi/test.sh | 31 +++++++++ test/cases/010_platforms/000_qemu/group.sh | 35 ++++++++++ .../cases/010_platforms/001_hyperkit/group.sh | 37 +++++++++++ .../010_platforms/010_gcp/000_build/test.sh | 27 ++++++++ .../010_platforms/010_gcp/000_build/test.yml | 34 ++++++++++ .../010_platforms/010_gcp/001_run/test.sh | 24 +++++++ test/cases/010_platforms/010_gcp/group.sh | 37 +++++++++++ .../020_packet/000_build/test.sh | 27 ++++++++ .../020_packet/000_build/test.yml | 31 +++++++++ test/cases/010_platforms/020_packet/group.sh | 37 +++++++++++ .../030_vmware/000_build/test.sh | 27 ++++++++ .../030_vmware/000_build/test.yml | 31 +++++++++ test/cases/010_platforms/group.sh | 37 +++++++++++ .../{ => 020_stress/000_ltp}/test-ltp.yml | 4 -- test/cases/020_stress/000_ltp/test.sh | 24 +++++++ .../010_virtsock}/test-virtsock-server.yml | 0 test/cases/020_stress/010_virtsock/test.sh | 4 ++ test/cases/020_stress/group.sh | 37 +++++++++++ .../000_docker-bench}/test-docker-bench.yml | 0 .../030_security/000_docker-bench/test.sh | 4 ++ test/cases/030_security/group.sh | 37 +++++++++++ test/cases/100_examples/000_minimal/test.sh | 25 +++++++ test/cases/100_examples/010_docker/test.sh | 25 +++++++ test/cases/100_examples/020_sshd/test.sh | 25 +++++++ test/cases/100_examples/030_redis/test.sh | 25 +++++++ test/cases/100_examples/040_swap/test.sh | 25 +++++++ .../100_examples/050_node_exporter/test.sh | 25 +++++++ test/cases/_lib/lib.sh | 15 +++++ test/cases/group.sh | 41 ++++++++++++ test/kmod/run_test.sh | 10 --- 53 files changed, 1123 insertions(+), 66 deletions(-) create mode 100644 test/.gitignore create mode 100644 test/README.md rename test/cases/{ => 000_config/000_kernel}/test-kernel-config.yml (93%) create mode 100644 test/cases/000_config/000_kernel/test.sh rename test/{kmod => cases/000_config/010_kmod}/Dockerfile (100%) rename test/{kmod => cases/000_config/010_kmod}/check.sh (100%) rename test/{kmod => cases/000_config/010_kmod}/kmod.yml (67%) rename test/{kmod => cases/000_config/010_kmod}/src/Makefile (100%) rename test/{kmod => cases/000_config/010_kmod}/src/hello_world.c (100%) create mode 100644 test/cases/000_config/010_kmod/test.sh create mode 100644 test/cases/000_config/group.sh create mode 100644 test/cases/010_platforms/000_qemu/000_build/test.sh create mode 100644 test/cases/010_platforms/000_qemu/000_build/test.yml create mode 100644 test/cases/010_platforms/000_qemu/001_run/test.sh create mode 100644 test/cases/010_platforms/000_qemu/010_build_iso/test.sh create mode 100644 test/cases/010_platforms/000_qemu/010_build_iso/test.yml create mode 100644 test/cases/010_platforms/000_qemu/011_run_iso/test.sh create mode 100644 test/cases/010_platforms/000_qemu/020_build_efi/test.sh create mode 100644 test/cases/010_platforms/000_qemu/020_build_efi/test.yml create mode 100644 test/cases/010_platforms/000_qemu/021_run_efi/test.sh create mode 100644 test/cases/010_platforms/000_qemu/group.sh create mode 100644 test/cases/010_platforms/001_hyperkit/group.sh create mode 100644 test/cases/010_platforms/010_gcp/000_build/test.sh create mode 100644 test/cases/010_platforms/010_gcp/000_build/test.yml create mode 100644 test/cases/010_platforms/010_gcp/001_run/test.sh create mode 100644 test/cases/010_platforms/010_gcp/group.sh create mode 100644 test/cases/010_platforms/020_packet/000_build/test.sh create mode 100644 test/cases/010_platforms/020_packet/000_build/test.yml create mode 100644 test/cases/010_platforms/020_packet/group.sh create mode 100644 test/cases/010_platforms/030_vmware/000_build/test.sh create mode 100644 test/cases/010_platforms/030_vmware/000_build/test.yml create mode 100644 test/cases/010_platforms/group.sh rename test/cases/{ => 020_stress/000_ltp}/test-ltp.yml (91%) create mode 100644 test/cases/020_stress/000_ltp/test.sh rename test/cases/{ => 020_stress/010_virtsock}/test-virtsock-server.yml (100%) create mode 100644 test/cases/020_stress/010_virtsock/test.sh create mode 100644 test/cases/020_stress/group.sh rename test/cases/{ => 030_security/000_docker-bench}/test-docker-bench.yml (100%) create mode 100644 test/cases/030_security/000_docker-bench/test.sh create mode 100644 test/cases/030_security/group.sh create mode 100644 test/cases/100_examples/000_minimal/test.sh create mode 100644 test/cases/100_examples/010_docker/test.sh create mode 100644 test/cases/100_examples/020_sshd/test.sh create mode 100644 test/cases/100_examples/030_redis/test.sh create mode 100644 test/cases/100_examples/040_swap/test.sh create mode 100644 test/cases/100_examples/050_node_exporter/test.sh create mode 100644 test/cases/_lib/lib.sh create mode 100644 test/cases/group.sh delete mode 100755 test/kmod/run_test.sh diff --git a/.gitignore b/.gitignore index 65c8f4530..4346282c1 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,6 @@ Dockerfile.media *.vhdx *.efi *.qcow2 -*-kernel +*-kernel$ *-cmdline artifacts/* diff --git a/Makefile b/Makefile index 1362f365b..85232dfec 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .PHONY: default all -default: bin/moby bin/linuxkit +default: bin/moby bin/linuxkit bin/rtf all: default VERSION="0.0" # dummy for now @@ -24,6 +24,15 @@ bin/moby: | bin rm tmp_moby_bin.tar touch $@ +RTF_COMMIT=3ced00340aacfc1932e8c03281bf3bfc586c147c +RTF_CMD=github.com/linuxkit/rtf/cmd +bin/rtf: | bin + docker run --rm --log-driver=none $(CROSS) $(GO_COMPILE) --clone-path github.com/linuxkit/rtf --clone https://github.com/linuxkit/rtf.git --commit $(RTF_COMMIT) --package github.com/linuxkit/rtf --ldflags "-X $(RTF_CMD).GitCommit=$(RTF_COMMIT) -X $(RTF_CMD).Version=$(VERSION)" -o $@ > tmp_rtf_bin.tar + tar xf tmp_rtf_bin.tar > $@ + rm tmp_rtf_bin.tar + touch $@ + + LINUXKIT_DEPS=$(wildcard src/cmd/linuxkit/*.go) Makefile vendor.conf bin/linuxkit: $(LINUXKIT_DEPS) | bin tar cf - vendor -C src/cmd/linuxkit . | docker run --rm --net=none --log-driver=none -i $(CROSS) $(GO_COMPILE) --package github.com/linuxkit/linuxkit --ldflags "-X main.GitCommit=$(GIT_COMMIT) -X main.Version=$(VERSION)" -o $@ > tmp_linuxkit_bin.tar @@ -66,4 +75,3 @@ ci-pr: .PHONY: clean clean: rm -rf bin *.log *-kernel *-cmdline *.img *.iso *.gz *.qcow2 *.vhd *.vmx *.vmdk *.tar - $(MAKE) -C test clean diff --git a/README.md b/README.md index 9fb50bd88..9a748be9c 100644 --- a/README.md +++ b/README.md @@ -39,14 +39,39 @@ You can use `linuxkit run ` to execute the image you created with `moby bu This will use a suitable backend for your platform or you can choose one, for example VMWare. See `linuxkit run --help`. -`make test` or `make test-hyperkit` will run the test suite - Additional, platform specific information is available for: - [macOS](docs/mac.md) - [Google Cloud](docs/gcp.md) We'll add more detailed docs for other platforms in the future. +#### Running the Tests + +The test suite uses [`rtf`](https://github.com/linuxkit/rtf) +To install this you should use `make bin/rtf && make install`. + +To run the test suite: + +``` +cd test +rtf -x run +``` + +This will run the tests and put the results in a the `_results` directory! + +Run control is handled using labels and with pattern matching. +To run add a label you may use: + +``` +rtf -x -l slow run +``` + +To run tests that match the pattern `linuxkit.examples` you would use the following command: + +``` +rtf -x run linuxkit.examples +``` + ## Building your own customised image To customise, copy or modify the [`linuxkit.yml`](linuxkit.yml) to your own `file.yml` or use one of the [examples](examples/) and then run `moby build file.yml` to diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 000000000..d99da0079 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,2 @@ +_results +cases/_tmp diff --git a/test/Makefile b/test/Makefile index d5520efce..e8690bee7 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,11 +1,13 @@ .PHONY: default pr all -default: check-deps kernel-config -pr: check-deps kernel-config ../artifacts/test.img.tar.gz -all: check-deps kernel-config ltp ../artifacts/test.img.tar.gz ../artifacts/test-ltp.img.tar.gz +default: check-deps test +pr: check-deps test-pr +# TODO: all should point to test-all once ltp is no longer required +all: check-deps test-pr ltp MOBY:=$(shell command -v moby 2> /dev/null) LINUXKIT:=$(shell command -v linuxkit 2> /dev/null) +RTF:=$(shell command -v rtf 2> /dev/null) .PHONY: check-deps check-deps: @@ -15,54 +17,31 @@ endif ifndef LINUXKIT $(error "linuxkit binary not found. please install it.") endif +ifndef RTF + $(error "rtf is not available. please install it!") +endif + +# TODO: Remove this section once we no longer depend on this in CI +### ------- define check_test_log @cat $1 |grep -q 'test suite PASSED' endef -../artifacts: - mkdir -p $@ - -test-kernel-config-initrd.img: $(MOBY) cases/test-kernel-config.yml - $(MOBY) build --pull cases/test-kernel-config.yml - -# uses qemu -.PHONY: kernel-config -kernel-config: $(LINUXKIT) test-kernel-config-initrd.img test-kernel-config-kernel test-kernel-config-cmdline - $(LINUXKIT) run qemu test-kernel-config 2>&1 | tee test.log - $(call check_test_log, test.log) - -# qemu only at this time -.PHONY: qemu-efi -efi: $(LINUXKIT) test-kernel-config-efi.iso - $(LINUXKIT) run qemu -uefi test-kernel-config | tee test-efi.log - $(call check_test_log, test-efi.log) - -# For GCP tests -../artifacts/test.img.tar.gz: test-kernel-config.img.tar.gz | ../artifacts - mv test-kernel-config.img.tar.gz ../artifacts/test.img.tar.gz - -.PHONY: gcp -gcp: export CLOUDSDK_IMAGE_NAME?=test-kernel-config -gcp: $(LINUXKIT) ../test.img.tar.gz - $(LINUXKIT) push gcp ../artifacts/test.img.tar.gz - $(LINUXKIT) run gcp $(CLOUDSDK_IMAGE_NAME) | tee test-gcp.log - $(call check_test_log, test-gcp.log) - -# For LTP tests -test-ltp.img.tar.gz: $(MOBY) cases/test-ltp.yml - $(MOBY) build --pull cases/test-ltp.yml - -../artifacts/test-ltp.img.tar.gz: test-ltp.img.tar.gz | ../artifacts - mv test-ltp.img.tar.gz ../artifacts - .PHONY: ltp ltp: export CLOUDSDK_IMAGE_NAME?=test-ltp ltp: $(LINUXKIT) test-ltp.img.tar.gz - $(LINUXKIT) push gcp ../artifacts/test-ltp.img.tar.gz + $(MOBY) build --pull cases/020_stress/000_ltp/test-ltp.yml + $(LINUXKIT) push gcp test-ltp.img.tar.gz $(LINUXKIT) run gcp -skip-cleanup -machine n1-highcpu-4 $(CLOUDSDK_IMAGE_NAME) | tee test-ltp.log $(call check_test_log, test-ltp.log) +### ------ -.PHONY: clean -clean: - rm -rf bin *.log *-kernel *-cmdline *.img *.iso *.tar.gz *.qcow2 *.vhd *.vmx *.vmdk +test: + @rtf -l build -x run + +test-pr: + @rtf -vvv -l build -x run + +test-all: + @rtf -vvv -x -l build,slow run diff --git a/test/README.md b/test/README.md new file mode 100644 index 000000000..48e48ce25 --- /dev/null +++ b/test/README.md @@ -0,0 +1,19 @@ +Linuxkit Tests Labels +===================== + +## Usage of Artifacts vs Temporary Directory + +As the Build Machines have no secrets they will not be able to test running the build output on any cloud providers. +In this instance, the build tests should copy their output to the `LINUXKIT_ARTIFACTS_DIRECTORY` + +## Labels + +The `gcp` label is applied when the system where the tests are being run meets the requirements for using Google Cloud Platform. + +These requirements are: +- The system has the necessary `CLOUDSDK_*` environment variables exported +- The system has either keys for a GCP service account or is able to use application default credentials + +The `packet.net` label is applied when a system is able to create machines on Packet.net + +The `vmware` label is used when the machine has VMware Workstation or Fusion installed diff --git a/test/cases/test-kernel-config.yml b/test/cases/000_config/000_kernel/test-kernel-config.yml similarity index 93% rename from test/cases/test-kernel-config.yml rename to test/cases/000_config/000_kernel/test-kernel-config.yml index 8f2c6a2f6..cdcd3f6ad 100644 --- a/test/cases/test-kernel-config.yml +++ b/test/cases/000_config/000_kernel/test-kernel-config.yml @@ -21,7 +21,6 @@ onboot: - name: check-kernel-config image: "linuxkit/test-kernel-config:ecff41279ccbc408079a3996a956432651c6eb9c" readonly: true -services: - name: poweroff image: "linuxkit/poweroff:961412b8ef5c5285de0d40ec076701d955eaa084" pid: host @@ -31,6 +30,3 @@ services: readonly: true outputs: - format: kernel+initrd - - format: iso-bios - - format: iso-efi - - format: gcp-img diff --git a/test/cases/000_config/000_kernel/test.sh b/test/cases/000_config/000_kernel/test.sh new file mode 100644 index 000000000..4a407455e --- /dev/null +++ b/test/cases/000_config/000_kernel/test.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# SUMMARY: Test the kernel configuration is suitable for running Docker +# LABELS: +# REPEAT: +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +clean_up() { + find . -iname "test-kernel-config*" -not -iname "*.yml" -exec rm -rf {} \; +} +trap clean_up EXIT + +# Test code goes here +moby build test-kernel-config +RESULT="$(linuxkit run qemu test-kernel-config)" +echo "${RESULT}" | grep -q "suite PASSED" + +exit 0 diff --git a/test/kmod/Dockerfile b/test/cases/000_config/010_kmod/Dockerfile similarity index 100% rename from test/kmod/Dockerfile rename to test/cases/000_config/010_kmod/Dockerfile diff --git a/test/kmod/check.sh b/test/cases/000_config/010_kmod/check.sh similarity index 100% rename from test/kmod/check.sh rename to test/cases/000_config/010_kmod/check.sh diff --git a/test/kmod/kmod.yml b/test/cases/000_config/010_kmod/kmod.yml similarity index 67% rename from test/kmod/kmod.yml rename to test/cases/000_config/010_kmod/kmod.yml index 6ee81d0e9..176244c7e 100644 --- a/test/kmod/kmod.yml +++ b/test/cases/000_config/010_kmod/kmod.yml @@ -13,5 +13,12 @@ onboot: - /lib/modules:/lib/modules capabilities: - all + - name: poweroff + image: "linuxkit/poweroff:961412b8ef5c5285de0d40ec076701d955eaa084" + pid: host + command: ["/bin/sh", "/poweroff.sh", "3"] + capabilities: + - CAP_SYS_BOOT + readonly: true outputs: - format: kernel+initrd diff --git a/test/kmod/src/Makefile b/test/cases/000_config/010_kmod/src/Makefile similarity index 100% rename from test/kmod/src/Makefile rename to test/cases/000_config/010_kmod/src/Makefile diff --git a/test/kmod/src/hello_world.c b/test/cases/000_config/010_kmod/src/hello_world.c similarity index 100% rename from test/kmod/src/hello_world.c rename to test/cases/000_config/010_kmod/src/hello_world.c diff --git a/test/cases/000_config/010_kmod/test.sh b/test/cases/000_config/010_kmod/test.sh new file mode 100644 index 000000000..fc5481a5c --- /dev/null +++ b/test/cases/000_config/010_kmod/test.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# SUMMARY: Test build and insertion of kernel modules +# LABELS: +# REPEAT: +# AUTHOR: Rolf Neugebauer + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME="kmod-test" + +clean_up() { + docker rmi ${IMAGE_NAME} || true + find . -iname "kmod*" -not -iname "*.yml" -exec rm -rf {} \; +} +trap clean_up EXIT + +# Make sure we have the latest kernel image +docker pull linuxkit/kernel:4.9.x +# Build a package +docker build -t ${IMAGE_NAME} . +# Build a LinuxKit image with kernel module (and test script) +moby build kmod +# Run it +linuxkit run qemu kmod | grep -q "Hello LinuxKit" diff --git a/test/cases/000_config/group.sh b/test/cases/000_config/group.sh new file mode 100644 index 000000000..d9b73eb99 --- /dev/null +++ b/test/cases/000_config/group.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# SUMMARY: LinuxKit configuration tests +# LABELS: +# For the top level group.sh also specify a 'NAME:' comment + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +#. "${RT_PROJECT_ROOT}/_lib/lib.sh" + + +group_init() { + # Group initialisation code goes here + return 0 +} + +group_deinit() { + # Group de-initialisation code goes here + return 0 +} + +CMD=$1 +case $CMD in +init) + group_init + res=$? + ;; +deinit) + group_deinit + res=$? + ;; +*) + res=1 + ;; +esac + +exit $res + diff --git a/test/cases/010_platforms/000_qemu/000_build/test.sh b/test/cases/010_platforms/000_qemu/000_build/test.sh new file mode 100644 index 000000000..1b8a42ebf --- /dev/null +++ b/test/cases/010_platforms/000_qemu/000_build/test.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# SUMMARY: Test building an image for qemu +# LABELS: build +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=test-qemu-build + +clean_up() { + # remove any files, containers, images etc + find . -iname "${IMAGE_NAME}*" -not -iname "*.yml" -exec rm {} \; +} + +trap clean_up EXIT + +# Test code goes here +moby build -name "${IMAGE_NAME}" test.yml +[ -f "${IMAGE_NAME}-kernel" ] || exit 1 +[ -f "${IMAGE_NAME}-initrd.img" ] || exit 1 +[ -f "${IMAGE_NAME}-cmdline" ]|| exit 1 + +find . -iname "${IMAGE_NAME}-*" -exec cp {} "${LINUXKIT_TMPDIR}/{}" \; +exit 0 diff --git a/test/cases/010_platforms/000_qemu/000_build/test.yml b/test/cases/010_platforms/000_qemu/000_build/test.yml new file mode 100644 index 000000000..f3d1a822c --- /dev/null +++ b/test/cases/010_platforms/000_qemu/000_build/test.yml @@ -0,0 +1,31 @@ +kernel: + image: "linuxkit/kernel:4.9.x" + cmdline: "console=ttyS0 console=tty0 page_poison=1" +init: + - linuxkit/init:f71c3b30ac1ba4ef16c160c89610fa4976f9752f + - linuxkit/runc:b0fb122e10dbb7e4e45115177a61a3f8d68c19a9 + - linuxkit/containerd:60e2486a74c665ba4df57e561729aec20758daed +onboot: + - name: dhcpcd + image: "linuxkit/dhcpcd:8837289b78ecd80f59524883085424e115dd0b3a" + binds: + - /var:/var + - /tmp/etc:/etc + capabilities: + - CAP_NET_ADMIN + - CAP_NET_BIND_SERVICE + - CAP_NET_RAW + net: host + command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] + - name: poweroff + image: "linuxkit/poweroff:961412b8ef5c5285de0d40ec076701d955eaa084" + pid: host + command: ["/bin/sh", "/poweroff.sh", "10"] + capabilities: + - CAP_SYS_BOOT + readonly: true +trust: + image: + - linuxkit/kernel +outputs: + - format: kernel+initrd diff --git a/test/cases/010_platforms/000_qemu/001_run/test.sh b/test/cases/010_platforms/000_qemu/001_run/test.sh new file mode 100644 index 000000000..4857046f4 --- /dev/null +++ b/test/cases/010_platforms/000_qemu/001_run/test.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# SUMMARY: Test running an image with qemu +# LABELS: +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=test-qemu-build + +clean_up() { + # remove any files, containers, images etc + rm -rf "${LINUXKIT_TMPDIR:?}/${IMAGE_NAME:?}*" || true +} + +trap clean_up EXIT + +# Test code goes here +[ -f "${LINUXKIT_TMPDIR}/${IMAGE_NAME}-kernel" ] || exit 1 +linuxkit run qemu "${LINUXKIT_TMPDIR}/${IMAGE_NAME}" | grep -q "Welcome to LinuxKit" +exit 0 diff --git a/test/cases/010_platforms/000_qemu/010_build_iso/test.sh b/test/cases/010_platforms/000_qemu/010_build_iso/test.sh new file mode 100644 index 000000000..8e7f0289b --- /dev/null +++ b/test/cases/010_platforms/000_qemu/010_build_iso/test.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# SUMMARY: Test building an ISO image for qemu +# LABELS: build +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=test-qemu-build + +clean_up() { + # remove any files, containers, images etc + find . -iname "${IMAGE_NAME}*" -not -iname "*.yml" -exec rm {} \; +} + +trap clean_up EXIT + +# Test code goes here +moby build -name "${IMAGE_NAME}" test.yml +[ -f "${IMAGE_NAME}.iso" ] || exit 1 + +cp "${IMAGE_NAME}.iso" "${LINUXKIT_TMPDIR}/" +exit 0 diff --git a/test/cases/010_platforms/000_qemu/010_build_iso/test.yml b/test/cases/010_platforms/000_qemu/010_build_iso/test.yml new file mode 100644 index 000000000..6bb6bdf4f --- /dev/null +++ b/test/cases/010_platforms/000_qemu/010_build_iso/test.yml @@ -0,0 +1,31 @@ +kernel: + image: "linuxkit/kernel:4.9.x" + cmdline: "console=ttyS0 console=tty0 page_poison=1" +init: + - linuxkit/init:f71c3b30ac1ba4ef16c160c89610fa4976f9752f + - linuxkit/runc:b0fb122e10dbb7e4e45115177a61a3f8d68c19a9 + - linuxkit/containerd:60e2486a74c665ba4df57e561729aec20758daed +onboot: + - name: dhcpcd + image: "linuxkit/dhcpcd:8837289b78ecd80f59524883085424e115dd0b3a" + binds: + - /var:/var + - /tmp/etc:/etc + capabilities: + - CAP_NET_ADMIN + - CAP_NET_BIND_SERVICE + - CAP_NET_RAW + net: host + command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] + - name: poweroff + image: "linuxkit/poweroff:961412b8ef5c5285de0d40ec076701d955eaa084" + pid: host + command: ["/bin/sh", "/poweroff.sh", "10"] + capabilities: + - CAP_SYS_BOOT + readonly: true +trust: + image: + - linuxkit/kernel +outputs: + - format: iso-bios diff --git a/test/cases/010_platforms/000_qemu/011_run_iso/test.sh b/test/cases/010_platforms/000_qemu/011_run_iso/test.sh new file mode 100644 index 000000000..571a47827 --- /dev/null +++ b/test/cases/010_platforms/000_qemu/011_run_iso/test.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# SUMMARY: Test running an ISO image with qemu +# LABELS: +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=test-qemu-build + +clean_up() { + # remove any files, containers, images etc + rm -rf "${LINUXKIT_TMPDIR:?}/${IMAGE_NAME:?}*" || true +} + +trap clean_up EXIT + +# Test code goes here +[ -f "${LINUXKIT_TMPDIR}/${IMAGE_NAME}.iso" ] || exit 1 +linuxkit run qemu -iso "${LINUXKIT_TMPDIR}/${IMAGE_NAME}" | grep -q "Welcome to LinuxKit" +exit 0 diff --git a/test/cases/010_platforms/000_qemu/020_build_efi/test.sh b/test/cases/010_platforms/000_qemu/020_build_efi/test.sh new file mode 100644 index 000000000..763090372 --- /dev/null +++ b/test/cases/010_platforms/000_qemu/020_build_efi/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# SUMMARY: Test building a UEFI image for qemu +# LABELS: build +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=test-qemu-build + +clean_up() { + # remove any files, containers, images etc + find . -iname "${IMAGE_NAME}*" -not -iname "*.yml" -exec rm {} \; +} + +trap clean_up EXIT + +# Test code goes here +moby build -name "${IMAGE_NAME}" test.yml +[ -f "${IMAGE_NAME}-efi.iso" ] || exit 1 +cp "${IMAGE_NAME}-efi.iso" "${LINUXKIT_TMPDIR}/" +exit 0 diff --git a/test/cases/010_platforms/000_qemu/020_build_efi/test.yml b/test/cases/010_platforms/000_qemu/020_build_efi/test.yml new file mode 100644 index 000000000..5e6aecb10 --- /dev/null +++ b/test/cases/010_platforms/000_qemu/020_build_efi/test.yml @@ -0,0 +1,31 @@ +kernel: + image: "linuxkit/kernel:4.9.x" + cmdline: "console=ttyS0 console=tty0 page_poison=1" +init: + - linuxkit/init:f71c3b30ac1ba4ef16c160c89610fa4976f9752f + - linuxkit/runc:b0fb122e10dbb7e4e45115177a61a3f8d68c19a9 + - linuxkit/containerd:60e2486a74c665ba4df57e561729aec20758daed +onboot: + - name: dhcpcd + image: "linuxkit/dhcpcd:8837289b78ecd80f59524883085424e115dd0b3a" + binds: + - /var:/var + - /tmp/etc:/etc + capabilities: + - CAP_NET_ADMIN + - CAP_NET_BIND_SERVICE + - CAP_NET_RAW + net: host + command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] + - name: poweroff + image: "linuxkit/poweroff:961412b8ef5c5285de0d40ec076701d955eaa084" + pid: host + command: ["/bin/sh", "/poweroff.sh", "10"] + capabilities: + - CAP_SYS_BOOT + readonly: true +trust: + image: + - linuxkit/kernel +outputs: + - format: iso-efi diff --git a/test/cases/010_platforms/000_qemu/021_run_efi/test.sh b/test/cases/010_platforms/000_qemu/021_run_efi/test.sh new file mode 100644 index 000000000..6b02ce3e4 --- /dev/null +++ b/test/cases/010_platforms/000_qemu/021_run_efi/test.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# SUMMARY: Test running a UEFI image with qemu +# LABELS: +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=test-qemu-build + +clean_up() { + # remove any files, containers, images etc + rm -rf "${LINUXKIT_TMPDIR:?}/${IMAGE_NAME:?}*" || true +} + +trap clean_up EXIT + +if command -v qemu; then + if [ ! -f /usr/share/ovmf/bios.bin ]; then + exit RT_CANCEL + fi +fi + + +# Test code goes here +[ -f "${LINUXKIT_TMPDIR}/${IMAGE_NAME}-efi.iso" ] || exit 1 +linuxkit run qemu -uefi "${LINUXKIT_TMPDIR}/${IMAGE_NAME}" | grep -q "Welcome to LinuxKit" +exit 0 diff --git a/test/cases/010_platforms/000_qemu/group.sh b/test/cases/010_platforms/000_qemu/group.sh new file mode 100644 index 000000000..185399e68 --- /dev/null +++ b/test/cases/010_platforms/000_qemu/group.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# SUMMARY: Linuxkit Qemu Tests +# LABELS: + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +#. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +group_init() { + # Group initialisation code goes here + return 0 +} + +group_deinit() { + # Group de-initialisation code goes here + return 0 +} + +CMD=$1 +case $CMD in +init) + group_init + res=$? + ;; +deinit) + group_deinit + res=$? + ;; +*) + res=1 + ;; +esac + +exit $res + diff --git a/test/cases/010_platforms/001_hyperkit/group.sh b/test/cases/010_platforms/001_hyperkit/group.sh new file mode 100644 index 000000000..95d0819e3 --- /dev/null +++ b/test/cases/010_platforms/001_hyperkit/group.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# SUMMARY: LinuxKit Hyperkit tests +# LABELS: darwin +# For the top level group.sh also specify a 'NAME:' comment + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +#. "${RT_PROJECT_ROOT}/_lib/lib.sh" + + +group_init() { + # Group initialisation code goes here + return 0 +} + +group_deinit() { + # Group de-initialisation code goes here + return 0 +} + +CMD=$1 +case $CMD in +init) + group_init + res=$? + ;; +deinit) + group_deinit + res=$? + ;; +*) + res=1 + ;; +esac + +exit $res + diff --git a/test/cases/010_platforms/010_gcp/000_build/test.sh b/test/cases/010_platforms/010_gcp/000_build/test.sh new file mode 100644 index 000000000..9f847a26c --- /dev/null +++ b/test/cases/010_platforms/010_gcp/000_build/test.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# SUMMARY: Test building an image for GCP +# LABELS: build +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=gcp + +clean_up() { + # remove any files, containers, images etc + rm -rf ${IMAGE_NAME}* +} + +trap clean_up EXIT + +# Test code goes here +moby build -name "${IMAGE_NAME}" test.yml +[ -f "${IMAGE_NAME}.img.tar.gz" ] || exit 1 +# As build and run on different machines, copy to the artifacts directory +cp -f "${IMAGE_NAME}.img.tar.gz" "${LINUXKIT_ARTIFACTS_DIR}/test.img.tar.gz" + +exit 0 diff --git a/test/cases/010_platforms/010_gcp/000_build/test.yml b/test/cases/010_platforms/010_gcp/000_build/test.yml new file mode 100644 index 000000000..f807e78f4 --- /dev/null +++ b/test/cases/010_platforms/010_gcp/000_build/test.yml @@ -0,0 +1,34 @@ +# FIXME: This should use the minimal example +# We continue to use the kernel-config-test as CI is currently expecting to see a success message +kernel: + image: "linuxkit/kernel:4.9.x" + cmdline: "console=ttyS0" +init: + - linuxkit/init:deea956a9ab07bf262083e93a86930bdc610cc2f + - linuxkit/runc:2649198589ef0020d99f613adaeda45ce0093a38 + - linuxkit/containerd:cf2614f5a96c569a0bd4bd54e054a65ba17d167f + - linuxkit/ca-certificates:3344cdca1bc59fdfa17bd7f0fcbf491b9dbaa288 +onboot: + - name: dhcpcd + image: "linuxkit/dhcpcd:2def74ab3f9233b4c09ebb196ba47c27c08b0ed8" + binds: + - /var:/var + - /tmp:/etc + capabilities: + - CAP_NET_ADMIN + - CAP_NET_BIND_SERVICE + - CAP_NET_RAW + net: host + command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] + - name: check-kernel-config + image: "linuxkit/test-kernel-config:ecff41279ccbc408079a3996a956432651c6eb9c" + readonly: true + - name: poweroff + image: "linuxkit/poweroff:961412b8ef5c5285de0d40ec076701d955eaa084" + pid: host + command: ["/bin/sh", "/poweroff.sh", "3"] + capabilities: + - CAP_SYS_BOOT + readonly: true +outputs: + - format: gcp-img diff --git a/test/cases/010_platforms/010_gcp/001_run/test.sh b/test/cases/010_platforms/010_gcp/001_run/test.sh new file mode 100644 index 000000000..5779c0aee --- /dev/null +++ b/test/cases/010_platforms/010_gcp/001_run/test.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# SUMMARY: Test running an image with qemu +# LABELS: gcp +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=test + +clean_up() { + # remove any files, containers, images etc + echo "Nothing to cleanup..." +} + +trap clean_up EXIT + +# Test code goes here +[ -f "${LINUXKIT_ARTIFACTS_DIR}/${IMAGE_NAME}.img.tar.gz" ] || exit 1 +linuxkit run gcp "${LINUXKIT_ARTIFACTS_DIR}/${IMAGE_NAME}" | grep -q "Welcome to LinuxKit" +exit 0 diff --git a/test/cases/010_platforms/010_gcp/group.sh b/test/cases/010_platforms/010_gcp/group.sh new file mode 100644 index 000000000..d9b73eb99 --- /dev/null +++ b/test/cases/010_platforms/010_gcp/group.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# SUMMARY: LinuxKit configuration tests +# LABELS: +# For the top level group.sh also specify a 'NAME:' comment + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +#. "${RT_PROJECT_ROOT}/_lib/lib.sh" + + +group_init() { + # Group initialisation code goes here + return 0 +} + +group_deinit() { + # Group de-initialisation code goes here + return 0 +} + +CMD=$1 +case $CMD in +init) + group_init + res=$? + ;; +deinit) + group_deinit + res=$? + ;; +*) + res=1 + ;; +esac + +exit $res + diff --git a/test/cases/010_platforms/020_packet/000_build/test.sh b/test/cases/010_platforms/020_packet/000_build/test.sh new file mode 100644 index 000000000..0fd2c1018 --- /dev/null +++ b/test/cases/010_platforms/020_packet/000_build/test.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# SUMMARY: Test building an image for packet.net +# LABELS: build +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=packet + +clean_up() { + # remove any files, containers, images etc + rm -rf ${IMAGE_NAME}* +} + +trap clean_up EXIT + +# Test code goes here +moby build --name "${IMAGE_NAME}" test.yml +[ -f "${IMAGE_NAME}-kernel" ] || exit 1 + +# As build and run on different machines, copy to the artifacts directory +find . -iname "${IMAGE_NAME}-*" -exec cp {} "${LINUXKIT_ARTFACTS_DIR}/{}" \; +exit 0 diff --git a/test/cases/010_platforms/020_packet/000_build/test.yml b/test/cases/010_platforms/020_packet/000_build/test.yml new file mode 100644 index 000000000..f3d1a822c --- /dev/null +++ b/test/cases/010_platforms/020_packet/000_build/test.yml @@ -0,0 +1,31 @@ +kernel: + image: "linuxkit/kernel:4.9.x" + cmdline: "console=ttyS0 console=tty0 page_poison=1" +init: + - linuxkit/init:f71c3b30ac1ba4ef16c160c89610fa4976f9752f + - linuxkit/runc:b0fb122e10dbb7e4e45115177a61a3f8d68c19a9 + - linuxkit/containerd:60e2486a74c665ba4df57e561729aec20758daed +onboot: + - name: dhcpcd + image: "linuxkit/dhcpcd:8837289b78ecd80f59524883085424e115dd0b3a" + binds: + - /var:/var + - /tmp/etc:/etc + capabilities: + - CAP_NET_ADMIN + - CAP_NET_BIND_SERVICE + - CAP_NET_RAW + net: host + command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] + - name: poweroff + image: "linuxkit/poweroff:961412b8ef5c5285de0d40ec076701d955eaa084" + pid: host + command: ["/bin/sh", "/poweroff.sh", "10"] + capabilities: + - CAP_SYS_BOOT + readonly: true +trust: + image: + - linuxkit/kernel +outputs: + - format: kernel+initrd diff --git a/test/cases/010_platforms/020_packet/group.sh b/test/cases/010_platforms/020_packet/group.sh new file mode 100644 index 000000000..d9b73eb99 --- /dev/null +++ b/test/cases/010_platforms/020_packet/group.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# SUMMARY: LinuxKit configuration tests +# LABELS: +# For the top level group.sh also specify a 'NAME:' comment + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +#. "${RT_PROJECT_ROOT}/_lib/lib.sh" + + +group_init() { + # Group initialisation code goes here + return 0 +} + +group_deinit() { + # Group de-initialisation code goes here + return 0 +} + +CMD=$1 +case $CMD in +init) + group_init + res=$? + ;; +deinit) + group_deinit + res=$? + ;; +*) + res=1 + ;; +esac + +exit $res + diff --git a/test/cases/010_platforms/030_vmware/000_build/test.sh b/test/cases/010_platforms/030_vmware/000_build/test.sh new file mode 100644 index 000000000..c3c66d854 --- /dev/null +++ b/test/cases/010_platforms/030_vmware/000_build/test.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# SUMMARY: Test building an image for VMware +# LABELS: build +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=vmware + +clean_up() { + # remove any files, containers, images etc + rm -rf ${IMAGE_NAME}* +} + +trap clean_up EXIT + +# Test code goes here +moby build --name "${IMAGE_NAME}" test.yml +[ -f "${IMAGE_NAME}.vmdk" ] || exit 1 +# As build and run on different machines, copy to the artifacts directory +cp "${IMAGE_NAME}.vmdk" "${LINUXKIT_ARTIFACTS_DIR}/" +exit 0 + diff --git a/test/cases/010_platforms/030_vmware/000_build/test.yml b/test/cases/010_platforms/030_vmware/000_build/test.yml new file mode 100644 index 000000000..008a49ddb --- /dev/null +++ b/test/cases/010_platforms/030_vmware/000_build/test.yml @@ -0,0 +1,31 @@ +kernel: + image: "linuxkit/kernel:4.9.x" + cmdline: "console=ttyS0 console=tty0 page_poison=1" +init: + - linuxkit/init:f71c3b30ac1ba4ef16c160c89610fa4976f9752f + - linuxkit/runc:b0fb122e10dbb7e4e45115177a61a3f8d68c19a9 + - linuxkit/containerd:60e2486a74c665ba4df57e561729aec20758daed +onboot: + - name: dhcpcd + image: "linuxkit/dhcpcd:8837289b78ecd80f59524883085424e115dd0b3a" + binds: + - /var:/var + - /tmp/etc:/etc + capabilities: + - CAP_NET_ADMIN + - CAP_NET_BIND_SERVICE + - CAP_NET_RAW + net: host + command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] + - name: poweroff + image: "linuxkit/poweroff:961412b8ef5c5285de0d40ec076701d955eaa084" + pid: host + command: ["/bin/sh", "/poweroff.sh", "10"] + capabilities: + - CAP_SYS_BOOT + readonly: true +trust: + image: + - linuxkit/kernel +outputs: + - format: vmdk diff --git a/test/cases/010_platforms/group.sh b/test/cases/010_platforms/group.sh new file mode 100644 index 000000000..0421ffaf7 --- /dev/null +++ b/test/cases/010_platforms/group.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# SUMMARY: LinuxKit platform tests +# LABELS: +# For the top level group.sh also specify a 'NAME:' comment + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +#. "${RT_PROJECT_ROOT}/_lib/lib.sh" + + +group_init() { + # Group initialisation code goes here + return 0 +} + +group_deinit() { + # Group de-initialisation code goes here + return 0 +} + +CMD=$1 +case $CMD in +init) + group_init + res=$? + ;; +deinit) + group_deinit + res=$? + ;; +*) + res=1 + ;; +esac + +exit $res + diff --git a/test/cases/test-ltp.yml b/test/cases/020_stress/000_ltp/test-ltp.yml similarity index 91% rename from test/cases/test-ltp.yml rename to test/cases/020_stress/000_ltp/test-ltp.yml index 543d4e9c3..c47555f88 100644 --- a/test/cases/test-ltp.yml +++ b/test/cases/020_stress/000_ltp/test-ltp.yml @@ -15,7 +15,6 @@ onboot: - /etc/ltp/baseline:/etc/ltp/baseline capabilities: - all -services: - name: poweroff image: "linuxkit/poweroff:961412b8ef5c5285de0d40ec076701d955eaa084" pid: host @@ -26,7 +25,4 @@ files: - path: /etc/ltp/baseline contents: "100" outputs: - - format: kernel+initrd - - format: iso-bios - - format: iso-efi - format: gcp-img diff --git a/test/cases/020_stress/000_ltp/test.sh b/test/cases/020_stress/000_ltp/test.sh new file mode 100644 index 000000000..4516d75e1 --- /dev/null +++ b/test/cases/020_stress/000_ltp/test.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# SUMMARY: Run the Linux Testing Project tests +# LABELS: slow, gcp +# REPEAT: +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +clean_up() { + find . -iname "test-ltp*" -not -iname "*.yml" -exec rm -rf {} \; +} +trap clean_up EXIT + +# Test code goes here +moby build test-ltp +linuxkit push test-ltp.img.tar.gz +RESULT="$(linuxkit run gcp -skip-cleanup -machine n1-highcpu-4 test-ltp)" +echo "${RESULT}" | grep -q "suite has passed" + +exit 0 diff --git a/test/cases/test-virtsock-server.yml b/test/cases/020_stress/010_virtsock/test-virtsock-server.yml similarity index 100% rename from test/cases/test-virtsock-server.yml rename to test/cases/020_stress/010_virtsock/test-virtsock-server.yml diff --git a/test/cases/020_stress/010_virtsock/test.sh b/test/cases/020_stress/010_virtsock/test.sh new file mode 100644 index 000000000..f08447049 --- /dev/null +++ b/test/cases/020_stress/010_virtsock/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# LABELS: windows, skip + +# FIXME: Write this test!!! diff --git a/test/cases/020_stress/group.sh b/test/cases/020_stress/group.sh new file mode 100644 index 000000000..303b26465 --- /dev/null +++ b/test/cases/020_stress/group.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# SUMMARY: LinuxKit stress tests +# LABELS: +# For the top level group.sh also specify a 'NAME:' comment + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +#. "${RT_PROJECT_ROOT}/_lib/lib.sh" + + +group_init() { + # Group initialisation code goes here + return 0 +} + +group_deinit() { + # Group de-initialisation code goes here + return 0 +} + +CMD=$1 +case $CMD in +init) + group_init + res=$? + ;; +deinit) + group_deinit + res=$? + ;; +*) + res=1 + ;; +esac + +exit $res + diff --git a/test/cases/test-docker-bench.yml b/test/cases/030_security/000_docker-bench/test-docker-bench.yml similarity index 100% rename from test/cases/test-docker-bench.yml rename to test/cases/030_security/000_docker-bench/test-docker-bench.yml diff --git a/test/cases/030_security/000_docker-bench/test.sh b/test/cases/030_security/000_docker-bench/test.sh new file mode 100644 index 000000000..59c178ccb --- /dev/null +++ b/test/cases/030_security/000_docker-bench/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# LABELS: skip + +# FIXME: Write this test!!! diff --git a/test/cases/030_security/group.sh b/test/cases/030_security/group.sh new file mode 100644 index 000000000..df8edfc84 --- /dev/null +++ b/test/cases/030_security/group.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# SUMMARY: LinuxKit security tests +# LABELS: +# For the top level group.sh also specify a 'NAME:' comment + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +#. "${RT_PROJECT_ROOT}/_lib/lib.sh" + + +group_init() { + # Group initialisation code goes here + return 0 +} + +group_deinit() { + # Group de-initialisation code goes here + return 0 +} + +CMD=$1 +case $CMD in +init) + group_init + res=$? + ;; +deinit) + group_deinit + res=$? + ;; +*) + res=1 + ;; +esac + +exit $res + diff --git a/test/cases/100_examples/000_minimal/test.sh b/test/cases/100_examples/000_minimal/test.sh new file mode 100644 index 000000000..0365beb63 --- /dev/null +++ b/test/cases/100_examples/000_minimal/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# SUMMARY: Test the minimal example +# LABELS: +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=minimal + +clean_up() { + # remove any files, containers, images etc + rm -rf ${IMAGE_NAME}* +} + +trap clean_up EXIT + +# Test code goes here +moby build "${LINUXKIT_EXAMPLES_DIR}/${IMAGE_NAME}.yml" + +exit 0 + diff --git a/test/cases/100_examples/010_docker/test.sh b/test/cases/100_examples/010_docker/test.sh new file mode 100644 index 000000000..52b1c4f35 --- /dev/null +++ b/test/cases/100_examples/010_docker/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# SUMMARY: Test the docker example +# LABELS: +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=docker + +clean_up() { + # remove any files, containers, images etc + rm -rf ${IMAGE_NAME}* +} + +trap clean_up EXIT + +# Test code goes here +moby build "${LINUXKIT_EXAMPLES_DIR}/${IMAGE_NAME}.yml" + +exit 0 + diff --git a/test/cases/100_examples/020_sshd/test.sh b/test/cases/100_examples/020_sshd/test.sh new file mode 100644 index 000000000..caa41c173 --- /dev/null +++ b/test/cases/100_examples/020_sshd/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# SUMMARY: Test the sshd example +# LABELS: +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=sshd + +clean_up() { + # remove any files, containers, images etc + rm -rf ${IMAGE_NAME}* +} + +trap clean_up EXIT + +# Test code goes here +moby build "${LINUXKIT_EXAMPLES_DIR}/${IMAGE_NAME}.yml" + +exit 0 + diff --git a/test/cases/100_examples/030_redis/test.sh b/test/cases/100_examples/030_redis/test.sh new file mode 100644 index 000000000..9cc432e28 --- /dev/null +++ b/test/cases/100_examples/030_redis/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# SUMMARY: Test the redis-os example +# LABELS: +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=redis-os + +clean_up() { + # remove any files, containers, images etc + rm -rf ${IMAGE_NAME}* +} + +trap clean_up EXIT + +# Test code goes here +moby build "${LINUXKIT_EXAMPLES_DIR}/${IMAGE_NAME}.yml" + +exit 0 + diff --git a/test/cases/100_examples/040_swap/test.sh b/test/cases/100_examples/040_swap/test.sh new file mode 100644 index 000000000..953ea8e0b --- /dev/null +++ b/test/cases/100_examples/040_swap/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# SUMMARY: Test the swap example +# LABELS: +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=swap + +clean_up() { + # remove any files, containers, images etc + rm -rf ${IMAGE_NAME}* +} + +trap clean_up EXIT + +# Test code goes here +moby build "${LINUXKIT_EXAMPLES_DIR}/${IMAGE_NAME}.yml" + +exit 0 + diff --git a/test/cases/100_examples/050_node_exporter/test.sh b/test/cases/100_examples/050_node_exporter/test.sh new file mode 100644 index 000000000..a4a1f45bb --- /dev/null +++ b/test/cases/100_examples/050_node_exporter/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# SUMMARY: Test the node_exporter example +# LABELS: +# AUTHOR: Dave Tucker + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +IMAGE_NAME=node_exporter + +clean_up() { + # remove any files, containers, images etc + rm -rf ${IMAGE_NAME}* +} + +trap clean_up EXIT + +# Test code goes here +moby build "${LINUXKIT_EXAMPLES_DIR}/${IMAGE_NAME}.yml" + +exit 0 + diff --git a/test/cases/_lib/lib.sh b/test/cases/_lib/lib.sh new file mode 100644 index 000000000..500ace37d --- /dev/null +++ b/test/cases/_lib/lib.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Source the main regression test library if present +[ -f "${RT_LIB}" ] && . "${RT_LIB}" + +# Temporary directory for tests to use. +LINUXKIT_TMPDIR="${RT_PROJECT_ROOT}/_tmp" +LINUXKIT_ARTIFACTS_DIR="${RT_PROJECT_ROOT}/../../artifacts" + +# The top-level group.sh of the project creates a env.sh file +# containing environment variables for tests. Source it if present. +[ -f "${LINUXKIT_TMPDIR}/env.sh" ] && . "${LINUXKIT_TMPDIR}/env.sh" + +# FIXME: Should source the rtf/lib/lib.sh instead +RT_CANCEL=253 diff --git a/test/cases/group.sh b/test/cases/group.sh new file mode 100644 index 000000000..6a22618f8 --- /dev/null +++ b/test/cases/group.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# NAME: linuxkit +# SUMMARY: LinuxKit Regression Tests +# LABELS: + +# Source libraries. Uncomment if needed/defined +# . "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +group_init() { + # Group initialisation code goes here + [ -r "${LINUXKIT_TMPDIR}" ] && rm -rf "${LINUXKIT_TMPDIR}" + mkdir "${LINUXKIT_TMPDIR}" + [ -r "${LINUXKIT_ARTIFACTS_DIR}" ] && rm -rf "${LINUXKIT_ARTIFACTS_DIR}" + mkdir "${LINUXKIT_ARTIFACTS_DIR}" + echo "export LINUXKIT_EXAMPLES_DIR=${RT_PROJECT_ROOT}/../../examples" >> "${LINUXKIT_TMPDIR}/env.sh" + return 0 +} + +group_deinit() { + # Group de-initialisation code goes here + return 0 +} + +CMD=$1 +case $CMD in +init) + group_init + res=$? + ;; +deinit) + group_deinit + res=$? + ;; +*) + res=1 + ;; +esac + +exit $res + diff --git a/test/kmod/run_test.sh b/test/kmod/run_test.sh deleted file mode 100755 index f0ffe7f27..000000000 --- a/test/kmod/run_test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#! /bin/sh - -# Make sure we have the latest kernel image -docker pull linuxkit/kernel:4.9.x -# Build a package -docker build -t kmod-test . -# Build a LinuxKit image with kernel module (and test script) -moby build kmod -# Run it -linuxkit run kmod