#!/bin/bash
# Test the x86_64 emulator on aarch64 and s390x images for now
# https://github.com/coreos/fedora-coreos-tracker/issues/1237
#
## kola:
##   # This test should pass everywhere if it passes anywhere.
##   platforms: qemu
##   # This test doesn't make meaningful changes to the system and should
##   # be able to be combined with other tests.
##   exclusive: false
##   # This test pulls a container from a registry.
##   tags: needs-internet
##   # Only run on fcos, as rhel does not support emulation
##   distros: fcos
##   # We decided to ship x86_64 emulator to only these arches for now.
##   architectures: aarch64 s390x

set -xeuo pipefail

. $KOLA_EXT_DATA/commonlib.sh

case "$(arch)" in
    aarch64|s390x)
        containerArch=$(podman run --arch=amd64 --rm registry.fedoraproject.org/fedora:37 arch)
        if [ "$containerArch" != "x86_64" ]; then
            fatal "Test failed: x86_64 qemu emulator failed to run"
        fi
        ok "Test passed: x86_64 qemu emulator works on $(arch)" ;;
    *)
    # We shouldn't reach this point
    fatal "No qemu-user-static support for $(arch)" ;;
esac
