diff --git a/.cargo/config.toml b/.cargo/config.toml index c9d99de8..a5ed15ea 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -2,4 +2,4 @@ target = "aarch64-unknown-none-softfloat" [target.aarch64-unknown-none-softfloat] -runner = "scripts/qemu-runner.sh" +runner = "scripts/qemu_runner.py" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e75e51db..d77f7391 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,13 +38,13 @@ jobs: - name: Run tests if: ${{ matrix.smp-feature == '' }} run: | - cargo run -r --no-default-features -- /bin/usertest >> usertest.log + cargo run -r --no-default-features -- --init /bin/usertest >> usertest.log cargo test -r --no-default-features >> unittest.log # If any feature is enabled - name: Run tests if: ${{ matrix.smp-feature == 'smp' }} run: | - cargo run -r --no-default-features --features "${{ matrix.smp-feature }}" -- /bin/usertest >> usertest.log + cargo run -r --no-default-features --features "${{ matrix.smp-feature }}" -- --init /bin/usertest >> usertest.log cargo test -r --no-default-features --features "${{ matrix.smp-feature }}" >> unittest.log - name: Display usertest output run: cat usertest.log diff --git a/scripts/qemu-runner.sh b/scripts/qemu-runner.sh deleted file mode 100755 index 1827e701..00000000 --- a/scripts/qemu-runner.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -set -e - -# First argument: the ELF file to run (required) -# Second argument: init script to run (optional, defaults to /bin/sh) -# Parse args: -if [ $# -lt 1 ]; then - echo "Usage: $0 " - exit 1 -fi - -if [ -n "$2" ]; then - append_args="--init=$2" -else - append_args="--init=/bin/sh --init-arg=-i" -fi - - -base="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" - -elf="$1" -bin="${elf%.elf}.bin" - -# Convert to binary format -aarch64-none-elf-objcopy -O binary "$elf" "$bin" -qemu-system-aarch64 -M virt,gic-version=3 -initrd moss.img -cpu cortex-a72 -m 2G -smp 4 -nographic -s -kernel "$bin" -append "$append_args --rootfs=ext4fs --automount=/dev,devfs --automount=/tmp,tmpfs --automount=/proc,procfs --automount=/sys,sysfs" diff --git a/scripts/qemu_runner.py b/scripts/qemu_runner.py new file mode 100755 index 00000000..5ffbd25f --- /dev/null +++ b/scripts/qemu_runner.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 + +import argparse +import subprocess + +parser = argparse.ArgumentParser(description="QEMU runner") + +parser.add_argument("elf_executable", help="Location of compiled ELF executable to run") +# QEMU options +parser.add_argument("--init", default="/bin/sh", help="Location of the init process (in the rootfs)") +parser.add_argument("--rootfs", default="moss.img", help="Location of the root filesystem image to use") +parser.add_argument("--cpu", default="cortex-a72") +parser.add_argument("--smp", default=4, help="Number of CPU cores to use") +parser.add_argument("--memory", default="2G") +parser.add_argument("--debug", action="store_true", help="Enable QEMU debugging") + + + +args = parser.parse_args() + + +elf_executable = args.elf_executable +bin_executable_location = elf_executable.replace(".elf", "") + ".bin" +# Convert the ELF executable to a binary format +subprocess.run(["aarch64-none-elf-objcopy", "-O", "binary", elf_executable, bin_executable_location], check=True) + +append_args = "" + +if args.init.split("/")[-1] in ["bash", "sh"]: + append_args = f"--init={args.init} --init-arg=-i" +else: + append_args = f"--init={args.init}" + +default_args = { + "-M": "virt,gic-version=3", + "-initrd": args.rootfs, + "-cpu": args.cpu, + "-m": args.memory, + "-smp": str(args.smp), + "-nographic": None, + "-s": None, + "-kernel": bin_executable_location, + "-append": f"{append_args} --rootfs=ext4fs --automount=/dev,devfs --automount=/tmp,tmpfs --automount=/proc,procfs --automount=/sys,sysfs" +} + +if args.debug: + default_args["-S"] = None + +qemu_command = ["qemu-system-aarch64"] + +for key, value in default_args.items(): + qemu_command.append(key) + if value is not None: + qemu_command.append(value) + +subprocess.run(qemu_command, check=True)