From 1fe139a71bf03454e4966c20ecc9726554174dff Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Wed, 24 Apr 2024 10:53:04 +0100 Subject: [PATCH] tests/env.sh: Add aarch64 support Signed-off-by: Alberto Faria --- .packit.yaml | 6 +++-- plans/tests.fmf | 3 +++ tests/env.sh | 49 ++++++++++++++++++++++++++++++++++---- tests/t/bootc-disk-size.sh | 2 ++ tests/t/bootc-rootfs.sh | 2 ++ 5 files changed, 55 insertions(+), 7 deletions(-) diff --git a/.packit.yaml b/.packit.yaml index be29c80..5393f37 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -9,10 +9,12 @@ jobs: skip_build: true enable_net: true targets: - # TODO: Replace these three with fedora-all-x86_64 once Fedora 38 is gone. - - fedora-rawhide-x86_64 + # TODO: Replace these three with fedora-stable-x86_64 once Fedora 38 is gone. - fedora-40-x86_64 - fedora-39-x86_64 + # TODO: Replace these three with fedora-stable-aarch64 one Fedora 38 is gone. + - fedora-40-aarch64 + - fedora-39-aarch64 identifier: docker tmt_plan: /tests/docker diff --git a/plans/tests.fmf b/plans/tests.fmf index c98e0fd..cd7bc4d 100644 --- a/plans/tests.fmf +++ b/plans/tests.fmf @@ -11,6 +11,7 @@ prepare: - cargo - coreutils - crun + - crun-krun - docker - genisoimage - grep @@ -35,6 +36,8 @@ execute: set -ex export PATH=$PATH:/root/.cargo/bin LIBGUESTFS_BACKEND=direct + lscpu + # set the test VM's Fedora version to the host's to run the tests under the # requested environment tag=$( awk -F= '/^VERSION_ID=/ {print tolower($2)}' /etc/os-release ) diff --git a/tests/env.sh b/tests/env.sh index f750c78..ce5d40d 100755 --- a/tests/env.sh +++ b/tests/env.sh @@ -125,6 +125,15 @@ trap '__extra_cleanup; rm -fr "$temp_dir"' EXIT export RUST_BACKTRACE=1 RUST_LIB_BACKTRACE=1 +arch=$( uname -m ) +case "$arch" in +x86_64|aarch64) + ;; +*) + >&2 echo "Unsupported arch \"$arch\"" + ;; +esac + case "${1:-}" in build) if (( $# != 1 )); then @@ -143,21 +152,37 @@ build) # expand base image - __log_and_run qemu-img create -f qcow2 "$temp_dir/image.qcow2" 50G + root_part=$( + virt-filesystems --add "$temp_dir/image" --long | + awk '/^\/dev\// {if ($4 == "fedora") print $1}' + ) + + __log_and_run qemu-img create -f qcow2 "$temp_dir/image.qcow2" 20G __log_and_run virt-resize \ --quiet \ - --expand /dev/sda4 \ + --expand "$root_part" \ "$temp_dir/image" \ "$temp_dir/image.qcow2" rm "$temp_dir/image" + # enable nested virtualization + + if [[ "$arch" == aarch64 ]]; then + __log_and_run virt-customize \ + --quiet \ + --no-network \ + --add "$temp_dir/image.qcow2" \ + --append-line '/etc/default/grub:GRUB_CMDLINE_LINUX_DEFAULT="kvm-arm.mode=nested"' \ + --run-command 'grub2-mkconfig -o /boot/grub2/grub.cfg' + fi + # launch VM from base image file __log_and_run podman run \ --name "$container_name-build" \ --runtime "$runtime" \ - --memory 8g \ + --memory 4g \ --rm -dit \ --rootfs "$temp_dir" \ --persistent @@ -177,6 +202,15 @@ build) # get a predictable keypair __exec 'ssh-keygen -q -f .ssh/id_rsa -N "" && sudo cp -r .ssh /root/' + case "$arch" in + x86_64) + qemu_system_pkg=qemu-system-x86-core + ;; + aarch64) + qemu_system_pkg=qemu-system-aarch64-core + ;; + esac + __exec sudo dnf update -y __exec sudo dnf install -y \ bash \ @@ -195,7 +229,7 @@ build) openssh-clients \ podman \ qemu-img \ - qemu-system-x86-core \ + "$qemu_system_pkg" \ shadow-utils \ util-linux \ virtiofsd @@ -251,15 +285,20 @@ start) # shellcheck disable=SC2317 __extra_cleanup() { + __exec df -h __log_and_run podman stop --time 0 "$container_name" } - # load test images onto VM + # ensure nested hardware-accelerated virt is supported __exec() { __log_and_run podman exec "$container_name" --as fedora "$@" } + __exec '[[ -e /dev/kvm ]] || { sudo dmesg; exit 1; }' + + # load test images onto VM + chmod a+rx "$temp_dir" # so user "fedora" in guest can access it for image in "${TEST_IMAGES[@]}"; do diff --git a/tests/t/bootc-disk-size.sh b/tests/t/bootc-disk-size.sh index 157cf03..7581087 100644 --- a/tests/t/bootc-disk-size.sh +++ b/tests/t/bootc-disk-size.sh @@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later +__skip + image="${TEST_IMAGES[fedora-bootc]}" user="${TEST_IMAGES_DEFAULT_USER[fedora-bootc]}" diff --git a/tests/t/bootc-rootfs.sh b/tests/t/bootc-rootfs.sh index f5a1700..baa43ec 100644 --- a/tests/t/bootc-rootfs.sh +++ b/tests/t/bootc-rootfs.sh @@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later +__skip + "$UTIL_DIR/extract-vm-image.sh" "${TEST_IMAGES[fedora-bootc]}" "$TEMP_DIR/image" __run() {