]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
test: compute VMLINUZ in run-qemu only when it is needed
authorJo Zzsi <jozzsicsataban@gmail.com>
Sat, 19 Jul 2025 20:13:20 +0000 (16:13 -0400)
committerLaszlo <laszlo.gombos@gmail.com>
Sun, 20 Jul 2025 12:33:35 +0000 (08:33 -0400)
Currently VMLINUZ is computed and set even when it is not needed
(e.g. for test 80). Move the computation to run-qemu instead
and only set it when needed.

test/run-qemu
test/test-functions

index 0f68e04d40cd386adb8d0e84c0c4a57735db3dda..841e7695363ce1ee2fc1c91db8dd48329322ba9e 100755 (executable)
@@ -7,6 +7,39 @@ export PATH=/usr/sbin:/usr/bin:/sbin:/bin
 ARCH="${ARCH-$(uname -m)}"
 QEMU_CPU="${QEMU_CPU:-max}"
 
+set_vmlinux_env() {
+    VMLINUZ=${VMLINUZ-"/lib/modules/${KVERSION}/vmlinuz"}
+    if ! [ -f "$VMLINUZ" ]; then
+        VMLINUZ="/lib/modules/${KVERSION}/vmlinux"
+    fi
+
+    if ! [ -f "$VMLINUZ" ]; then
+        [[ -f /etc/machine-id ]] && read -r MACHINE_ID < /etc/machine-id
+
+        if [[ ${MACHINE_ID-} ]] && { [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]]; }; then
+            VMLINUZ="/boot/${MACHINE_ID}/$KVERSION/linux"
+        elif [ -f "/boot/vmlinuz-${KVERSION}" ]; then
+            VMLINUZ="/boot/vmlinuz-${KVERSION}"
+        elif [ -f "/boot/vmlinux-${KVERSION}" ]; then
+            VMLINUZ="/boot/vmlinux-${KVERSION}"
+        elif [ -f "/boot/kernel-${KVERSION}" ]; then
+            VMLINUZ="/boot/kernel-${KVERSION}"
+        elif [ -f "/boot/Image-${KVERSION}" ]; then
+            VMLINUZ="/boot/Image-${KVERSION}"
+        fi
+    fi
+
+    if ! [ -f "$VMLINUZ" ]; then
+        VMLINUZ=$(find /boot/vmlinuz-* -type f 2> /dev/null | tail -1)
+    fi
+
+    if ! [ -f "$VMLINUZ" ]; then
+        echo "Could not find a Linux kernel version $KVERSION to test with!" >&2
+        echo "Please install linux." >&2
+        exit 1
+    fi
+}
+
 [[ -x /usr/bin/qemu ]] && BIN=/usr/bin/qemu && ARGS=(-cpu "$QEMU_CPU")
 (lsmod | grep -q '^kqemu ') && BIN=/usr/bin/qemu && ARGS=(-kernel-kqemu -cpu host)
 [[ -z ${NO_KVM-} && -c /dev/kvm && -x /usr/bin/kvm ]] && BIN=/usr/bin/kvm && ARGS=(-cpu host)
@@ -56,6 +89,7 @@ fi
 
 # only set -kernel if -initrd is specified
 if [[ $* == *-initrd* ]]; then
+    set_vmlinux_env
     ARGS+=(-kernel "$VMLINUZ")
 fi
 
index 3d09c92d9eb9039b3b1ef028f2d2983e42d2bea9..ca776df0b075819a2fec5a391aa1a89556e5a2aa 100644 (file)
@@ -110,46 +110,12 @@ determine_kernel_version() {
     # shellcheck disable=SC2012
     [[ ${KVERSION-} ]] || KVERSION="$(cd /usr/lib/modules && ls -1v | tail -1)"
     [[ ${KVERSION-} ]] || KVERSION="$(uname -r)"
-}
-
-set_vmlinux_env() {
-    VMLINUZ=${VMLINUZ-"/lib/modules/${KVERSION}/vmlinuz"}
-    if ! [ -f "$VMLINUZ" ]; then
-        VMLINUZ="/lib/modules/${KVERSION}/vmlinux"
-    fi
-
-    if ! [ -f "$VMLINUZ" ]; then
-        [[ -f /etc/machine-id ]] && read -r MACHINE_ID < /etc/machine-id
-
-        if [[ ${MACHINE_ID-} ]] && { [[ -d /boot/${MACHINE_ID} ]] || [[ -L /boot/${MACHINE_ID} ]]; }; then
-            VMLINUZ="/boot/${MACHINE_ID}/$KVERSION/linux"
-        elif [ -f "/boot/vmlinuz-${KVERSION}" ]; then
-            VMLINUZ="/boot/vmlinuz-${KVERSION}"
-        elif [ -f "/boot/vmlinux-${KVERSION}" ]; then
-            VMLINUZ="/boot/vmlinux-${KVERSION}"
-        elif [ -f "/boot/kernel-${KVERSION}" ]; then
-            VMLINUZ="/boot/kernel-${KVERSION}"
-        elif [ -f "/boot/Image-${KVERSION}" ]; then
-            VMLINUZ="/boot/Image-${KVERSION}"
-        fi
-    fi
-
-    if ! [ -f "$VMLINUZ" ]; then
-        VMLINUZ=$(find /boot/vmlinuz-* -type f 2> /dev/null | tail -1)
-    fi
-
-    if ! [ -f "$VMLINUZ" ]; then
-        echo "Could not find a Linux kernel version $KVERSION to test with!" >&2
-        echo "Please install linux." >&2
-        exit 1
-    fi
 
-    export VMLINUZ
+    export KVERSION
 }
 
 set_test_envonment_variables() {
     determine_kernel_version
-    set_vmlinux_env
 }
 
 command -v test_check &> /dev/null || test_check() {