From 0c9322191cb72a071c5de6c7b748d21961a0558f Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Sun, 19 Jan 2025 22:17:50 +0100 Subject: [PATCH 01/57] run_test.sh: fix signing related scoping --- run_test.sh | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/run_test.sh b/run_test.sh index df7d8e4e..6d12fbe1 100755 --- a/run_test.sh +++ b/run_test.sh @@ -447,12 +447,6 @@ dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built EOF if (( NO_SIGNING_TOOL == 0 )); then - SIGNING_PROLOGUE_="${SIGNING_PROLOGUE}" - SIGNING_PROLOGUE="${SIGNING_PROLOGUE_command} -Signing key: /tmp/dkms_test_private_key -Public certificate (MOK): /tmp/dkms_test_certificate -" - echo 'Building the test module with bad sign_file path in framework file' cp test/framework/bad_sign_file_path.conf /etc/dkms/framework.conf.d/dkms_test_framework.conf run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF @@ -508,14 +502,19 @@ EOF BUILT_MODULE_PATH="/var/lib/dkms/dkms_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/module/dkms_test.ko${mod_compression_ext}" CURRENT_HASH="$(modinfo -F sig_hashalgo "${BUILT_MODULE_PATH}")" + cp test/framework/temp_key_cert.conf /etc/dkms/framework.conf.d/dkms_test_framework.conf + SIGNING_PROLOGUE_="${SIGNING_PROLOGUE}" + SIGNING_PROLOGUE="${SIGNING_PROLOGUE_command} +Signing key: /tmp/dkms_test_private_key +Public certificate (MOK): /tmp/dkms_test_certificate +" + echo ' Building the test module using a different hash algorithm' if kmod_broken_hashalgo; then echo ' Current kmod has broken hash algorithm code. Skipping...' elif [[ "${CURRENT_HASH}" == "unknown" ]]; then echo ' Current kmod reports unknown hash algorithm. Skipping...' else - cp test/framework/temp_key_cert.conf /etc/dkms/framework.conf.d/dkms_test_framework.conf - if [[ "${CURRENT_HASH}" == "sha512" ]]; then ALTER_HASH="sha256" else @@ -533,12 +532,8 @@ ${ALTER_HASH} EOF rm /tmp/dkms_test_kconfig fi - - rm /etc/dkms/framework.conf.d/dkms_test_framework.conf fi -cp test/framework/temp_key_cert.conf /etc/dkms/framework.conf.d/dkms_test_framework.conf - echo 'Building the test module again by force' run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF ${SIGNING_PROLOGUE} @@ -750,6 +745,13 @@ if [[ -e "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_comp exit 1 fi +if (( NO_SIGNING_TOOL == 0 )); then + echo 'Removing temporary files' + rm /tmp/dkms_test_private_key /tmp/dkms_test_certificate + SIGNING_PROLOGUE="${SIGNING_PROLOGUE_}" + rm /etc/dkms/framework.conf.d/dkms_test_framework.conf +fi + remove_module_source_tree /usr/src/dkms_test-1.0 echo 'Building the test module by config file (combining add, build)' @@ -922,13 +924,6 @@ EOF run_status_with_expected_output 'dkms_test' << EOF EOF -echo 'Removing temporary files' -if (( NO_SIGNING_TOOL == 0 )); then - rm /tmp/dkms_test_private_key /tmp/dkms_test_certificate - SIGNING_PROLOGUE="${SIGNING_PROLOGUE_}" -fi -rm /etc/dkms/framework.conf.d/dkms_test_framework.conf - remove_module_source_tree /usr/src/dkms_test-1.0 echo 'Checking that the environment is clean again' From 6159c3498f6e3c5239750e753f6b973faa8fa2da Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Sun, 24 Nov 2024 22:50:25 +0100 Subject: [PATCH 02/57] dkms: merge prepare_build, actual_build and clean_build --- dkms.in | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/dkms.in b/dkms.in index 43c32ec4..1cbf87aa 100644 --- a/dkms.in +++ b/dkms.in @@ -1132,8 +1132,8 @@ prepare_signing() do_signing=1 } -# Get ready to build a module that has been registered with DKMS. -prepare_build() +# Build a module that has been registered with DKMS. +prepare_and_actual_build() { # If the module has not been added, try to add it. if ! is_module_added "$module" "$module_version" ; then @@ -1249,14 +1249,7 @@ prepare_build() # Run the pre_build script run_build_script pre_build "$pre_build" -} -# Build our previously prepared source tree. prepare_build must be called -# before calling this function. -actual_build() -{ - local -r base_dir="$dkms_tree/$module/$module_version/$kernelver/$arch" - local -r build_dir="$dkms_tree/$module/$module_version/build" local -r build_log="$build_dir/make.log" invoke_command "$clean" "Cleaning build area" '' background @@ -1325,11 +1318,7 @@ actual_build() # Run the post_build script run_build_script post_build "$post_build" -} -# Clean up after a build. -clean_build() -{ # Run the clean commands cd "$dkms_tree/$module/$module_version/build" invoke_command "$clean" "Cleaning build area" '' background @@ -1353,9 +1342,7 @@ prepare_kernel_and_signing() do_build() { prepare_kernel_and_signing - prepare_build - actual_build - clean_build + prepare_and_actual_build } # Force the installation of a module if this is listed From ce1e94bb6d1143e3d25517758244f3db8fc92b42 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 17 Dec 2024 22:26:27 +0100 Subject: [PATCH 03/57] run_test.sh: support testing make.log content --- run_test.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/run_test.sh b/run_test.sh index 6d12fbe1..46d5c8f4 100755 --- a/run_test.sh +++ b/run_test.sh @@ -238,6 +238,48 @@ run_with_expected_error() { rm ${expected_output_log} ${output_log} } +generalize_make_log() { + local output_log="$1" + + sed -r -i ' +# timestamp on line 2 +2s/.*// + +# minimize and unify compilation output between distributions +# we are not really interested in the compilation details +/warning: the compiler differs from the one used to build the kernel/d +/ The kernel was built by:/d +/ You are using:/d +/make(\[[0-9]+\])?: (Entering|Leaving) directory/d +s/ \[M\] / / +/^ /s/\/var\/lib\/dkms\/.*\/// +/^ AR built-in\.a$/d +/^ Building modules, stage 2\.$/d +/^ MODPOST Module\.symvers$/d +/^ MODPOST [0-9]+ modules$/d +/^ CC \.module-common\.o$/d +/^ BTF dkms_(.*_)?test.ko$/d +/Skipping BTF generation for (\/var\/lib\/dkms\/.*\/)?dkms_(.*_)?test.ko due to unavailability of vmlinux$/d +/^ CLEAN \.tmp_versions$/d +' ${output_log} +} + +check_make_log_content() { + local make_log="$1" + local output_log=test_cmd_output.log + local expected_output_log=test_cmd_expected_output.log + + cat > ${expected_output_log} + cat "$make_log" > ${output_log} + generalize_make_log ${output_log} + if ! diff -U3 ${expected_output_log} ${output_log} ; then + echo >&2 "Error: unexpected make.log difference" + rm ${expected_output_log} ${output_log} + return 1 + fi + rm ${expected_output_log} ${output_log} +} + check_module_source_tree_created() { if ! [[ -d "$1" ]] ; then echo >&2 "Error: directory '$1' was not created" @@ -422,6 +464,15 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built EOF +echo 'Checking make.log content' +check_make_log_content /var/lib/dkms/dkms_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/log/make.log << EOF +DKMS make.log for dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) + + CC dkms_test.o + CC dkms_test.mod.o + LD dkms_test.ko +EOF + echo 'Building the test module again' run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF Module dkms_test/1.0 already built for kernel ${KERNEL_VER} (${KERNEL_ARCH}), skip. You may override by specifying --force. @@ -1578,6 +1629,15 @@ run_status_with_expected_output 'dkms_noisy_test' << EOF dkms_noisy_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF +echo 'Checking make.log content' +check_make_log_content /var/lib/dkms/dkms_noisy_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/log/make.log << EOF +DKMS make.log for dkms_noisy_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) + + CC dkms_noisy_test.o + CC dkms_noisy_test.mod.o + LD dkms_noisy_test.ko +EOF + echo 'Unbuilding the noisy test module' run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_noisy_test -v 1.0 << EOF Module dkms_noisy_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): From f514096420df2b4c7365476cd80ef25405ec38be Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 17 Dec 2024 00:40:55 +0100 Subject: [PATCH 04/57] make.log: log command and exit code --- dkms.in | 3 +++ run_test.sh | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/dkms.in b/dkms.in index 1cbf87aa..ff28d62c 100644 --- a/dkms.in +++ b/dkms.in @@ -173,8 +173,11 @@ invoke_command() fi if [[ -n "$cmd_output_file" ]]; then + echo -e "$cmd_description" >> "$cmd_output_file" + echo -e "# command: $cmd" >> "$cmd_output_file" ( eval "$cmd" ) >> "$cmd_output_file" 2>&1 exitval=$? + echo -e "\n# exit code: $exitval" >> "$cmd_output_file" elif [[ -z "$cmd_output_file" && $cmd_mode == background && ! $verbose ]]; then ( eval "$cmd" ) >/dev/null 2>&1 exitval=$? diff --git a/run_test.sh b/run_test.sh index 46d5c8f4..cf36b4ec 100755 --- a/run_test.sh +++ b/run_test.sh @@ -468,9 +468,13 @@ echo 'Checking make.log content' check_make_log_content /var/lib/dkms/dkms_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/log/make.log << EOF DKMS make.log for dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Building module(s) +# command: make -j1 KERNELRELEASE=${KERNEL_VER} -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_test/1.0/build CC dkms_test.o CC dkms_test.mod.o LD dkms_test.ko + +# exit code: 0 EOF echo 'Building the test module again' @@ -1633,9 +1637,13 @@ echo 'Checking make.log content' check_make_log_content /var/lib/dkms/dkms_noisy_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/log/make.log << EOF DKMS make.log for dkms_noisy_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Building module(s) +# command: make -j1 KERNELRELEASE=${KERNEL_VER} -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_noisy_test/1.0/build CC dkms_noisy_test.o CC dkms_noisy_test.mod.o LD dkms_noisy_test.ko + +# exit code: 0 EOF echo 'Unbuilding the noisy test module' From cf07a7a371e493ac1d47081588ea9b4a35eca959 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 17 Dec 2024 04:52:48 +0100 Subject: [PATCH 05/57] make.log: log elapsed time --- dkms.in | 5 +++++ run_test.sh | 3 +++ 2 files changed, 8 insertions(+) diff --git a/dkms.in b/dkms.in index ff28d62c..a268abb4 100644 --- a/dkms.in +++ b/dkms.in @@ -173,11 +173,16 @@ invoke_command() fi if [[ -n "$cmd_output_file" ]]; then + local t_start + local t_end echo -e "$cmd_description" >> "$cmd_output_file" echo -e "# command: $cmd" >> "$cmd_output_file" + t_start=$SECONDS ( eval "$cmd" ) >> "$cmd_output_file" 2>&1 exitval=$? + t_end=$SECONDS echo -e "\n# exit code: $exitval" >> "$cmd_output_file" + echo "# elapsed time: $(date -u -d "0 $t_end sec - $t_start sec" +%T)" >> "$cmd_output_file" elif [[ -z "$cmd_output_file" && $cmd_mode == background && ! $verbose ]]; then ( eval "$cmd" ) >/dev/null 2>&1 exitval=$? diff --git a/run_test.sh b/run_test.sh index cf36b4ec..610d13f9 100755 --- a/run_test.sh +++ b/run_test.sh @@ -244,6 +244,7 @@ generalize_make_log() { sed -r -i ' # timestamp on line 2 2s/.*// +/# elapsed time:/s/[0-9]+:[0-9]+:[0-9]+// # minimize and unify compilation output between distributions # we are not really interested in the compilation details @@ -475,6 +476,7 @@ Building module(s) LD dkms_test.ko # exit code: 0 +# elapsed time: EOF echo 'Building the test module again' @@ -1644,6 +1646,7 @@ Building module(s) LD dkms_noisy_test.ko # exit code: 0 +# elapsed time: EOF echo 'Unbuilding the noisy test module' From b31c8e2003185350b710b26d59105db28ef4808a Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Mon, 23 Dec 2024 00:32:10 +0100 Subject: [PATCH 06/57] make.log: log dkms version --- dkms.in | 16 +++++++++------- run_test.sh | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/dkms.in b/dkms.in index a268abb4..99e2d96a 100644 --- a/dkms.in +++ b/dkms.in @@ -1152,6 +1152,7 @@ prepare_and_actual_build() local -r base_dir="$dkms_tree/$module/$module_version/$kernelver/$arch" local -r build_dir="$dkms_tree/$module/$module_version/build" local -r source_dir="$dkms_tree/$module/$module_version/source" + local -r build_log="$build_dir/make.log" local bd local bd_missing local status @@ -1199,6 +1200,9 @@ prepare_and_actual_build() rm -rf "$build_dir" cp -a "$source_dir/" "$build_dir" + echo "DKMS (@RELEASE_STRING@) make.log for $module/$module_version for kernel $kernelver ($arch)" >> "$build_log" + date >> "$build_log" + cd "$build_dir" # Apply any patches @@ -1258,11 +1262,7 @@ prepare_and_actual_build() # Run the pre_build script run_build_script pre_build "$pre_build" - local -r build_log="$build_dir/make.log" - invoke_command "$clean" "Cleaning build area" '' background - echo "DKMS make.log for $module/$module_version for kernel $kernelver ($arch)" >> "$build_log" - date >> "$build_log" local the_make_command the_make_command="${make_command/#make/make -j$parallel_jobs KERNELRELEASE=$kernelver}" @@ -1276,15 +1276,13 @@ prepare_and_actual_build() report_build_problem 7 \ "Build of ${built_module_name[$count]}$module_uncompressed_suffix failed for: $kernelver ($arch)" \ "Make sure the name of the generated module is correct and at the root of the" \ - "build directory, or consult make.log in the build directory" \ - "$build_dir for more information." + "build directory, or consult $build_log for more information." done cd - >/dev/null # Build success, so create DKMS structure for a built module mkdir -p "$base_dir/log" [[ $kernel_config ]] && cp -f "$kernel_config" "$base_dir/log/" - mv -f "$build_log" "$base_dir/log/make.log" 2>/dev/null # Save a copy of the new module mkdir "$base_dir/module" >/dev/null @@ -1330,8 +1328,12 @@ prepare_and_actual_build() # Run the clean commands cd "$dkms_tree/$module/$module_version/build" invoke_command "$clean" "Cleaning build area" '' background + cd - >/dev/null + # Save the log file + mv -f "$build_log" "$base_dir/log/make.log" 2>/dev/null + # Clean the build directory rm -rf "$dkms_tree/$module/$module_version/build" } diff --git a/run_test.sh b/run_test.sh index 610d13f9..67e4a343 100755 --- a/run_test.sh +++ b/run_test.sh @@ -404,6 +404,8 @@ else " fi +DKMS_VERSION="$(dkms --version)" + echo 'Preparing a clean test environment' clean_dkms_env @@ -467,7 +469,7 @@ EOF echo 'Checking make.log content' check_make_log_content /var/lib/dkms/dkms_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/log/make.log << EOF -DKMS make.log for dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +DKMS (${DKMS_VERSION}) make.log for dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) Building module(s) # command: make -j1 KERNELRELEASE=${KERNEL_VER} -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_test/1.0/build @@ -1637,7 +1639,7 @@ EOF echo 'Checking make.log content' check_make_log_content /var/lib/dkms/dkms_noisy_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/log/make.log << EOF -DKMS make.log for dkms_noisy_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +DKMS (${DKMS_VERSION}) make.log for dkms_noisy_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) Building module(s) # command: make -j1 KERNELRELEASE=${KERNEL_VER} -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_noisy_test/1.0/build From da5b09a11eae45bad2310ade35e67eae38fa6f4e Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Fri, 27 Dec 2024 00:50:01 +0100 Subject: [PATCH 07/57] make.log: log output from CLEAN commands --- dkms.in | 4 ++-- run_test.sh | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/dkms.in b/dkms.in index 99e2d96a..ee2b8e72 100644 --- a/dkms.in +++ b/dkms.in @@ -1262,7 +1262,7 @@ prepare_and_actual_build() # Run the pre_build script run_build_script pre_build "$pre_build" - invoke_command "$clean" "Cleaning build area" '' background + invoke_command "$clean" "Cleaning build area" "$build_log" background local the_make_command the_make_command="${make_command/#make/make -j$parallel_jobs KERNELRELEASE=$kernelver}" @@ -1327,7 +1327,7 @@ prepare_and_actual_build() # Run the clean commands cd "$dkms_tree/$module/$module_version/build" - invoke_command "$clean" "Cleaning build area" '' background + invoke_command "$clean" "Cleaning build area" "$build_log" background cd - >/dev/null diff --git a/run_test.sh b/run_test.sh index 67e4a343..5914704a 100755 --- a/run_test.sh +++ b/run_test.sh @@ -6,7 +6,8 @@ set -eu cd "$(dirname -- "$0")" # To use a specific kernel version, use the environment variable KERNEL_VER -KERNEL_VER="${KERNEL_VER:-$(uname -r)}" +UNAME_R="$(uname -r)" +KERNEL_VER="${KERNEL_VER:-${UNAME_R}}" KERNEL_ARCH="$(uname -m)" echo "Using kernel ${KERNEL_VER}/${KERNEL_ARCH}" @@ -471,12 +472,23 @@ echo 'Checking make.log content' check_make_log_content /var/lib/dkms/dkms_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/log/make.log << EOF DKMS (${DKMS_VERSION}) make.log for dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Cleaning build area +# command: make -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_test/1.0/build clean + +# exit code: 0 +# elapsed time: Building module(s) # command: make -j1 KERNELRELEASE=${KERNEL_VER} -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_test/1.0/build CC dkms_test.o CC dkms_test.mod.o LD dkms_test.ko +# exit code: 0 +# elapsed time: +Cleaning build area +# command: make -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_test/1.0/build clean + CLEAN Module.symvers + # exit code: 0 # elapsed time: EOF @@ -1641,6 +1653,14 @@ echo 'Checking make.log content' check_make_log_content /var/lib/dkms/dkms_noisy_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/log/make.log << EOF DKMS (${DKMS_VERSION}) make.log for dkms_noisy_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Cleaning build area +# command: make clean +make -C /lib/modules/${UNAME_R}/build M=/var/lib/dkms/dkms_noisy_test/1.0/build clean +make[1]: *** /lib/modules/${UNAME_R}/build: No such file or directory. Stop. +make: *** [Makefile:7: clean] Error 2 + +# exit code: 2 +# elapsed time: Building module(s) # command: make -j1 KERNELRELEASE=${KERNEL_VER} -C /lib/modules/${KERNEL_VER}/build M=/var/lib/dkms/dkms_noisy_test/1.0/build CC dkms_noisy_test.o @@ -1649,6 +1669,14 @@ Building module(s) # exit code: 0 # elapsed time: +Cleaning build area +# command: make clean +make -C /lib/modules/${UNAME_R}/build M=/var/lib/dkms/dkms_noisy_test/1.0/build clean +make[1]: *** /lib/modules/${UNAME_R}/build: No such file or directory. Stop. +make: *** [Makefile:7: clean] Error 2 + +# exit code: 2 +# elapsed time: EOF echo 'Unbuilding the noisy test module' From 496c118e61d45030abd773a003b76c49ea87aa19 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Sun, 29 Dec 2024 23:23:59 +0100 Subject: [PATCH 08/57] make.log: log output from applying patches --- dkms.in | 4 ++-- run_test.sh | 52 ++++++++++++++++++++++++---------------------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/dkms.in b/dkms.in index ee2b8e72..041976a7 100644 --- a/dkms.in +++ b/dkms.in @@ -1214,9 +1214,9 @@ prepare_and_actual_build() report_build_problem 5 \ "Patch $p as specified in dkms.conf cannot be" \ "found in $build_dir/patches/." - invoke_command "patch -p1 < ./patches/$p" "applying patch $p" || \ + invoke_command "patch -p1 < ./patches/$p" "Applying patch $p" "$build_log" background || \ report_build_problem 6 "Application of patch $p failed." \ - "Check $build_dir for more information." + "Consult $build_log for more information." done if [[ -f $kernel_source_dir/.kernelvariables ]]; then diff --git a/run_test.sh b/run_test.sh index 5914704a..471c429e 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1510,12 +1510,8 @@ set_signing_message "dkms_patches_test" "1.0" SIGNING_MESSAGE_patches="$SIGNING_MESSAGE" run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_patches_test -v 1.0 << EOF ${SIGNING_PROLOGUE} -applying patch patch1.patch...patching file Makefile -patching file dkms_patches_test.c - done. -applying patch subdir/patch2.patch...patching file Makefile -patching file dkms_patches_test.c - done. +Applying patch patch1.patch... done. +Applying patch subdir/patch2.patch... done. Cleaning build area... done. Building module(s)... done. ${SIGNING_MESSAGE_patches}Cleaning build area... done. @@ -1599,14 +1595,8 @@ set_signing_message "dkms_noisy_test" "1.0" SIGNING_MESSAGE_noisy="$SIGNING_MESSAGE" run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_noisy_test -v 1.0 << EOF ${SIGNING_PROLOGUE} -applying patch patch2.patch...patching file Makefile -patching file dkms_noisy_test.c - done. -applying patch patch1.patch...patching file Makefile -Hunk #1 succeeded at 3 (offset 2 lines). -patching file dkms_noisy_test.c -Hunk #1 succeeded at 18 (offset 2 lines). - done. +Applying patch patch2.patch... done. +Applying patch patch1.patch... done. Running the pre_build script: /var/lib/dkms/dkms_noisy_test/1.0/build/script.sh pre_build pre_build: line 1 @@ -1653,6 +1643,22 @@ echo 'Checking make.log content' check_make_log_content /var/lib/dkms/dkms_noisy_test/1.0/${KERNEL_VER}/${KERNEL_ARCH}/log/make.log << EOF DKMS (${DKMS_VERSION}) make.log for dkms_noisy_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Applying patch patch2.patch +# command: patch -p1 < ./patches/patch2.patch +patching file Makefile +patching file dkms_noisy_test.c + +# exit code: 0 +# elapsed time: +Applying patch patch1.patch +# command: patch -p1 < ./patches/patch1.patch +patching file Makefile +Hunk #1 succeeded at 3 (offset 2 lines). +patching file dkms_noisy_test.c +Hunk #1 succeeded at 18 (offset 2 lines). + +# exit code: 0 +# elapsed time: Cleaning build area # command: make clean make -C /lib/modules/${UNAME_R}/build M=/var/lib/dkms/dkms_noisy_test/1.0/build clean @@ -1751,14 +1757,8 @@ which does not match this kernel/arch/config. This indicates that it should not be built. Autoinstall of module dkms_noisy_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) -applying patch patch2.patch...patching file Makefile -patching file dkms_noisy_test.c - done. -applying patch patch1.patch...patching file Makefile -Hunk #1 succeeded at 3 (offset 2 lines). -patching file dkms_noisy_test.c -Hunk #1 succeeded at 18 (offset 2 lines). - done. +Applying patch patch2.patch... done. +Applying patch patch1.patch... done. Running the pre_build script: /var/lib/dkms/dkms_noisy_test/1.0/build/script.sh pre_build pre_build: line 1 @@ -1798,12 +1798,8 @@ post_install: line 5 Running depmod... done. Autoinstall of module dkms_patches_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) -applying patch patch1.patch...patching file Makefile -patching file dkms_patches_test.c - done. -applying patch subdir/patch2.patch...patching file Makefile -patching file dkms_patches_test.c - done. +Applying patch patch1.patch... done. +Applying patch subdir/patch2.patch... done. Cleaning build area... done. Building module(s)... done. ${SIGNING_MESSAGE_patches}Cleaning build area... done. From 241599d4fd7c9b893a6ec8a90d76ceebb1e0f23c Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Mon, 30 Dec 2024 04:47:12 +0100 Subject: [PATCH 09/57] make.log: log output from pre/post_build scripts Fixes: #333 --- dkms.in | 9 ++++++-- run_test.sh | 62 ++++++++++++++++++++++++++--------------------------- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/dkms.in b/dkms.in index 041976a7..eba43384 100644 --- a/dkms.in +++ b/dkms.in @@ -942,6 +942,7 @@ read_conf_or_die() { run_build_script() { # $1 = script type # $2 = script to run + # $3 = (optional) logfile for script output local script_type local run [[ $2 ]] || return 0 @@ -955,11 +956,15 @@ run_build_script() { esac run="$dkms_tree/$module/$module_version/$script_type/$2" if [[ -x ${run%% *} ]]; then + if [[ $3 ]]; then + invoke_command "cd $dkms_tree/$module/$module_version/$script_type/ && $run" "Running the $1 script" "$3" background || exit $? + else echo "Running the $1 script:" ( cd "$dkms_tree/$module/$module_version/$script_type/" exec $run ) + fi else echo "" warn "The $1 script is not executable." @@ -1260,7 +1265,7 @@ prepare_and_actual_build() fi # Run the pre_build script - run_build_script pre_build "$pre_build" + run_build_script pre_build "$pre_build" "$build_log" invoke_command "$clean" "Cleaning build area" "$build_log" background local the_make_command @@ -1323,7 +1328,7 @@ prepare_and_actual_build() done # Run the post_build script - run_build_script post_build "$post_build" + run_build_script post_build "$post_build" "$build_log" # Run the clean commands cd "$dkms_tree/$module/$module_version/build" diff --git a/run_test.sh b/run_test.sh index 471c429e..6b95d2ab 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1548,10 +1548,10 @@ set_signing_message "dkms_scripts_test" "1.0" SIGNING_MESSAGE_scripts="$SIGNING_MESSAGE" run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_scripts_test -v 1.0 << EOF ${SIGNING_PROLOGUE} -Running the pre_build script: +Running the pre_build script... done. Cleaning build area... done. Building module(s)... done. -${SIGNING_MESSAGE_scripts}Running the post_build script: +${SIGNING_MESSAGE_scripts}Running the post_build script... done. Cleaning build area... done. Running the pre_install script: Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_scripts_test.ko${mod_compression_ext} @@ -1597,24 +1597,12 @@ run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_noisy_test -v 1 ${SIGNING_PROLOGUE} Applying patch patch2.patch... done. Applying patch patch1.patch... done. -Running the pre_build script: -/var/lib/dkms/dkms_noisy_test/1.0/build/script.sh pre_build -pre_build: line 1 -pre_build: line 2/stderr -pre_build: line 3 -pre_build: line 4/stderr -pre_build: line 5 +Running the pre_build script... done. Cleaning build area...(bad exit status: 2) Failed command: make clean Building module(s)... done. -${SIGNING_MESSAGE_noisy}Running the post_build script: -/var/lib/dkms/dkms_noisy_test/1.0/build/script.sh post_build -post_build: line 1 -post_build: line 2/stderr -post_build: line 3 -post_build: line 4/stderr -post_build: line 5 +${SIGNING_MESSAGE_noisy}Running the post_build script... done. Cleaning build area...(bad exit status: 2) Failed command: make clean @@ -1657,6 +1645,17 @@ Hunk #1 succeeded at 3 (offset 2 lines). patching file dkms_noisy_test.c Hunk #1 succeeded at 18 (offset 2 lines). +# exit code: 0 +# elapsed time: +Running the pre_build script +# command: cd /var/lib/dkms/dkms_noisy_test/1.0/build/ && /var/lib/dkms/dkms_noisy_test/1.0/build/script.sh pre_build +/var/lib/dkms/dkms_noisy_test/1.0/build/script.sh pre_build +pre_build: line 1 +pre_build: line 2/stderr +pre_build: line 3 +pre_build: line 4/stderr +pre_build: line 5 + # exit code: 0 # elapsed time: Cleaning build area @@ -1673,6 +1672,17 @@ Building module(s) CC dkms_noisy_test.mod.o LD dkms_noisy_test.ko +# exit code: 0 +# elapsed time: +Running the post_build script +# command: cd /var/lib/dkms/dkms_noisy_test/1.0/build/ && /var/lib/dkms/dkms_noisy_test/1.0/build/script.sh post_build +/var/lib/dkms/dkms_noisy_test/1.0/build/script.sh post_build +post_build: line 1 +post_build: line 2/stderr +post_build: line 3 +post_build: line 4/stderr +post_build: line 5 + # exit code: 0 # elapsed time: Cleaning build area @@ -1759,24 +1769,12 @@ This indicates that it should not be built. Autoinstall of module dkms_noisy_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) Applying patch patch2.patch... done. Applying patch patch1.patch... done. -Running the pre_build script: -/var/lib/dkms/dkms_noisy_test/1.0/build/script.sh pre_build -pre_build: line 1 -pre_build: line 2/stderr -pre_build: line 3 -pre_build: line 4/stderr -pre_build: line 5 +Running the pre_build script... done. Cleaning build area...(bad exit status: 2) Failed command: make clean Building module(s)... done. -${SIGNING_MESSAGE_noisy}Running the post_build script: -/var/lib/dkms/dkms_noisy_test/1.0/build/script.sh post_build -post_build: line 1 -post_build: line 2/stderr -post_build: line 3 -post_build: line 4/stderr -post_build: line 5 +${SIGNING_MESSAGE_noisy}Running the post_build script... done. Cleaning build area...(bad exit status: 2) Failed command: make clean @@ -1807,10 +1805,10 @@ Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_patches_test.ko$ Running depmod... done. Autoinstall of module dkms_scripts_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) -Running the pre_build script: +Running the pre_build script... done. Cleaning build area... done. Building module(s)... done. -${SIGNING_MESSAGE_scripts}Running the post_build script: +${SIGNING_MESSAGE_scripts}Running the post_build script... done. Cleaning build area... done. Running the pre_install script: Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_scripts_test.ko${mod_compression_ext} From 71a8a559998cea3422ae4ae9d145a972402e7144 Mon Sep 17 00:00:00 2001 From: Martin Rys Date: Fri, 17 Jan 2025 15:07:30 +0100 Subject: [PATCH 10/57] Set compression levels to upstream defaults --- dkms.in | 6 +++--- dkms_framework.conf.in | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dkms.in b/dkms.in index eba43384..252a22bd 100644 --- a/dkms.in +++ b/dkms.in @@ -2704,9 +2704,9 @@ verbose="" symlink_modules="" # Set compression defaults -compress_gzip_opts="-9" -compress_xz_opts="--check=crc32 --lzma2=dict=1MiB" -compress_zstd_opts="-q -T0 -19" +compress_gzip_opts="-6" +compress_xz_opts="--check=crc32 --lzma2=dict=1MiB -6" +compress_zstd_opts="-q -T0 -3" # Check that we can write temporary files tmpfile=$(mktemp_or_die) diff --git a/dkms_framework.conf.in b/dkms_framework.conf.in index 8adc54dc..088f5d32 100644 --- a/dkms_framework.conf.in +++ b/dkms_framework.conf.in @@ -51,6 +51,6 @@ # Compression settings DKMS uses when compressing modules. The defaults are # tuned for maximum compression at the expense of speed when compressing. -# compress_gzip_opts="-9" -# compress_xz_opts="--check=crc32 --lzma2=dict=1MiB" -# compress_zstd_opts="-q -T0 -19" +# compress_gzip_opts="-6" +# compress_xz_opts="--check=crc32 --lzma2=dict=1MiB -6" +# compress_zstd_opts="-q -T0 -3" From 3c069ab74792ae56e1334f4b5f74aeefae4d378b Mon Sep 17 00:00:00 2001 From: Martin Rys Date: Mon, 20 Jan 2025 18:36:36 +0100 Subject: [PATCH 11/57] Do not pass compression values in dkms.in, only document defaults in framework --- dkms.in | 6 +++--- dkms_framework.conf.in | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dkms.in b/dkms.in index 252a22bd..00650ccb 100644 --- a/dkms.in +++ b/dkms.in @@ -2704,9 +2704,9 @@ verbose="" symlink_modules="" # Set compression defaults -compress_gzip_opts="-6" -compress_xz_opts="--check=crc32 --lzma2=dict=1MiB -6" -compress_zstd_opts="-q -T0 -3" +compress_gzip_opts="" +compress_xz_opts="--check=crc32 --lzma2=dict=1MiB" +compress_zstd_opts="-q -T0" # Check that we can write temporary files tmpfile=$(mktemp_or_die) diff --git a/dkms_framework.conf.in b/dkms_framework.conf.in index 088f5d32..974099d2 100644 --- a/dkms_framework.conf.in +++ b/dkms_framework.conf.in @@ -50,7 +50,8 @@ # parallel_jobs=2 # Compression settings DKMS uses when compressing modules. The defaults are -# tuned for maximum compression at the expense of speed when compressing. +# used for reasonable compression times. But one might instead wish to use +# maximum compression at the expense of speed when compressing. # compress_gzip_opts="-6" # compress_xz_opts="--check=crc32 --lzma2=dict=1MiB -6" # compress_zstd_opts="-q -T0 -3" From bcdefbffd5bc8cb20c7c4e2c0493c10188ca5ced Mon Sep 17 00:00:00 2001 From: Martin Rys Date: Mon, 20 Jan 2025 18:37:55 +0100 Subject: [PATCH 12/57] Remove superfluous "but" --- dkms_framework.conf.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dkms_framework.conf.in b/dkms_framework.conf.in index 974099d2..ed1b242b 100644 --- a/dkms_framework.conf.in +++ b/dkms_framework.conf.in @@ -50,8 +50,8 @@ # parallel_jobs=2 # Compression settings DKMS uses when compressing modules. The defaults are -# used for reasonable compression times. But one might instead wish to use -# maximum compression at the expense of speed when compressing. +# used, for reasonable compression times. One might instead wish to use +# maximum compression, at the expense of speed when compressing. # compress_gzip_opts="-6" # compress_xz_opts="--check=crc32 --lzma2=dict=1MiB -6" # compress_zstd_opts="-q -T0 -3" From f3604754070f431745c89f608edb9b962a02ab38 Mon Sep 17 00:00:00 2001 From: Simone Caronni Date: Wed, 22 Jan 2025 14:12:08 +0100 Subject: [PATCH 13/57] Install specific targets during tests --- .github/workflows/tests.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2753dec9..cb6450de 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -54,22 +54,26 @@ jobs: if: matrix.distro.name == 'almalinux' || contains(matrix.distro.name, 'centos') || contains(matrix.distro.name, 'fedora') run: | yum install -y diffutils elfutils-libelf gcc kernel kernel-devel make openssl patch + make install-redhat - name: Install Alpine dependencies if: matrix.distro.name == 'alpine' run: | apk --no-cache --update add bash gcc linux${{ matrix.distro.variant }} linux${{ matrix.distro.variant }}-dev make openssl coreutils patch + make install - name: Install Arch Linux dependencies if: matrix.distro.name == 'archlinux' run: | pacman -Syu --noconfirm diffutils gcc make linux${{ matrix.distro.variant }} linux${{ matrix.distro.variant }}-headers openssl patch + make install - name: Install Debian dependencies if: matrix.distro.name == 'debian' run: | apt-get update -q apt-get install -qy make linux-headers-amd64 linux-image-amd64 openssl xz-utils patch + make install-debian - name: Install Gentoo Linux dependencies if: matrix.distro.name == 'gentoo/stage3' @@ -77,22 +81,20 @@ jobs: echo -e "MAKEOPTS=\"-j$(nproc) -l$(nproc)\"\nACCEPT_LICENSE=\"*\"" >> /etc/portage/make.conf wget --progress=dot:mega -O - https://github.com/gentoo-mirror/gentoo/archive/master.tar.gz | tar -xz && mv gentoo-master /var/db/repos/gentoo FEATURES="getbinpkg binpkg-ignore-signature parallel-fetch parallel-install pkgdir-index-trusted" USE="-initramfs" emerge --quiet --noreplace -j$(nproc) -l$(nproc) --autounmask-continue --with-bdeps=n '>=sys-kernel/gentoo-kernel-bin-6.6.0' + make install - name: Install openSUSE leap dependencies if: contains(matrix.distro.name, 'opensuse') run: | zypper --non-interactive install diffutils elfutils gcc kernel${{ matrix.distro.variant }} kernel${{ matrix.distro.variant }}-devel make openssl patch + make install - name: Install Ubuntu dependencies if: matrix.distro.name == 'ubuntu' run: | apt-get update -q apt-get install -qy gcc make linux-headers-generic linux-image-generic openssl shim-signed patch - - - name: Install dkms - run: | - sed -i -e '/echo -en "."/d' dkms.in - make install + make install-debian - name: Run tests run: | From 1055c43e30c2426e9e0b6bd648df512ca2ae8e23 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Wed, 22 Jan 2025 06:42:34 +0100 Subject: [PATCH 14/57] .gitignore: update after renaming generated files --- .gitignore | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d201c009..0bd49a6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,16 @@ /dist dkms dkms.8 +dkms.bash-completion +dkms.zsh-completion +dkms_framework.conf dkms_autoinstaller dkms.service -kernel_install.d_dkms -kernel_postinst.d_dkms +dkms_common.postinst +debian_kernel_install.d +debian_kernel_postinst.d +debian_kernel_prerm.d +redhat_kernel_install.d + test_cmd_expected_output.log test_cmd_output.log From 1b4f5975f074ee9b59e0fab9986f1b0b259f5d56 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 21 Jan 2025 14:55:26 +0100 Subject: [PATCH 15/57] Makefile: enumerate generated files only once --- Makefile | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index a7e4f87f..ee088660 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ SED_SUBSTITUTIONS = \ %: %.in $(SED) $(SED_SUBSTITUTIONS) $< > $@ -all: \ +GENERATED= \ dkms \ dkms.8 \ dkms_autoinstaller \ @@ -43,20 +43,11 @@ all: \ debian_kernel_prerm.d \ redhat_kernel_install.d +all: $(GENERATED) + clean: -rm -rf dist/ - -rm -f dkms - -rm -f dkms.8 - -rm -f dkms_autoinstaller - -rm -f dkms.bash-completion - -rm -f dkms.zsh-completion - -rm -f dkms_common.postinst - -rm -f dkms_framework.conf - -rm -f dkms.service - -rm -f debian_kernel_install.d - -rm -f debian_kernel_postinst.d - -rm -f debian_kernel_prerm.d - -rm -f redhat_kernel_install.d + $(RM) $(GENERATED) install: all $(if $(strip $(VAR)),$(error Setting VAR is not supported)) From 376278f6d6b00fe15efd4648f5fef50a83448678 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 21 Jan 2025 14:03:42 +0100 Subject: [PATCH 16/57] dkms_autoinstaller: drop unused lsb function remainders etc. there is no /etc/sysconfig/ on Debian (or derivatives) --- dkms_autoinstaller.in | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/dkms_autoinstaller.in b/dkms_autoinstaller.in index c6e8cbfd..73a4152e 100644 --- a/dkms_autoinstaller.in +++ b/dkms_autoinstaller.in @@ -17,21 +17,10 @@ ### END INIT INFO -if [ -f /lib/lsb/init-functions ]; then - . /lib/lsb/init-functions -elif [ -f /etc/rc.d/init.d/functions ]; then - . /etc/rc.d/init.d/functions -fi - exec="@SBINDIR@/dkms" -prog=${exec##*/} test -f $exec || exit 0 -[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog - -uname_s=$(uname -s) - _get_kernel_dir() { KVER=$1 DIR="@MODDIR@/$KVER/build" From 58ff47de89fbb02b673d638be53d594b9ac8675f Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 21 Jan 2025 14:32:53 +0100 Subject: [PATCH 17/57] dkms_autoinstaller: flatten kernel header test --- dkms_autoinstaller.in | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/dkms_autoinstaller.in b/dkms_autoinstaller.in index 73a4152e..2a942128 100644 --- a/dkms_autoinstaller.in +++ b/dkms_autoinstaller.in @@ -18,21 +18,10 @@ exec="@SBINDIR@/dkms" +MODDIR="@MODDIR@" test -f $exec || exit 0 -_get_kernel_dir() { - KVER=$1 - DIR="@MODDIR@/$KVER/build" - echo $DIR -} - -_check_kernel_dir() { - DIR=$(_get_kernel_dir $1) - test -e $DIR/include - return $? -} - case "$1" in start) if [ -n "$2" ]; then @@ -40,7 +29,7 @@ case "$1" in else kernel=$(uname -r) fi - if ! _check_kernel_dir $kernel; then + if [ ! -d "$MODDIR/$kernel/build/include" ]; then echo "Automatic installation of modules for kernel $kernel was skipped since the kernel headers for this kernel do not seem to be installed." else dkms autoinstall --kernelver $kernel From 5f92267496c06adccfdbd1fe61d71c2b16e001c5 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Fri, 17 Jan 2025 10:29:40 +0100 Subject: [PATCH 18/57] run_test.sh: test 'dkms add by config file' --- run_test.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/run_test.sh b/run_test.sh index 6b95d2ab..145f7067 100755 --- a/run_test.sh +++ b/run_test.sh @@ -442,13 +442,38 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0: added EOF -echo 'Adding the test module again (expected error)' +echo 'Adding the test module by directory again (expected error)' run_with_expected_error 3 dkms add test/dkms_test-1.0 << EOF Error! DKMS tree already contains: dkms_test/1.0 You cannot add the same module/version combo more than once. EOF +echo 'Removing the test module' +run_with_expected_output dkms remove --all -m dkms_test -v 1.0 << EOF +Deleting module dkms_test/1.0 completely from the DKMS tree. +EOF +run_status_with_expected_output 'dkms_test' << EOF +EOF + +remove_module_source_tree /usr/src/dkms_test-1.0 + +echo 'Adding the test module by config file' +run_with_expected_output dkms add test/dkms_test-1.0/dkms.conf << EOF +Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0 +EOF +check_module_source_tree_created /usr/src/dkms_test-1.0 +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0: added +EOF + +echo 'Adding the test module by config file again (expected error)' +run_with_expected_error 3 dkms add test/dkms_test-1.0/dkms.conf << EOF + +Error! DKMS tree already contains: dkms_test/1.0 +You cannot add the same module/version combo more than once. +EOF + echo 'Adding the test module by version (expected error)' run_with_expected_error 3 dkms add -m dkms_test -v 1.0 << EOF From f8530d907f6f5e930402a4f41afd51bc338d1401 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Fri, 17 Jan 2025 10:06:33 +0100 Subject: [PATCH 19/57] run_test.sh: shuffle 'dkms add by version' tests --- run_test.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/run_test.sh b/run_test.sh index 145f7067..26b0269d 100755 --- a/run_test.sh +++ b/run_test.sh @@ -474,7 +474,22 @@ Error! DKMS tree already contains: dkms_test/1.0 You cannot add the same module/version combo more than once. EOF -echo 'Adding the test module by version (expected error)' +echo 'Removing the test module' +run_with_expected_output dkms remove --all -m dkms_test -v 1.0 << EOF +Deleting module dkms_test/1.0 completely from the DKMS tree. +EOF +run_status_with_expected_output 'dkms_test' << EOF +EOF + +echo 'Adding the test module by version' +run_with_expected_output dkms add -m dkms_test -v 1.0 << EOF +Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0 +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0: added +EOF + +echo 'Adding the test module by version again (expected error)' run_with_expected_error 3 dkms add -m dkms_test -v 1.0 << EOF Error! DKMS tree already contains: dkms_test/1.0 @@ -763,21 +778,6 @@ if ! [[ -d /usr/src/dkms_test-1.0 ]] ; then exit 1 fi -echo 'Adding the test module by version' -run_with_expected_output dkms add -m dkms_test -v 1.0 << EOF -Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0 -EOF -run_status_with_expected_output 'dkms_test' << EOF -dkms_test/1.0: added -EOF - -echo 'Removing the test module' -run_with_expected_output dkms remove --all -m dkms_test -v 1.0 << EOF -Deleting module dkms_test/1.0 completely from the DKMS tree. -EOF -run_status_with_expected_output 'dkms_test' << EOF -EOF - echo 'Installing the test module by version (combining add, build, install)' run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF ${SIGNING_PROLOGUE} From 54f6bb837f8ae6bfd9278bbf28b8067130313be1 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Thu, 16 Jan 2025 12:09:49 +0100 Subject: [PATCH 20/57] run_test.sh: split off a section for autoinstall etc. tests --- run_test.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/run_test.sh b/run_test.sh index 26b0269d..f0c82eac 100755 --- a/run_test.sh +++ b/run_test.sh @@ -850,6 +850,13 @@ fi remove_module_source_tree /usr/src/dkms_test-1.0 +echo 'Checking that the environment is clean again' +check_no_dkms_test + +############################################################################ +echo '*** Testing dkms autoinstall/kernel_{postinst/prerm}' +############################################################################ + echo 'Building the test module by config file (combining add, build)' run_with_expected_output dkms build -k "${KERNEL_VER}" test/dkms_test-1.0/dkms.conf << EOF ${SIGNING_PROLOGUE} @@ -859,11 +866,12 @@ Cleaning build area... done. Building module(s)... done. ${SIGNING_MESSAGE}Cleaning build area... done. EOF +check_module_source_tree_created /usr/src/dkms_test-1.0 run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built EOF -echo "Running dkms autoinstall (module already built)" +echo 'Running dkms autoinstall (module built but not installed)' run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF Autoinstall of module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} @@ -896,7 +904,7 @@ dkms_test/1.0: added EOF rm -f /etc/dkms/no-autoinstall -echo "Running dkms autoinstall" +echo 'Running dkms autoinstall' run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF ${SIGNING_PROLOGUE} Autoinstall of module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) @@ -912,7 +920,7 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF -echo "Running dkms autoinstall again" +echo 'Running dkms autoinstall again' run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF EOF run_status_with_expected_output 'dkms_test' << EOF @@ -966,7 +974,7 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built EOF -echo 'Running dkms kernel_prerm' +echo 'Running dkms kernel_prerm (module built but not installed)' run_with_expected_output dkms kernel_prerm -k "${KERNEL_VER}" << EOF dkms: removing module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... @@ -985,7 +993,7 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0: added EOF -echo "Running dkms kernel_postinst" +echo 'Running dkms kernel_postinst' run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << EOF ${SIGNING_PROLOGUE} Autoinstall of module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) @@ -1001,15 +1009,15 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF -echo "Running dkms kernel_postinst again" +echo 'Running dkms kernel_postinst again' run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << EOF EOF run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF -echo 'Removing the test module with --all' -run_with_expected_output dkms remove --all -m dkms_test -v 1.0 << EOF +echo 'Removing the test module' +run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF Module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): Before uninstall, this module version was ACTIVE on this kernel. Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} From 1a0250c576e9c196718e2fb9f4b5baf4ca8d05da Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Thu, 16 Jan 2025 13:35:50 +0100 Subject: [PATCH 21/57] run_test.sh: move the noautoinstall tests --- run_test.sh | 158 +++++++++++++++++++++++++--------------------------- 1 file changed, 75 insertions(+), 83 deletions(-) diff --git a/run_test.sh b/run_test.sh index f0c82eac..d5f582a6 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1033,6 +1033,81 @@ remove_module_source_tree /usr/src/dkms_test-1.0 echo 'Checking that the environment is clean again' check_no_dkms_test +############################################################################ +echo '*** Testing dkms on a module with AUTOINSTALL=""' +############################################################################ + +echo 'Adding the noautoinstall test module' +run_with_expected_output dkms add test/dkms_noautoinstall_test-1.0 << EOF +Creating symlink /var/lib/dkms/dkms_noautoinstall_test/1.0/source -> /usr/src/dkms_noautoinstall_test-1.0 +EOF +check_module_source_tree_created /usr/src/dkms_noautoinstall_test-1.0 +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added +EOF + +echo 'Running dkms autoinstall' +run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added +EOF + +echo 'Building the noautoinstall test module' +set_signing_message "dkms_noautoinstall_test" "1.0" +run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF +${SIGNING_PROLOGUE} +Cleaning build area... done. +Building module(s)... done. +${SIGNING_MESSAGE}Cleaning build area... done. +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built +EOF + +echo 'Installing the noautoinstall test module' +run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF +Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_noautoinstall_test.ko${mod_compression_ext} +Running depmod... done. +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +EOF + +echo 'Uninstalling the noautoinstall test module' +run_with_expected_output dkms uninstall -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF +Module dkms_noautoinstall_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): +Before uninstall, this module version was ACTIVE on this kernel. +Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_noautoinstall_test.ko${mod_compression_ext} +Running depmod... done. +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built +EOF + +echo 'Unbuilding the noautoinstall test module' +run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF +Module dkms_noautoinstall_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added +EOF + +echo 'Removing the noautoinstall test module' +run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF +Module dkms_noautoinstall_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +Module dkms_noautoinstall_test/1.0 is not built for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... + +Deleting module dkms_noautoinstall_test/1.0 completely from the DKMS tree. +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +EOF + +remove_module_source_tree /usr/src/dkms_noautoinstall_test-1.0 + +echo 'Checking that the environment is clean again' +check_no_dkms_test + ############################################################################ echo '*** Testing dkms modules with dependencies' ############################################################################ @@ -2087,89 +2162,6 @@ remove_module_source_tree \ echo 'Checking that the environment is clean again' check_no_dkms_test -############################################################################ -echo '*** Testing dkms on a regular module with AUTOINSTALL=""' -############################################################################ - -echo 'Adding the noautoinstall test module by directory' -run_with_expected_output dkms add test/dkms_noautoinstall_test-1.0 << EOF -Creating symlink /var/lib/dkms/dkms_noautoinstall_test/1.0/source -> /usr/src/dkms_noautoinstall_test-1.0 -EOF -check_module_source_tree_created /usr/src/dkms_noautoinstall_test-1.0 -run_status_with_expected_output 'dkms_noautoinstall_test' << EOF -dkms_noautoinstall_test/1.0: added -EOF - -echo "Running dkms autoinstall" -run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF -EOF -run_status_with_expected_output 'dkms_noautoinstall_test' << EOF -dkms_noautoinstall_test/1.0: added -EOF - -echo 'Building the noautoinstall test module' -set_signing_message "dkms_noautoinstall_test" "1.0" -run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF -${SIGNING_PROLOGUE} -Cleaning build area... done. -Building module(s)... done. -${SIGNING_MESSAGE}Cleaning build area... done. -EOF -run_status_with_expected_output 'dkms_noautoinstall_test' << EOF -dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built -EOF - -echo 'Installing the noautoinstall test module' -run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF -Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_noautoinstall_test.ko${mod_compression_ext} -Running depmod... done. -EOF -run_status_with_expected_output 'dkms_noautoinstall_test' << EOF -dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed -EOF - -echo 'Uninstalling the noautoinstall test module' -run_with_expected_output dkms uninstall -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF -Module dkms_noautoinstall_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): -Before uninstall, this module version was ACTIVE on this kernel. -Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_noautoinstall_test.ko${mod_compression_ext} -Running depmod... done. -EOF -run_status_with_expected_output 'dkms_noautoinstall_test' << EOF -dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built -EOF -if [[ -e "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_noautoinstall_test.ko${mod_compression_ext}" ]] ; then - echo >&2 "Error: module not removed in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_noautoinstall_test.ko${mod_compression_ext}" - exit 1 -fi - -echo 'Unbuilding the noautoinstall test module' -run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF -Module dkms_noautoinstall_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... -EOF -run_status_with_expected_output 'dkms_noautoinstall_test' << EOF -dkms_noautoinstall_test/1.0: added -EOF - -echo 'Removing the noautoinstall test module' -run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF -Module dkms_noautoinstall_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... -Module dkms_noautoinstall_test/1.0 is not built for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... - -Deleting module dkms_noautoinstall_test/1.0 completely from the DKMS tree. -EOF -run_status_with_expected_output 'dkms_noautoinstall_test' << EOF -EOF -if ! [[ -d /usr/src/dkms_noautoinstall_test-1.0 ]] ; then - echo >&2 'Error: directory /usr/src/dkms_noautoinstall_test-1.0 was removed' - exit 1 -fi - -remove_module_source_tree /usr/src/dkms_noautoinstall_test-1.0 - -echo 'Checking that the environment is clean again' -check_no_dkms_test - ############################################################################ echo '*** Testing malformed/borderline dkms.conf' ############################################################################ From b3cdc19114ef78892202c3eaf60a395870cbadf3 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Mon, 20 Jan 2025 10:19:53 +0100 Subject: [PATCH 22/57] run_test.sh: test 'dkms kernel_postinst/prerm' with a noautoinstall module --- run_test.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/run_test.sh b/run_test.sh index d5f582a6..e3e46236 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1053,6 +1053,13 @@ run_status_with_expected_output 'dkms_noautoinstall_test' << EOF dkms_noautoinstall_test/1.0: added EOF +echo 'Running dkms kernel_postinst' +run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << EOF +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added +EOF + echo 'Building the noautoinstall test module' set_signing_message "dkms_noautoinstall_test" "1.0" run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF @@ -1074,6 +1081,32 @@ run_status_with_expected_output 'dkms_noautoinstall_test' << EOF dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF +echo 'Running dkms kernel_prerm' +run_with_expected_output dkms kernel_prerm -k "${KERNEL_VER}" << EOF +dkms: removing module dkms_noautoinstall_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Module dkms_noautoinstall_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): +Before uninstall, this module version was ACTIVE on this kernel. +Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_noautoinstall_test.ko${mod_compression_ext} + +Running depmod... done. +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added +EOF + +echo 'Installing the noautoinstall test module' +run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF +${SIGNING_PROLOGUE} +Cleaning build area... done. +Building module(s)... done. +${SIGNING_MESSAGE}Cleaning build area... done. +Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_noautoinstall_test.ko${mod_compression_ext} +Running depmod... done. +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +EOF + echo 'Uninstalling the noautoinstall test module' run_with_expected_output dkms uninstall -k "${KERNEL_VER}" -m dkms_noautoinstall_test -v 1.0 << EOF Module dkms_noautoinstall_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): From e4f798c95b167f4deb1c5a8cdd7313c43325973e Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Thu, 16 Jan 2025 02:10:15 +0100 Subject: [PATCH 23/57] run_test.sh: test 'dkms autoinstall' without modules --- run_test.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/run_test.sh b/run_test.sh index e3e46236..b96dd80b 100755 --- a/run_test.sh +++ b/run_test.sh @@ -70,6 +70,7 @@ TEST_TMPFILES=( "/tmp/dkms_test_certificate" "/tmp/dkms_test_kconfig" "/etc/dkms/framework.conf.d/dkms_test_framework.conf" + "/etc/dkms/no-autoinstall" "test_cmd_output.log" "test_cmd_stdout.log" "test_cmd_stderr.log" @@ -857,6 +858,28 @@ check_no_dkms_test echo '*** Testing dkms autoinstall/kernel_{postinst/prerm}' ############################################################################ +echo 'Testing without modules and without headers' + +echo ' Running dkms autoinstall' +run_with_expected_output dkms autoinstall -k "${KERNEL_VER}-noheaders" << EOF +EOF + +echo 'Testing without modules but with /etc/dkms/no-autoinstall' +touch /etc/dkms/no-autoinstall + +echo ' Running dkms autoinstall' +run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF +Automatic installation of modules has been disabled. +EOF + +rm -f /etc/dkms/no-autoinstall + +echo 'Testing without modules' + +echo ' Running dkms autoinstall' +run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF +EOF + echo 'Building the test module by config file (combining add, build)' run_with_expected_output dkms build -k "${KERNEL_VER}" test/dkms_test-1.0/dkms.conf << EOF ${SIGNING_PROLOGUE} From 846366e396635100a5d8c406942ad44c599b7710 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Mon, 20 Jan 2025 11:54:52 +0100 Subject: [PATCH 24/57] run_test.sh: test 'dkms kernel_postinst/prerm' without modules --- run_test.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/run_test.sh b/run_test.sh index b96dd80b..af92aa82 100755 --- a/run_test.sh +++ b/run_test.sh @@ -864,6 +864,14 @@ echo ' Running dkms autoinstall' run_with_expected_output dkms autoinstall -k "${KERNEL_VER}-noheaders" << EOF EOF +echo ' Running dkms kernel_postinst' +run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}-noheaders" << EOF +EOF + +echo ' Running dkms kernel_prerm' +run_with_expected_output dkms kernel_prerm -k "${KERNEL_VER}-noheaders" << EOF +EOF + echo 'Testing without modules but with /etc/dkms/no-autoinstall' touch /etc/dkms/no-autoinstall @@ -872,6 +880,15 @@ run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF Automatic installation of modules has been disabled. EOF +echo ' Running dkms kernel_postinst' +run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << EOF +Automatic installation of modules has been disabled. +EOF + +echo ' Running dkms kernel_prerm' +run_with_expected_output dkms kernel_prerm -k "${KERNEL_VER}" << EOF +EOF + rm -f /etc/dkms/no-autoinstall echo 'Testing without modules' @@ -880,6 +897,14 @@ echo ' Running dkms autoinstall' run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF EOF +echo ' Running dkms kernel_postinst' +run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << EOF +EOF + +echo ' Running dkms kernel_prerm' +run_with_expected_output dkms kernel_prerm -k "${KERNEL_VER}" << EOF +EOF + echo 'Building the test module by config file (combining add, build)' run_with_expected_output dkms build -k "${KERNEL_VER}" test/dkms_test-1.0/dkms.conf << EOF ${SIGNING_PROLOGUE} From 4cfd8f7c3ff5bdc474d6c7a7d0ecb78695ce6e87 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Mon, 20 Jan 2025 13:04:59 +0100 Subject: [PATCH 25/57] run_test.sh: test 'dkms_autoinstaller' without modules --- run_test.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/run_test.sh b/run_test.sh index af92aa82..f86de68e 100755 --- a/run_test.sh +++ b/run_test.sh @@ -855,7 +855,7 @@ echo 'Checking that the environment is clean again' check_no_dkms_test ############################################################################ -echo '*** Testing dkms autoinstall/kernel_{postinst/prerm}' +echo '*** Testing dkms autoinstall/kernel_{postinst/prerm}, dkms_autoinstaller' ############################################################################ echo 'Testing without modules and without headers' @@ -864,6 +864,13 @@ echo ' Running dkms autoinstall' run_with_expected_output dkms autoinstall -k "${KERNEL_VER}-noheaders" << EOF EOF +if [[ -x /usr/lib/dkms/dkms_autoinstaller ]]; then +echo ' Running dkms_autoinstaller' +run_with_expected_output /usr/lib/dkms/dkms_autoinstaller start "${KERNEL_VER}-noheaders" << EOF +Automatic installation of modules for kernel ${KERNEL_VER}-noheaders was skipped since the kernel headers for this kernel do not seem to be installed. +EOF +fi + echo ' Running dkms kernel_postinst' run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}-noheaders" << EOF EOF @@ -880,6 +887,13 @@ run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF Automatic installation of modules has been disabled. EOF +if [[ -x /usr/lib/dkms/dkms_autoinstaller ]]; then +echo ' Running dkms_autoinstaller' +run_with_expected_output /usr/lib/dkms/dkms_autoinstaller start "${KERNEL_VER}" << EOF +Automatic installation of modules has been disabled. +EOF +fi + echo ' Running dkms kernel_postinst' run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << EOF Automatic installation of modules has been disabled. @@ -897,6 +911,12 @@ echo ' Running dkms autoinstall' run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF EOF +if [[ -x /usr/lib/dkms/dkms_autoinstaller ]]; then +echo ' Running dkms_autoinstaller' +run_with_expected_output /usr/lib/dkms/dkms_autoinstaller start "${KERNEL_VER}" << EOF +EOF +fi + echo ' Running dkms kernel_postinst' run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << EOF EOF From b0689ac3d131bb48f4da197aec25600731b4e055 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Mon, 20 Jan 2025 17:22:39 +0100 Subject: [PATCH 26/57] run_test.sh: test 'dkms kernel_postinst/prerm' without headers --- run_test.sh | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/run_test.sh b/run_test.sh index f86de68e..d5a212e6 100755 --- a/run_test.sh +++ b/run_test.sh @@ -962,6 +962,26 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0: added EOF +echo 'Testing without headers' + +echo ' Running dkms autoinstall (expected error)' +run_with_expected_error 21 dkms autoinstall -k "${KERNEL_VER}-noheaders" << EOF + +Error! Your kernel headers for kernel ${KERNEL_VER}-noheaders cannot be found at /lib/modules/${KERNEL_VER}-noheaders/build or /lib/modules/${KERNEL_VER}-noheaders/source. +Please install the linux-headers-${KERNEL_VER}-noheaders package or use the --kernelsourcedir option to tell DKMS where it's located. +EOF + +echo ' Running dkms kernel_postinst (expected error)' +run_with_expected_error 21 dkms kernel_postinst -k "${KERNEL_VER}-noheaders" << EOF + +Error! Your kernel headers for kernel ${KERNEL_VER}-noheaders cannot be found at /lib/modules/${KERNEL_VER}-noheaders/build or /lib/modules/${KERNEL_VER}-noheaders/source. +Please install the linux-headers-${KERNEL_VER}-noheaders package or use the --kernelsourcedir option to tell DKMS where it's located. +EOF + +echo ' Running dkms kernel_prerm' +run_with_expected_output dkms kernel_prerm -k "${KERNEL_VER}-noheaders" << EOF +EOF + touch /etc/dkms/no-autoinstall echo "Running dkms autoinstall with /etc/dkms/no-autoinstall present" run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF @@ -995,13 +1015,6 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF -echo "Running dkms autoinstall for a kernel without headers installed (expected error)" -run_with_expected_error 21 dkms autoinstall -k "${KERNEL_VER}-noheaders" << EOF - -Error! Your kernel headers for kernel ${KERNEL_VER}-noheaders cannot be found at /lib/modules/${KERNEL_VER}-noheaders/build or /lib/modules/${KERNEL_VER}-noheaders/source. -Please install the linux-headers-${KERNEL_VER}-noheaders package or use the --kernelsourcedir option to tell DKMS where it's located. -EOF - echo 'Running dkms kernel_prerm w/o kernel argument (expected error)' run_with_expected_error 4 dkms kernel_prerm << EOF From c34f463e8dbcb73b21eed6b9939a012ca5277fd8 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Mon, 20 Jan 2025 17:22:39 +0100 Subject: [PATCH 27/57] run_test.sh: test 'dkms_autoinstaller' without headers --- run_test.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/run_test.sh b/run_test.sh index d5a212e6..78483118 100755 --- a/run_test.sh +++ b/run_test.sh @@ -971,6 +971,13 @@ Error! Your kernel headers for kernel ${KERNEL_VER}-noheaders cannot be found at Please install the linux-headers-${KERNEL_VER}-noheaders package or use the --kernelsourcedir option to tell DKMS where it's located. EOF +if [[ -x /usr/lib/dkms/dkms_autoinstaller ]]; then +echo ' Running dkms_autoinstaller' +run_with_expected_output /usr/lib/dkms/dkms_autoinstaller start "${KERNEL_VER}-noheaders" << EOF +Automatic installation of modules for kernel ${KERNEL_VER}-noheaders was skipped since the kernel headers for this kernel do not seem to be installed. +EOF +fi + echo ' Running dkms kernel_postinst (expected error)' run_with_expected_error 21 dkms kernel_postinst -k "${KERNEL_VER}-noheaders" << EOF From 8f5234db1df0da2648914593b0742135a1311a99 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Mon, 20 Jan 2025 17:58:10 +0100 Subject: [PATCH 28/57] run_test.sh: test 'dkms kernel_postinst/prerm' with /etc/dkms/no-autoinstall --- run_test.sh | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/run_test.sh b/run_test.sh index 78483118..52b28711 100755 --- a/run_test.sh +++ b/run_test.sh @@ -989,14 +989,42 @@ echo ' Running dkms kernel_prerm' run_with_expected_output dkms kernel_prerm -k "${KERNEL_VER}-noheaders" << EOF EOF +echo 'Testing with /etc/dkms/no-autoinstall' touch /etc/dkms/no-autoinstall -echo "Running dkms autoinstall with /etc/dkms/no-autoinstall present" + +echo ' Running dkms autoinstall' run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF Automatic installation of modules has been disabled. EOF run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0: added EOF + +echo ' Running dkms kernel_postinst' +run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << EOF +Automatic installation of modules has been disabled. +EOF + +echo ' Installing the test module' +run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF +${SIGNING_PROLOGUE} +Cleaning build area... done. +Building module(s)... done. +${SIGNING_MESSAGE}Cleaning build area... done. +Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} +Running depmod... done. +EOF + +echo ' Running dkms kernel_prerm' +run_with_expected_output dkms kernel_prerm -k "${KERNEL_VER}" << EOF +dkms: removing module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): +Before uninstall, this module version was ACTIVE on this kernel. +Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} + +Running depmod... done. +EOF + rm -f /etc/dkms/no-autoinstall echo 'Running dkms autoinstall' From e53215e49a9506a845575799952b5519d0acd9f8 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Mon, 20 Jan 2025 17:58:10 +0100 Subject: [PATCH 29/57] run_test.sh: test 'dkms_autoinstaller' with /etc/dkms/no-autoinstall --- run_test.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/run_test.sh b/run_test.sh index 52b28711..a633d9d8 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1000,6 +1000,13 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0: added EOF +if [[ -x /usr/lib/dkms/dkms_autoinstaller ]]; then +echo ' Running dkms_autoinstaller' +run_with_expected_output /usr/lib/dkms/dkms_autoinstaller start "${KERNEL_VER}" << EOF +Automatic installation of modules has been disabled. +EOF +fi + echo ' Running dkms kernel_postinst' run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << EOF Automatic installation of modules has been disabled. From 3bfdd60f65352b5e36141ff7b6b7c6fbaed8cbe1 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 21 Jan 2025 11:07:07 +0100 Subject: [PATCH 30/57] run_test.sh: test 'dkms_autoinstaller' with a normal module --- run_test.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/run_test.sh b/run_test.sh index a633d9d8..a38130f8 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1057,6 +1057,42 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF +if [[ -x /usr/lib/dkms/dkms_autoinstaller ]]; then +echo 'Unbuilding the test module' +run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF +Module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): +Before uninstall, this module version was ACTIVE on this kernel. +Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} +Running depmod... done. +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0: added +EOF + +echo 'Running dkms_autoinstaller' +run_with_expected_output /usr/lib/dkms/dkms_autoinstaller start "${KERNEL_VER}" << EOF +${SIGNING_PROLOGUE} +Autoinstall of module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Cleaning build area... done. +Building module(s)... done. +${SIGNING_MESSAGE}Cleaning build area... done. +Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} +Running depmod... done. + +Autoinstall on ${KERNEL_VER} succeeded for module(s) dkms_test. +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +EOF + +echo 'Running dkms_autoinstaller again' +run_with_expected_output /usr/lib/dkms/dkms_autoinstaller start "${KERNEL_VER}" << EOF +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +EOF +fi + echo 'Running dkms kernel_prerm w/o kernel argument (expected error)' run_with_expected_error 4 dkms kernel_prerm << EOF From 2504f2b0ea8e8632a686c5ce6b0640ccc17f7d55 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 21 Jan 2025 11:48:08 +0100 Subject: [PATCH 31/57] run_test.sh: test 'dkms_autoinstaller' with a noautoinstall module --- run_test.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/run_test.sh b/run_test.sh index a38130f8..3c9db0d9 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1212,6 +1212,15 @@ run_status_with_expected_output 'dkms_noautoinstall_test' << EOF dkms_noautoinstall_test/1.0: added EOF +if [[ -x /usr/lib/dkms/dkms_autoinstaller ]]; then +echo 'Running dkms_autoinstaller' +run_with_expected_output /usr/lib/dkms/dkms_autoinstaller start "${KERNEL_VER}" << EOF +EOF +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added +EOF +fi + echo 'Running dkms kernel_postinst' run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << EOF EOF From 5aadef0850db07293095c3a56c191f82ee52206a Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 21 Jan 2025 12:06:19 +0100 Subject: [PATCH 32/57] run_test.sh: test 'dkms autoinstall' with a failing module --- run_test.sh | 60 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/run_test.sh b/run_test.sh index 3c9db0d9..fdae78d9 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1189,6 +1189,40 @@ EOF remove_module_source_tree /usr/src/dkms_test-1.0 +echo 'Adding failing test module' +run_with_expected_output dkms add test/dkms_failing_test-1.0 << EOF +Creating symlink /var/lib/dkms/dkms_failing_test/1.0/source -> /usr/src/dkms_failing_test-1.0 +EOF +check_module_source_tree_created /usr/src/dkms_failing_test-1.0 + +echo ' Running autoinstall with failing test module (expected error)' +run_with_expected_error 11 dkms autoinstall -k "${KERNEL_VER}" << EOF +${SIGNING_PROLOGUE} +Autoinstall of module dkms_failing_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Cleaning build area... done. +Building module(s)...(bad exit status: 2) +Failed command: +make -j1 KERNELRELEASE=${KERNEL_VER} all + +Error! Bad return status for module build on kernel: ${KERNEL_VER} (${KERNEL_ARCH}) +Consult /var/lib/dkms/dkms_failing_test/1.0/build/make.log for more information. + +Autoinstall on ${KERNEL_VER} failed for module(s) dkms_failing_test(10). + +Error! One or more modules failed to install during autoinstall. +Refer to previous errors for more information. +EOF + +echo ' Removing failing test module' +run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_failing_test -v 1.0 << EOF +Module dkms_failing_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +Module dkms_failing_test/1.0 is not built for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... + +Deleting module dkms_failing_test/1.0 completely from the DKMS tree. +EOF + +remove_module_source_tree /usr/src/dkms_failing_test-1.0 + echo 'Checking that the environment is clean again' check_no_dkms_test @@ -3028,29 +3062,13 @@ run_with_expected_output dkms add test/dkms_failing_test-1.0 << EOF Creating symlink /var/lib/dkms/dkms_failing_test/1.0/source -> /usr/src/dkms_failing_test-1.0 EOF check_module_source_tree_created /usr/src/dkms_failing_test-1.0 -echo 'Running autoinstall with failing test module (expected error)' -run_with_expected_error 11 dkms autoinstall -k "${KERNEL_VER}" << EOF -${SIGNING_PROLOGUE} -Autoinstall of module dkms_failing_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) -Cleaning build area... done. -Building module(s)...(bad exit status: 2) -Failed command: -make -j1 KERNELRELEASE=${KERNEL_VER} all - -Error! Bad return status for module build on kernel: ${KERNEL_VER} (${KERNEL_ARCH}) -Consult /var/lib/dkms/dkms_failing_test/1.0/build/make.log for more information. - -Autoinstall on ${KERNEL_VER} failed for module(s) dkms_failing_test(10). - -Error! One or more modules failed to install during autoinstall. -Refer to previous errors for more information. -EOF echo 'Adding test module with dependencies on failing test module by directory' run_with_expected_output dkms add test/dkms_failing_dependencies_test-1.0 << EOF Creating symlink /var/lib/dkms/dkms_failing_dependencies_test/1.0/source -> /usr/src/dkms_failing_dependencies_test-1.0 EOF check_module_source_tree_created /usr/src/dkms_failing_dependencies_test-1.0 + echo 'Running autoinstall with failing test module and test module with dependencies on the failing module (expected error)' run_with_expected_error 11 dkms autoinstall -k "${KERNEL_VER}" << EOF ${SIGNING_PROLOGUE} @@ -3080,14 +3098,6 @@ EOF remove_module_source_tree /usr/src/dkms_failing_test-1.0 -echo 'Running autoinstall with test module with missing dependencies (expected error)' -run_with_expected_error 11 dkms autoinstall -k "${KERNEL_VER}" << EOF -dkms_failing_dependencies_test/1.0 autoinstall failed due to missing dependencies: dkms_failing_test. - -Error! One or more modules failed to install during autoinstall. -Refer to previous errors for more information. -EOF - echo 'Removing test module with dependencies' run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_failing_dependencies_test -v 1.0 << EOF Module dkms_failing_dependencies_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... From 9df065584b2c8a77cb972272aa9e5bed32a7f252 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 21 Jan 2025 12:50:13 +0100 Subject: [PATCH 33/57] run_test.sh: test 'dkms kernel_postinst' with a failing module --- run_test.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/run_test.sh b/run_test.sh index fdae78d9..299ae687 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1213,6 +1213,24 @@ Error! One or more modules failed to install during autoinstall. Refer to previous errors for more information. EOF +echo ' Running dkms kernel_postinst with failing test module (expected error)' +run_with_expected_error 11 dkms kernel_postinst -k "${KERNEL_VER}" << EOF +${SIGNING_PROLOGUE} +Autoinstall of module dkms_failing_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Cleaning build area... done. +Building module(s)...(bad exit status: 2) +Failed command: +make -j1 KERNELRELEASE=${KERNEL_VER} all + +Error! Bad return status for module build on kernel: ${KERNEL_VER} (${KERNEL_ARCH}) +Consult /var/lib/dkms/dkms_failing_test/1.0/build/make.log for more information. + +Autoinstall on ${KERNEL_VER} failed for module(s) dkms_failing_test(10). + +Error! One or more modules failed to install during autoinstall. +Refer to previous errors for more information. +EOF + echo ' Removing failing test module' run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_failing_test -v 1.0 << EOF Module dkms_failing_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... From d36dcd0eaba1cf2c8c5df0b5db4e1f7e44026cbd Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 21 Jan 2025 13:35:30 +0100 Subject: [PATCH 34/57] run_test.sh: test 'dkms_autoinstaller' with a failing module --- run_test.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/run_test.sh b/run_test.sh index 299ae687..168a7556 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1213,6 +1213,26 @@ Error! One or more modules failed to install during autoinstall. Refer to previous errors for more information. EOF +if [[ -x /usr/lib/dkms/dkms_autoinstaller ]]; then +echo ' Running dkms_autoinstaller with failing test module (expected error)' +run_with_expected_error 11 /usr/lib/dkms/dkms_autoinstaller start "${KERNEL_VER}" << EOF +${SIGNING_PROLOGUE} +Autoinstall of module dkms_failing_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Cleaning build area... done. +Building module(s)...(bad exit status: 2) +Failed command: +make -j1 KERNELRELEASE=${KERNEL_VER} all + +Error! Bad return status for module build on kernel: ${KERNEL_VER} (${KERNEL_ARCH}) +Consult /var/lib/dkms/dkms_failing_test/1.0/build/make.log for more information. + +Autoinstall on ${KERNEL_VER} failed for module(s) dkms_failing_test(10). + +Error! One or more modules failed to install during autoinstall. +Refer to previous errors for more information. +EOF +fi + echo ' Running dkms kernel_postinst with failing test module (expected error)' run_with_expected_error 11 dkms kernel_postinst -k "${KERNEL_VER}" << EOF ${SIGNING_PROLOGUE} From 8817168dec44636a861bca04f60c3d42c1ce77c3 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Tue, 21 Jan 2025 14:25:54 +0100 Subject: [PATCH 35/57] dkms_autoinstaller: restore error propagation map any autoinstall error to 1 for a lsb compliant exit code --- dkms_autoinstaller.in | 1 + run_test.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dkms_autoinstaller.in b/dkms_autoinstaller.in index 2a942128..dbc639e6 100644 --- a/dkms_autoinstaller.in +++ b/dkms_autoinstaller.in @@ -34,6 +34,7 @@ case "$1" in else dkms autoinstall --kernelver $kernel res=$? + test $res = 0 fi ;; stop|restart|force-reload|status|reload) diff --git a/run_test.sh b/run_test.sh index 168a7556..38ca3d05 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1215,7 +1215,7 @@ EOF if [[ -x /usr/lib/dkms/dkms_autoinstaller ]]; then echo ' Running dkms_autoinstaller with failing test module (expected error)' -run_with_expected_error 11 /usr/lib/dkms/dkms_autoinstaller start "${KERNEL_VER}" << EOF +run_with_expected_error 1 /usr/lib/dkms/dkms_autoinstaller start "${KERNEL_VER}" << EOF ${SIGNING_PROLOGUE} Autoinstall of module dkms_failing_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) Cleaning build area... done. From 9454ee1f113d80053cb1219ad4ffe6c9c7dd9f85 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Fri, 17 Jan 2025 09:44:44 +0100 Subject: [PATCH 36/57] run_test.sh: split off a section for signing tests --- run_test.sh | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/run_test.sh b/run_test.sh index 38ca3d05..56e0377b 100755 --- a/run_test.sh +++ b/run_test.sh @@ -558,6 +558,37 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built EOF +echo 'Removing the test module with --all' +run_with_expected_output dkms remove --all -m dkms_test -v 1.0 << EOF +Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... + +Deleting module dkms_test/1.0 completely from the DKMS tree. +EOF +run_status_with_expected_output 'dkms_test' << EOF +EOF +if [[ -e "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then + echo >&2 "Error: module not removed in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" + exit 1 +fi + +remove_module_source_tree /usr/src/dkms_test-1.0 + +echo 'Checking that the environment is clean again' +check_no_dkms_test + + ############################################################################ + echo '*** Testing module signing' + ############################################################################ + + echo 'Adding the test module' + run_with_expected_output dkms add test/dkms_test-1.0 << EOF +Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0 +EOF + check_module_source_tree_created /usr/src/dkms_test-1.0 + run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0: added +EOF + if (( NO_SIGNING_TOOL == 0 )); then echo 'Building the test module with bad sign_file path in framework file' cp test/framework/bad_sign_file_path.conf /etc/dkms/framework.conf.d/dkms_test_framework.conf @@ -826,8 +857,8 @@ EOF fi fi -echo 'Removing the test module with --all' -run_with_expected_output dkms remove --all -m dkms_test -v 1.0 << EOF + echo 'Removing the test module' + run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF Module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): Before uninstall, this module version was ACTIVE on this kernel. Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} @@ -837,10 +868,6 @@ Deleting module dkms_test/1.0 completely from the DKMS tree. EOF run_status_with_expected_output 'dkms_test' << EOF EOF -if [[ -e "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then - echo >&2 "Error: module not removed in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" - exit 1 -fi if (( NO_SIGNING_TOOL == 0 )); then echo 'Removing temporary files' From 542b83e17f4c4bcf72ef0936ee259fe225ab2f6c Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Wed, 22 Jan 2025 10:36:14 +0100 Subject: [PATCH 37/57] run_test.sh: split basic tests from signing tests --- run_test.sh | 195 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 139 insertions(+), 56 deletions(-) diff --git a/run_test.sh b/run_test.sh index 56e0377b..e1cf1b7e 100755 --- a/run_test.sh +++ b/run_test.sh @@ -558,9 +558,147 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built EOF +echo 'Building the test module again by force' +run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF +${SIGNING_PROLOGUE} +Cleaning build area... done. +Building module(s)... done. +${SIGNING_MESSAGE}Cleaning build area... done. +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built +EOF + +echo 'Installing the test module' +run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF +Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} +Running depmod... done. +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +EOF +if ! [[ -f "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then + echo >&2 "Error: module not found in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" + exit 1 +fi + +echo 'Installing the test module again' +run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF +Module dkms_test/1.0 already installed on kernel ${KERNEL_VER} (${KERNEL_ARCH}), skip. You may override by specifying --force. +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +EOF + +echo 'Installing the test module again by force' +run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF +Module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): +Before uninstall, this module version was ACTIVE on this kernel. +Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} +Running depmod... done. + +Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} +Running depmod... done. +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +EOF + +echo 'Checking modinfo' +run_with_expected_output sh -c "$(declare -f modinfo_quad); modinfo_quad /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" << EOF +description: A Simple dkms test module +filename: /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} +license: GPL +version: 1.0 +EOF + +echo 'Uninstalling the test module' +run_with_expected_output dkms uninstall -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF +Module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): +Before uninstall, this module version was ACTIVE on this kernel. +Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} +Running depmod... done. +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built +EOF +if [[ -e "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then + echo >&2 "Error: module not removed in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" + exit 1 +fi + +echo 'Uninstalling the test module again' +run_with_expected_output dkms uninstall -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF +Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built +EOF + +echo 'Unbuilding the test module' +run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF +Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0: added +EOF + +echo 'Unbuilding the test module again' +run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF +Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +Module dkms_test/1.0 is not built for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0: added +EOF + +echo 'Removing the test module' +run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF +Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +Module dkms_test/1.0 is not built for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... + +Deleting module dkms_test/1.0 completely from the DKMS tree. +EOF +run_status_with_expected_output 'dkms_test' << EOF +EOF +if ! [[ -d /usr/src/dkms_test-1.0 ]] ; then + echo >&2 'Error: directory /usr/src/dkms_test-1.0 was removed' + exit 1 +fi + +echo 'Installing the test module by version (combining add, build, install)' +run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF +${SIGNING_PROLOGUE} +Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0 + +Cleaning build area... done. +Building module(s)... done. +${SIGNING_MESSAGE}Cleaning build area... done. +Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} +Running depmod... done. +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +EOF +if ! [[ -f "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then + echo >&2 "Error: module not found in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" + exit 1 +fi + +echo 'Checking modinfo' +run_with_expected_output sh -c "$(declare -f modinfo_quad); modinfo_quad /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" << EOF +description: A Simple dkms test module +filename: /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} +license: GPL +version: 1.0 +EOF + echo 'Removing the test module with --all' run_with_expected_output dkms remove --all -m dkms_test -v 1.0 << EOF -Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... +Module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): +Before uninstall, this module version was ACTIVE on this kernel. +Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} +Running depmod... done. Deleting module dkms_test/1.0 completely from the DKMS tree. EOF @@ -702,32 +840,6 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF -echo 'Installing the test module again' -run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF -Module dkms_test/1.0 already installed on kernel ${KERNEL_VER} (${KERNEL_ARCH}), skip. You may override by specifying --force. -EOF -run_status_with_expected_output 'dkms_test' << EOF -dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed -EOF -if ! [[ -f "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then - echo >&2 "Error: module not found in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" - exit 1 -fi - -echo 'Installing the test module again by force' -run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF -Module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): -Before uninstall, this module version was ACTIVE on this kernel. -Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} -Running depmod... done. - -Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} -Running depmod... done. -EOF -run_status_with_expected_output 'dkms_test' << EOF -dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed -EOF - echo 'Checking modinfo' run_with_expected_output sh -c "$(declare -f modinfo_quad); modinfo_quad /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" << EOF description: A Simple dkms test module @@ -766,18 +878,6 @@ EOF run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built EOF -if [[ -e "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then - echo >&2 "Error: module not removed in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" - exit 1 -fi - -echo 'Uninstalling the test module again' -run_with_expected_output dkms uninstall -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF -Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... -EOF -run_status_with_expected_output 'dkms_test' << EOF -dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built -EOF echo 'Unbuilding the test module' run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF @@ -787,15 +887,6 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0: added EOF -echo 'Unbuilding the test module again' -run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF -Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... -Module dkms_test/1.0 is not built for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... -EOF -run_status_with_expected_output 'dkms_test' << EOF -dkms_test/1.0: added -EOF - echo 'Removing the test module' run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... @@ -805,10 +896,6 @@ Deleting module dkms_test/1.0 completely from the DKMS tree. EOF run_status_with_expected_output 'dkms_test' << EOF EOF -if ! [[ -d /usr/src/dkms_test-1.0 ]] ; then - echo >&2 'Error: directory /usr/src/dkms_test-1.0 was removed' - exit 1 -fi echo 'Installing the test module by version (combining add, build, install)' run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF @@ -824,10 +911,6 @@ EOF run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF -if ! [[ -f "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" ]] ; then - echo >&2 "Error: module not found in /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" - exit 1 -fi echo 'Checking modinfo' run_with_expected_output sh -c "$(declare -f modinfo_quad); modinfo_quad /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" << EOF From d5b7601e2ffc38edc80bf365cc42b98f73c6329f Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Sun, 19 Jan 2025 03:38:33 +0100 Subject: [PATCH 38/57] run_test.sh: the whole signing section needs signing enabled --- run_test.sh | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/run_test.sh b/run_test.sh index e1cf1b7e..8dd0a8c1 100755 --- a/run_test.sh +++ b/run_test.sh @@ -714,6 +714,7 @@ remove_module_source_tree /usr/src/dkms_test-1.0 echo 'Checking that the environment is clean again' check_no_dkms_test +if (( NO_SIGNING_TOOL == 0 )); then ############################################################################ echo '*** Testing module signing' ############################################################################ @@ -727,7 +728,6 @@ EOF dkms_test/1.0: added EOF -if (( NO_SIGNING_TOOL == 0 )); then echo 'Building the test module with bad sign_file path in framework file' cp test/framework/bad_sign_file_path.conf /etc/dkms/framework.conf.d/dkms_test_framework.conf run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF @@ -739,7 +739,7 @@ Building module(s)... done. Cleaning build area... done. EOF - echo ' Building the test module with bad mok_signing_key path in framework file' + echo 'Building the test module with bad mok_signing_key path in framework file' cp test/framework/bad_key_file_path.conf /etc/dkms/framework.conf.d/dkms_test_framework.conf run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF ${SIGNING_PROLOGUE_command} @@ -752,7 +752,7 @@ Building module(s)... done. ${SIGNING_MESSAGE}Cleaning build area... done. EOF - echo ' Building the test module with bad mok_certificate path in framework file' + echo 'Building the test module with bad mok_certificate path in framework file' cp test/framework/bad_cert_file_path.conf /etc/dkms/framework.conf.d/dkms_test_framework.conf run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF ${SIGNING_PROLOGUE_command} @@ -766,7 +766,7 @@ ${SIGNING_MESSAGE}Cleaning build area... done. EOF rm /tmp/dkms_test_private_key - echo ' Building the test module with path contains variables in framework file' + echo 'Building the test module with path contains variables in framework file' mkdir "/tmp/dkms_test_dir_${KERNEL_VER}/" cp test/framework/variables_in_path.conf /etc/dkms/framework.conf.d/dkms_test_framework.conf run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF @@ -790,7 +790,7 @@ Signing key: /tmp/dkms_test_private_key Public certificate (MOK): /tmp/dkms_test_certificate " - echo ' Building the test module using a different hash algorithm' + echo 'Building the test module using a different hash algorithm' if kmod_broken_hashalgo; then echo ' Current kmod has broken hash algorithm code. Skipping...' elif [[ "${CURRENT_HASH}" == "unknown" ]]; then @@ -813,7 +813,6 @@ ${ALTER_HASH} EOF rm /tmp/dkms_test_kconfig fi -fi echo 'Building the test module again by force' run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF @@ -826,10 +825,8 @@ run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built EOF -if (( NO_SIGNING_TOOL == 0 )); then echo ' Extracting serial number (aka sig_key in modinfo) from the certificate' CERT_SERIAL="$(cert_serial /tmp/dkms_test_certificate)" -fi echo 'Installing the test module' run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF @@ -848,7 +845,6 @@ license: GPL version: 1.0 EOF -if (( NO_SIGNING_TOOL == 0 )); then echo ' Checking module signature' SIG_KEY="$(modinfo -F sig_key "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" | tr -d ':')" SIG_HASH="$(modinfo -F sig_hashalgo "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}")" @@ -866,7 +862,6 @@ if (( NO_SIGNING_TOOL == 0 )); then ${CERT_SERIAL} EOF fi -fi echo 'Uninstalling the test module' run_with_expected_output dkms uninstall -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF @@ -920,7 +915,6 @@ license: GPL version: 1.0 EOF -if (( NO_SIGNING_TOOL == 0 )); then echo ' Checking module signature' SIG_KEY="$(modinfo -F sig_key "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" | tr -d ':')" SIG_HASH="$(modinfo -F sig_hashalgo "/lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}")" @@ -938,7 +932,6 @@ if (( NO_SIGNING_TOOL == 0 )); then ${CERT_SERIAL} EOF fi -fi echo 'Removing the test module' run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF @@ -952,17 +945,16 @@ EOF run_status_with_expected_output 'dkms_test' << EOF EOF -if (( NO_SIGNING_TOOL == 0 )); then echo 'Removing temporary files' rm /tmp/dkms_test_private_key /tmp/dkms_test_certificate SIGNING_PROLOGUE="${SIGNING_PROLOGUE_}" rm /etc/dkms/framework.conf.d/dkms_test_framework.conf -fi remove_module_source_tree /usr/src/dkms_test-1.0 echo 'Checking that the environment is clean again' check_no_dkms_test +fi ############################################################################ echo '*** Testing dkms autoinstall/kernel_{postinst/prerm}, dkms_autoinstaller' From 02cc580a21afb619ce9f60425e231615112840f5 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Sun, 19 Jan 2025 05:41:33 +0100 Subject: [PATCH 39/57] run_test.sh: use SIGNING_PROLOGUE_tmp_key_cert --- run_test.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/run_test.sh b/run_test.sh index 8dd0a8c1..6fbfbf66 100755 --- a/run_test.sh +++ b/run_test.sh @@ -784,8 +784,7 @@ EOF CURRENT_HASH="$(modinfo -F sig_hashalgo "${BUILT_MODULE_PATH}")" cp test/framework/temp_key_cert.conf /etc/dkms/framework.conf.d/dkms_test_framework.conf - SIGNING_PROLOGUE_="${SIGNING_PROLOGUE}" - SIGNING_PROLOGUE="${SIGNING_PROLOGUE_command} + SIGNING_PROLOGUE_tmp_key_cert="${SIGNING_PROLOGUE_command} Signing key: /tmp/dkms_test_private_key Public certificate (MOK): /tmp/dkms_test_certificate " @@ -803,7 +802,7 @@ Public certificate (MOK): /tmp/dkms_test_certificate fi echo "CONFIG_MODULE_SIG_HASH=\"${ALTER_HASH}\"" > /tmp/dkms_test_kconfig run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --config /tmp/dkms_test_kconfig --force << EOF -${SIGNING_PROLOGUE} +${SIGNING_PROLOGUE_tmp_key_cert} Cleaning build area... done. Building module(s)... done. ${SIGNING_MESSAGE}Cleaning build area... done. @@ -816,7 +815,7 @@ EOF echo 'Building the test module again by force' run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF -${SIGNING_PROLOGUE} +${SIGNING_PROLOGUE_tmp_key_cert} Cleaning build area... done. Building module(s)... done. ${SIGNING_MESSAGE}Cleaning build area... done. @@ -894,7 +893,7 @@ EOF echo 'Installing the test module by version (combining add, build, install)' run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF -${SIGNING_PROLOGUE} +${SIGNING_PROLOGUE_tmp_key_cert} Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0 Cleaning build area... done. @@ -947,7 +946,6 @@ EOF echo 'Removing temporary files' rm /tmp/dkms_test_private_key /tmp/dkms_test_certificate - SIGNING_PROLOGUE="${SIGNING_PROLOGUE_}" rm /etc/dkms/framework.conf.d/dkms_test_framework.conf remove_module_source_tree /usr/src/dkms_test-1.0 From aa0a95996e055fa97b9e417fd0320cd30faaf47c Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Wed, 22 Jan 2025 11:24:54 +0100 Subject: [PATCH 40/57] run_test.sh: simplify signing tests --- run_test.sh | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/run_test.sh b/run_test.sh index 6fbfbf66..946ea19e 100755 --- a/run_test.sh +++ b/run_test.sh @@ -862,37 +862,22 @@ ${CERT_SERIAL} EOF fi -echo 'Uninstalling the test module' -run_with_expected_output dkms uninstall -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF + echo 'Removing the test module' + run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF Module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): Before uninstall, this module version was ACTIVE on this kernel. Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} Running depmod... done. -EOF -run_status_with_expected_output 'dkms_test' << EOF -dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built -EOF - -echo 'Unbuilding the test module' -run_with_expected_output dkms unbuild -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF -Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... -EOF -run_status_with_expected_output 'dkms_test' << EOF -dkms_test/1.0: added -EOF - -echo 'Removing the test module' -run_with_expected_output dkms remove -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF -Module dkms_test/1.0 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... -Module dkms_test/1.0 is not built for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... Deleting module dkms_test/1.0 completely from the DKMS tree. EOF run_status_with_expected_output 'dkms_test' << EOF EOF -echo 'Installing the test module by version (combining add, build, install)' -run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF + remove_module_source_tree /usr/src/dkms_test-1.0 + + echo 'Installing the test module (combining add, build, install)' + run_with_expected_output dkms install -k "${KERNEL_VER}" test/dkms_test-1.0 << EOF ${SIGNING_PROLOGUE_tmp_key_cert} Creating symlink /var/lib/dkms/dkms_test/1.0/source -> /usr/src/dkms_test-1.0 @@ -902,6 +887,7 @@ ${SIGNING_MESSAGE}Cleaning build area... done. Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} Running depmod... done. EOF + check_module_source_tree_created /usr/src/dkms_test-1.0 run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF From 61146929572a6bb69aeb68432a3998f4b5d350d7 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Wed, 22 Jan 2025 11:42:03 +0100 Subject: [PATCH 41/57] run_test.sh: reindent the signing tests section --- run_test.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/run_test.sh b/run_test.sh index 946ea19e..624e4baf 100755 --- a/run_test.sh +++ b/run_test.sh @@ -813,26 +813,26 @@ EOF rm /tmp/dkms_test_kconfig fi -echo 'Building the test module again by force' -run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF + echo 'Building the test module again by force' + run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF ${SIGNING_PROLOGUE_tmp_key_cert} Cleaning build area... done. Building module(s)... done. ${SIGNING_MESSAGE}Cleaning build area... done. EOF -run_status_with_expected_output 'dkms_test' << EOF + run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built EOF echo ' Extracting serial number (aka sig_key in modinfo) from the certificate' CERT_SERIAL="$(cert_serial /tmp/dkms_test_certificate)" -echo 'Installing the test module' -run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF + echo 'Installing the test module' + run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 << EOF Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} Running depmod... done. EOF -run_status_with_expected_output 'dkms_test' << EOF + run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF @@ -871,7 +871,7 @@ Running depmod... done. Deleting module dkms_test/1.0 completely from the DKMS tree. EOF -run_status_with_expected_output 'dkms_test' << EOF + run_status_with_expected_output 'dkms_test' << EOF EOF remove_module_source_tree /usr/src/dkms_test-1.0 @@ -888,12 +888,12 @@ Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_com Running depmod... done. EOF check_module_source_tree_created /usr/src/dkms_test-1.0 -run_status_with_expected_output 'dkms_test' << EOF + run_status_with_expected_output 'dkms_test' << EOF dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF -echo 'Checking modinfo' -run_with_expected_output sh -c "$(declare -f modinfo_quad); modinfo_quad /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" << EOF + echo 'Checking modinfo' + run_with_expected_output sh -c "$(declare -f modinfo_quad); modinfo_quad /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext}" << EOF description: A Simple dkms test module filename: /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} license: GPL @@ -927,17 +927,17 @@ Running depmod... done. Deleting module dkms_test/1.0 completely from the DKMS tree. EOF -run_status_with_expected_output 'dkms_test' << EOF + run_status_with_expected_output 'dkms_test' << EOF EOF echo 'Removing temporary files' rm /tmp/dkms_test_private_key /tmp/dkms_test_certificate rm /etc/dkms/framework.conf.d/dkms_test_framework.conf -remove_module_source_tree /usr/src/dkms_test-1.0 + remove_module_source_tree /usr/src/dkms_test-1.0 -echo 'Checking that the environment is clean again' -check_no_dkms_test + echo 'Checking that the environment is clean again' + check_no_dkms_test fi ############################################################################ From f5d9ec87d1002be8191331356df6307fe8c3aa7c Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Thu, 23 Jan 2025 23:14:39 +0100 Subject: [PATCH 42/57] run_test.sh: test 'dkms autoinstall --all' --- run_test.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/run_test.sh b/run_test.sh index 624e4baf..03ed18c1 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1120,6 +1120,13 @@ EOF rm -f /etc/dkms/no-autoinstall +echo 'Running dkms autoinstall --all (expected error)' +run_with_expected_error 21 dkms autoinstall --all << EOF + +Error! Your kernel headers for kernel cannot be found at /lib/modules//build or /lib/modules//source. +Please install the linux-headers- package or use the --kernelsourcedir option to tell DKMS where it's located. +EOF + echo 'Running dkms autoinstall' run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF ${SIGNING_PROLOGUE} From 8b22e4ffd57324710fa96e7a4b5f6ee4a1d2c091 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Thu, 23 Jan 2025 23:32:36 +0100 Subject: [PATCH 43/57] dkms: forbid 'dkms autoinstall --all' which has never worked Fixes: #484 --- dkms.in | 1 + run_test.sh | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dkms.in b/dkms.in index 00650ccb..cbeb854e 100644 --- a/dkms.in +++ b/dkms.in @@ -2956,6 +2956,7 @@ add | build | install) ${action}_module ;; autoinstall) + check_all_is_banned $action check_root && autoinstall ;; match) diff --git a/run_test.sh b/run_test.sh index 03ed18c1..e95332f7 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1121,10 +1121,9 @@ EOF rm -f /etc/dkms/no-autoinstall echo 'Running dkms autoinstall --all (expected error)' -run_with_expected_error 21 dkms autoinstall --all << EOF +run_with_expected_error 5 dkms autoinstall --all << EOF -Error! Your kernel headers for kernel cannot be found at /lib/modules//build or /lib/modules//source. -Please install the linux-headers- package or use the --kernelsourcedir option to tell DKMS where it's located. +Error! The action autoinstall does not support the --all parameter. EOF echo 'Running dkms autoinstall' From dc97689a6a899228199b9d73d713dc3a7bcde419 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Fri, 24 Jan 2025 10:39:09 +0100 Subject: [PATCH 44/57] dkms: have_one_kernel: test check_all_is_banned first --- dkms.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkms.in b/dkms.in index cbeb854e..6fa44805 100644 --- a/dkms.in +++ b/dkms.in @@ -363,11 +363,11 @@ check_all_is_banned() # A little test function for DKMS commands that only work on one kernel. have_one_kernel() { + check_all_is_banned $1 if (( ${#kernelver[@]} != 1 )); then [[ $1 =~ kernel_(postinst|prerm) ]] && die 4 "The action $1 requires exactly one kernel version parameter on the command line." die 4 "The action $1 does not support multiple kernel version parameters on the command line." fi - check_all_is_banned $1 } # Set up the kernelver and arch arrays. You must have a 1:1 correspondence -- From d07034f01caeb0d970c468afd719afb4191d8937 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Fri, 24 Jan 2025 10:42:20 +0100 Subject: [PATCH 45/57] dkms: also forbid 'dkms autoinstall -k -k ' autoinstall doesn't have a loop over kernels --- dkms.in | 2 +- run_test.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dkms.in b/dkms.in index 6fa44805..6badc93d 100644 --- a/dkms.in +++ b/dkms.in @@ -2956,7 +2956,7 @@ add | build | install) ${action}_module ;; autoinstall) - check_all_is_banned $action + have_one_kernel $action check_root && autoinstall ;; match) diff --git a/run_test.sh b/run_test.sh index e95332f7..689f4b3c 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1126,6 +1126,12 @@ run_with_expected_error 5 dkms autoinstall --all << EOF Error! The action autoinstall does not support the --all parameter. EOF +echo 'Running dkms autoinstall for more than one kernel version (same version twice for this test) (expected error)' +run_with_expected_error 4 dkms autoinstall -k "${KERNEL_VER}" -k "${KERNEL_VER}" << EOF + +Error! The action autoinstall does not support multiple kernel version parameters on the command line. +EOF + echo 'Running dkms autoinstall' run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF ${SIGNING_PROLOGUE} From 8479b980c45599cdd28b68591891b29579fde63c Mon Sep 17 00:00:00 2001 From: Simone Caronni Date: Thu, 23 Jan 2025 16:41:27 +0100 Subject: [PATCH 46/57] Also delete collisions folder when a kernel is gone --- dkms.in | 9 ++------- run_test.sh | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/dkms.in b/dkms.in index 6badc93d..675a69dc 100644 --- a/dkms.in +++ b/dkms.in @@ -1767,16 +1767,11 @@ do_uninstall() fi # Delete the original_module if nothing for this kernel is installed anymore - if [[ $was_active && -d $dkms_tree/$module/original_module/$1/$2 && ! -d $dkms_tree/$module/original_module/$1/$2/collisions ]]; then + if [[ $was_active && -d $dkms_tree/$module/original_module/$1/$2 ]]; then echo "" - echo "Removing original_module from DKMS tree for kernel $1 ($2)" + echo "Removing original module(s) from DKMS tree for kernel $1 ($2)" rm -rf "$dkms_tree/$module/original_module/$1/$2" 2>/dev/null [[ $(find $dkms_tree/$module/original_module/$1/* -maxdepth 0 -type d 2>/dev/null) ]] || rm -rf "$dkms_tree/$module/original_module/$1" - elif [[ $was_active && -d $dkms_tree/$module/original_module/$1/$2/collisions ]]; then - echo "" - echo "Keeping directory $dkms_tree/$module/original_module/$1/$2/collisions/" - echo "for your reference purposes. Your kernel originally contained multiple" - echo "same-named modules and this directory is now where these are located." fi [[ $(find $dkms_tree/$module/original_module/* -maxdepth 0 -type d 2>/dev/null) ]] || rm -rf "$dkms_tree/$module/original_module" } diff --git a/run_test.sh b/run_test.sh index 689f4b3c..00628181 100755 --- a/run_test.sh +++ b/run_test.sh @@ -1878,7 +1878,7 @@ Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compr Restoring archived original module Running depmod... done. -Removing original_module from DKMS tree for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Removing original module(s) from DKMS tree for kernel ${KERNEL_VER} (${KERNEL_ARCH}) EOF if [ "${expected_dest_loc}" != "kernel/extra" ]; then # A replaced module originating from a kernel image should get restored @@ -1935,7 +1935,7 @@ Deleting /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compr Restoring archived original module Running depmod... done. -Removing original_module from DKMS tree for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Removing original module(s) from DKMS tree for kernel ${KERNEL_VER} (${KERNEL_ARCH}) Deleting module dkms_replace_test/2.0 completely from the DKMS tree. EOF From ccc6eb951827d3278827d2d241f14013411525bc Mon Sep 17 00:00:00 2001 From: Simone Caronni Date: Thu, 30 Jan 2025 10:11:36 +0100 Subject: [PATCH 47/57] Adjustments for SUSE output in RPM scriptlets --- dkms.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dkms.in b/dkms.in index 675a69dc..540f7ab5 100644 --- a/dkms.in +++ b/dkms.in @@ -192,7 +192,7 @@ invoke_command() fi if [ -n "$progresspid" ]; then - kill "$progresspid" >/dev/null 2>&1 + kill -9 "$progresspid" >/dev/null 2>&1 wait "$progresspid" 2>/dev/null fi @@ -333,9 +333,9 @@ set_module_suffix() # $1 = the kernel to base the module_suffix on kernel_test="${1:-$(uname -r)}" module_uncompressed_suffix=".ko" - find $install_tree/$kernel_test/ -name "*.ko.gz" | grep -q . && module_compressed_suffix=".gz" - find $install_tree/$kernel_test/ -name "*.ko.xz" | grep -q . && module_compressed_suffix=".xz" - find $install_tree/$kernel_test/ -name "*.ko.zst" | grep -q . && module_compressed_suffix=".zst" + find $install_tree/$kernel_test/ -name "*.ko.gz" 2>/dev/null | grep -q . && module_compressed_suffix=".gz" + find $install_tree/$kernel_test/ -name "*.ko.xz" 2>/dev/null | grep -q . && module_compressed_suffix=".xz" + find $install_tree/$kernel_test/ -name "*.ko.zst" 2>/dev/null | grep -q . && module_compressed_suffix=".zst" module_suffix="$module_uncompressed_suffix$module_compressed_suffix" } From 789ca41e84fab6665f6acf6984c2acf45d791490 Mon Sep 17 00:00:00 2001 From: Simone Caronni Date: Thu, 30 Jan 2025 11:38:24 +0100 Subject: [PATCH 48/57] Rework weak modules logic - Fix variable check when determining if NO_WEAK_MODULES is set. - kABI is available only on SUSE and RHEL platforms, so avoid setting parameters for all other distributions. - For SUSE, use the new script provided in suse-module-tools and not the one provided by suse-module-tools-legacy. --- dkms.in | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/dkms.in b/dkms.in index 540f7ab5..c4c80dbd 100644 --- a/dkms.in +++ b/dkms.in @@ -1512,9 +1512,9 @@ do_install() # Add to kabi-tracking if [[ -z $NO_WEAK_MODULES ]]; then - if [[ ${weak_modules} ]]; then - echo "Adding any weak-modules" - list_each_installed_module "$module" "$kernelver" "$arch" | ${weak_modules} ${weak_modules_no_initrd} --add-modules + if [[ ${weak_modules_add} ]]; then + echo "Adding linked weak modules..." + list_each_installed_module "$module" "$kernelver" "$arch" | ${weak_modules_add} fi fi @@ -1723,9 +1723,9 @@ do_uninstall() echo "Before uninstall, this module version was ACTIVE on this kernel." # remove kabi-tracking if last instance removed if [[ -z $NO_WEAK_MODULES ]]; then - if [[ ${weak_modules} ]] && (module_status_built $module $module_version |grep -q "installed"); then - echo "Removing any linked weak-modules" - list_each_installed_module "$module" "$1" "$2" | ${weak_modules} ${weak_modules_no_initrd} --remove-modules + if [[ ${weak_modules_remove} ]] && (module_status_built $module $module_version |grep -q "installed"); then + echo "Removing linked weak modules..." + list_each_installed_module "$module" "$1" "$2" | ${weak_modules_remove} fi fi @@ -1906,8 +1906,8 @@ find_module_from_ko() module_status_weak() { # $1 = module, $2 = module version, $3 = kernel version weak installed to, # $4 = kernel arch, $5 = kernel version built for - [[ -z $NO_WEAK_MODULES ]] || return 1 - [[ $weak_modules ]] || return 1 + [[ -n $NO_WEAK_MODULES ]] || return 1 + [[ $weak_modules_add ]] && [[ $weak_modules_remove ]] || continue local m local v local k @@ -2714,7 +2714,6 @@ rm -f "$tmpfile" # These can come from the environment or the config file [[ ! ${ADDON_MODULES_DIR} && -e /etc/sysconfig/module-init-tools ]] && . /etc/sysconfig/module-init-tools addon_modules_dir="${ADDON_MODULES_DIR}" -weak_modules="${WEAK_MODULES_BIN}" # Source in configuration not related to signing read_framework_conf $dkms_framework_nonsigning_variables @@ -2741,13 +2740,12 @@ module_uncompressed_suffix="" module_compressed_suffix="" rpm_safe_upgrade="" declare -a directive_array=() kernelver=() arch=() -weak_modules='' +weak_modules_add='' +weak_modules_remove='' last_mvka='' last_mvka_conf='' try_source_tree='' die_is_fatal="yes" -[ -x /sbin/weak-modules ] && weak_modules='/sbin/weak-modules' -[ -x /usr/lib/module-init-tools/weak-modules ] && weak_modules='/usr/lib/module-init-tools/weak-modules' no_depmod="" delayed_depmod="" prepared_kernel="none" @@ -2921,11 +2919,6 @@ if [[ $arch && $all ]]; then "--all on the command line." fi -# Since initramfs/initrd rebuild is not requested, skip it with Redhat's weak-modules -if [[ $weak_modules ]]; then - weak_modules_no_initrd="--no-initramfs" -fi - # Default to -j parallel_jobs=${parallel_jobs:-$(get_num_cpus)} @@ -2936,6 +2929,23 @@ parallel_jobs=${parallel_jobs:-$(get_num_cpus)} [[ $action =~ kernel_(postinst|prerm) ]] && have_one_kernel "$action" setup_kernels_arches "$action" + +# Since initramfs/initrd rebuild is not requested, skip it with Redhat's weak-modules +if [[ -z $NO_WEAK_MODULES ]]; then + case "$running_distribution" in + rhel*) + weak_modules_add='/usr/sbin/weak-modules --no-initramfs --add-modules' + weak_modules_remove='/usr/sbin/weak-modules --no-initramfs --remove-modules' + ;; + sles* | suse* | opensuse*) + weak_modules_add='/usr/lib/module-init-tools/weak-modules2 --add-kernel-modules ${kernelver}' + weak_modules_remove='/usr/lib/module-init-tools/weak-modules2 --remove-kernel-modules ${kernelver}' + ;; + *) + ;; + esac +fi + case "$action" in remove | unbuild | uninstall) check_module_args $action From d2a142a54c09b475c486b292e4f172a691458307 Mon Sep 17 00:00:00 2001 From: Simone Caronni Date: Thu, 30 Jan 2025 13:52:12 +0100 Subject: [PATCH 49/57] Grep new output for linked modules in tests --- run_test.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run_test.sh b/run_test.sh index 00628181..255c0a89 100755 --- a/run_test.sh +++ b/run_test.sh @@ -187,9 +187,9 @@ run_status_with_expected_output() { generalize_expected_output() { local output_log=$1 - # On CentOS, weak-modules is executed. Drop it from the output, to be more generic - sed -i '/^Adding any weak-modules$/d' ${output_log} - sed -i '/^Removing any linked weak-modules$/d' ${output_log} + # On Red Hat and SUSE based distributions, weak-modules is executed. Drop it from the output, to be more generic + sed -i '/^Adding linked weak modules.*$/d' ${output_log} + sed -i '/^Removing linked weak modules.*$/d' ${output_log} # Signing related output. Drop it from the output, to be more generic if (( NO_SIGNING_TOOL == 0 )); then sed -i '/^EFI variables are not supported on this system/d' ${output_log} From 11638f8bc7b547649b3c7d061ebf38e674e3736a Mon Sep 17 00:00:00 2001 From: Simone Caronni Date: Thu, 30 Jan 2025 14:37:58 +0100 Subject: [PATCH 50/57] Update NO_WEAK_MODULES description in man page --- dkms.8.in | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dkms.8.in b/dkms.8.in index 02372db7..f1f6adc8 100644 --- a/dkms.8.in +++ b/dkms.8.in @@ -596,11 +596,9 @@ module. If unset, it is assumed to be "make clean". .B NO_WEAK_MODULES= The .B NO_WEAK_MODULES -parameter prevents dkms from creating a symlink into the weak-updates directory, which is the -default on Red Hat derivatives. The weak modules facility was designed to eliminate the need to -rebuild kernel modules when kernel upgrades occur and relies on the symbols within the kABI. +parameter prevents dkms from creating a symlink into the weak-updates directory. The weak modules facility was designed to eliminate the need to rebuild kernel modules when kernel upgrades occur and relies on the symbols within the kABI. -Fedora does not guaranteed a stable kABI so it should be disabled in the specific module override by setting it to "yes". For example, for an Nvidia DKMS module you would set the following in /etc/dkms/nvidia.conf: +The kABI kernel module interface is currently supported on Red Hat Enterprise Linux (and derivatives), SUSE Linux Enterprise Server and openSUSE Leap. NO_WEAK_MODULES="yes" .TP From b5a04853ccb92acd35a714d74320d8d94dab6750 Mon Sep 17 00:00:00 2001 From: Simone Caronni Date: Thu, 30 Jan 2025 14:38:16 +0100 Subject: [PATCH 51/57] Update version --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ee088660..d46b8645 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ -RELEASE_DATE := "19 December 2024" +RELEASE_DATE := "30 January 2025" RELEASE_MAJOR := 3 RELEASE_MINOR := 1 -RELEASE_MICRO := 4 +RELEASE_MICRO := 5 RELEASE_NAME := dkms RELEASE_VERSION := $(RELEASE_MAJOR).$(RELEASE_MINOR).$(RELEASE_MICRO) RELEASE_STRING := $(RELEASE_NAME)-$(RELEASE_VERSION) From 878c618084ef73a44bac6ef90687a0058570553c Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Wed, 19 Apr 2023 17:37:54 +0200 Subject: [PATCH 52/57] dkms: do not perform rpm queries on Debian/Ubuntu/Arch based distributions Closes #329 --- dkms.in | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dkms.in b/dkms.in index c4c80dbd..63c0dfe1 100644 --- a/dkms.in +++ b/dkms.in @@ -397,6 +397,11 @@ setup_kernels_arches() kernelver[0]=$(uname -r) fi if [[ ! $arch ]]; then + case "$running_distribution" in + debian* | ubuntu* | arch*) + arch[0]=$(uname -m) + ;; + *) kernelver_rpm=$(rpm -qf "$install_tree/$kernelver" 2>/dev/null | \ grep -v "not owned by any package" | grep kernel | head -n 1) if ! arch[0]=$(rpm -q --queryformat "%{ARCH}" "$kernelver_rpm" 2>/dev/null); then @@ -405,6 +410,8 @@ setup_kernels_arches() arch[0]="ia32e" fi fi + ;; + esac fi if [[ ! $arch ]]; then die 12 "Could not determine architecture." @@ -1739,7 +1746,15 @@ do_uninstall() while [[ ${dir_to_remove} != ${dir_to_remove#/} ]]; do dir_to_remove="${dir_to_remove#/}" done + + case "$running_distribution" in + debian* | ubuntu* | arch*) + (if cd "$install_tree/$1"; then rmdir -p --ignore-fail-on-non-empty "${dir_to_remove}"; fi || true) + ;; + *) (if cd "$install_tree/$1"; then rpm -qf "${dir_to_remove}" >/dev/null 2>&1 || rmdir -p --ignore-fail-on-non-empty "${dir_to_remove}"; fi || true) + ;; + esac else echo "Module ${dest_module_name[$count]}$module_suffix was not found within $install_tree/$1/" fi From e351be6d634e96f3a7d69cfb22f2fc220e47593e Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Sat, 1 Feb 2025 02:47:06 +0100 Subject: [PATCH 53/57] reindent --- dkms.in | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dkms.in b/dkms.in index 63c0dfe1..d43cae19 100644 --- a/dkms.in +++ b/dkms.in @@ -402,14 +402,14 @@ setup_kernels_arches() arch[0]=$(uname -m) ;; *) - kernelver_rpm=$(rpm -qf "$install_tree/$kernelver" 2>/dev/null | \ - grep -v "not owned by any package" | grep kernel | head -n 1) - if ! arch[0]=$(rpm -q --queryformat "%{ARCH}" "$kernelver_rpm" 2>/dev/null); then - arch[0]=$(uname -m) - if [[ $arch = x86_64 ]] && grep -q Intel /proc/cpuinfo && ls $install_tree/$kernelver/build/configs 2>/dev/null | grep -q "ia32e"; then - arch[0]="ia32e" - fi - fi + kernelver_rpm=$(rpm -qf "$install_tree/$kernelver" 2>/dev/null | \ + grep -v "not owned by any package" | grep kernel | head -n 1) + if ! arch[0]=$(rpm -q --queryformat "%{ARCH}" "$kernelver_rpm" 2>/dev/null); then + arch[0]=$(uname -m) + if [[ $arch = x86_64 ]] && grep -q Intel /proc/cpuinfo && ls $install_tree/$kernelver/build/configs 2>/dev/null | grep -q "ia32e"; then + arch[0]="ia32e" + fi + fi ;; esac fi @@ -1752,7 +1752,7 @@ do_uninstall() (if cd "$install_tree/$1"; then rmdir -p --ignore-fail-on-non-empty "${dir_to_remove}"; fi || true) ;; *) - (if cd "$install_tree/$1"; then rpm -qf "${dir_to_remove}" >/dev/null 2>&1 || rmdir -p --ignore-fail-on-non-empty "${dir_to_remove}"; fi || true) + (if cd "$install_tree/$1"; then rpm -qf "${dir_to_remove}" >/dev/null 2>&1 || rmdir -p --ignore-fail-on-non-empty "${dir_to_remove}"; fi || true) ;; esac else From a3ae33bc76fff1db3aa76a153e77154cb7f3bd46 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Wed, 6 Dec 2023 00:34:52 +0100 Subject: [PATCH 54/57] common.postinst: only build AUTOINSTALL="yes" modules on installation --- dkms_common.postinst.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dkms_common.postinst.in b/dkms_common.postinst.in index e6c430d7..e4065ac8 100644 --- a/dkms_common.postinst.in +++ b/dkms_common.postinst.in @@ -155,6 +155,13 @@ if [ -z "$autoinstall" ]; then exit 0 fi +dkms_conf="/var/lib/dkms/$NAME/$VERSION/source/dkms.conf" +autoinstall=$(bash -c 'AUTOINSTALL=; . "'"$dkms_conf"'" >/dev/null 2>&1; echo $AUTOINSTALL') +if [ -z "$autoinstall" ]; then + echo "Not building the $NAME module which does not have AUTOINSTALL enabled." + exit 0 +fi + # On 1st installation, let us look for a directory # in @MODDIR@ which matches $(uname -r). If none # is found it is possible that buildd is being used From 8149171f2587954f7f6675d301c78e3d4196d9c1 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Sat, 26 Oct 2024 23:51:39 +0200 Subject: [PATCH 55/57] common.postinst: improve blank line placement separate modules/kernels with blank lines --- dkms_common.postinst.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dkms_common.postinst.in b/dkms_common.postinst.in index e4065ac8..5b403942 100644 --- a/dkms_common.postinst.in +++ b/dkms_common.postinst.in @@ -213,9 +213,9 @@ if [ -n "$ARCH" ]; then fi for KERNEL in $KERNELS; do + echo "" dkms_status=$(dkms status -m $NAME -v $VERSION -k $KERNEL $ARCH) if [ $(echo $KERNEL | grep -c "BOOT") -gt 0 ]; then - echo "" echo "Module build and install for $KERNEL was skipped as " echo "it is a BOOT variant" continue From 0ddfd0d03b79a5dcbfe3346b4fc8132c851491d0 Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Thu, 23 Jan 2025 02:57:30 +0100 Subject: [PATCH 56/57] dkms: add kernel_preinst action --- dkms.in | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/dkms.in b/dkms.in index d43cae19..8d9d9663 100644 --- a/dkms.in +++ b/dkms.in @@ -72,7 +72,7 @@ # 11: autoinstall: One or more modules failed to install during autoinstall. # 12: setup_kernels_arches(): Could not determine architecture. # 13: build: Aborting build of module ... for kernel ... due to missing BUILD_DEPENDS: ... -# 14: kernel_prerm: dkms kernel_prerm for kernel ... failed for module(s) ... +# 14: kernel_preinst/prerm: dkms kernel_preinst/prerm for kernel ... failed for module(s) ... # 21: prepare_kernel(): Your kernel headers for kernel ... cannot be found ... # 77: skipped due to BUILD_EXCLUSIVE # 101: install: pre_install failed, aborting install. @@ -258,7 +258,7 @@ show_usage() echo "Usage: $0 [action] [options]" echo " [action] = { add | remove | build | unbuild | install | uninstall | match |" echo " autoinstall | mktarball | ldtarball | status | generate_mok |" - echo " kernel_postinst | kernel_prerm }" + echo " kernel_preinst | kernel_postinst | kernel_prerm }" echo " [options] = [-m module] [-v module-version] [-k kernel-version] [-a arch]" echo " [-c dkms.conf-location] [-q] [--force] [--force-version-override] [--all]" echo " [--templatekernel=kernel] [--directive='cli-directive=cli-value']" @@ -365,7 +365,7 @@ check_all_is_banned() have_one_kernel() { check_all_is_banned $1 if (( ${#kernelver[@]} != 1 )); then - [[ $1 =~ kernel_(postinst|prerm) ]] && die 4 "The action $1 requires exactly one kernel version parameter on the command line." + [[ $1 =~ kernel_(preinst|postinst|prerm) ]] && die 4 "The action $1 requires exactly one kernel version parameter on the command line." die 4 "The action $1 does not support multiple kernel version parameters on the command line." fi } @@ -2637,6 +2637,45 @@ autoinstall() { fi } +# This is roughly the inverse action to 'autoinstall'. It is supposed to be +# called before upgrade of a kernel to first remove all modules that are +# currently built or installed for that kernel to ensure they get rebuilt +# by kernel_postinst later on. +# Upon initial installation of a kernel this is a no-op. +# +# Ideally we should only mark them as needing a rebuild instead of removing +# them right away, but such functionality is yet to be implemented. +kernel_preinst() +{ + local m + local v + local failed + + have_one_kernel kernel_prerm + + # run depmod only once after uninstalling all dkms modules + delayed_depmod=1 + + while IFS='/' read m v; do + is_module_built "$m" "$v" "$kernelver" "$arch" || continue + read_conf_or_die "$kernelver" "$arch" "$dkms_tree/$m/$v/source/dkms.conf" + [[ $AUTOINSTALL ]] || continue + echo "dkms: removing module $m/$v for kernel $kernelver ($arch)" >&2 + (module="$m" module_version="$v" unbuild_module) || failed="$failed $m/$v($?)" + done < <(list_module_version_combos) + + if [[ -f $dkms_tree/depmod-pending-$kernelver-$arch ]]; then + rm -f $dkms_tree/depmod-pending-$kernelver-$arch + invoke_command "do_depmod $1" "Running depmod" '' background + fi + delayed_depmod= + + # clean leftover empty directories + [[ ! -d $install_tree/$kernelver ]] || find "$install_tree/$kernelver" -type d -empty -delete + + [[ -z $failed ]] || die 14 "dkms kernel_preinst for kernel $kernelver ($arch) failed for module(s)$failed." +} + # A wrapper for 'autoinstall', to be used in combination with 'kernel_prerm'. kernel_postinst() { @@ -2765,7 +2804,7 @@ no_depmod="" delayed_depmod="" prepared_kernel="none" -action_re='^(remove|(auto|un)?install|match|mktarball|(un)?build|add|status|ldtarball|generate_mok|kernel_(postinst|prerm))$' +action_re='^(remove|(auto|un)?install|match|mktarball|(un)?build|add|status|ldtarball|generate_mok|kernel_(preinst|postinst|prerm))$' # Parse command line arguments while (($# > 0)); do @@ -2941,7 +2980,7 @@ parallel_jobs=${parallel_jobs:-$(get_num_cpus)} [[ "$parallel_jobs" = 0 ]] && parallel_jobs="" # Require explicit --kernelver argument -[[ $action =~ kernel_(postinst|prerm) ]] && have_one_kernel "$action" +[[ $action =~ kernel_(preinst|postinst|prerm) ]] && have_one_kernel "$action" setup_kernels_arches "$action" @@ -3001,7 +3040,7 @@ generate_mok) read_framework_conf $dkms_framework_signing_variables prepare_mok ;; -kernel_postinst | kernel_prerm) +kernel_preinst | kernel_postinst | kernel_prerm) check_root && have_one_kernel "$action" && "$action" ;; *) From 5d05111a6ce4038226b6c34907964c2c38e6dc1f Mon Sep 17 00:00:00 2001 From: Andreas Beckmann Date: Thu, 23 Jan 2025 02:58:43 +0100 Subject: [PATCH 57/57] debian: add kernel_preinst.d hook On kernel upgrades (w/o version change, but no guarantee that there was no ABI change), uninstall && unbuild all AUTOINSTALL=yes modules currently built for the kernel to ensure they get rebuilt by the kernel_postinst.d hook. No-op on initial installation of a kernel version. --- .gitignore | 1 + Makefile | 2 ++ debian_kernel_preinst.d.in | 11 +++++++++++ 3 files changed, 14 insertions(+) create mode 100644 debian_kernel_preinst.d.in diff --git a/.gitignore b/.gitignore index 0bd49a6a..29155b76 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ dkms.service dkms_common.postinst debian_kernel_install.d debian_kernel_postinst.d +debian_kernel_preinst.d debian_kernel_prerm.d redhat_kernel_install.d diff --git a/Makefile b/Makefile index d46b8645..c4b3da39 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,7 @@ GENERATED= \ dkms.service \ debian_kernel_install.d \ debian_kernel_postinst.d \ + debian_kernel_preinst.d \ debian_kernel_prerm.d \ redhat_kernel_install.d @@ -82,6 +83,7 @@ install-debian: install install -D -m 0755 debian_kernel_install.d $(DESTDIR)$(KINSTALL)/40-dkms.install install -D -m 0755 debian_kernel_postinst.d $(DESTDIR)$(KCONF)/postinst.d/dkms install -D -m 0755 debian_kernel_postinst.d $(DESTDIR)$(KCONF)/header_postinst.d/dkms + install -D -m 0755 debian_kernel_preinst.d $(DESTDIR)$(KCONF)/preinst.d/dkms install -D -m 0755 debian_kernel_prerm.d $(DESTDIR)$(KCONF)/prerm.d/dkms install-doc: diff --git a/debian_kernel_preinst.d.in b/debian_kernel_preinst.d.in new file mode 100644 index 00000000..bfc175d0 --- /dev/null +++ b/debian_kernel_preinst.d.in @@ -0,0 +1,11 @@ +#!/bin/sh + +# This script is triggered when the kernel (linux-image) package is being +# installed/upgraded. We're passed the version of the kernel being installed. +inst_kern=$1 + +if command -v dkms > /dev/null; then + dkms kernel_preinst -k "$inst_kern" +fi + +exit 0