mirror of
https://salsa.debian.org/kernel-team/initramfs-tools.git
synced 2026-01-26 15:39:08 +00:00
The `/lib64` to `/usr/lib64` symlink is needed for `/usr/lib64/ld-linux-x86-64.so.2`. Otherwise dash will not find the programs.
177 lines
4.8 KiB
Bash
177 lines
4.8 KiB
Bash
# -*- mode: sh -*-
|
|
|
|
# Find kernel flavour and release
|
|
KVER=
|
|
for flavour in $SUPPORTED_FLAVOURS; do
|
|
KVER="$(dpkg-query -Wf '${Depends}' "linux-image-${flavour}" 2>/dev/null | tr ',' '\n' | sed -n 's/^ *linux-image-\([-a-z0-9+.]*\).*/\1/p')"
|
|
if [ "$KVER" ]; then
|
|
break
|
|
fi
|
|
done
|
|
if [ -z "$KVER" ]; then
|
|
echo >&2 "E: Test must set SUPPORTED_FLAVOURS and depend on those flavours"
|
|
exit 2
|
|
fi
|
|
|
|
ARCHITECTURE=$(dpkg --print-architecture)
|
|
case "$ARCHITECTURE" in
|
|
arm64)
|
|
# The Ubuntu arm64 autopkgtest runs rarely into the 1200 seconds timeout.
|
|
QEMU_TIMEOUT=1800
|
|
;;
|
|
armhf)
|
|
# qemu-busybox on Ubuntu armhf runs into the 300 seconds timeout.
|
|
QEMU_TIMEOUT=600
|
|
;;
|
|
ppc64el)
|
|
# Slowest execution seen in Ubuntu ppc64el autopkgtest: 230 seconds
|
|
QEMU_TIMEOUT=600
|
|
;;
|
|
s390x)
|
|
# Slowest execution seen in Ubuntu s390x autopkgtest: 58 seconds
|
|
QEMU_TIMEOUT=120
|
|
;;
|
|
*)
|
|
QEMU_TIMEOUT=60
|
|
esac
|
|
|
|
if [ -n "${AUTOPKGTEST_TMP-}" ]; then
|
|
export TMPDIR="${AUTOPKGTEST_TMP}"
|
|
fi
|
|
|
|
BASEDIR="$(mktemp -d -t initramfs-test.XXXXXXXXXX)"
|
|
|
|
# Skeleton configuration directory
|
|
CONFDIR="${BASEDIR}/config"
|
|
mkdir -p "${CONFDIR}"
|
|
cp conf/initramfs.conf "${CONFDIR}/initramfs.conf"
|
|
echo "RESUME=none" >>"${CONFDIR}/initramfs.conf"
|
|
touch "${CONFDIR}/modules"
|
|
mkdir "${CONFDIR}/scripts"
|
|
|
|
# initramfs image file
|
|
INITRAMFS="${BASEDIR}/initrd.img"
|
|
|
|
# root disk image file
|
|
ROOTDISK="${BASEDIR}/rootdisk.raw"
|
|
|
|
# root disk interface type (for qemu) and device name (for Linux)
|
|
test -n "${ROOTDISK_QEMU_IF}" || ROOTDISK_QEMU_IF=virtio
|
|
test -n "${ROOTDISK_LINUX_NAME}" || ROOTDISK_LINUX_NAME=vda
|
|
|
|
# Create a root fs with a trivial userspace
|
|
ROOTDIR="${BASEDIR}/rootdir"
|
|
INIT_MESSAGE='root fs init system started successfully'
|
|
for subdir in "" dev proc run sys usr usr/bin usr/lib usr/lib64 usr/sbin; do
|
|
mkdir "${ROOTDIR}/${subdir}"
|
|
done
|
|
for subdir in bin lib lib64 sbin; do
|
|
ln -s "usr/$subdir" "${ROOTDIR}/${subdir}"
|
|
done
|
|
cat >"${ROOTDIR}/sbin/init" <<EOF
|
|
#!/bin/sh -e
|
|
test -b /dev/${ROOTDISK_LINUX_NAME}
|
|
test -d /proc/1
|
|
test -d /run/initramfs
|
|
test -d /sys/class
|
|
test -d /usr/bin
|
|
echo '${INIT_MESSAGE}'
|
|
poweroff
|
|
EOF
|
|
chmod a+x "${ROOTDIR}/sbin/init"
|
|
cp /usr/lib/klibc/bin/sh "${ROOTDIR}/bin/sh"
|
|
cp /usr/lib/klibc/bin/poweroff "${ROOTDIR}/bin/poweroff"
|
|
cp "$(dpkg -L libklibc | grep '/klibc-.*\.so$')" "${ROOTDIR}/lib/"
|
|
|
|
# VM output file
|
|
OUTPUT="${BASEDIR}/output.log"
|
|
|
|
build_initramfs() {
|
|
echo "build_initramfs: /usr/sbin/mkinitramfs -d ${CONFDIR} -o ${INITRAMFS} ${KVER}"
|
|
/usr/sbin/mkinitramfs -d "${CONFDIR}" -o "${INITRAMFS}" "${KVER}"
|
|
}
|
|
|
|
build_fs_ext2() {
|
|
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)"
|
|
|
|
# Add fudge factor
|
|
blocks="$((blocks + 28 + blocks / 4))"
|
|
inodes="$((inodes + 10))"
|
|
|
|
# genext2fs writes status messages to stderr; hide that from
|
|
# autopkgtest
|
|
genext2fs 2>&1 -b "${blocks}" -N "${inodes}" -U -d "${dir}" "${disk}"
|
|
}
|
|
|
|
build_rootfs_ext2() {
|
|
build_fs_ext2 "${ROOTDIR}" "${ROOTDISK}"
|
|
}
|
|
|
|
_run_qemu() {
|
|
local extra_params="$*"
|
|
local console cpu efi_code efi_vars efi_vars_copy machine
|
|
|
|
case "$ARCHITECTURE" in
|
|
arm64)
|
|
machine="virt,gic-version=max"
|
|
cpu="max,pauth-impdef=on"
|
|
efi_code=/usr/share/AAVMF/AAVMF_CODE.fd
|
|
efi_vars=/usr/share/AAVMF/AAVMF_VARS.fd
|
|
;;
|
|
armhf)
|
|
machine="virt"
|
|
efi_code=/usr/share/AAVMF/AAVMF32_CODE.fd
|
|
efi_vars=/usr/share/AAVMF/AAVMF32_VARS.fd
|
|
console=ttyAMA0
|
|
;;
|
|
ppc64el)
|
|
machine="cap-ccf-assist=off,cap-cfpc=broken,cap-ibs=broken,cap-sbbc=broken"
|
|
console=hvc0
|
|
;;
|
|
esac
|
|
|
|
if test -f "${efi_vars-}"; then
|
|
efi_vars_copy="${BASEDIR}/${efi_vars##*/}"
|
|
cp "$efi_vars" "$efi_vars_copy"
|
|
fi
|
|
|
|
echo "I: Running qemu-system-${ARCHITECTURE} (with a timeout of $QEMU_TIMEOUT seconds)..."
|
|
timeout --foreground "$QEMU_TIMEOUT" \
|
|
"qemu-system-${ARCHITECTURE}" ${machine:+-machine "${machine}"} -cpu "${cpu-max}" -m 1G \
|
|
-drive "file=${ROOTDISK},if=${ROOTDISK_QEMU_IF},media=disk,format=raw" \
|
|
${efi_code:+-drive "file=${efi_code},if=pflash,format=raw,read-only=on"} \
|
|
${efi_vars:+-drive "file=${efi_vars_copy},if=pflash,format=raw"} \
|
|
${USRDISK:+-drive "file=${USRDISK},if=${USRDISK_QEMU_IF},media=disk,format=raw"} \
|
|
-device virtio-rng-pci,rng=rng0 -object rng-random,filename=/dev/urandom,id=rng0 \
|
|
-nographic -no-reboot -kernel /boot/vmlinu*-"${KVER}" -initrd "${INITRAMFS}" \
|
|
-nodefaults -chardev stdio,id=char0 -serial chardev:char0 \
|
|
-append "root=/dev/${ROOTDISK_LINUX_NAME} ro console=${console:-ttyS0},115200 ${extra_params}" | tee "${OUTPUT}"
|
|
}
|
|
|
|
run_qemu_nocheck() {
|
|
# hide error messages from autopkgtest
|
|
_run_qemu 2>&1 "$@"
|
|
}
|
|
|
|
run_qemu() {
|
|
_run_qemu "panic=-1"
|
|
grep -qF "${INIT_MESSAGE}" "${OUTPUT}"
|
|
}
|
|
|
|
check_no_output() {
|
|
local msg="$1"
|
|
if grep -qF "${msg}" "${OUTPUT}"; then
|
|
echo >&2 "E: Message '${msg}' found in log output '${OUTPUT}."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
check_no_network_configuration() {
|
|
check_no_output "Waiting up to 180 secs for"
|
|
}
|