archboot/usr/bin/archboot-testsuite.sh

183 lines
7.1 KiB
Bash
Raw Normal View History

2024-06-10 15:04:08 +02:00
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-or-later
# created by Tobias Powalowski <tpowa@archlinux.org>
. /usr/lib/archboot/common.sh
2024-07-12 10:27:53 +02:00
_LOOP="/dev/loop0"
_IMG="/test.img"
_PASS="/passphrase"
2024-06-10 15:04:08 +02:00
_usage () {
2024-08-01 10:27:47 +02:00
echo -e "\e[1m\e[36mArchboot\e[m\e[1m - Testsuite\e[m"
echo -e "\e[1m--------------------\e[m"
2024-06-12 22:39:54 +02:00
echo "Run automatic tests to detect errors/changes."
echo ""
2024-08-01 10:27:47 +02:00
echo -e "Usage: \e[1m${_BASENAME} run\e[m"
2024-06-10 15:04:08 +02:00
exit 0
}
2024-06-10 16:37:22 +02:00
_run_test () {
2024-07-14 10:59:31 +02:00
echo -e "\e[1mTestsuite checking ${1}...\e[m"
2024-06-10 16:37:22 +02:00
}
2024-06-10 16:27:05 +02:00
_result() {
if [[ -s ${1} ]]; then
2024-06-10 16:49:46 +02:00
echo -e "\e[1;94m=> \e[1;91mFAILED\e[m"
2024-07-14 08:40:42 +02:00
_TEST_FAIL=1
2024-06-10 16:27:05 +02:00
else
2024-07-14 10:57:17 +02:00
echo -e "\e[1;94m=> \e[1;92mOK\e[m"
2024-06-10 16:27:05 +02:00
fi
}
2024-06-10 15:04:08 +02:00
[[ -z "${1}" || "${1}" != "run" ]] && _usage
_archboot_check
2024-06-11 09:10:49 +02:00
echo "Waiting for pacman keyring..."
2024-06-11 12:31:10 +02:00
_pacman_keyring
2024-07-18 11:48:28 +02:00
pacman -Sy &>"${_LOG}"
2024-07-14 11:05:44 +02:00
echo -e "\e[1mArchboot Environment Stats:\e[m"
2024-07-14 10:48:32 +02:00
echo "Bootup speed (seconds): $(systemd-analyze | rg -o '= (.*)s' -r '$1') |\
2024-07-14 14:16:51 +02:00
Packages: $(pacman -Q | wc -l)"
echo "Available Memory (M): $(rg -o 'Ava.* (.*)[0-9]{3} k' -r '$1' </proc/meminfo) |\
2024-07-14 14:15:47 +02:00
Rootfs Size (M): $(du -sh / 2>"${_NO_LOG}" | rg -o '(.*)M' -r '$1')"
2024-06-13 07:22:22 +02:00
_run_test "journal"
2024-06-25 21:00:29 +02:00
if ! journalctl -p3 -xb | rg -q 'No entries'; then
journalctl -p3 -xb >>journal-error.log
2024-06-10 15:04:08 +02:00
fi
_result journal-error.log
2024-07-14 08:40:42 +02:00
_run_test "ldd"
2024-07-14 08:42:46 +02:00
echo -n "/usr/bin "
2024-06-10 15:04:08 +02:00
for i in /usr/bin/*; do
2024-06-25 21:00:29 +02:00
if ldd "${i}" 2>"${_NO_LOG}" | rg -q 'not found'; then
echo "${i}" >>ldd-error.log
ldd "${i}" | rg 'not found' >>ldd-error.log
2024-06-10 15:04:08 +02:00
fi
done
2024-07-14 08:42:46 +02:00
echo -n "/usr/lib "
2024-07-05 08:02:01 +02:00
for i in $(fd -u -t x -E '*.so.*' -E '*.so' -E 'ssh-sk-helper' . /usr/lib); do
2024-06-25 21:00:29 +02:00
if ldd "${i}" 2>"${_NO_LOG}" | rg -q 'not found'; then
echo "${i}" >>ldd-error.log
ldd "${i}" | rg 'not found' >>ldd-error.log
2024-06-11 10:27:13 +02:00
fi
done
# ignore wrong reported libsystemd-shared by libsystemd-core
2024-06-18 17:51:06 +02:00
for i in $(fd -u '.so' /usr/lib); do
2024-06-25 21:00:29 +02:00
if ldd "${i}" 2>"${_NO_LOG}" | rg -v 'tree_sitter|libsystemd-shared' | rg -q 'not found'; then
echo "${i}" >>ldd-error.log
ldd "${i}" | rg 'not found' >>ldd-error.log
2024-06-11 10:27:13 +02:00
fi
done
_result ldd-error.log
2024-06-11 22:40:17 +02:00
_run_test "on missing base binaries"
2024-06-10 16:37:22 +02:00
# not needed binaries, that are tolerated
2024-07-20 13:41:26 +02:00
_BASE_BLACKLIST="arpd backup bashbug bootctl enosys exch fsck.cramfs fsck.minix gawk-5.3.0 \
2024-06-11 08:20:12 +02:00
gawkbug gencat getconf iconv iconvconfig importctl lastlog2 ld.so locale lsclocks makedb \
makepkg-template memusage memusagestat mkfs.bfs mkfs.cramfs mkfs.minix mtrace newgidmap \
2024-07-19 21:08:40 +02:00
newuidmap pcprofiledump pivot_root pldd pstree.x11 restore routel run0 setpgid sln sotruss \
sprof switch_root systemd-confext systemd-cryptsetup systemd-delta systemd-home-fallback-shell \
systemd-repart systemd-run systemd-vmspawn systemd-vpick varlinkctl xtrace"
2024-06-10 15:14:27 +02:00
archboot-binary-check.sh base &>>"${_LOG}"
2024-06-10 16:08:07 +02:00
#shellcheck disable=SC2013
for i in $(rg '/usr/bin/(.*)' -r '$1' binary.log); do
2024-06-25 21:00:29 +02:00
if ! echo "${_BASE_BLACKLIST}" | rg -qw "${i}"; then
echo "${i}" >> base-binary-error.log
2024-06-10 15:04:08 +02:00
fi
done
_result base-binary-error.log
2024-06-11 22:40:17 +02:00
_run_test "modules included /usr/lib/firmware"
2024-07-14 10:35:51 +02:00
archboot-fw-check.sh run
_result fw-error.log
2024-06-10 16:01:52 +02:00
# uninstall base again!
2024-06-13 07:37:01 +02:00
pacman --noconfirm -Rdd base gettext &>>"${_LOG}"
2024-06-18 08:21:43 +02:00
_run_test "licenses"
2024-07-25 07:48:17 +02:00
#shellcheck disable=SC2046
2024-06-25 22:22:08 +02:00
for i in $(pacman -Ql $(pacman -Q | sd ' .*' '') | rg -o '/usr/share/licenses/.*'); do
[[ -e "${i}" ]] || echo "${i}" | rg -v '/xz/' >>license-error.log
2024-06-18 08:21:43 +02:00
done
_result license-error.log
2024-07-11 20:20:05 +02:00
_run_test "filesystems"
2024-07-12 10:27:53 +02:00
dd if=/dev/zero of="${_IMG}" bs=1M count=1000 &>"${_NO_LOG}"
2024-07-12 10:15:19 +02:00
sync
2024-07-12 10:27:53 +02:00
losetup -f "${_IMG}"
2024-07-11 19:34:39 +02:00
for i in bcachefs btrfs ext4 swap vfat xfs; do
2024-07-11 18:41:50 +02:00
if [[ "${i}" == "swap" ]]; then
2024-07-12 10:32:05 +02:00
echo -n "${i} "
2024-07-12 10:27:53 +02:00
mkswap "${_LOOP}" &>"${_NO_LOG}" ||\
2024-07-12 07:53:51 +02:00
echo "Creation error: ${i}" >> filesystems-error.log
2024-07-11 18:41:50 +02:00
else
2024-07-18 07:21:47 +02:00
if modinfo ${i} &>"${_NO_LOG}"; then
echo -n "${i} "
mkfs.${i} "${_LOOP}" &>"${_NO_LOG}" ||\
echo "Creation error: ${i}" >> filesystems-error.log
mount "${_LOOP}" /mnt &>"${_NO_LOG}" ||\
echo "Mount error: ${i}" >> filesystems-error.log
umount /mnt &>"${_NO_LOG}" || echo "Unmount error: ${i}" >> filesystems-error.log
fi
2024-07-11 18:41:50 +02:00
fi
2024-07-12 10:27:53 +02:00
wipefs -a "${_LOOP}" &>"${_NO_LOG}"
2024-07-11 18:34:46 +02:00
done
2024-07-11 22:23:30 +02:00
_result filesystems-error.log
2024-07-11 21:41:35 +02:00
_run_test "blockdevices"
2024-07-12 10:32:05 +02:00
echo -n "mdadm "
2024-07-12 10:27:53 +02:00
mdadm --create /dev/md0 --run --level=1 --raid-devices=2 "${_LOOP}" missing &>"${_NO_LOG}" ||\
2024-07-12 07:53:51 +02:00
echo "Creation error: mdadm" >> blockdevices-error.log
2024-07-11 21:41:35 +02:00
wipefs -a -f /dev/md0 &>"${_NO_LOG}"
2024-07-12 07:53:51 +02:00
mdadm --manage --stop /dev/md0 &>"${_NO_LOG}" ||\
2024-07-12 10:27:53 +02:00
echo "Remove error: mdadm" >> blockdevices-error.log
wipefs -a -f "${_LOOP}" &>"${_NO_LOG}"
dd if=/dev/zero of="${_IMG}" bs=1M count=10 &>"${_NO_LOG}"
2024-07-11 21:41:35 +02:00
sync
2024-07-12 10:32:05 +02:00
echo -n "lvm "
2024-07-12 10:27:53 +02:00
pvcreate -y "${_LOOP}" &>"${_NO_LOG}" ||\
2024-07-12 07:53:51 +02:00
echo "Creation error: lvm pv" >> blockdevices-error.log
2024-07-12 10:27:53 +02:00
vgcreate /dev/mapper/test "${_LOOP}" &>"${_NO_LOG}" ||\
2024-07-12 07:53:51 +02:00
echo "Creation error: lvm vg" >> blockdevices-error.log
lvcreate -W y -C y -y -l +100%FREE /dev/mapper/test -n /dev/mapper/test-test &>"${_NO_LOG}" ||\
echo "Creation error: lvm lv" >> blockdevices-error.log
2024-07-12 09:22:58 +02:00
lvremove -f /dev/mapper/test-test &>"${_NO_LOG}" ||\
2024-07-12 10:27:53 +02:00
echo "Remove error: lvm lv" >> blockdevices-error.log
2024-07-12 09:22:58 +02:00
vgremove -f test &>"${_NO_LOG}" ||\
2024-07-12 10:27:53 +02:00
echo "Remove error: lvm vg" >> blockdevices-error.log
pvremove -f "${_LOOP}" &>"${_NO_LOG}" ||\
echo "Remove error: lvm pv" >> blockdevices-error.log
2024-07-12 10:32:05 +02:00
echo -n "cryptsetup "
2024-07-12 10:27:53 +02:00
echo "12345678" >"${_PASS}"
cryptsetup -q luksFormat "${_LOOP}" <"${_PASS}" ||\
2024-07-12 07:53:51 +02:00
echo "Creation error: cryptsetup" >> blockdevices-error.log
2024-07-12 10:27:53 +02:00
cryptsetup luksOpen "${_LOOP}" testluks <"${_PASS}" ||\
2024-07-12 07:53:51 +02:00
echo "Creation error: cryptsetup open" >> blockdevices-error.log
2024-07-12 10:20:15 +02:00
cryptsetup remove testluks ||\
2024-07-12 10:27:53 +02:00
echo "Remove error: cryptsetup" >> blockdevices-error.log
2024-07-12 07:53:51 +02:00
losetup -D
2024-07-12 10:27:53 +02:00
rm "${_IMG}"
2024-07-11 21:41:35 +02:00
_result blockdevices-error.log
2024-07-14 11:06:39 +02:00
echo -e "Starting Wi-Fi check in \e[1m10\e[m seconds... \e[1;92mCTRL-C\e[m to stop now."
sleep 10
2024-07-14 11:08:58 +02:00
_run_test "Wi-Fi... this takes a while"
echo -n "Setting up hwsim... "
if archboot-hwsim.sh test &>"${_LOG}"; then
echo -n "iwctl tests running... "
iwctl station wlan1 scan
sleep 5
iwctl station wlan1 get-networks | rg -q test || echo "Wi-Fi get-networks error" >> iwctl-error.log
iwctl --passphrase=12345678 station wlan1 connect test || echo "Wi-Fi connect error" >> iwctl-error.log
iwctl station wlan1 disconnect || echo "Wi-Fi iwctl disconnect error" >> iwctl-error.log
else
2024-08-12 22:59:58 +02:00
echo "Hwsim setup failed." >> iwctl-error.log
fi
2024-07-11 20:06:53 +02:00
_result iwctl-error.log
2024-06-13 19:25:26 +02:00
echo -e "Starting none tracked files in \e[1m10\e[m seconds... \e[1;92mCTRL-C\e[m to stop now."
sleep 10
2024-06-13 19:25:26 +02:00
_run_test "none tracked files in /usr/lib... this takes a while"
for i in $(fd -u -E '/modules/' -E '/udev/' -E 'gconv-modules.cache' -E 'locale-archive' . /usr/lib); do
2024-07-10 21:40:20 +02:00
#shellcheck disable=SC2086
2024-07-18 11:47:18 +02:00
pacman -Qo ${i} &>"${_LOG}" || echo ${i} >> pacman-error.log
done
_result pacman-error.log
2024-06-13 07:46:22 +02:00
echo -e "Starting pacman database check in \e[1m10\e[m seconds... \e[1;92mCTRL-C\e[m to stop now."
sleep 10
2024-06-13 19:25:26 +02:00
_run_test "pacman database... this takes a while"
2024-08-01 10:27:47 +02:00
archboot-not-installed.sh run &>>"${_LOG}"
_result not-installed.log
2024-07-14 11:35:10 +02:00
echo -e "\e[1mResult:\e[m"
2024-07-14 11:16:34 +02:00
if [[ -z "${_TEST_FAIL}" ]]; then
2024-07-14 11:29:23 +02:00
echo -e "\e[1;94m=> \e[1;92mAll tests finished successfully.\e[m"
2024-07-14 11:16:34 +02:00
else
2024-07-14 11:29:23 +02:00
echo -e "\e[1;94m=> \e[1;91mAn error was detected. Please check the corresponding log files.\e[m"
2024-07-14 11:16:34 +02:00
exit 1
fi