1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
#!/bin/sh
# run upstream system integration tests via mkosi
set -e
set -x
RELEASE=$(
. /etc/os-release;
if [ "$ID" = "ubuntu" ]; then
echo "$VERSION_CODENAME"
elif [ "$ID" = "debian" ]; then
if [ -n "$VERSION_ID" ] && [ -n "$VERSION_CODENAME" ]; then
echo "$VERSION_CODENAME"
else
debian_version="$(cat /etc/debian_version)"
if [ "${debian_version#*/}" = sid ]; then
if [ ! -f /etc/apt/preferences.d/autopkgtest-unstable.pref ] && ( [ "$VERSION_CODENAME" = sid ] || grep -q -r sid /etc/apt/sources.list* || grep -q -r unstable /etc/apt/sources.list* ); then
echo "sid"
else
echo "$VERSION_CODENAME"
fi
fi
fi
fi
)
cleanup () {
if [ -f "${workdir}/btrfs/build/meson-logs/testlog.txt" ]; then
zstd --force --ultra -20 -o "${AUTOPKGTEST_ARTIFACTS}/testlog.txt.zst" "${workdir}/btrfs/build/meson-logs/testlog.txt"
fi
if [ -d "${workdir}/btrfs/build/test/journal" ]; then
cp -r "${workdir}/btrfs/build/test/journal" "$AUTOPKGTEST_ARTIFACTS"
for j in "${AUTOPKGTEST_ARTIFACTS}/journal"/*.journal; do
if [ ! -f "$j" ]; then
continue
fi
zstd --force --rm --ultra -20 -o "$j.zst" "$j"
done
fi
if [ -n "$workdir" ]; then
umount "$workdir/btrfs" || true
losetup --detach "$loop" || true
rm -rf "$workdir"
fi
}
# apparmor is not compatible with swtpm
aa-teardown >/dev/null 2>&1 || true
# we need user namespaces for some tests running in nspawn
sysctl -we kernel.apparmor_restrict_unprivileged_unconfined=0
sysctl -we kernel.apparmor_restrict_unprivileged_userns=0
mkdir -p /run/systemd/resolved.conf.d/
tee /run/systemd/resolved.conf.d/dns.conf <<EOF
[Resolve]
DNS=1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
EOF
systemctl try-reload-or-restart systemd-resolved.service || true
# We need to have a dependency the packages but no need to run them
systemctl disable --now systemd-homed.service systemd-userdbd.service systemd-userdbd.socket
workdir="$(mktemp --directory --tmpdir=/var/tmp integration-tests.XXXXXXXXXX)"
trap cleanup EXIT
# We need to make nearly identical copies of large images, so set up a BTRFS volume that
# can use copy-on-write and compression, as the available disk space is very limited
truncate --size=100G "$workdir/btrfs.raw"
mkfs.btrfs "$workdir/btrfs.raw"
mkdir -p "$workdir/btrfs"
loop="$(losetup --find --show --direct-io=on "$workdir/btrfs.raw")"
mount "$loop" "$workdir/btrfs" --options compress=zstd:1,user_subvol_rm_allowed,noatime,discard=async,space_cache=v2
# mkosi will drop privileges and fail if it detects that is ran under sudo,
# so unset these variables to hide it
unset SUDO_USER SUDO_UID SUDO_GID
mkosi_tree="${AUTOPKGTEST_TMP}/mkosi"
git clone https://github.com/systemd/mkosi.git "$mkosi_tree"
# If we have it, pin the mkosi version to the same one used by Github Actions, to ensure consistency
if [ -f .github/workflows/mkosi.yml ]; then
mkosi_hash="$(grep systemd/mkosi@ .github/workflows/mkosi.yml | sed "s|.*systemd/mkosi@||g")"
git -C "$mkosi_tree" checkout "$mkosi_hash"
fi
apt_dir="/etc/apt"
local_binaries=""
if [ -d "${AUTOPKGTEST_TMP}/../binaries" ]; then
# If locally built binaries are being used, prepare /etc/apt so that
# it will not conflict with settings implied by PackageDirectories=
# used below.
local_binaries="$(realpath "${AUTOPKGTEST_TMP}/../binaries")"
apt_dir="$(mktemp -d)/apt"
cp -r /etc/apt "$apt_dir"
if [ -e "${apt_dir}/sources.list" ]; then
sed -i "\|${local_binaries}|d" "${apt_dir}/sources.list"
fi
for sources in $(find "${apt_dir}/sources.list.d" -type f -name "*.list"); do
sed -i "\|${local_binaries}|d" "$sources"
done
for sources in $(find "${apt_dir}/sources.list.d" -type f -name "*.sources"); do
sed -i "\|URIs:.*${local_binaries}|i Enabled: no" $sources
done
fi
# Moved in v258
mkosi_local_conf="mkosi.local.conf"
if [ -d mkosi ]; then
mkosi_local_conf="mkosi/mkosi.local.conf"
fi
tee "${mkosi_local_conf}" <<EOF
[Output]
Format=disk
[Build]
WorkspaceDirectory=$workdir
PackageCacheDirectory=$workdir/cache
SandboxTrees=${apt_dir}:/etc/apt/
ToolsTree=
Environment=NO_BUILD=1 NO_SYNC=1 ARTIFACT_DIRECTORY="$AUTOPKGTEST_ARTIFACTS" TEST_SAVE_JOURNAL=fail TEST_SHOW_JOURNAL=warning
Incremental=no
[Distribution]
${RELEASE:+"Release=${RELEASE}"}
[Content]
KernelCommandLine=systemd.default_device_timeout_sec=240
${local_binaries:+"PackageDirectories=${local_binaries}"}
[Runtime]
RuntimeBuildSources=no
EOF
# mkosi registers a pid with machined before it is assigned to a scope, so machined
# associates it with the user session, and kills it later when the machine is shut down,
# disable registration to avoid it. This is a workaround for versions older than 25, where
# MachinedRegister=no does the same.
if systemd-analyze compare-versions "$(git -C "$mkosi_tree" describe | tr -d 'v')" lt 25; then
sed -i "/ register_machine(/d" "$mkosi_tree/mkosi/qemu.py"
else
tee -a "${mkosi_local_conf}" <<EOF
[Runtime]
Register=no
EOF
fi
# kernel 6.12 broke mounting btrfs filesystems from loop devices, so switch to ext4
sed -i "s/Format=btrfs/Format=ext4/" mkosi.repart/10-root.conf || true
# qemu/vsock does not appear to work on ppc64el/s390x, so skip those tests
# qemu tests time out on arm64, so skip them
dpkgarch=$(dpkg --print-architecture)
if [ "$dpkgarch" = ppc64el ] || [ "$dpkgarch" = s390x ] || [ "$dpkgarch" = arm64 ]; then
export TEST_NO_QEMU=1
fi
# If we don't have KVM, the explicitly disable it, as mkosi will fail. But try to load the module first.
modprobe kvm || true
if [ ! -e /dev/kvm ]; then
export TEST_NO_KVM=1
fi
export ARTIFACT_DIRECTORY="$AUTOPKGTEST_ARTIFACTS"
export PATH="${mkosi_tree}/bin:$PATH"
export TEST_SAVE_JOURNAL=fail
export TEST_SHOW_JOURNAL=warning
export QEMU_TIMEOUT=2400
export NSPAWN_TIMEOUT=2400
export SYSTEMD_INTEGRATION_TESTS=1
export NO_BUILD=1
export NO_SYNC=1
mkosi --debug genkey
mkosi summary
meson setup "${workdir}/btrfs/build" -Dintegration-tests=true -Dtests=true
if [ -f mkosi/mkosi.key ]; then
cp mkosi/mkosi.key mkosi/mkosi.crt "${workdir}/btrfs/build"
else
cp mkosi.key mkosi.crt "${workdir}/btrfs/build"
fi
ln -sf "${workdir}/btrfs/build" build
mkosi -f
meson test -C "${workdir}/btrfs/build" --no-rebuild --suite integration-tests --print-errorlogs --no-stdsplit --num-processes "$(($(nproc) - 1))"
|