From db2be70f8855b1b2879fde1f226a1ea4aa25bda1 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sun, 5 Mar 2023 11:08:21 +0100 Subject: [PATCH] tests: split out creation of mmdebstrap chroot into its own test to avoid running the same thing multiple times and speed up tests --- coverage.txt | 14 ++++++++++- ...eck-for-bit-by-bit-identical-format-output | 24 ++++--------------- tests/mmdebstrap | 20 ++++++++++++++++ 3 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 tests/mmdebstrap diff --git a/coverage.txt b/coverage.txt index 5b75c2b..f49751f 100644 --- a/coverage.txt +++ b/coverage.txt @@ -56,8 +56,20 @@ Needs-Root: true Test: mount-is-missing Needs-QEMU: true -Test: check-for-bit-by-bit-identical-format-output +Test: mmdebstrap Needs-Root: true +Modes: root +Formats: tar squashfs ext2 +Variants: essential apt minbase buildd - standard +Skip-If: + variant == "standard" and dist in ["oldstable", "stable"] # #864082, #1004557, #1004558 + variant == "important" and dist == "oldstable" # /var/lib/systemd/catalog/database differs + fmt == "squashfs" and dist == "oldstable" # squashfs-tools-ng is not available + fmt == "ext2" and dist == "oldstable" # genext2fs does not support SOURCE_DATE_EPOCH + mode == "fakechroot" and variant in ["-", "standard"] # no extended attributes + variant == "standard" and hostarch in ["armel", "armhf", "mipsel"] # #1031276 + +Test: check-for-bit-by-bit-identical-format-output Modes: unshare fakechroot Formats: tar squashfs ext2 Variants: essential apt minbase buildd - standard diff --git a/tests/check-for-bit-by-bit-identical-format-output b/tests/check-for-bit-by-bit-identical-format-output index 6187a2c..0ffdde3 100644 --- a/tests/check-for-bit-by-bit-identical-format-output +++ b/tests/check-for-bit-by-bit-identical-format-output @@ -3,9 +3,7 @@ set -eu export LC_ALL=C.UTF-8 export SOURCE_DATE_EPOCH={{ SOURCE_DATE_EPOCH }} -trap "rm -f /tmp/debian-chroot-{{ MODE }}.{{ FORMAT }} /tmp/debian-chroot-root.{{ FORMAT }}" EXIT INT TERM - -[ "$(id -u)" -eq 0 ] +trap "rm -f /tmp/debian-chroot-{{ MODE }}.{{ FORMAT }}" EXIT INT TERM if ! id "${SUDO_USER:-user}" >/dev/null 2>&1; then if [ ! -e /mmdebstrap-testenv ]; then @@ -14,23 +12,9 @@ if ! id "${SUDO_USER:-user}" >/dev/null 2>&1; then fi useradd --home-dir "/home/${SUDO_USER:-user}" --create-home "${SUDO_USER:-user}" fi -prefix="runuser -u ${SUDO_USER:-user} --" - -{{ CMD }} --mode=root --variant={{ VARIANT }} {{ DIST }} /tmp/debian-chroot-root.{{ FORMAT }} {{ MIRROR }} -if [ "{{ FORMAT }}" = tar ]; then - printf 'ustar ' | cmp --bytes=6 --ignore-initial=257:0 /tmp/debian-chroot-root.tar - -elif [ "{{ FORMAT }}" = squashfs ]; then - printf 'hsqs' | cmp --bytes=4 /tmp/debian-chroot-root.squashfs - -elif [ "{{ FORMAT }}" = ext2 ]; then - printf '\123\357' | cmp --bytes=2 --ignore-initial=1080:0 /tmp/debian-chroot-root.ext2 - -else - echo "unknown format: {{ FORMAT }}" >&2 - exit 1 -fi - -$prefix {{ CMD }} --mode={{ MODE }} --variant={{ VARIANT }} {{ DIST }} /tmp/debian-chroot-{{ MODE }}.{{ FORMAT }} {{ MIRROR }} -cmp /tmp/debian-chroot-root.{{ FORMAT }} /tmp/debian-chroot-{{ MODE }}.{{ FORMAT }} \ - || diffoscope /tmp/debian-chroot-root.{{ FORMAT }} /tmp/debian-chroot-{{ MODE }}.{{ FORMAT }} +runuser -u "${SUDO_USER:-user}" -- {{ CMD }} --mode={{ MODE }} --variant={{ VARIANT }} {{ DIST }} /tmp/debian-chroot-{{ MODE }}.{{ FORMAT }} {{ MIRROR }} +cmp ./cache/mmdebstrap-{{ DIST }}-{{ VARIANT }}.{{ FORMAT }} /tmp/debian-chroot-{{ MODE }}.{{ FORMAT }} \ + || diffoscope ./cache/mmdebstrap-{{ DIST }}-{{ VARIANT }}.{{ FORMAT }} /tmp/debian-chroot-{{ MODE }}.{{ FORMAT }} # we cannot test chrootless mode here, because mmdebstrap relies on the # usrmerge package to set up merged-/usr and that doesn't work in chrootless diff --git a/tests/mmdebstrap b/tests/mmdebstrap new file mode 100644 index 0000000..3327fc6 --- /dev/null +++ b/tests/mmdebstrap @@ -0,0 +1,20 @@ +#!/bin/sh +set -eu +export LC_ALL=C.UTF-8 +export SOURCE_DATE_EPOCH={{ SOURCE_DATE_EPOCH }} + +[ "$(id -u)" -eq 0 ] +[ {{ MODE }} = "root" ] +case {{ FORMAT }} in tar|squashfs|ext2) : ;; *) exit 1;; esac + +{{ CMD }} --mode={{ MODE }} --variant={{ VARIANT }} {{ DIST }} ./cache/mmdebstrap-{{ DIST }}-{{ VARIANT }}.{{ FORMAT }} {{ MIRROR }} +if [ "{{ FORMAT }}" = tar ]; then + printf 'ustar ' | cmp --bytes=6 --ignore-initial=257:0 ./cache/mmdebstrap-{{ DIST }}-{{ VARIANT }}.tar - +elif [ "{{ FORMAT }}" = squashfs ]; then + printf 'hsqs' | cmp --bytes=4 ./cache/mmdebstrap-{{ DIST }}-{{ VARIANT }}.squashfs - +elif [ "{{ FORMAT }}" = ext2 ]; then + printf '\123\357' | cmp --bytes=2 --ignore-initial=1080:0 ./cache/mmdebstrap-{{ DIST }}-{{ VARIANT }}.ext2 - +else + echo "unknown format: {{ FORMAT }}" >&2 + exit 1 +fi