diff -Nru initramfs-tools-0.136ubuntu6.7/debian/changelog initramfs-tools-0.136ubuntu6.8/debian/changelog --- initramfs-tools-0.136ubuntu6.7/debian/changelog 2022-01-26 18:11:24.000000000 +0100 +++ initramfs-tools-0.136ubuntu6.8/debian/changelog 2024-03-19 13:12:51.000000000 +0100 @@ -1,3 +1,14 @@ +initramfs-tools (0.136ubuntu6.8) focal; urgency=medium + + * Fix configuring BOOTIF when using iSCSI (LP: #2056187) + * Port the net autopkgtest to the common test framework. This drops + depending on downloading a cloud image from the Internet and reduces + the execution time from 3:19 min down to 0:57 min. Also backport + autopkgtest improvements from version 0.142ubuntu23 to run the + test on all architectures and to check more results from qemu-net. + + -- Benjamin Drung Tue, 19 Mar 2024 13:12:51 +0100 + initramfs-tools (0.136ubuntu6.7) focal; urgency=medium * Increase image file to 2GB in autopkgtest (LP: #1958904) diff -Nru initramfs-tools-0.136ubuntu6.7/debian/tests/check-log initramfs-tools-0.136ubuntu6.8/debian/tests/check-log --- initramfs-tools-0.136ubuntu6.7/debian/tests/check-log 1970-01-01 01:00:00.000000000 +0100 +++ initramfs-tools-0.136ubuntu6.8/debian/tests/check-log 2024-03-19 13:12:27.000000000 +0100 @@ -0,0 +1,281 @@ +#!/usr/bin/python3 + +# pylint: disable=invalid-name +# pylint: enable=invalid-name + +"""Run given checks on the log output.""" + +import argparse +import json +import pathlib +import re +import shlex +import subprocess +import sys + + +class Check: + """The Check class contains all the checks that the caller can run.""" + + def __init__(self, log: str) -> None: + self.errors = 0 + self.command_outputs = self._extract_command_outputs_from_log(log) + + def _error(self, msg: str) -> None: + print("ERROR: " + msg) + self.errors += 1 + + @staticmethod + def _extract_command_outputs_from_log(log: str): + """Extract command outputs from the given log output. + + The output must be framed by a header and a footer line. The header + line contains the key surrounded by 10 # characters. The footer + line consist of 40 # characters. Returns a mapping from the output + key to the command output. + """ + marker = "#" * 10 + footer = "#" * 40 + matches = re.findall( + f"^{marker} ([^#]+) {marker}\n(.*?\n){footer}$", + log, + flags=re.DOTALL | re.MULTILINE, + ) + return {m[0]: m[1] for m in matches} + + def get_commands_from_ps_output(self): + """Get list of command from `ps -ww aux` output.""" + ps_output = self.command_outputs["ps -ww aux"] + lines = ps_output.strip().split("\n")[1:] + commands = [] + for line in lines: + columns = re.split(r"\s+", line, maxsplit=10) + commands.append(columns[10]) + return commands + + def get_ip_addr(self): + """Get IP address information from `ip addr` JSON output.""" + ip_addr = json.loads(self.command_outputs["ip -json addr"]) + assert isinstance(ip_addr, list) + return ip_addr + + def get_ip_route(self): + """Get IP route information from `ip route` JSON output.""" + ip_route = json.loads(self.command_outputs["ip -json route"]) + assert isinstance(ip_route, list) + return ip_route + + def run_checks(self, args) -> int: + """Run the checks and return the number of errors found. + + The methods of this class can be u + """ + if not args: + return self.errors + + try: + check = getattr(self, args[0]) + except AttributeError: + self._error(f"Check '{args[0]}' not found.") + return self.errors + check_args = [] + + for arg in args[1:]: + if not hasattr(self, arg): + check_args.append(arg) + continue + + check(*check_args) + check = getattr(self, arg) + check_args = [] + + check(*check_args) + return self.errors + + def _check_is_subset(self, expected, actual) -> None: + """Check that the first dictionary is a subset of the second one. + + Log errors if the sets are different. + """ + unexpected = actual - expected + if unexpected: + self._error(f"Not expected entries: {unexpected}") + + def _check_is_subdict( + self, + expected_dict, + actual_dict, + log_prefix: str, + ) -> None: + """Check that the first dictionary is a subset of the second one. + + Log errors if differences are found. + """ + missing_keys = set(expected_dict.keys()) - set(actual_dict.keys()) + if missing_keys: + self._error(f"{log_prefix}Missing keys: {missing_keys}") + for key, expected_value in sorted(expected_dict.items()): + actual_value = actual_dict.get(key, "") + if expected_value != actual_value: + self._error( + f"{log_prefix}Value for key '{key}' differs:" + f" '{expected_value}' expected, but got '{actual_value}'" + ) + + # Below are all checks that the user might call. + + def has_hostname(self, hostname_pattern: str) -> None: + """Check that the hostname matches the given regular expression.""" + hostname = self.command_outputs["hostname"].strip() + if re.fullmatch(hostname_pattern, hostname): + print(f"hostname '{hostname}' matches pattern '{hostname_pattern}'") + return + self._error( + f"hostname '{hostname}' does not match" + f" expected pattern '{hostname_pattern}'" + ) + + def has_interface_mtu(self, device_pattern: str, expected_mtu: str) -> None: + """Check that a matching network device has the expected MTU set.""" + for device in self.get_ip_addr(): + if not re.fullmatch(device_pattern, device["ifname"]): + continue + if str(device["mtu"]) == expected_mtu: + print(f"device {device['ifname']} has MTU {device['mtu']}") + return + self._error( + f"device {device['ifname']} has MTU {device['mtu']}" + f" but expected {expected_mtu}" + ) + return + self._error(f"no link found that matches '{device_pattern}'") + + def has_ip_addr(self, family: str, addr_pattern: str, device_pattern: str) -> None: + """Check that a matching network device has a matching IP address.""" + for device in self.get_ip_addr(): + if not re.fullmatch(device_pattern, device["ifname"]): + continue + for addr in device["addr_info"]: + if addr["family"] != family or addr["scope"] != "global": + continue + address = f"{addr['local']}/{addr['prefixlen']}" + if re.fullmatch(addr_pattern, address): + print(f"found addr {address} for {device['ifname']}: {addr}") + return + self._error( + f"addr {address} for {device['ifname']}" + f" does not match {addr_pattern}: {addr}" + ) + return + name = {"inet": "IPv4", "inet6": "IPv6"}[family] + self._error( + f"no link found that matches '{device_pattern}' and has an {name} address" + ) + + def has_ipv4_addr(self, addr_pattern: str, device_pattern: str) -> None: + """Check that a matching network device has a matching IPv4 address.""" + self.has_ip_addr("inet", addr_pattern, device_pattern) + + def has_ipv6_addr(self, addr_pattern: str, device_pattern: str) -> None: + """Check that a matching network device has a matching IPv6 address.""" + self.has_ip_addr("inet6", addr_pattern, device_pattern) + + def has_ipv4_default_route(self, gateway_pattern: str, device_pattern: str) -> None: + """Check that the IPv4 default route is via a matching gateway and device.""" + for route in self.get_ip_route(): + if route["dst"] != "default": + continue + if not re.fullmatch(gateway_pattern, route["gateway"]) or not re.fullmatch( + device_pattern, route["dev"] + ): + self._error( + f"Default IPv4 route does not match expected gateway pattern" + f" '{gateway_pattern}' or dev pattern '{device_pattern}': {route}" + ) + continue + print( + f"found IPv4 default route via {route['gateway']}" + f" for {route['dev']}: {route}" + ) + return + self._error("no IPv4 default route found") + + def has_net_conf(self, min_expected_files: str, *expected_net_confs: str) -> None: + """Compare the /run/net*.conf files. + + There must be at least one /run/net*.conf file in the log output and no + unexpected one. The format is `=`. + """ + + expected = dict(nc.split("=", maxsplit=1) for nc in expected_net_confs) + prog = re.compile(r"/run/net[^#]+\.conf") + got = { + key: value for key, value in self.command_outputs.items() if prog.match(key) + } + + if len(got) < int(min_expected_files): + self._error( + f"Expected at least {min_expected_files} /run/net*.conf files," + f" but got only {len(got)}: {set(got.keys())}" + ) + self._check_is_subset(set(expected.keys()), set(got.keys())) + + for net_dev in sorted(got.keys()): + log_prefix = f"{net_dev}: " + expected_net_conf = parse_net_conf(expected.get(net_dev, "")) + actual_net_conf = parse_net_conf(got.get(net_dev, "")) + self._check_is_subdict(expected_net_conf, actual_net_conf, log_prefix) + print(f"compared {len(expected_net_conf)} items from {net_dev}") + + def has_no_running_processes(self) -> None: + """Check that there are no remaining running processes from the initrd.""" + processes = drop_kernel_processes(self.get_commands_from_ps_output()) + + udevd = "/lib/systemd/systemd-udevd --daemon --resolve-names=never" + if udevd in processes and get_architecture() != "amd64": + print( + "Warning: Ignoring running /lib/systemd/systemd-udevd processes." + " See https://launchpad.net/bugs/2025369" + ) + processes = [p for p in processes if p != udevd] + + if len(processes) == 2: + print(f"found only expected init and ps process: {processes}") + return + self._error( + f"Expected only init and ps process, but got {len(processes)}: {processes}" + ) + + +def drop_kernel_processes(processes): + """Return a list of processes with the kernel processes dropped.""" + return [p for p in processes if not p.startswith("[") and not p.endswith("]")] + + +def get_architecture() -> str: + """Return architecture of packages dpkg installs.""" + cmd = ["dpkg", "--print-architecture"] + process = subprocess.run(cmd, capture_output=True, check=True, text=True) + return process.stdout.strip() + + +def parse_net_conf(net_conf: str): + """Parse /run/net*.conf file and return a key to value mapping.""" + items = shlex.split(net_conf) + return dict(item.split("=", maxsplit=1) for item in items) + + +def main(arguments) -> int: + """Run given checks on the log output. Return number of errors.""" + parser = argparse.ArgumentParser() + parser.add_argument("log_file", metavar="log-file") + parser.add_argument("checks", metavar="check", nargs="+") + args = parser.parse_args(arguments) + + log = pathlib.Path(args.log_file).read_text(encoding="ascii") + check = Check(log) + return check.run_checks(args.checks) + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff -Nru initramfs-tools-0.136ubuntu6.7/debian/tests/check-results initramfs-tools-0.136ubuntu6.8/debian/tests/check-results --- initramfs-tools-0.136ubuntu6.7/debian/tests/check-results 2021-03-18 19:48:17.000000000 +0100 +++ initramfs-tools-0.136ubuntu6.8/debian/tests/check-results 1970-01-01 01:00:00.000000000 +0100 @@ -1,86 +0,0 @@ -#!/usr/bin/python3 - -import json -import os -import sys - -in_error = False - -def error(msg): - print("ERROR: " + msg) - global in_error - in_error = True - -def has_link(name): - for l in links: - if l['ifname'] == name: - return - error("link {} not found".format(name)) - -def has_an_ipv4_addr(name): - for l in addrs: - if l['ifname'] == name: - for addr in l['addr_info']: - if addr['family'] == 'inet' and addr['scope'] == 'global': - print("found addr {} for {}".format(addr, name)) - return - error("{} appears to have no addresses".format(name)) - return - error("link {} not found".format(name)) - -def has_no_ipv4_addr(name): - for l in addrs: - if l['ifname'] == name: - for addr in l['addr_info']: - if addr['family'] == 'inet' and addr['scope'] == 'global': - error("found addr {} for {}".format(addr, name)) - return - print("{} appears to have no addresses".format(name)) - return - error("link {} not found".format(name)) - -def has_ipv4_addr(name, wanted_addr): - for l in addrs: - if l['ifname'] == name: - for addr in l['addr_info']: - if addr['family'] == 'inet' and addr['scope'] == 'global': - if addr['local'] == wanted_addr: - print("found addr {} for {}".format(addr, name)) - return - error("{} appears not to have address {}".format(name, wanted_addr)) - return - error("link {} not found".format(name)) - -result_dir = sys.argv[1] -with open(os.path.join(result_dir, 'link.json')) as fp: - links = json.load(fp) -with open(os.path.join(result_dir, 'addr.json')) as fp: - addrs = json.load(fp) - -with open(os.path.join(result_dir, 'ps.txt'), encoding='utf-8', errors='replace') as fp: - ps_output = fp.read() - -if 'dhclient' in ps_output: - error("dhclient appears to be running") - -i = 2 -while i < len(sys.argv): - a = sys.argv[i] - i += 1 - if a == 'has_link': - has_link(sys.argv[i]) - i += 1 - elif a == 'has_an_ipv4_addr': - has_an_ipv4_addr(sys.argv[i]) - i += 1 - elif a == 'has_no_ipv4_addr': - has_no_ipv4_addr(sys.argv[i]) - i += 1 - elif a == 'has_ipv4_addr': - has_ipv4_addr(sys.argv[i], sys.argv[i+1]) - i += 2 - else: - error("unknown check {}".format(a)) - -if in_error: - sys.exit(1) diff -Nru initramfs-tools-0.136ubuntu6.7/debian/tests/control initramfs-tools-0.136ubuntu6.8/debian/tests/control --- initramfs-tools-0.136ubuntu6.7/debian/tests/control 2021-03-18 19:48:17.000000000 +0100 +++ initramfs-tools-0.136ubuntu6.8/debian/tests/control 2024-03-19 13:05:17.000000000 +0100 @@ -5,14 +5,63 @@ Test-Command: ./tests/run-tests Depends: netplan.io Restrictions: allow-stderr +Features: test-name=unit-tests -Tests: net -Depends: curl, - initramfs-tools, +# Note: These tests need root on Ubuntu, because the kernel is only readable by root. See https://launchpad.net/bugs/759725 +Tests: qemu-klibc +Architecture: amd64 armhf s390x +Depends: genext2fs, + ipxe-qemu, + klibc-utils, + linux-image-generic, + qemu-efi-arm [armhf], + qemu-kvm, + @ +Restrictions: needs-root + +Tests: qemu-busybox +Architecture: amd64 armhf s390x +Depends: busybox | busybox-initramfs, + genext2fs, + ipxe-qemu, + klibc-utils, + linux-image-generic, + qemu-efi-arm [armhf], + qemu-kvm, + @ +Restrictions: needs-root + +Tests: qemu-ata-only +Architecture: amd64 +Depends: genext2fs, klibc-utils, linux-image-generic, qemu-kvm, @ +Restrictions: needs-root + +Tests: qemu-virtio-only qemu-separate-usr qemu-panic-shell +Architecture: amd64 arm64 armhf ppc64el s390x +Depends: genext2fs, + ipxe-qemu, + klibc-utils, + linux-image-generic, + qemu-efi-aarch64 [arm64], + qemu-efi-arm [armhf], + qemu-kvm, + seabios [ppc64el], + @ +Restrictions: needs-root + +Tests: qemu-net +Architecture: amd64 arm64 armhf ppc64el s390x +Depends: genext2fs, + iproute2, + ipxe-qemu, isc-dhcp-client, + klibc-utils, linux-image-generic, - lsb-release, - parted, + procps, python3, - qemu-system -Restrictions: needs-root, allow-stderr + qemu-efi-aarch64 [arm64], + qemu-efi-arm [armhf], + qemu-kvm, + seabios [ppc64el], + @ +Restrictions: needs-root diff -Nru initramfs-tools-0.136ubuntu6.7/debian/tests/hooks/drop-hostname initramfs-tools-0.136ubuntu6.8/debian/tests/hooks/drop-hostname --- initramfs-tools-0.136ubuntu6.7/debian/tests/hooks/drop-hostname 1970-01-01 01:00:00.000000000 +0100 +++ initramfs-tools-0.136ubuntu6.8/debian/tests/hooks/drop-hostname 2024-03-19 11:03:30.000000000 +0100 @@ -0,0 +1,17 @@ +#!/bin/sh + +PREREQ="" + +prereqs() +{ + echo "$PREREQ" +} + +case "$1" in +prereqs) + prereqs + exit 0 + ;; +esac + +rm -f "${DESTDIR}/etc/hostname" diff -Nru initramfs-tools-0.136ubuntu6.7/debian/tests/hooks/persistent-net initramfs-tools-0.136ubuntu6.8/debian/tests/hooks/persistent-net --- initramfs-tools-0.136ubuntu6.7/debian/tests/hooks/persistent-net 1970-01-01 01:00:00.000000000 +0100 +++ initramfs-tools-0.136ubuntu6.8/debian/tests/hooks/persistent-net 2024-03-19 13:05:17.000000000 +0100 @@ -0,0 +1,32 @@ +#!/bin/sh + +PREREQ="" + +prereqs() +{ + echo "$PREREQ" +} + +case "$1" in +prereqs) + prereqs + exit 0 + ;; +esac + +persist_net() { + name="$1" + mac="$2" + + mkdir -p "${DESTDIR}/etc/systemd/network" + cat >"${DESTDIR}/etc/systemd/network/10-persistent-${name}.link" < "${IMAGE}-uuid" -mkdir -p mnt -mount "${dev}p1" mnt -tar --xattrs-include=* -C mnt -xf images/"$filename" -rm -f mnt/sbin/init -cat > mnt/sbin/init << \EOF -#!/bin/sh -set -x -rm -rf /result -mkdir /result -# Run twice, once for the logs, once for the test harness -ip addr -ip link -for file in /run/net-*.conf /run/net6-*.conf; do - [ -f $file ] || continue; - cat $file - cp $file /result -done -ip -json addr > /result/addr.json -ip -json link > /result/link.json -ps aux | tee /result/ps.txt -sync -exec /lib/systemd/systemd-shutdown poweroff -EOF -chmod u+x mnt/sbin/init -umount mnt -losetup -d "$dev" diff -Nru initramfs-tools-0.136ubuntu6.7/debian/tests/qemu-ata-only initramfs-tools-0.136ubuntu6.8/debian/tests/qemu-ata-only --- initramfs-tools-0.136ubuntu6.7/debian/tests/qemu-ata-only 1970-01-01 01:00:00.000000000 +0100 +++ initramfs-tools-0.136ubuntu6.8/debian/tests/qemu-ata-only 2024-03-19 13:05:17.000000000 +0100 @@ -0,0 +1,23 @@ +#!/bin/sh -e + +# Note: The qemu machines used on arm64, armhf, ppc64el, and s390x have no IDE +SUPPORTED_FLAVOURS='amd64 generic' +ROOTDISK_QEMU_IF=ide +ROOTDISK_LINUX_NAME=sda +. debian/tests/test-common + +cat >>"${CONFDIR}/initramfs.conf" <"${CONFDIR}/modules" <>"${CONFDIR}/initramfs.conf" <>"${CONFDIR}/initramfs.conf" <>"${CONFDIR}/initramfs.conf" <"${CONFDIR}/modules" <>"${CONFDIR}/initramfs.conf" <"${CONFDIR}/modules" <>"${CONFDIR}/initramfs.conf" <"${CONFDIR}/modules" < "${ROOTDIR}/etc/fstab" "/dev/${USRDISK_LINUX_NAME} /usr ext2 defaults 0 2" +USRDIR="$(mktemp -d)" +mv "${ROOTDIR}/usr/"* "${USRDIR}" + +build_rootfs_ext2 +build_fs_ext2 "${USRDIR}" "${USRDISK}" + +run_qemu + +# Check that fsck ran on both devices +# Needs FSTYPE config parameter (see Debian bug #923400) +#grep -q "^/dev/${ROOTDISK_LINUX_NAME}: clean," "${OUTPUT}" +#grep -q "^/dev/${USRDISK_LINUX_NAME}: clean," "${OUTPUT}" diff -Nru initramfs-tools-0.136ubuntu6.7/debian/tests/qemu-virtio-only initramfs-tools-0.136ubuntu6.8/debian/tests/qemu-virtio-only --- initramfs-tools-0.136ubuntu6.7/debian/tests/qemu-virtio-only 1970-01-01 01:00:00.000000000 +0100 +++ initramfs-tools-0.136ubuntu6.8/debian/tests/qemu-virtio-only 2024-03-19 13:05:17.000000000 +0100 @@ -0,0 +1,22 @@ +#!/bin/sh -e + +SUPPORTED_FLAVOURS='amd64 arm64 armmp powerpc64 s390x generic' +ROOTDISK_QEMU_IF=virtio +ROOTDISK_LINUX_NAME=vda +. debian/tests/test-common + +cat >>"${CONFDIR}/initramfs.conf" <"${CONFDIR}/modules" <&2 + echo "Usage: ${0##*/} kernel initrd append [extra_args]" >&2 + exit 1 +fi + +kernel="$1" +initrd="$2" +append="$3" +shift 3 + +ARCHITECTURE=$(dpkg --print-architecture) + +case "$ARCHITECTURE" in +amd64) + qemu="qemu-system-x86_64" + ;; +arm64) + qemu="qemu-system-aarch64" + machine="virt,gic-version=max" + cpu="max" + efi_code=/usr/share/AAVMF/AAVMF_CODE.fd + efi_vars=/usr/share/AAVMF/AAVMF_VARS.fd + ;; +armhf) + qemu="qemu-system-arm" + machine="virt" + cpu=cortex-a7 + efi_code=/usr/share/AAVMF/AAVMF32_CODE.fd + efi_vars=/usr/share/AAVMF/AAVMF32_VARS.fd + console=ttyAMA0 + ;; +ppc64el) + qemu="qemu-system-ppc64" + machine="cap-ccf-assist=off,cap-cfpc=broken,cap-ibs=broken,cap-sbbc=broken" + console=hvc0 + ;; +*) + qemu="qemu-system-${ARCHITECTURE}" +esac + +if [ -c /dev/kvm ] && [ "$ARCHITECTURE" != "ppc64el" ]; then + kvm=-enable-kvm + cpu=host +fi + +if test -f "${efi_vars-}"; then + efi_vars_copy="$(mktemp -t "${efi_vars##*/}.XXXXXXXXXX")" + cp "$efi_vars" "$efi_vars_copy" +fi + +set -- ${machine:+-machine "${machine}"} ${kvm:+"$kvm"} ${cpu:+-cpu "${cpu}"} -m 1G \ + ${efi_code:+-drive "file=${efi_code},if=pflash,format=raw,read-only=on"} \ + ${efi_vars:+-drive "file=${efi_vars_copy},if=pflash,format=raw"} \ + -nodefaults -no-reboot -kernel "${kernel}" -initrd "${initrd}" "$@" \ + -append "console=${console:-ttyS0},115200 ro ${append}" +echo "${0##*/}: $qemu $*" +exec "$qemu" "$@" diff -Nru initramfs-tools-0.136ubuntu6.7/debian/tests/scripts/local-bottom/configure_network initramfs-tools-0.136ubuntu6.8/debian/tests/scripts/local-bottom/configure_network --- initramfs-tools-0.136ubuntu6.7/debian/tests/scripts/local-bottom/configure_network 1970-01-01 01:00:00.000000000 +0100 +++ initramfs-tools-0.136ubuntu6.8/debian/tests/scripts/local-bottom/configure_network 2024-03-19 13:05:17.000000000 +0100 @@ -0,0 +1,28 @@ +#!/bin/sh + +PREREQ="" +prereqs() +{ + echo "$PREREQ" +} +case $1 in +# get pre-requisites +prereqs) + prereqs + exit 0 + ;; +esac + +. /scripts/functions + +case "$IP" in +""|none|off) + case "$IP6" in + ""|none|off) ;; # Do nothing + *) + configure_networking + esac + ;; +*) + configure_networking +esac diff -Nru initramfs-tools-0.136ubuntu6.7/debian/tests/test-common initramfs-tools-0.136ubuntu6.8/debian/tests/test-common --- initramfs-tools-0.136ubuntu6.7/debian/tests/test-common 1970-01-01 01:00:00.000000000 +0100 +++ initramfs-tools-0.136ubuntu6.8/debian/tests/test-common 2024-03-19 13:12:34.000000000 +0100 @@ -0,0 +1,200 @@ +# -*- 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 + +case "$(dpkg --print-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" +mkdir "${CONFDIR}/hooks" +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/modules usr/lib64 usr/sbin; do + mkdir -p "${ROOTDIR}/${subdir}" +done +for subdir in bin lib lib64 sbin; do + ln -s "usr/${subdir}" "${ROOTDIR}/${subdir}" +done +cat >"${ROOTDIR}/sbin/init" <"${root_dir}/sbin/init" <&1 +} + +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_append="$1" + shift + + echo "I: Running qemu (with a timeout of $QEMU_TIMEOUT seconds)..." + timeout --foreground "$QEMU_TIMEOUT" \ + debian/tests/run-qemu /boot/vmlinu*-"${KVER}" "${INITRAMFS}" \ + "root=/dev/${ROOTDISK_LINUX_NAME} ${extra_append}" -nographic \ + -drive "file=${ROOTDISK},if=${ROOTDISK_QEMU_IF},media=disk,format=raw" \ + ${USRDISK:+-drive "file=${USRDISK},if=${USRDISK_QEMU_IF},media=disk,format=raw"} \ + -chardev stdio,id=char0 -serial chardev:char0 "$@" | tee "${OUTPUT}" +} + +run_qemu_nocheck() { + # hide error messages from autopkgtest + _run_qemu "${1-}" 2>&1 +} + +run_qemu() { + _run_qemu "panic=-1 $*" \ + -device "virtio-net-pci,netdev=lan0,mac=52:54:00:65:43:21" \ + -netdev "user,id=lan0,net=10.0.3.0/24,ipv6-net=fec7::/48,hostname=pizza,dnssearch=test,domainname=example.com,bootfile=/path/to/bootfile2" \ + -device "virtio-net-pci,netdev=lan1,mac=52:54:00:12:34:56" \ + -netdev "user,id=lan1,hostname=goulash,dnssearch=example,dnssearch=example.net,domainname=test,bootfile=/path/to/bootfile" + grep -qF "${INIT_MESSAGE}" "${OUTPUT}" +} + +check_output() { + local msg="$1" + if ! grep -qF "${msg}" "${OUTPUT}"; then + echo >&2 "E: Message '${msg}' not found in log output '${OUTPUT}." + exit 1 + fi +} diff -Nru initramfs-tools-0.136ubuntu6.7/scripts/functions initramfs-tools-0.136ubuntu6.8/scripts/functions --- initramfs-tools-0.136ubuntu6.7/scripts/functions 2021-03-18 19:48:17.000000000 +0100 +++ initramfs-tools-0.136ubuntu6.8/scripts/functions 2024-03-19 13:11:24.000000000 +0100 @@ -346,19 +346,12 @@ # The NIC is to be configured if this file does not exist. # Ip-Config tries to create this file and when it succeds # creating the file, ipconfig is not run again. - for x in /run/net-"${DEVICE}".conf /run/net-*.conf ; do - if [ -e "$x" ]; then - IP=done - break - fi - done - - for x in /run/net6-"${DEVICE}".conf /run/net6-*.conf ; do - if [ -e "$x" ]; then - IP6=done - break - fi - done + if [ -z "${DEVICE}" ] && ls /run/net-*.conf >/dev/null 2>&1 || [ -e /run/net-"${DEVICE}".conf ]; then + IP="done" + fi + if [ -z "${DEVICE6}" ] && ls /run/net6-*.conf >/dev/null 2>&1 || [ -e /run/net6-"${DEVICE6}".conf ]; then + IP6="done" + fi # if we've reached a point where both IP and IP6 are "done", # then we're finished with network configuration.