Merge branch 'shellcheck-tests' into 'debian/latest'

fix shellcheck complaints in tests

See merge request kernel-team/initramfs-tools!144
This commit is contained in:
Ben Hutchings 2025-02-25 01:23:59 +00:00
commit af25dc3ff4
9 changed files with 19 additions and 14 deletions

2
debian/salsa-ci.yml vendored
View File

@ -20,5 +20,5 @@ shellcheck:
- apt-get update
- apt-get install -y shellcheck
- |
shellcheck hook-functions $(find hooks scripts -type f) $({ find . -maxdepth 1 -type f -executable; find debian -maxdepth 1 -type f; find docs kernel -type f; } | xargs grep -l '^#!/bin/sh')
shellcheck hook-functions $(find hooks scripts -type f) $({ find . -maxdepth 1 -type f -executable; find debian -maxdepth 1 -type f; find debian/tests docs kernel tests -type f; } | xargs grep -l '^#!/bin/sh')
needs: []

View File

@ -7,10 +7,10 @@ SUPPORTED_FLAVOURS='alpha-smp amd64 arm64 armmp parisc loong64 m68k powerpc64 po
SOURCEDIR=/usr/lib/initramfs-test-copy-file
mkdir -p "${SOURCEDIR}/dir1"
echo -n 1 >"${SOURCEDIR}/dir1/file1"
printf "1" >"${SOURCEDIR}/dir1/file1"
ln -s dir1 "${SOURCEDIR}/dir2"
echo -n 22 >"${SOURCEDIR}/file2"
echo -n 333 >"${SOURCEDIR}/file3"
printf "22" >"${SOURCEDIR}/file2"
printf "333" >"${SOURCEDIR}/file3"
cat >>"${CONFDIR}/initramfs.conf" <<EOF
MODULES=list

View File

@ -21,5 +21,6 @@ build_initramfs
build_rootfs_ext2
# shellcheck disable=SC2119
run_qemu
check_no_network_configuration

View File

@ -15,6 +15,7 @@ lsinitramfs "${INITRAMFS}" | grep -qw busybox
build_rootfs_ext2
# shellcheck disable=SC2119
run_qemu
check_no_network_configuration

View File

@ -11,10 +11,11 @@ BUSYBOX=n
FSTYPE=ext2
EOF
build_initramfs
! lsinitramfs "${INITRAMFS}" | grep -qw busybox
! lsinitramfs "${INITRAMFS}" | grep -qw busybox || { echo "Error: busybox found in ${INITRAMFS}!" >&2; exit 1; }
build_rootfs_ext2
# shellcheck disable=SC2119
run_qemu
check_no_network_configuration

View File

@ -28,9 +28,9 @@ grep -qF "(initramfs) " "${OUTPUT}"
run_qemu_nocheck "panic=-1"
check_no_network_configuration
grep -qF "Rebooting automatically due to panic= boot argument" "${OUTPUT}"
! grep -qF "(initramfs) " "${OUTPUT}"
! grep -qF "(initramfs) " "${OUTPUT}" || { echo "Error: '(initramfs) ' found in output log!" >&2; exit 1; }
run_qemu_nocheck "panic=0"
check_no_network_configuration
grep -qF "Halting automatically due to panic= boot argument" "${OUTPUT}"
! grep -qF "(initramfs) " "${OUTPUT}"
! grep -qF "(initramfs) " "${OUTPUT}" || { echo "Error: '(initramfs) ' found in output log!" >&2; exit 1; }

View File

@ -30,6 +30,7 @@ mv "${ROOTDIR}/usr/"* "${USRDIR}"
build_rootfs_ext2
build_fs_ext2 "${USRDIR}" "${USRDISK}"
# shellcheck disable=SC2119
run_qemu
check_no_network_configuration

View File

@ -20,5 +20,6 @@ build_initramfs
build_rootfs_ext2
# shellcheck disable=SC2119
run_qemu
check_no_network_configuration

View File

@ -1,4 +1,5 @@
# -*- mode: sh -*-
# shellcheck shell=sh
# Find kernel flavour and release
KVER=
@ -17,7 +18,7 @@ fi
# avoid warnings for this (see #1078168).
tr '\0' '\n' < "/lib/modules/$KVER/modules.builtin.modinfo" \
| sed -n -e 's/^[^=]*\.firmware=//p' \
| while read fw_file; do
| while read -r fw_file; do
mkdir -p "/lib/firmware/$(dirname "$fw_file")"
touch "/lib/firmware/$fw_file"
done
@ -93,7 +94,7 @@ cp "$(dpkg -L libklibc | grep '/klibc-.*\.so$')" "${ROOTDIR}/lib/"
OUTPUT="${BASEDIR}/output.log"
prepare_network_dumping_rootfs() {
local root_dir="${1-$ROOTDIR}"
local root_dir="$ROOTDIR"
echo "I: Preparing network dumping rootfs in $root_dir..."
cat >"${root_dir}/usr/sbin/init" <<EOF
#!/bin/sh
@ -135,10 +136,8 @@ poweroff
EOF
. /usr/share/initramfs-tools/hook-functions
verbose=y
DESTDIR="$root_dir"
for binary in /usr/bin/cat /usr/bin/ip /usr/bin/ps /usr/sbin/sysctl; do
copy_exec "$binary"
verbose=y DESTDIR="$root_dir" copy_exec "$binary"
done
}
@ -148,12 +147,13 @@ build_initramfs() {
}
build_fs_ext2() {
local blocks inodes
local dir="${1}"
local disk="${2}"
# Get directory size
local blocks="$(du --summarize "${dir}" | cut -f 1)"
local inodes="$(du --summarize --inodes "${dir}" | cut -f 1)"
blocks="$(du --summarize "${dir}" | cut -f 1)"
inodes="$(du --summarize --inodes "${dir}" | cut -f 1)"
# Add fudge factor
blocks="$((blocks + 28 + blocks / 4))"