import json
import os
from pathlib import Path

import pytest

from tuxrun.__main__ import main
from tuxrun.devices import Device
from tuxrun.devices.fvp import FVPLAVA, FVPMorelloAndroid
from tuxrun.devices.qemu import QemuArmv5
from tuxrun.exceptions import InvalidArgument

BASE = (Path(__file__) / "..").resolve()


def test_select():
    assert Device.select("qemu-armv5") == QemuArmv5
    assert Device.select("fvp-morello-android") == FVPMorelloAndroid
    assert Device.select("fvp-lava") == FVPLAVA

    with pytest.raises(InvalidArgument):
        Device.select("Hello")


ARTEFACTS = [
    "bzImage.gz",
    "zImage.xz",
    "modules.tar.xz",
    "tf-bl1.bin",
    "mcp_fw.bin",
    "mcp_romfw.bin",
    "android-nano.img.xz",
    "busybox.img.xz",
    "debian.img.xz",
    "core-image-minimal-morello-fvp.wic",
    "scp_fw.bin",
    "scp_romfw.bin",
    "fip.bin",
    "ubuntu.satadisk.xz",
    "startup.nsh",
    "kselftest.tar.xz",
]

FVP_MORELLO_ANDROID = [
    "--ap-romfw",
    "tf-bl1.bin",
    "--mcp-fw",
    "mcp_fw.bin",
    "--mcp-romfw",
    "mcp_romfw.bin",
    "--rootfs",
    "android-nano.img.xz",
    "--scp-fw",
    "scp_fw.bin",
    "--scp-romfw",
    "scp_romfw.bin",
    "--fip",
    "fip.bin",
]

metadata = {
    "results": {
        "artifacts": {"kernel": ["bzImage.gz"], "modules": ["modules.tar.xz"]},
    },
    "build": {"target_arch": "arm64"},
}


@pytest.fixture
def artefacts(tmp_path):
    os.chdir(tmp_path)
    for art in ARTEFACTS:
        (tmp_path / art).touch()
    (tmp_path / "metadata.json").write_text(json.dumps(metadata), encoding="utf-8")
    return tmp_path


