Skip to content

Commit

Permalink
test: Resolution logic for os-release
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Oct 23, 2023
1 parent 1ddf7a8 commit c8547d0
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dkms.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
50 changes: 50 additions & 0 deletions run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -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=(
Expand Down Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions test/dkms_osrelease_stub-1.0/Makefile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions test/dkms_osrelease_stub-1.0/dkms.conf
Original file line number Diff line number Diff line change
@@ -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"
23 changes: 23 additions & 0 deletions test/dkms_osrelease_stub-1.0/dkms_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

#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);

0 comments on commit c8547d0

Please sign in to comment.