diff --git a/test/cases/020_kernel/015_config_5.12.x/test.sh b/test/cases/020_kernel/015_config_5.12.x/test.sh new file mode 100644 index 000000000..fdfccb99c --- /dev/null +++ b/test/cases/020_kernel/015_config_5.12.x/test.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# SUMMARY: Sanity check on the kernel config file +# LABELS: +# REPEAT: + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +NAME=kconfig + +clean_up() { + rm -rf ${NAME}-* +} +trap clean_up EXIT + +# Test code goes here +linuxkit build -format kernel+initrd -name "${NAME}" test.yml +RESULT="$(linuxkit run ${NAME})" +echo "${RESULT}" | grep -q "suite PASSED" + +exit 0 diff --git a/test/cases/020_kernel/015_config_5.12.x/test.yml b/test/cases/020_kernel/015_config_5.12.x/test.yml new file mode 100644 index 000000000..0a70329f2 --- /dev/null +++ b/test/cases/020_kernel/015_config_5.12.x/test.yml @@ -0,0 +1,15 @@ +kernel: + image: linuxkit/kernel:5.12.14 + cmdline: "console=ttyS0 console=ttyAMA0" +init: + - linuxkit/init:78fb57c7da07c4e43c3a37b27755581da087a3b6 + - linuxkit/runc:bf1e0c61fb4678d6428d0aabbd80db5ea24e4d4d +onboot: + - name: check-kernel-config + image: linuxkit/test-kernel-config:6b4d6aff84721c069ec38a89c88c2d725b6cc6c0 + - name: poweroff + image: linuxkit/poweroff:afe4b3ab865afe1e3ed5c88e58f57808f4f5119f + command: ["/bin/sh", "/poweroff.sh", "3"] +trust: + org: + - linuxkit diff --git a/test/cases/020_kernel/115_kmod_5.12.x/Dockerfile b/test/cases/020_kernel/115_kmod_5.12.x/Dockerfile new file mode 100644 index 000000000..756b95170 --- /dev/null +++ b/test/cases/020_kernel/115_kmod_5.12.x/Dockerfile @@ -0,0 +1,23 @@ +# This Dockerfile extracts the kernel headers from the kernel image +# and then compiles a simple hello world kernel module against them. +# In the last stage, it creates a package, which can be used for +# testing. + +FROM linuxkit/kernel:5.12.14 AS ksrc + +# Extract headers and compile module +FROM linuxkit/kernel:5.12.14-builder AS build +RUN apk add build-base elfutils-dev + +COPY --from=ksrc /kernel-dev.tar / +RUN tar xf kernel-dev.tar + +WORKDIR /kmod +COPY ./src/* ./ +RUN make all + +# Package +FROM alpine:3.11 +COPY --from=build /kmod/hello_world.ko / +COPY check.sh /check.sh +ENTRYPOINT ["/bin/sh", "/check.sh"] diff --git a/test/cases/020_kernel/115_kmod_5.12.x/check.sh b/test/cases/020_kernel/115_kmod_5.12.x/check.sh new file mode 100755 index 000000000..02e491624 --- /dev/null +++ b/test/cases/020_kernel/115_kmod_5.12.x/check.sh @@ -0,0 +1,15 @@ +#!/bin/sh +function failed { + printf "Kernel module test suite FAILED\n" + /sbin/poweroff -f +} + +uname -a +modinfo hello_world.ko || failed +insmod hello_world.ko || failed +[ -n "$(dmesg | grep -o 'Hello LinuxKit')" ] || failed +rmmod hello_world || failed + +printf "Kernel module test suite PASSED\n" + +/sbin/poweroff -f diff --git a/test/cases/020_kernel/115_kmod_5.12.x/src/Makefile b/test/cases/020_kernel/115_kmod_5.12.x/src/Makefile new file mode 100644 index 000000000..31c8215dd --- /dev/null +++ b/test/cases/020_kernel/115_kmod_5.12.x/src/Makefile @@ -0,0 +1,6 @@ +obj-m += hello_world.o +KVER=$(shell basename /usr/src/linux-headers-*) +all: + make -C /usr/src/$(KVER) M=$(PWD) modules +clean: + make -C /usr/src/$(KVER) M=$(PWD) clean diff --git a/test/cases/020_kernel/115_kmod_5.12.x/src/hello_world.c b/test/cases/020_kernel/115_kmod_5.12.x/src/hello_world.c new file mode 100644 index 000000000..7dd6d3ee2 --- /dev/null +++ b/test/cases/020_kernel/115_kmod_5.12.x/src/hello_world.c @@ -0,0 +1,22 @@ +/* + * A simple Hello World kernel module + */ +#include +#include + +int init_hello(void) +{ + printk(KERN_INFO "Hello LinuxKit\n"); + return 0; +} + +void exit_hello(void) +{ + printk(KERN_INFO "Goodbye LinuxKit.\n"); +} + +module_init(init_hello); +module_exit(exit_hello); +MODULE_AUTHOR("Rolf Neugebauer "); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("A simple Hello World kernel module for testing"); diff --git a/test/cases/020_kernel/115_kmod_5.12.x/test.sh b/test/cases/020_kernel/115_kmod_5.12.x/test.sh new file mode 100644 index 000000000..41e2304c3 --- /dev/null +++ b/test/cases/020_kernel/115_kmod_5.12.x/test.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# SUMMARY: Test build and insertion of kernel modules +# LABELS: +# REPEAT: + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +NAME=kmod +IMAGE_NAME=kmod-test + +clean_up() { + docker rmi ${IMAGE_NAME} || true + rm -rf ${NAME}-* +} +trap clean_up EXIT + +# Make sure we have the latest kernel image +docker pull linuxkit/kernel:5.12.14 +# Build a package +docker build -t ${IMAGE_NAME} . + +# Build and run a LinuxKit image with kernel module (and test script) +linuxkit build -docker -format kernel+initrd -name "${NAME}" test.yml +RESULT="$(linuxkit run ${NAME})" +echo "${RESULT}" | grep -q "Hello LinuxKit" + +exit 0 diff --git a/test/cases/020_kernel/115_kmod_5.12.x/test.yml b/test/cases/020_kernel/115_kmod_5.12.x/test.yml new file mode 100644 index 000000000..1824bdc5a --- /dev/null +++ b/test/cases/020_kernel/115_kmod_5.12.x/test.yml @@ -0,0 +1,20 @@ +kernel: + image: linuxkit/kernel:5.12.14 + cmdline: "console=ttyS0 console=ttyAMA0" +init: + - linuxkit/init:78fb57c7da07c4e43c3a37b27755581da087a3b6 + - linuxkit/runc:bf1e0c61fb4678d6428d0aabbd80db5ea24e4d4d +onboot: + - name: check + image: kmod-test + binds: + - /dev:/dev + - /lib/modules:/lib/modules + capabilities: + - all + - name: poweroff + image: linuxkit/poweroff:afe4b3ab865afe1e3ed5c88e58f57808f4f5119f + command: ["/bin/sh", "/poweroff.sh", "3"] +trust: + org: + - linuxkit diff --git a/test/cases/020_kernel/215_tags_5.12.x/test.sh b/test/cases/020_kernel/215_tags_5.12.x/test.sh new file mode 100644 index 000000000..3ba327d51 --- /dev/null +++ b/test/cases/020_kernel/215_tags_5.12.x/test.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# SUMMARY: Test existence and correctness of kernel builder tag, label and file +# LABELS: +# REPEAT: + +set -e + +KERNEL=linuxkit/kernel:5.12.14 + +# just include the common test +. ../tags.sh