@pytest.mark.parametrize(
    "args,filename",
    [
        (
            ["--device", "qemu-arm64"],
            "qemu-arm64.yaml",
        ),
        (
            ["--device", "qemu-arm64", "--timeouts", "deploy=4", "boot=12"],
            "qemu-arm64-timeouts.yaml",
        ),
        (
            ["--device", "qemu-arm64", "--tests", "ltp-fcntl-locktests"],
            "qemu-arm64-ltp-fcntl-locktests.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--tests",
                "kselftest-arm64",
            ],
            "qemu-arm64-kselftest-arm64.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian/bookworm/arm64/rootfs.ext4.xz",
                "--tests",
                "hacking-session",
                "--parameters",
                "PUB_KEY=ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDNNtK2rxgzZ5qQHteYg3zh_rSD46m72eI8eL0nOoA_6dnLSQ_yHQsJkbtucJRQS1hu_hlgtNGNrURmXPUk5ZiWvSSpFinsnSmjbCRj5k1B2cbhuxeqdgcgOm5vvydVrPnRjekV0_DULCH_W2mooMH9cz1ouxUs08cdQivalmn6svrcoe3ozUklvEX7rDquv_vgx1_mcdmNuMNvQ6_k9PF2Q0Fi_qzYQbB_MSQGnNUx15lljOEKla5PwuwQsPWbHKh_r_XBz_lrK47PTRoxE5HPgpeCLxWx6L32BYLAxiCXIOBxNomfj__lFk0ZzQobAhvgAwSmEcVJAcotgch0bUN7N_Nr_RfBiqTguk0ADn1HPo4scwbYMl5MWNFg0CPZjIyYsKpeXZN2uM_Q_mUVC_WNKTjsmMWPcnoSjF8BbJsF1rzObg_QwJu0oNMkVj77bEDzSFsuQ8y9ovdaaXn26aYiDn2SKFC9MJTjZg22ncAK9MZmLoF3761mucWQjD51MXM_ anders@monster",
            ],
            "qemu-arm64-hacking-session.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://example.com/script.sh",
                "/",
                "--tests",
                "hacking-session",
                "--parameters",
                "PUB_KEY=ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDNNtK2rxgzZ5qQHteYg3zh_rSD46m72eI8eL0nOoA_6dnLSQ_yHQsJkbtucJRQS1hu_hlgtNGNrURmXPUk5ZiWvSSpFinsnSmjbCRj5k1B2cbhuxeqdgcgOm5vvydVrPnRjekV0_DULCH_W2mooMH9cz1ouxUs08cdQivalmn6svrcoe3ozUklvEX7rDquv_vgx1_mcdmNuMNvQ6_k9PF2Q0Fi_qzYQbB_MSQGnNUx15lljOEKla5PwuwQsPWbHKh_r_XBz_lrK47PTRoxE5HPgpeCLxWx6L32BYLAxiCXIOBxNomfj__lFk0ZzQobAhvgAwSmEcVJAcotgch0bUN7N_Nr_RfBiqTguk0ADn1HPo4scwbYMl5MWNFg0CPZjIyYsKpeXZN2uM_Q_mUVC_WNKTjsmMWPcnoSjF8BbJsF1rzObg_QwJu0oNMkVj77bEDzSFsuQ8y9ovdaaXn26aYiDn2SKFC9MJTjZg22ncAK9MZmLoF3761mucWQjD51MXM_ anders@monster",
            ],
            "qemu-arm64-overlay-script.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "/usr/lib/",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/trixie/arm64/rootfs.ext4.xz",
            ],
            "qemu-arm64-module-path.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-db-sqlite-insert-small.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-db-sqlite-insert-small",
            ],
            "qemu-arm64-mmtests-db-sqlite-insert-small.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-hpc-scimarkc-small.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-hpc-scimarkc-small",
            ],
            "qemu-arm64-mmtests-hpc-scimarkc-small.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-io-blogbench.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-io-blogbench",
            ],
            "qemu-arm64-mmtests-io-blogbench.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-io-fio-randread-async-randwrite.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-io-fio-randread-async-randwrite",
            ],
            "qemu-arm64-mmtests-io-fio-randread-async-randwrite.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-io-fio-randread-async-seqwrite.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-io-fio-randread-async-seqwrite",
            ],
            "qemu-arm64-mmtests-io-fio-randread-async-seqwrite.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-io-fio-randread-sync-heavywrite.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-io-fio-randread-sync-heavywrite",
            ],
            "qemu-arm64-mmtests-io-fio-randread-sync-heavywrite.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-io-fio-randread-sync-randwrite.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-io-fio-randread-sync-randwrite",
            ],
            "qemu-arm64-mmtests-io-fio-randread-sync-randwrite.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-io-fsmark-small-file-stream.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-io-fsmark-small-file-stream",
            ],
            "qemu-arm64-mmtests-io-fsmark-small-file-stream.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-memdb-redis-benchmark-small.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-memdb-redis-benchmark-small",
            ],
            "qemu-arm64-mmtests-memdb-redis-benchmark-small.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-memdb-redis-memtier-small.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-memdb-redis-memtier-small",
            ],
            "qemu-arm64-mmtests-memdb-redis-memtier-small.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-scheduler-schbench.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-scheduler-schbench",
            ],
            "qemu-arm64-mmtests-scheduler-schbench.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-scheduler-sysbench-cpu.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-scheduler-sysbench-cpu",
            ],
            "qemu-arm64-mmtests-scheduler-sysbench-cpu.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-scheduler-sysbench-thread.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-scheduler-sysbench-thread",
            ],
            "qemu-arm64-mmtests-scheduler-sysbench-thread.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-aim9-disk.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-aim9-disk",
            ],
            "qemu-arm64-mmtests-workload-aim9-disk.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-coremark.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-coremark",
            ],
            "qemu-arm64-mmtests-workload-coremark.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-cyclictest-fine-hackbench.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-cyclictest-fine-hackbench",
            ],
            "qemu-arm64-mmtests-workload-cyclictest-fine-hackbench.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-cyclictest-hackbench.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-cyclictest-hackbench",
            ],
            "qemu-arm64-mmtests-workload-cyclictest-hackbench.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-ebizzy.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-ebizzy",
            ],
            "qemu-arm64-mmtests-workload-ebizzy.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-pmqtest-hackbench.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-pmqtest-hackbench",
            ],
            "qemu-arm64-mmtests-workload-pmqtest-hackbench.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-af-alg.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-af-alg",
            ],
            "qemu-arm64-mmtests-workload-stressng-af-alg.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-bad-altstack.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-bad-altstack",
            ],
            "qemu-arm64-mmtests-workload-stressng-bad-altstack.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-class-io-parallel.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-class-io-parallel",
            ],
            "qemu-arm64-mmtests-workload-stressng-class-io-parallel.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-context.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-context",
            ],
            "qemu-arm64-mmtests-workload-stressng-context.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-fork.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-fork",
            ],
            "qemu-arm64-mmtests-workload-stressng-fork.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-get.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-get",
            ],
            "qemu-arm64-mmtests-workload-stressng-get.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-getdent.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-getdent",
            ],
            "qemu-arm64-mmtests-workload-stressng-getdent.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-madvise.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-madvise",
            ],
            "qemu-arm64-mmtests-workload-stressng-madvise.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-mmap.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-mmap",
            ],
            "qemu-arm64-mmtests-workload-stressng-mmap.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-usemem.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-usemem",
            ],
            "qemu-arm64-mmtests-workload-usemem.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-vm-splice.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-vm-splice",
            ],
            "qemu-arm64-mmtests-workload-stressng-vm-splice.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-zombie.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-zombie",
            ],
            "qemu-arm64-mmtests-workload-stressng-zombie.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-will-it-scale-io-processes.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-will-it-scale-io-processes",
            ],
            "qemu-arm64-mmtests-workload-will-it-scale-io-processes.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-will-it-scale-io-threads.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-will-it-scale-io-threads",
            ],
            "qemu-arm64-mmtests-workload-will-it-scale-io-threads.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-will-it-scale-pf-processes.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-will-it-scale-pf-processes",
            ],
            "qemu-arm64-mmtests-workload-will-it-scale-pf-processes.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-will-it-scale-pf-threads.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-will-it-scale-pf-threads",
            ],
            "qemu-arm64-mmtests-workload-will-it-scale-pf-threads.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-will-it-scale-sys-processes.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-will-it-scale-sys-processes",
            ],
            "qemu-arm64-mmtests-workload-will-it-scale-sys-processes.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-will-it-scale-sys-threads.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-will-it-scale-sys-threads",
            ],
            "qemu-arm64-mmtests-workload-will-it-scale-sys-threads.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-get.tar.xz",
                "/mmtests",
                "--tests",
                "mmtests-workload-stressng-get",
                "--parameters",
                "ITERATIONS=2",
            ],
            "qemu-arm64-mmtests-workload-stressng-get-iterations-2.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-workload-stressng-get.tar.xz",
                "/opt/mmtests",
                "--tests",
                "mmtests-workload-stressng-get",
                "--parameters",
                "ITERATIONS=4",
                "--parameters",
                "MMTESTS_PATH=/opt/mmtests",
            ],
            "qemu-arm64-mmtests-workload-stressng-get-iterations-4-mmtests_path.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian-mmtests/bookworm/arm64/rootfs.ext4.xz",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/xfstests/master/xfstests.tar.xz",
                "/opt/",
                "--tests",
                "xfstests-ext4",
            ],
            "qemu-arm64-xfstests-ext4.yaml",
        ),
        (
            [
                "--device",
                "qemu-arm64",
                "--boot-args",
                "rw",
                "--kernel",
                "https://example.com/Image.gz",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--rootfs",
                "https://storage.tuxboot.com/debian/bookworm/arm64/rootfs.ext4.xz",
                "--tests",
                "systemd-analyze",
            ],
            "qemu-arm64-systemd-analyze.yaml",
        ),
        (
            ["--device", "qemu-arm64be"],
            "qemu-arm64be.yaml",
        ),
        (
            ["--device", "qemu-arm64be", "--qemu-image", "docker.io/qemu/qemu:latest"],
            "qemu-arm64be-qemu-image.yaml",
        ),
        (
            ["--device", "qemu-armv5"],
            "qemu-armv5.yaml",
        ),
        (
            ["--device", "qemu-armv5", "--tests", "ltp-fs_bind"],
            "qemu-armv5-ltp-fs_bind.yaml",
        ),
        (
            ["--device", "qemu-armv7"],
            "qemu-armv7.yaml",
        ),
        (
            [
                "--device",
                "qemu-armv7",
                "--tests",
                "kselftest-ipc",
                "--parameters",
                "KSELFTEST=https://example.com/kselftest.tar.xz",
            ],
            "qemu-armv7-kselftest-ipc.yaml",
        ),
        (
            [
                "--device",
                "qemu-armv7",
                "--tests",
                "kselftest-ipc",
                "--parameters",
                "KSELFTEST=https://example.com/kselftest.tar.xz",
                "SKIPFILE=/skipfile.yaml",
            ],
            "qemu-armv7-kselftest-ipc-skipfile.yaml",
        ),
        (
            [
                "--device",
                "qemu-armv7",
                "--tests",
                "kselftest-ipc",
                "--parameters",
                "CPUPOWER=https://example.com/cpupower.tar.xz",
                "KSELFTEST=https://example.com/kselftest.tar.xz",
            ],
            "qemu-armv7-kselftest-ipc-cpupower.yaml",
        ),
        (
            [
                "--device",
                "qemu-armv7",
                "--tests",
                "ltp-fs_perms_simple",
                "--tests",
                "ltp-fsx",
                "--tests",
                "ltp-nptl",
                "--timeouts",
                "ltp-fs_perms_simple=4",
                "--timeouts",
                "ltp-fsx=3",
            ],
            "qemu-armv7-ltp-mutliple-tests.yaml",
        ),
        (
            [
                "--device",
                "qemu-armv7",
                "--tests",
                "ltp-fs_perms_simple",
                "ltp-fsx",
                "ltp-nptl",
                "--timeouts",
                "ltp-fs_perms_simple=4",
                "ltp-fsx=3",
            ],
            "qemu-armv7-ltp-timeouts.yaml",
        ),
        (
            ["--device", "qemu-armv7", "--kernel", "zImage.xz"],
            "qemu-armv7-kernel-xz.yaml",
        ),
        (
            ["--device", "qemu-armv7be"],
            "qemu-armv7be.yaml",
        ),
        (
            [
                "--device",
                "qemu-armv7be",
                "--qemu-image",
                "docker.io/linaro/tuxrun-qemu:latest",
            ],
            "qemu-armv7be-qemu-image.yaml",
        ),
        (
            ["--device", "qemu-armv7be", "--prompt", "root@tuxrun"],
            "qemu-armv7be-prompt.yaml",
        ),
        (
            ["--device", "qemu-i386"],
            "qemu-i386.yaml",
        ),
        (
            ["--device", "qemu-i386", "--tests", "kunit"],
            "qemu-i386-kunit.yaml",
        ),
        (
            [
                "--device",
                "qemu-i386",
                "--tests",
                "kunit",
                "--parameters",
                "KUNIT_TEST_MODULE=test.ko",
            ],
            "qemu-i386-kunit-module.yaml",
        ),
        (
            ["--device", "qemu-i386", "--tests", "libgpiod"],
            "qemu-i386-libgpiod.yaml",
        ),
        (
            ["--device", "qemu-i386", "--tests", "libhugetlbfs"],
            "qemu-i386-libhugetlbfs.yaml",
        ),
        (
            ["--device", "qemu-i386", "--tests", "perf"],
            "qemu-i386-perf.yaml",
        ),
        (
            [
                "--device",
                "qemu-i386",
                "--tests",
                "perf",
                "--overlay",
                "http://example.com/overlay1.tar.xz",
                "--overlay",
                "http://example.com/overlay2.tar.xz",
                "--parameters",
                "PERF=https://example.com/perf.tar.xz",
            ],
            "qemu-i386-perf-parameters.yaml",
        ),
        (
            ["--device", "qemu-i386", "--tests", "rcutorture"],
            "qemu-i386-rcutorture.yaml",
        ),
        (
            ["--device", "qemu-i386", "--tests", "v4l2"],
            "qemu-i386-v4l2.yaml",
        ),
        (
            ["--device", "qemu-i386", "--tests", "vdso"],
            "qemu-i386-vdso.yaml",
        ),
        (
            [
                "--device",
                "qemu-i386",
                "--tests",
                "kunit",
                "--overlay",
                "http://example.com/overlay1.tar.xz",
                "--overlay",
                "http://example.com/overlay2.tar.xz",
            ],
            "qemu-i386-kunit-overlays.yaml",
        ),
        (
            [
                "--device",
                "qemu-i386",
                "--tests",
                "kunit",
                "--overlay",
                "http://example.com/overlay1.tar.xz",
                "/overlay1/",
                "--overlay",
                "http://example.com/overlay2.tar.xz",
                "/overlay2/",
            ],
            "qemu-i386-kunit-overlays-paths.yaml",
        ),
        (
            ["--device", "qemu-i386", "--tests", "kvm-unit-tests"],
            "qemu-i386-kvm-unit-tests.yaml",
        ),
        (
            ["--device", "qemu-i386", "--kernel", "bzImage.gz"],
            "qemu-i386-kernel-gz.yaml",
        ),
        (
            ["--device", "qemu-i386", "--boot-args", "bla blo"],
            "qemu-i386-boot-args.yaml",
        ),
        (
            [
                "--device",
                "qemu-i386",
                "--tests",
                "kselftest-ipc",
                "--parameters",
                "CPUPOWER=https://example.com/cpupower.tar.xz",
                "KSELFTEST=https://example.com/kselftest.tar.xz",
            ],
            "qemu-i386-kselftest-ipc.yaml",
        ),
        (
            ["--device", "qemu-mips32"],
            "qemu-mips32.yaml",
        ),
        (
            [
                "--device",
                "qemu-mips32",
                "--modules",
                "https://example.com/modules.tar.xz",
            ],
            "qemu-mips32-modules.yaml",
        ),
        (
            [
                "--device",
                "qemu-mips32",
                "--modules",
                "https://example.com/modules.tgz",
            ],
            "qemu-mips32-modules-tgz.yaml",
        ),
        (
            [
                "--device",
                "qemu-mips32",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--overlay",
                "http://example.com/overlay2.tar.xz",
                "--tests",
                "kunit",
            ],
            "qemu-mips32-modules-overlays-kunit.yaml",
        ),
        (
            ["--device", "qemu-mips32", "--", "cat", "/proc/cpuinfo"],
            "qemu-mips32-command.yaml",
        ),
        (
            ["--device", "qemu-mips32el"],
            "qemu-mips32el.yaml",
        ),
        (
            ["--device", "qemu-mips64"],
            "qemu-mips64.yaml",
        ),
        (
            ["--device", "qemu-mips64"],
            "qemu-mips64el.yaml",
        ),
        (
            ["--device", "qemu-ppc32"],
            "qemu-ppc32.yaml",
        ),
        (
            ["--device", "qemu-ppc64"],
            "qemu-ppc64.yaml",
        ),
        (
            ["--device", "qemu-ppc64le"],
            "qemu-ppc64le.yaml",
        ),
        (
            ["--device", "qemu-s390"],
            "qemu-s390.yaml",
        ),
        (
            ["--device", "qemu-s390", "--tests", "ltp-smoke"],
            "qemu-s390-ltp-smoke.yaml",
        ),
        (
            [
                "--device",
                "qemu-s390",
                "--tests",
                "ltp-smoke",
                "--parameters",
                "SKIPFILE=skipfile-lkft.yaml",
            ],
            "qemu-s390-ltp-smoke-skipfile.yaml",
        ),
        (
            ["--device", "qemu-riscv32"],
            "qemu-riscv32.yaml",
        ),
        (
            ["--device", "qemu-riscv64"],
            "qemu-riscv64.yaml",
        ),
        (
            ["--device", "qemu-sh4"],
            "qemu-sh4.yaml",
        ),
        (
            ["--device", "qemu-sh4", "--boot-args", "hello"],
            "qemu-sh4-boot-args.yaml",
        ),
        (
            ["--device", "qemu-sparc64"],
            "qemu-sparc64.yaml",
        ),
        (
            ["--device", "qemu-x86_64"],
            "qemu-x86_64.yaml",
        ),
        (
            ["--device", "qemu-x86_64", "--enable-kvm"],
            "qemu-x86_64-enable-kvm.yaml",
        ),
        (
            [
                "--device",
                "qemu-x86_64",
                "--rootfs",
                "https://example.com/rootfs.ext4.zst",
            ],
            "qemu-x86_64-rootfs-zst.yaml",
        ),
        (
            [
                "--device",
                "qemu-x86_64",
                "--rootfs",
                "https://example.com/rootfs.ext4",
            ],
            "qemu-x86_64-rootfs.yaml",
        ),
        (
            [
                "--device",
                "qemu-x86_64",
                "--rootfs",
                "https://example.com/rootfs.ext4.gz",
            ],
            "qemu-x86_64-rootfs-gz.yaml",
        ),
        (
            [
                "--device",
                "fvp-aemva",
                "--bl1",
                "tf-bl1.bin",
                "--fip",
                "fip.bin",
                "--kernel",
                "zImage.xz",
                "--rootfs",
                "https://example.com/rootfs.ext4.zst",
                "--uefi",
                "https://example.com/uefi.bin",
            ],
            "fvp-aemva-kernel-xz.yaml",
        ),
        (
            [
                "--device",
                "fvp-aemva",
                "--bl1",
                "tf-bl1.bin",
                "--fip",
                "fip.bin",
                "--rootfs",
                "https://example.com/rootfs.ext4.zst",
                "--tests",
                "ltp-smoke",
            ],
            "fvp-aemva-ltp-smoke.yaml",
        ),
        (
            [
                "--device",
                "fvp-aemva",
                "--bl1",
                "tf-bl1.bin",
                "--fip",
                "fip.bin",
                "--rootfs",
                "https://example.com/rootfs.ext4.zst",
            ],
            "fvp-aemva.yaml",
        ),
        (
            [
                "--device",
                "fvp-aemva",
                "--prompt",
                "root@tuxrun",
            ],
            "fvp-aemva-prompt.yaml",
        ),
        (
            [
                "--device",
                "fvp-aemva",
                "--bl1",
                "tf-bl1.bin",
                "--fip",
                "fip.bin",
                "--modules",
                "https://example.com/modules.tar.xz",
            ],
            "fvp-aemva-modules.yaml",
        ),
        (
            [
                "--device",
                "fvp-aemva",
                "--bl1",
                "tf-bl1.bin",
                "--fip",
                "fip.bin",
                "--modules",
                "https://example.com/modules.tar.xz",
                "/usr/",
            ],
            "fvp-aemva-modules-path-usr.yaml",
        ),
        (
            [
                "--device",
                "fvp-aemva",
                "--bl1",
                "tf-bl1.bin",
                "--fip",
                "fip.bin",
                "--modules",
                "https://example.com/modules.tar.gz",
            ],
            "fvp-aemva-modules-tar-gz.yaml",
        ),
        (
            [
                "--device",
                "fvp-aemva",
            ],
            "fvp-aemva-defaults.yaml",
        ),
        (
            ["--device", "fvp-morello-android", *FVP_MORELLO_ANDROID],
            "fvp-morello-android.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "binder",
            ],
            "fvp-morello-android-binder.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "bionic",
            ],
            "fvp-morello-android-bionic.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "bionic",
                "--parameters",
                "GTEST_FILTER=hello",
                "BIONIC_TEST_TYPE=dynamic",
            ],
            "fvp-morello-android-bionic-params.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "boringssl",
                "--parameters",
                "SYSTEM_URL=system.tar.xz",
            ],
            "fvp-morello-android-boringssl.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "boringssl",
                "--parameters",
                "SYSTEM_URL=system.tar.xz",
                "--timeouts",
                "boringssl=4212",
            ],
            "fvp-morello-android-boringssl-timeouts.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "compartment",
                "--parameters",
                "USERDATA=userdata.tar.xz",
            ],
            "fvp-morello-android-compartment.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "device-tree",
            ],
            "fvp-morello-android-device-tree.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "dvfs",
            ],
            "fvp-morello-android-dvfs.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "libjpeg-turbo",
                "--parameters",
                "SYSTEM_URL=system.tar.xz",
                "LIBJPEG_TURBO_URL=libjpeg.tar.xz",
            ],
            "fvp-morello-android-libjpeg-turbo.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "libpdfium",
                "--parameters",
                "SYSTEM_URL=system.tar.xz",
                "PDFIUM_URL=pdfium.tar.xz",
            ],
            "fvp-morello-android-libpdfium.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "libpng",
                "--parameters",
                "SYSTEM_URL=system.tar.xz",
                "PNG_URL=png.tar.xz",
            ],
            "fvp-morello-android-libpng.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "lldb",
                "--parameters",
                "LLDB_URL=lldb.tar.xz",
                "TC_URL=toolchain.tar.xz",
            ],
            "fvp-morello-android-lldb.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "logd",
                "--parameters",
                "USERDATA=userdata.tar.xz",
            ],
            "fvp-morello-android-logd.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "multicore",
            ],
            "fvp-morello-android-multicore.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "smc91x",
            ],
            "fvp-morello-android-smc91x.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "virtio_net",
            ],
            "fvp-morello-android-virtio_net.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-android",
                *FVP_MORELLO_ANDROID,
                "--tests",
                "zlib",
                "--parameters",
                "SYSTEM_URL=system.tar.xz",
            ],
            "fvp-morello-android-zlib.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-busybox",
                "--ap-romfw",
                "tf-bl1.bin",
                "--mcp-fw",
                "mcp_fw.bin",
                "--mcp-romfw",
                "mcp_romfw.bin",
                "--rootfs",
                "busybox.img.xz",
                "--scp-fw",
                "scp_fw.bin",
                "--scp-romfw",
                "scp_romfw.bin",
                "--fip",
                "fip.bin",
            ],
            "fvp-morello-busybox.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-busybox",
                "--ap-romfw",
                "tf-bl1.bin",
                "--mcp-fw",
                "mcp_fw.bin",
                "--mcp-romfw",
                "mcp_romfw.bin",
                "--rootfs",
                "busybox.img.xz",
                "--scp-fw",
                "scp_fw.bin",
                "--scp-romfw",
                "scp_romfw.bin",
                "--fip",
                "fip.bin",
                "--tests",
                "purecap",
            ],
            "fvp-morello-busybox-purecap.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-grub",
                "--ap-romfw",
                "tf-bl1.bin",
                "--mcp-fw",
                "mcp_fw.bin",
                "--mcp-romfw",
                "mcp_romfw.bin",
                "--rootfs",
                "debian.img.xz",
                "--scp-fw",
                "scp_fw.bin",
                "--scp-romfw",
                "scp_romfw.bin",
                "--fip",
                "fip.bin",
                "--tests",
                "boot-debian-dt",
            ],
            "fvp-morello-grub-boot-debian-dt.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-grub",
                "--ap-romfw",
                "tf-bl1.bin",
                "--mcp-fw",
                "mcp_fw.bin",
                "--mcp-romfw",
                "mcp_romfw.bin",
                "--rootfs",
                "debian.img.xz",
                "--scp-fw",
                "scp_fw.bin",
                "--scp-romfw",
                "scp_romfw.bin",
                "--fip",
                "fip.bin",
                "--tests",
                "boot-busybox-dt",
            ],
            "fvp-morello-grub-boot-busybox-dt.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-grub",
                "--ap-romfw",
                "tf-bl1.bin",
                "--mcp-fw",
                "mcp_fw.bin",
                "--mcp-romfw",
                "mcp_romfw.bin",
                "--rootfs",
                "debian.img.xz",
                "--scp-fw",
                "scp_fw.bin",
                "--scp-romfw",
                "scp_romfw.bin",
                "--fip",
                "fip.bin",
                "--tests",
                "boot-debian-acpi",
            ],
            "fvp-morello-grub-boot-debian-acpi.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-grub",
                "--ap-romfw",
                "tf-bl1.bin",
                "--mcp-fw",
                "mcp_fw.bin",
                "--mcp-romfw",
                "mcp_romfw.bin",
                "--rootfs",
                "debian.img.xz",
                "--scp-fw",
                "scp_fw.bin",
                "--scp-romfw",
                "scp_romfw.bin",
                "--fip",
                "fip.bin",
                "--tests",
                "boot-busybox-acpi",
            ],
            "fvp-morello-grub-boot-busybox-acpi.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-debian",
                "--ap-romfw",
                "tf-bl1.bin",
                "--mcp-fw",
                "mcp_fw.bin",
                "--mcp-romfw",
                "mcp_romfw.bin",
                "--rootfs",
                "debian.img.xz",
                "--scp-fw",
                "scp_fw.bin",
                "--scp-romfw",
                "scp_romfw.bin",
                "--fip",
                "fip.bin",
                "--tests",
                "debian-purecap",
            ],
            "fvp-morello-debian-purecap.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-busybox",
                "--ap-romfw",
                "tf-bl1.bin",
                "--mcp-fw",
                "mcp_fw.bin",
                "--mcp-romfw",
                "mcp_romfw.bin",
                "--rootfs",
                "busybox.img.xz",
                "--scp-fw",
                "scp_fw.bin",
                "--scp-romfw",
                "scp_romfw.bin",
                "--fip",
                "fip.bin",
                "--tests",
                "smc91x",
            ],
            "fvp-morello-busybox-smc91x.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-oe",
                "--ap-romfw",
                "tf-bl1.bin",
                "--mcp-fw",
                "mcp_fw.bin",
                "--mcp-romfw",
                "mcp_romfw.bin",
                "--rootfs",
                "core-image-minimal-morello-fvp.wic",
                "--scp-fw",
                "scp_fw.bin",
                "--scp-romfw",
                "scp_romfw.bin",
                "--fip",
                "fip.bin",
            ],
            "fvp-morello-oe.yaml",
        ),
        (
            [
                "--device",
                "fvp-morello-ubuntu",
                "--ap-romfw",
                "tf-bl1.bin",
                "--mcp-fw",
                "mcp_fw.bin",
                "--mcp-romfw",
                "mcp_romfw.bin",
                "--scp-fw",
                "scp_fw.bin",
                "--scp-romfw",
                "scp_romfw.bin",
                "--fip",
                "fip.bin",
            ],
            "fvp-morello-ubuntu.yaml",
        ),
        (
            ["--tuxmake", ".", "--tests", "kselftest-cgroup"],
            "tuxmake.yaml",
        ),
        (
            [
                "--tuxmake",
                ".",
                "--tests",
                "kselftest-cgroup",
                "--parameters",
                "KSELFTEST=$BUILD/kselftest.tar.xz",
            ],
            "tuxmake-parameters.yaml",
        ),
        (
            [
                "--device",
                "fvp-lava",
                "--fvp-ubl-license",
                "test-license-key",
                "--job-definition",
                f"{BASE}/refs/definitions/fvp-lava-job-definition.yaml",
            ],
            "fvp-lava-job-definition.yaml",
        ),
        (
            [
                "--device",
                "ssh-device",
                "--ssh-host",
                "127.0.0.1",
                "--ssh-user",
                "testuser",
                "--ssh-identity-file",
                f"{BASE}/refs/dummy.pem",
                "--ssh-prompt",
                "testuser",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-io-blogbench2.tar.xz",
                "/mmtests",
                "--overlay",
                "https://storage.tuxboot.com/overlays/debian/bookworm/arm64/mmtests/master/config-io-blogbench.tar.xz",
                "/mmtests",
                "--tests",
                "ltp-smoke",
            ],
            "ssh-device.yaml",
        ),
        (
            [
                "--device",
                "avh-rpi4b",
                "--secrets",
                "avh_api_token=avhapitoken",
                "--kernel",
                "https://example.com/Image",
                "--dtb",
                "https://example.com/devicetree",
                "--rootfs",
                "https://example.com/rootfs.ext4",
            ],
            "avh-rpi4b.yaml",
        ),
        (
            [
                "--device",
                "avh-imx93",
                "--secrets",
                "avh_api_token=avhapitoken",
                "--kernel",
                "https://example.com/Image",
                "--dtb",
                "https://example.com/devicetree",
                "--rootfs",
                "https://example.com/rootfs.ext4",
            ],
            "avh-imx93.yaml",
        ),
        (
            [
                "--device",
                "avh-imx93",
                "--secrets",
                "avh_api_token=avhapitoken",
                "--kernel",
                "https://example.com/Image",
                "--dtb",
                "https://example.com/devicetree",
                "--rootfs",
                "https://example.com/rootfs.ext4",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--partition",
                "1",
            ],
            "avh-imx93-module-overlay.yaml",
        ),
        (
            [
                "--device",
                "avh-imx93",
                "--secrets",
                "avh_api_token=avhapitoken",
                "--kernel",
                "https://example.com/Image",
                "--dtb",
                "https://example.com/devicetree",
                "--rootfs",
                "https://example.com/rootfs.ext4",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--partition",
                "1",
                "--boot-args",
                "console=ttyLP0,115200 earlycon= root=/dev/mmcblk0p2",
            ],
            "avh-imx93-boot-args.yaml",
        ),
        (
            [
                "--device",
                "avh-imx93",
                "--secrets",
                "avh_api_token=avhapitoken",
                "--kernel",
                "https://example.com/Image",
                "--dtb",
                "https://example.com/devicetree",
                "--rootfs",
                "https://example.com/rootfs.ext4",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--partition",
                "1",
                "--boot-args",
                "console=ttyLP0,115200 earlycon= root=/dev/mmcblk0p2",
                "--tests",
                "ltp-smoke",
            ],
            "avh-imx93-ltp-smoke.yaml",
        ),
        (
            [
                "--device",
                "avh-imx93",
                "--secrets",
                "avh_api_token=avhapitoken",
                "--kernel",
                "https://example.com/Image",
                "--dtb",
                "https://example.com/devicetree",
                "--rootfs",
                "https://example.com/rootfs.ext4",
                "--modules",
                "https://example.com/modules.tar.xz",
                "--partition",
                "1",
                "--boot-args",
                "console=ttyLP0,115200 earlycon= root=/dev/mmcblk0p2",
                "--tests",
                "ltp-smoke",
                "--tests",
                "kselftest-arm64",
            ],
            "avh-imx93-multiple-tests.yaml",
        ),
    ],
)
def test_definition(monkeypatch, mocker, tmpdir, artefacts, args, filename):
    monkeypatch.setattr("tuxrun.__main__.sys.argv", ["tuxrun"] + args)
    mocker.patch("tuxrun.__main__.Runtime.select", side_effect=Exception)
    mocker.patch("tuxrun.assets.__download_and_cache__", side_effect=lambda a, b: a)
    mocker.patch(
        "tuxrun.__main__.get_test_definitions", return_value="file://testdef.tar.zst"
    )
    mocker.patch("tempfile.mkdtemp", return_value=tmpdir)
    mocker.patch("shutil.rmtree")

    with pytest.raises(Exception):
        main()
    data = (tmpdir / "definition.yaml").read_text(encoding="utf-8")

    for art in ARTEFACTS:
        data = data.replace(f"file://{artefacts}/{art}", f"/DATA/{art}")
    data = data.replace(
        f'container_name: "{artefacts.name}"', 'container_name: "tuxrun-ci"'
    )
    data = data.replace(
        f'network_from: "{artefacts.name}"', 'network_from: "tuxrun-ci"'
    )

    if os.environ.get("TUXRUN_RENDER"):
        (BASE / "refs" / "definitions" / filename).write_text(data, encoding="utf-8")
    assert data == (BASE / "refs" / "definitions" / filename).read_text(
        encoding="utf-8"
    )


