test: Add kerel tests for 4.15

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer 2018-02-02 10:50:57 +00:00
parent f6bc92666a
commit a4907741af
8 changed files with 157 additions and 0 deletions

View File

@ -0,0 +1,25 @@
#!/bin/sh
# SUMMARY: Sanity check on the kernel config file
# disabled for arm64: https://github.com/linuxkit/linuxkit/issues/2807
# LABELS: amd64
# 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

View File

@ -0,0 +1,15 @@
kernel:
image: linuxkit/kernel:4.15
cmdline: "console=ttyS0 console=ttyAMA0"
init:
- linuxkit/init:e650be6c21ef9ecb33534858fc63fb8bc5028c6e
- linuxkit/runc:52ecfdef1ae051e7fd5ac5f1d0b7dd859adff015
onboot:
- name: check-kernel-config
image: linuxkit/test-kernel-config:80bb1cd57205e47b5976f7fa4fb036384d012a1d
- name: poweroff
image: linuxkit/poweroff:f9a0a5e52fd2a97908bda33db2afffafe4a6a67d
command: ["/bin/sh", "/poweroff.sh", "3"]
trust:
org:
- linuxkit

View File

@ -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:4.15 AS ksrc
# Extract headers and compile module
FROM linuxkit/alpine:d307c8a386fa3f32cddda9409b9687e191cdd6f1 AS build
RUN apk add build-base libelf-dev
COPY --from=ksrc /kernel-dev.tar /
RUN tar xf kernel-dev.tar
WORKDIR /kmod
COPY ./src/* ./
RUN make all
# Package
FROM alpine:3.7
COPY --from=build /kmod/hello_world.ko /
COPY check.sh /check.sh
ENTRYPOINT ["/bin/sh", "/check.sh"]

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,22 @@
/*
* A simple Hello World kernel module
*/
#include <linux/module.h>
#include <linux/kernel.h>
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 <rolf.neugebauer@docker.com>");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("A simple Hello World kernel module for testing");

View File

@ -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:4.9.79
# Build a package
docker build -t ${IMAGE_NAME} .
# Build and run a LinuxKit image with kernel module (and test script)
linuxkit build -format kernel+initrd -name "${NAME}" test.yml
RESULT="$(linuxkit run ${NAME})"
echo "${RESULT}" | grep -q "Hello LinuxKit"
exit 0

View File

@ -0,0 +1,20 @@
kernel:
image: linuxkit/kernel:4.15
cmdline: "console=ttyS0 console=ttyAMA0"
init:
- linuxkit/init:e650be6c21ef9ecb33534858fc63fb8bc5028c6e
- linuxkit/runc:52ecfdef1ae051e7fd5ac5f1d0b7dd859adff015
onboot:
- name: check
image: kmod-test
binds:
- /dev:/dev
- /lib/modules:/lib/modules
capabilities:
- all
- name: poweroff
image: linuxkit/poweroff:f9a0a5e52fd2a97908bda33db2afffafe4a6a67d
command: ["/bin/sh", "/poweroff.sh", "3"]
trust:
org:
- linuxkit