Skip to content

Commit

Permalink
testing: quality-of-life improvements
Browse files Browse the repository at this point in the history
- Pre-build EFI executables in each distribution when possible
- Prefer running the EFI executable if one exists
- Allow selection of pre-built per-distribution images when running
  • Loading branch information
ahesford committed Dec 1, 2023
1 parent dab2378 commit ba75e3e
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 27 deletions.
2 changes: 1 addition & 1 deletion testing/helpers/chroot-void.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
# Pre-install zfsbootmenu
if [ -x /root/zbm-populate.sh ]; then
xbps-query -Rp run_depends zfsbootmenu | xargs xbps-install -y
xbps-install -y git
xbps-install -y git gummiboot-efistub
SKIP_PERL=yes /root/zbm-populate.sh
rm /root/zbm-populate.sh
fi
3 changes: 3 additions & 0 deletions testing/helpers/configure-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ echo 'root:zfsbootmenu' | chpasswd -c SHA256
if [ -x /root/zbm-populate.sh ]; then
apt-get install --yes --no-install-recommends \
git dracut-core fzf kexec-tools cpanminus gcc make
if [[ "$0" =~ "debian" ]]; then
apt-get install --yes --no-install-recommends systemd-boot-efi
fi
/root/zbm-populate.sh
rm /root/zbm-populate.sh
fi
Expand Down
6 changes: 3 additions & 3 deletions testing/helpers/pool-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,16 @@ fi
# Pre-populate the test environment with ZBM from the testbed
if [ -d "${CHROOT_MNT}/zfsbootmenu" ]; then
if chroot "${CHROOT_MNT}" /usr/bin/generate-zbm --prefix vmlinuz; then
for f in vmlinuz-bootmenu initramfs-bootmenu.img; do
for f in vmlinuz-bootmenu initramfs-bootmenu.img vmlinuz.EFI; do
file="${CHROOT_MNT}/zfsbootmenu/build/${f}"
[ -f "${file}" ] || continue

if [ -d "${TESTDIR}" ]; then
mv "${file}" "${TESTDIR}/${f}.${DISTRO}"
cp "${file}" "${TESTDIR}/${f}.${DISTRO}"
chmod 644 "${TESTDIR}/${f}.${DISTRO}"

if [ ! -e "${TESTDIR}/${f}" ] || [ -L "${TESTDIR}/${f}" ]; then
ln -sf "${f}.${DISTRO}" "${TESTDIR}/${f}"
ln -Tsf "${f}.${DISTRO}" "${TESTDIR}/${f}"
fi
fi
done
Expand Down
7 changes: 7 additions & 0 deletions testing/helpers/zbm-populate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ if [ -f /etc/zfsbootmenu/config.yaml ]; then
-e 's@ImageDir:.*@ImageDir: /zfsbootmenu/build@' \
-e '/BootMountPoint:/d' -i /etc/zfsbootmenu/config.yaml

# Build the EFI executable if the stub is available
for stubdir in /usr/lib/gummiboot /usr/lib/systemd/boot/efi; do
[ -r "${stubdir}/linuxx64.efi.stub" ] || continue
sed -e 's/Enabled:.*/Enabled: true/' -i /etc/zfsbootmenu/config.yaml
break
done

case "${INITCPIO,,}" in
yes|y|on|1)
sed -e "s/InitCPIO:.*/InitCPIO: true/" -i /etc/zfsbootmenu/config.yaml
Expand Down
101 changes: 78 additions & 23 deletions testing/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,67 @@ error() {
}

