mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-18 17:01:07 +00:00
tests: Add tests for the 5.1.x kernel
Signed-off-by: Rolf Neugebauer <rn@rneugeba.io>
This commit is contained in:
parent
0a46f29a05
commit
d72c928a1e
24
test/cases/020_kernel/008_config_5.1.x/test.sh
Normal file
24
test/cases/020_kernel/008_config_5.1.x/test.sh
Normal file
@ -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
|
15
test/cases/020_kernel/008_config_5.1.x/test.yml
Normal file
15
test/cases/020_kernel/008_config_5.1.x/test.yml
Normal file
@ -0,0 +1,15 @@
|
||||
kernel:
|
||||
image: linuxkit/kernel:5.1.1
|
||||
cmdline: "console=ttyS0 console=ttyAMA0"
|
||||
init:
|
||||
- linuxkit/init:v0.7
|
||||
- linuxkit/runc:v0.7
|
||||
onboot:
|
||||
- name: check-kernel-config
|
||||
image: linuxkit/test-kernel-config:0e9308f871ac86c680d64836a050547a2feebb36
|
||||
- name: poweroff
|
||||
image: linuxkit/poweroff:b498d30dd9660090565537fceb9e757618737a85
|
||||
command: ["/bin/sh", "/poweroff.sh", "3"]
|
||||
trust:
|
||||
org:
|
||||
- linuxkit
|
23
test/cases/020_kernel/018_kmod_5.1.x/Dockerfile
Normal file
23
test/cases/020_kernel/018_kmod_5.1.x/Dockerfile
Normal 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:5.1.1 AS ksrc
|
||||
|
||||
# Extract headers and compile module
|
||||
FROM linuxkit/alpine:86cd4f51b49fb9a078b50201d892a3c7973d48ec 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.9
|
||||
COPY --from=build /kmod/hello_world.ko /
|
||||
COPY check.sh /check.sh
|
||||
ENTRYPOINT ["/bin/sh", "/check.sh"]
|
15
test/cases/020_kernel/018_kmod_5.1.x/check.sh
Executable file
15
test/cases/020_kernel/018_kmod_5.1.x/check.sh
Executable 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
|
6
test/cases/020_kernel/018_kmod_5.1.x/src/Makefile
Normal file
6
test/cases/020_kernel/018_kmod_5.1.x/src/Makefile
Normal 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
|
22
test/cases/020_kernel/018_kmod_5.1.x/src/hello_world.c
Normal file
22
test/cases/020_kernel/018_kmod_5.1.x/src/hello_world.c
Normal 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");
|
31
test/cases/020_kernel/018_kmod_5.1.x/test.sh
Normal file
31
test/cases/020_kernel/018_kmod_5.1.x/test.sh
Normal 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:5.1.1
|
||||
# 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
|
20
test/cases/020_kernel/018_kmod_5.1.x/test.yml
Normal file
20
test/cases/020_kernel/018_kmod_5.1.x/test.yml
Normal file
@ -0,0 +1,20 @@
|
||||
kernel:
|
||||
image: linuxkit/kernel:5.1.1
|
||||
cmdline: "console=ttyS0 console=ttyAMA0"
|
||||
init:
|
||||
- linuxkit/init:v0.7
|
||||
- linuxkit/runc:v0.7
|
||||
onboot:
|
||||
- name: check
|
||||
image: kmod-test
|
||||
binds:
|
||||
- /dev:/dev
|
||||
- /lib/modules:/lib/modules
|
||||
capabilities:
|
||||
- all
|
||||
- name: poweroff
|
||||
image: linuxkit/poweroff:b498d30dd9660090565537fceb9e757618737a85
|
||||
command: ["/bin/sh", "/poweroff.sh", "3"]
|
||||
trust:
|
||||
org:
|
||||
- linuxkit
|
Loading…
Reference in New Issue
Block a user