def test_fvp_aemva_extra_assets(tmpdir):
    device = Device.select("fvp-aemva")()

    # 1/ default case
    asset = device.extra_assets(dtb=None, kernel=None, tmpdir=tmpdir, tux_boot_args="")
    assert len(asset) == 1
    assert asset[0] == f"file://{tmpdir / 'startup.nsh'}"
    assert (tmpdir / "startup.nsh").read_text(
        encoding="utf-8"
    ) == "Image dtb=fvp-base-revc.dtb systemd.log_level=warning console=ttyAMA0 earlycon=pl011,0x1c090000 root=/dev/vda ip=dhcp"

    # 2/ custom urls
    asset = device.extra_assets(
        dtb="file://hello/world/fdt.dtb",
        kernel="http://example.com/kernel",
        tmpdir=tmpdir,
        tux_boot_args="",
    )
    assert len(asset) == 1
    assert asset[0] == f"file://{tmpdir / 'startup.nsh'}"
    assert (tmpdir / "startup.nsh").read_text(
        encoding="utf-8"
    ) == "kernel dtb=fdt.dtb systemd.log_level=warning console=ttyAMA0 earlycon=pl011,0x1c090000 root=/dev/vda ip=dhcp"

    # 3/ compression
    asset = device.extra_assets(
        dtb="file://tmp/my-dtb", kernel="Image.gz", tmpdir=tmpdir, tux_boot_args=None
    )
    assert len(asset) == 1
    assert asset[0] == f"file://{tmpdir / 'startup.nsh'}"
    assert (tmpdir / "startup.nsh").read_text(
        encoding="utf-8"
    ) == "Image dtb=my-dtb systemd.log_level=warning console=ttyAMA0 earlycon=pl011,0x1c090000 root=/dev/vda ip=dhcp"

    # 4/ custom boot-args
    asset = device.extra_assets(
        dtb=None, kernel=None, tmpdir=tmpdir, tux_boot_args="debug"
    )
    assert len(asset) == 1
    assert asset[0] == f"file://{tmpdir / 'startup.nsh'}"
    assert (tmpdir / "startup.nsh").read_text(
        encoding="utf-8"
    ) == "Image dtb=fvp-base-revc.dtb systemd.log_level=warning debug console=ttyAMA0 earlycon=pl011,0x1c090000 root=/dev/vda ip=dhcp"
