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: | diff --git a/.gitignore b/.gitignore index d201c009..29155b76 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,17 @@ /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_preinst.d +debian_kernel_prerm.d +redhat_kernel_install.d + test_cmd_expected_output.log test_cmd_output.log diff --git a/Makefile b/Makefile index a7e4f87f..c4b3da39 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) @@ -29,7 +29,7 @@ SED_SUBSTITUTIONS = \ %: %.in $(SED) $(SED_SUBSTITUTIONS) $< > $@ -all: \ +GENERATED= \ dkms \ dkms.8 \ dkms_autoinstaller \ @@ -40,23 +40,15 @@ all: \ dkms.service \ debian_kernel_install.d \ debian_kernel_postinst.d \ + debian_kernel_preinst.d \ 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)) @@ -91,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 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 diff --git a/dkms.in b/dkms.in index 35ca8e77..81b9f485 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. @@ -173,8 +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=$? @@ -184,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 @@ -250,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']" @@ -325,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" } @@ -355,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." + [[ $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 - check_all_is_banned $1 } # Set up the kernelver and arch arrays. You must have a 1:1 correspondence -- @@ -390,14 +398,21 @@ setup_kernels_arches() kernelver[0]=$(uname -r) fi if [[ ! $arch ]]; then - 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 ]] && [[ -r /proc/cpuinfo ]] && grep -q Intel /proc/cpuinfo && ls $install_tree/$kernelver/build/configs 2>/dev/null | grep -q "ia32e"; then - arch[0]="ia32e" - fi - fi + 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 + arch[0]=$(uname -m) + if [[ $arch = x86_64 ]] && [[ -r /proc/cpuinfo ]] && 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 if [[ ! $arch ]]; then die 12 "Could not determine architecture." @@ -935,6 +950,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 @@ -948,11 +964,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." @@ -1133,8 +1153,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 @@ -1145,6 +1165,7 @@ prepare_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 @@ -1192,6 +1213,9 @@ prepare_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 @@ -1203,9 +1227,9 @@ prepare_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 @@ -1249,20 +1273,9 @@ prepare_build() fi # 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" + run_build_script pre_build "$pre_build" "$build_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" + 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}" @@ -1276,15 +1289,13 @@ 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 @@ -1325,17 +1336,17 @@ actual_build() done # Run the post_build script - run_build_script post_build "$post_build" -} + run_build_script post_build "$post_build" "$build_log" -# 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 + invoke_command "$clean" "Cleaning build area" "$build_log" 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" } @@ -1354,9 +1365,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 @@ -1511,9 +1520,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 @@ -1722,9 +1731,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 @@ -1738,7 +1747,15 @@ do_uninstall() while [[ ${dir_to_remove} != ${dir_to_remove#/} ]]; do dir_to_remove="${dir_to_remove#/}" done - (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) + + 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 @@ -1766,16 +1783,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" } @@ -1910,8 +1922,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 @@ -2626,6 +2638,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() { @@ -2703,9 +2754,9 @@ verbose="" symlink_modules="" # Set compression defaults -compress_gzip_opts="-9" +compress_gzip_opts="" compress_xz_opts="--check=crc32 --lzma2=dict=1MiB" -compress_zstd_opts="-q -T0 -19" +compress_zstd_opts="-q -T0" # Check that we can write temporary files tmpfile=$(mktemp_or_die) @@ -2718,7 +2769,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 @@ -2745,18 +2795,17 @@ 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" -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 @@ -2919,11 +2968,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)} @@ -2931,9 +2975,26 @@ 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" + +# 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 @@ -2949,6 +3010,7 @@ add | build | install) ${action}_module ;; autoinstall) + have_one_kernel $action check_root && autoinstall ;; match) @@ -2973,7 +3035,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" ;; *) diff --git a/dkms_autoinstaller.in b/dkms_autoinstaller.in index c6e8cbfd..dbc639e6 100644 --- a/dkms_autoinstaller.in +++ b/dkms_autoinstaller.in @@ -17,33 +17,11 @@ ### 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##*/} +MODDIR="@MODDIR@" 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" - echo $DIR -} - -_check_kernel_dir() { - DIR=$(_get_kernel_dir $1) - test -e $DIR/include - return $? -} - case "$1" in start) if [ -n "$2" ]; then @@ -51,11 +29,12 @@ 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 res=$? + test $res = 0 fi ;; stop|restart|force-reload|status|reload) diff --git a/dkms_common.postinst.in b/dkms_common.postinst.in index e6c430d7..5b403942 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 @@ -206,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 diff --git a/dkms_framework.conf.in b/dkms_framework.conf.in index 8adc54dc..ed1b242b 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. -# compress_gzip_opts="-9" -# compress_xz_opts="--check=crc32 --lzma2=dict=1MiB" -# compress_zstd_opts="-q -T0 -19" +# 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" diff --git a/run_test.sh b/run_test.sh index df7d8e4e..255c0a89 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}" @@ -69,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" @@ -185,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} @@ -238,6 +240,49 @@ 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/.*// +/# 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 +/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" @@ -361,6 +406,8 @@ else " fi +DKMS_VERSION="$(dkms --version)" + echo 'Preparing a clean test environment' clean_dkms_env @@ -396,14 +443,54 @@ 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 '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 + +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 '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 @@ -422,6 +509,31 @@ 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 (${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 + 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. @@ -446,99 +558,6 @@ run_status_with_expected_output 'dkms_test' << EOF 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 -Sign command: /no/such/file -Binary /no/such/file not found, modules won't be signed - -Cleaning build area... done. -Building module(s)... done. -Cleaning build area... done. -EOF - - 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} -Signing key: /no/such/path.key -Public certificate (MOK): /var/lib/dkms/mok.pub -Key file /no/such/path.key not found and can't be generated, modules won't be signed - -Cleaning build area... done. -Building module(s)... done. -${SIGNING_MESSAGE}Cleaning build area... done. -EOF - - 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} -Signing key: /tmp/dkms_test_private_key -Public certificate (MOK): /no/such/path.crt -Certificate file /no/such/path.crt not found and can't be generated, modules won't be signed - -Cleaning build area... done. -Building module(s)... done. -${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' - 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 -Sign command: /lib/modules/${KERNEL_VER}/build/scripts/sign-file -Signing key: /tmp/dkms_test_dir_${KERNEL_VER}/key -Public certificate (MOK): /tmp/dkms_test_dir_${KERNEL_VER}/cert - -Cleaning build area... done. -Building module(s)... done. -${SIGNING_MESSAGE}Cleaning build area... done. -EOF - rm -r "/tmp/dkms_test_dir_${KERNEL_VER}/" - - 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}")" - - 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 - ALTER_HASH="sha512" - 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} -Cleaning build area... done. -Building module(s)... done. -${SIGNING_MESSAGE}Cleaning build area... done. -EOF - run_with_expected_output sh -c "modinfo -F sig_hashalgo '${BUILT_MODULE_PATH}'" << EOF -${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} @@ -550,11 +569,6 @@ 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 Installing /lib/modules/${KERNEL_VER}/${expected_dest_loc}/dkms_test.ko${mod_compression_ext} @@ -563,6 +577,10 @@ 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 @@ -571,10 +589,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 'Installing the test module again by force' run_with_expected_output dkms install -k "${KERNEL_VER}" -m dkms_test -v 1.0 --force << EOF @@ -598,26 +612,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}")" - - if kmod_broken_hashalgo; then - echo ' Current kmod has broken hash algorithm code. Skipping...' - elif [[ "${SIG_HASH}" == "unknown" ]]; then - echo ' Current kmod reports unknown hash algorithm. Skipping...' - elif [[ ! "${SIG_KEY}" ]]; then - # kmod may not be linked with openssl and thus can't extract the key from module - echo >&2 "Error: module was not signed, or key is unknown" - exit 1 - else - run_with_expected_output sh -c "echo '${SIG_KEY}'" << EOF -${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 Module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): @@ -672,21 +666,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} @@ -714,26 +693,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}")" - - if kmod_broken_hashalgo; then - echo ' Current kmod has broken hash algorithm code. Skipping...' - elif [[ "${SIG_HASH}" == "unknown" ]]; then - echo ' Current kmod reports unknown hash algorithm. Skipping...' - elif [[ ! "${SIG_KEY}" ]]; then - # kmod may not be linked with openssl and thus can't extract the key from module - echo >&2 "Error: module was not signed, or key is unknown" - exit 1 - else - run_with_expected_output sh -c "echo '${SIG_KEY}'" << EOF -${CERT_SERIAL} -EOF - fi -fi - 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 for kernel ${KERNEL_VER} (${KERNEL_ARCH}): @@ -752,53 +711,428 @@ fi remove_module_source_tree /usr/src/dkms_test-1.0 -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} +echo 'Checking that the environment is clean again' +check_no_dkms_test + +if (( NO_SIGNING_TOOL == 0 )); then + ############################################################################ + 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 + + 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 +Sign command: /no/such/file +Binary /no/such/file not found, modules won't be signed 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 +Cleaning build area... done. EOF -echo "Running dkms autoinstall (module already built)" -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} -Running depmod... done. + 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} +Signing key: /no/such/path.key +Public certificate (MOK): /var/lib/dkms/mok.pub +Key file /no/such/path.key not found and can't be generated, modules won't be signed -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 +Cleaning build area... done. +Building module(s)... done. +${SIGNING_MESSAGE}Cleaning build area... done. 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 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 + 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} +Signing key: /tmp/dkms_test_private_key +Public certificate (MOK): /no/such/path.crt +Certificate file /no/such/path.crt not found and can't be generated, modules won't be signed + +Cleaning build area... done. +Building module(s)... done. +${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' + 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 +Sign command: /lib/modules/${KERNEL_VER}/build/scripts/sign-file +Signing key: /tmp/dkms_test_dir_${KERNEL_VER}/key +Public certificate (MOK): /tmp/dkms_test_dir_${KERNEL_VER}/cert + +Cleaning build area... done. +Building module(s)... done. +${SIGNING_MESSAGE}Cleaning build area... done. +EOF + rm -r "/tmp/dkms_test_dir_${KERNEL_VER}/" + + 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_tmp_key_cert="${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 + if [[ "${CURRENT_HASH}" == "sha512" ]]; then + ALTER_HASH="sha256" + else + ALTER_HASH="sha512" + 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_tmp_key_cert} +Cleaning build area... done. +Building module(s)... done. +${SIGNING_MESSAGE}Cleaning build area... done. +EOF + run_with_expected_output sh -c "modinfo -F sig_hashalgo '${BUILT_MODULE_PATH}'" << EOF +${ALTER_HASH} +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 +${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 +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 +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 ' 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}")" + + if kmod_broken_hashalgo; then + echo ' Current kmod has broken hash algorithm code. Skipping...' + elif [[ "${SIG_HASH}" == "unknown" ]]; then + echo ' Current kmod reports unknown hash algorithm. Skipping...' + elif [[ ! "${SIG_KEY}" ]]; then + # kmod may not be linked with openssl and thus can't extract the key from module + echo >&2 "Error: module was not signed, or key is unknown" + exit 1 + else + run_with_expected_output sh -c "echo '${SIG_KEY}'" << EOF +${CERT_SERIAL} +EOF + fi + + 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. + +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 '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 + +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 + 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 + + 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 ' 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}")" + + if kmod_broken_hashalgo; then + echo ' Current kmod has broken hash algorithm code. Skipping...' + elif [[ "${SIG_HASH}" == "unknown" ]]; then + echo ' Current kmod reports unknown hash algorithm. Skipping...' + elif [[ ! "${SIG_KEY}" ]]; then + # kmod may not be linked with openssl and thus can't extract the key from module + echo >&2 "Error: module was not signed, or key is unknown" + exit 1 + else + run_with_expected_output sh -c "echo '${SIG_KEY}'" << EOF +${CERT_SERIAL} +EOF + fi + + 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. + +Deleting module dkms_test/1.0 completely from the DKMS tree. +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 + + echo 'Checking that the environment is clean again' + check_no_dkms_test +fi + +############################################################################ +echo '*** Testing dkms autoinstall/kernel_{postinst/prerm}, dkms_autoinstaller' +############################################################################ + +echo 'Testing without modules and without headers' + +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 + +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 + +echo ' Running dkms autoinstall' +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. +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' + +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 + +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} +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. +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 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} +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 '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 '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 + +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 + +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 + +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 + +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. +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" +echo 'Running dkms autoinstall --all (expected error)' +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} Autoinstall of module dkms_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) @@ -814,19 +1148,48 @@ 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 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 +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 -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. +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 @@ -844,92 +1207,274 @@ 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. +Running depmod... done. +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0: added +EOF + +echo 'Running dkms kernel_prerm again' +run_with_expected_output dkms kernel_prerm -k "${KERNEL_VER}" << EOF +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0: added +EOF + +echo 'Building the test module' +run_with_expected_output dkms build -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. +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built +EOF + +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... + +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_test/1.0: added +EOF + +echo 'Running dkms kernel_postinst w/o kernel argument (expected error)' +run_with_expected_error 4 dkms kernel_postinst << EOF + +Error! The action kernel_postinst requires exactly one kernel version parameter on the command line. +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 +${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 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' +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. + +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 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 + +if [[ -x /usr/lib/dkms/dkms_autoinstaller ]]; then +echo ' Running dkms_autoinstaller with failing test module (expected error)' +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. +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} +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 + +############################################################################ +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 + +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_test' << EOF -dkms_test/1.0: added +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added EOF +fi -echo 'Running dkms kernel_prerm again' -run_with_expected_output dkms kernel_prerm -k "${KERNEL_VER}" << EOF +echo 'Running dkms kernel_postinst' +run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << EOF EOF -run_status_with_expected_output 'dkms_test' << EOF -dkms_test/1.0: added +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added EOF -echo 'Building the test module' -run_with_expected_output dkms build -k "${KERNEL_VER}" -m dkms_test -v 1.0 << 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_test' << EOF -dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built 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 is not installed for kernel ${KERNEL_VER} (${KERNEL_ARCH}). Skipping... - +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_test' << EOF -dkms_test/1.0: added +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed EOF -echo 'Running dkms kernel_postinst w/o kernel argument (expected error)' -run_with_expected_error 4 dkms kernel_postinst << 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} -Error! The action kernel_postinst requires exactly one kernel version parameter on the command line. +Running depmod... done. EOF -run_status_with_expected_output 'dkms_test' << EOF -dkms_test/1.0: added +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 +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} -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} +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 -Autoinstall on ${KERNEL_VER} succeeded for module(s) dkms_test. +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_test' << EOF -dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: built EOF -echo "Running dkms kernel_postinst again" -run_with_expected_output dkms kernel_postinst -k "${KERNEL_VER}" << 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_test' << EOF -dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +run_status_with_expected_output 'dkms_noautoinstall_test' << EOF +dkms_noautoinstall_test/1.0: added 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 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. +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_test/1.0 completely from the DKMS tree. +Deleting module dkms_noautoinstall_test/1.0 completely from the DKMS tree. EOF -run_status_with_expected_output 'dkms_test' << EOF +run_status_with_expected_output 'dkms_noautoinstall_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 +remove_module_source_tree /usr/src/dkms_noautoinstall_test-1.0 echo 'Checking that the environment is clean again' check_no_dkms_test @@ -1333,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 @@ -1390,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 @@ -1444,12 +1989,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. @@ -1486,10 +2027,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} @@ -1533,32 +2074,14 @@ 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. -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 +Applying patch patch2.patch... done. +Applying patch patch1.patch... done. +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 @@ -1583,6 +2106,74 @@ 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 (${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: +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 +# 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 + 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 +# 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' 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}): @@ -1655,32 +2246,14 @@ 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. -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 +Applying patch patch2.patch... done. +Applying patch patch1.patch... done. +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 @@ -1702,12 +2275,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. @@ -1715,10 +2284,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} @@ -1964,89 +2533,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' ############################################################################ @@ -2712,29 +3198,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} @@ -2764,14 +3234,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...