usage() {
cat <<EOF
Usage: $0 [options]
-a Set kernel command line
-A+ Append additional arguments to kernel command line
-d+ Set one or more non-standard disk images
cat <<-EOF
Usage: $0 [OPTIONS] [FLAGS]
Run a ZFSBootMenu testbed
OPTIONS
-a <cmdline>
Set kernel command line
-A <argument> (May be repeated)
Append additional argument to kernel command line
-C <cpus>
Set the number of CPUs in the virtual machine
-d <image> (May be repeated)
Attach the specified disk image to the test VM
-D <testbed-path>
Boot the testbed contained in the given directory
-M <memory>
Set the amount of memory in the virtual machine
-o <distro>
Attempt to boot image for a specific distribution;
requires boot files with a ".<distro>" extension
-S <efi-stub>
When creating EFI bundles, use the stub at the given path
-v <display>
Select the qemu display type
FLAGS
-f Force recreation of the initramfs
-s Enable serial console on stdio
-v Set type of qemu display to use
-D Set test directory
-c Enable dropbear remote access via crypt-ssh
-n Do not reset the controlling terminal after the VM exits
-e Boot the VM with an EFI bundle
-F Generate a flamegraph/flamechart using tracing data from ZBM
-E Enable early initramfs tracing
-i Use mkinitcpio to generate the testing initramfs
-B Use Busybox for mkinitcpio miser mode
-r Use Dracut to generate the testing initramfs
-e Boot the VM with an EFI bundle
-p Boot the VM with the kernel/initramfs pair
-E Enable early initramfs tracing
-F Generate a flamegraph/flamechart using tracing data from ZBM
-G Enable debug output for generate-zbm
-M Set the amount of memory for the virtual machine
-C Set the number of CPUs for the virtual machine
-B Use Busybox for mkinitcpio miser mode
-S Use alternate EFI stub file at specified path
-c Enable dropbear remote access via crypt-ssh
-n Do not reset the controlling terminal after the VM exits
-s Enable serial console on stdio
-h Show this message and exit
EOF
}

CMDOPTS="D:A:a:d:fsv:hineS:M:C:FEGcrB"
CMDOPTS="a:A:C:d:D:M:o:S:v:fiBrepEFGcnsh"


# First-pass option parsing just looks for test directory
while getopts "${CMDOPTS}" opt; do
Expand Down Expand Up @@ -93,10 +129,11 @@ SERIAL=0
DISPLAY_TYPE=
SSH_INCLUDE=0
RESET=1
EFI=0
EFI=
GENZBM_FLAGS=()
MISER=0
EFISTUB=
SUFFIX=

FLAME=0
EARLY_TRACING=0
Expand Down Expand Up @@ -150,6 +187,9 @@ while getopts "${CMDOPTS}" opt; do
*) echo "EFI bundles unsupported on $(uname -m)" ;;
esac
;;
p)
EFI=0
;;
S)
EFISTUB="$( realpath -e "${OPTARG}" )"
;;
Expand Down Expand Up @@ -180,6 +220,9 @@ while getopts "${CMDOPTS}" opt; do
B)
MISER=1
;;
o)
SUFFIX=".${OPTARG}"
;;
*)
;;
esac
Expand Down Expand Up @@ -361,18 +404,30 @@ if ((INITCPIO)) && ((MISER)); then
EOF
fi

# Image files the testbed may need to boot
BUNDLE="${TESTDIR}/vmlinuz.EFI${SUFFIX}"
KERNEL="${TESTDIR}/vmlinuz-bootmenu${SUFFIX}"
INITRD="${TESTDIR}/initramfs-bootmenu.img${SUFFIX}"

if [ -z "${EFI}" ]; then
# If an EFI option was not chosen, select a workable default
EFI=0
[ -f "${BUNDLE}" ] && EFI=1
fi

# Creation is required if either kernel or initramfs is missing
if ((EFI)) ; then
BUNDLE="${TESTDIR}/vmlinuz.EFI"
[ -f "${BUNDLE}" ] || CREATE=1
else
KERNEL="${TESTDIR}/vmlinuz-bootmenu"
[ -f "${KERNEL}" ] || CREATE=1

INITRD="${TESTDIR}/initramfs-bootmenu.img"
[ -f "${KERNEL}" ] || CREATE=1
[ -f "${INITRD}" ] || CREATE=1
fi

if ((CREATE)) && [ -n "${SUFFIX}" ]; then
error "distribution-specific images do not exist and will not be created"
fi

if ((CREATE)) ; then
yamlconf="${TESTDIR}/local.yaml"

Expand Down

0 comments on commit ba75e3e

Please sign in to comment.