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 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)) diff --git a/dkms.in b/dkms.in index 00650ccb..6badc93d 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 -- @@ -2956,6 +2956,7 @@ add | build | install) ${action}_module ;; autoinstall) + have_one_kernel $action check_root && autoinstall ;; match) 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/run_test.sh b/run_test.sh index 6b95d2ab..689f4b3c 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" @@ -442,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 @@ -517,94 +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 - 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}")" - - 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 - 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 -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} @@ -616,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} @@ -629,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 @@ -637,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 @@ -664,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}): @@ -738,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} @@ -780,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}): @@ -816,186 +709,772 @@ 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)' -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 -run_status_with_expected_output 'dkms_test' << EOF -dkms_test/1.0: added -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 -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 -Automatic installation of modules has been disabled. +Cleaning build area... done. +Building module(s)... done. +${SIGNING_MESSAGE}Cleaning build area... done. EOF -run_status_with_expected_output 'dkms_test' << 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' +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" -run_with_expected_output dkms autoinstall -k "${KERNEL_VER}" << EOF +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}) +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 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 + +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 + +Error! The action kernel_prerm requires exactly one kernel version parameter on the command line. +EOF +run_status_with_expected_output 'dkms_test' << EOF +dkms_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_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 +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_test/1.0 for kernel ${KERNEL_VER} (${KERNEL_ARCH}) +Autoinstall of module dkms_failing_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. +Building module(s)...(bad exit status: 2) +Failed command: +make -j1 KERNELRELEASE=${KERNEL_VER} all -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 +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. -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 +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 "Running dkms autoinstall for a kernel without headers installed (expected error)" -run_with_expected_error 21 dkms autoinstall -k "${KERNEL_VER}-noheaders" << 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... -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. +Deleting module dkms_failing_test/1.0 completely from the DKMS tree. EOF -echo 'Running dkms kernel_prerm w/o kernel argument (expected error)' -run_with_expected_error 4 dkms kernel_prerm << EOF +remove_module_source_tree /usr/src/dkms_failing_test-1.0 -Error! The action kernel_prerm requires exactly one kernel version parameter on the command line. +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 -run_status_with_expected_output 'dkms_test' << EOF -dkms_test/1.0, ${KERNEL_VER}, ${KERNEL_ARCH}: installed +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 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} +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 -Running depmod... done. +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 -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 @@ -2054,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' ############################################################################ @@ -2802,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} @@ -2854,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...