Debian Codegraph @

debian/tests/upstream

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