#!/bin/sh

# This test actually tests that yuzu is able to launch homebrew games
# using the GPU. It uses the "null" renderer, and should hence pass even
# on testbeds without GPUs.
#
# The tested homebrew game, "gpu_console.nro", has been built on
# 2025-04-26 using the devkitpro/devkita64 Docker container from the
# public-domain source code located in the
# /opt/devkitpro/examples/switch/graphics/opengl/gpu_console directory,
# which is also stored in the
# https://github.com/switchbrew/switch-examples Git repository.

set -eu

cd "$AUTOPKGTEST_TMP"

xz --decompress --stdout "$OLDPWD/debian/tests/gpu_console.nro.xz" > gpu_console.nro

# Enable the "null" renderer
printf '[Renderer]\nbackend\\default=false\nbackend=2\n' > config.ini

# Use SDL's offscreen driver unless told otherwise: offscreen and dummy
# are the only ones that can be expected to work in CI containers,
# but neither is selected unless explicitly requested.
#
# Can be overridden with e.g.
# SDL_VIDEODRIVER=wayland
# for manual testing.
if [ -z "${SDL_VIDEODRIVER-}" ]; then
    export SDL_VIDEODRIVER=offscreen
fi

mkdir "$AUTOPKGTEST_TMP/run"
XDG_RUNTIME_DIR="$AUTOPKGTEST_TMP/run" yuzu-cmd --config config.ini gpu_console.nro
