From c8547d0405ddfffb6cef8af6d5dc7d3ee4a35d8f Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Mon, 23 Oct 2023 05:56:30 -0700 Subject: [PATCH] test: Resolution logic for `os-release` --- dkms.in | 2 +- run_test.sh | 50 ++++++++++++++++++++++++ test/dkms_osrelease_stub-1.0/Makefile | 7 ++++ test/dkms_osrelease_stub-1.0/dkms.conf | 7 ++++ test/dkms_osrelease_stub-1.0/dkms_test.c | 23 +++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 test/dkms_osrelease_stub-1.0/Makefile create mode 100644 test/dkms_osrelease_stub-1.0/dkms.conf create mode 100644 test/dkms_osrelease_stub-1.0/dkms_test.c diff --git a/dkms.in b/dkms.in index e8216692..37f96646 100644 --- a/dkms.in +++ b/dkms.in @@ -2325,7 +2325,7 @@ unset CC CXX CFLAGS CXXFLAGS LDFLAGS # Set important variables current_kernel=$(uname -r) current_os=$(uname -s) -running_distribution=$(distro_version) +running_distribution=$(distro_version) || exit dkms_tree="/var/lib/dkms" source_tree="/usr/src" install_tree="/lib/modules" diff --git a/run_test.sh b/run_test.sh index 87c464d9..17b6fb80 100755 --- a/run_test.sh +++ b/run_test.sh @@ -29,6 +29,7 @@ TEST_MODULES=( "dkms_conf_test" "dkms_build_exclusive_test" "dkms_build_exclusive_dependencies_test" + "dkms_osrelease_stub" ) TEST_TMPDIRS=( "/usr/src/dkms_test-1.0/" @@ -44,6 +45,7 @@ TEST_TMPDIRS=( "/usr/src/dkms_conf_test-1.0" "/usr/src/dkms_build_exclusive_test-1.0" "/usr/src/dkms_build_exclusive_dependencies_test-1.0" + "/usr/src/dkms_osrelease_stub-1.0" "/tmp/dkms_test_dir_${KERNEL_VER}/" ) TEST_TMPFILES=( @@ -1541,6 +1543,54 @@ EOF echo 'Removing /usr/src/dkms_build_exclusive_test-1.0' rm -r /usr/src/dkms_build_exclusive_test-1.0 +############################################################################ +### Testing os-release detection ### +############################################################################ +# Get the contents of the os-release file. We do it first so symlinks resolve +osrelease_contents=$(for f in /etc/os-release /usr/lib/os-release; do + cat "$f" +done) +osrelease_cleanup() { + mv _etc-os-release /etc/os-release &>/dev/null + mv _usrlib-os-release /usr/lib/os-release &>/dev/null +} +trap osrelease_cleanup EXIT +mv /etc/os-release _etc-os-release &>/dev/null +mv /usr/lib/os-release _usrlib-os-release &>/dev/null + +echo "Fails when there are no os-release files" +run_with_expected_error 4 dkms add test/dkms_osrelease_stub-1.0 << EOF +Error! System is missing os-release file. +EOF + +cat > /etc/os-release <<< "$osrelease_contents" +echo 'Reads /etc/os-release' +run_with_expected_output dkms add test/dkms_osrelease_stub-1.0 << EOF +Creating symlink /var/lib/dkms/dkms_osrelease_stub/1.0/source -> /usr/src/dkms_osrelease_stub-1.0 +EOF +run_status_with_expected_output 'dkms_osrelease_stub' << EOF +dkms_osrelease_stub/1.0: added +EOF +run_with_expected_output dkms remove dkms_osrelease_stub/1.0 << EOF +Module dkms_osrelease_stub 1.0 is not installed for kernel 5.15.0-86-generic (x86_64). Skipping... +Module dkms_osrelease_stub 1.0 is not built for kernel 5.15.0-86-generic (x86_64). Skipping... +Deleting module dkms_osrelease_stub-1.0 completely from the DKMS tree. +EOF +rm -f /etc/os-release + +cat > /usr/lib/os-release <<< "$osrelease_contents" +echo 'Reads /usr/lib/os-release' +run_with_expected_output dkms add test/dkms_osrelease_stub-1.0 << EOF +Creating symlink /var/lib/dkms/dkms_osrelease_stub/1.0/source -> /usr/src/dkms_osrelease_stub-1.0 +EOF +run_status_with_expected_output 'dkms_osrelease_stub' << EOF +dkms_osrelease_stub/1.0: added +EOF +rm -f /usr/lib/os-release + +osrelease_cleanup +trap - EXIT + echo 'Checking that the environment is clean again' check_no_dkms_test diff --git a/test/dkms_osrelease_stub-1.0/Makefile b/test/dkms_osrelease_stub-1.0/Makefile new file mode 100644 index 00000000..c6c2d32e --- /dev/null +++ b/test/dkms_osrelease_stub-1.0/Makefile @@ -0,0 +1,7 @@ +obj-m += dkms_test.o + +all: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + +clean: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean diff --git a/test/dkms_osrelease_stub-1.0/dkms.conf b/test/dkms_osrelease_stub-1.0/dkms.conf new file mode 100644 index 00000000..22d01c62 --- /dev/null +++ b/test/dkms_osrelease_stub-1.0/dkms.conf @@ -0,0 +1,7 @@ +PACKAGE_NAME="dkms_osrelease_stub" +PACKAGE_VERSION="1.0" +BUILT_MODULE_NAME="dkms_osrelease_stub" + +AUTOINSTALL="yes" + +DEST_MODULE_LOCATION="/kernel/extra" diff --git a/test/dkms_osrelease_stub-1.0/dkms_test.c b/test/dkms_osrelease_stub-1.0/dkms_test.c new file mode 100644 index 00000000..93d00982 --- /dev/null +++ b/test/dkms_osrelease_stub-1.0/dkms_test.c @@ -0,0 +1,23 @@ +#include +#include +#include + +#define DKMS_TEST_VER "1.0" + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("A Simple dkms test module"); + +static int __init dkms_test_init(void) +{ + printk(KERN_INFO "DKMS Test Module -%s Loaded\n",DKMS_TEST_VER); + return 0; +} + +static void __exit dkms_test_cleanup(void) +{ + printk(KERN_INFO "Cleaning up after dkms test module.\n"); +} + +module_init(dkms_test_init); +module_exit(dkms_test_cleanup); +MODULE_VERSION(DKMS_TEST_VER);