diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d207d889..235b052b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,10 +2,10 @@ name: CI on: push: - branches: [ master ] + branches: [master] workflow_dispatch: pull_request: - branches: [ master ] + branches: [master] jobs: build-test: @@ -13,7 +13,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 # Use the toolchain from rust-toolchain.toml - name: Install Rust @@ -33,3 +33,31 @@ jobs: - name: Run unit tests for libkernel run: cargo test -p libkernel --target x86_64-unknown-linux-gnu --all-features + + - name: Install dependencies + run: sudo apt update && sudo apt install qemu-system-aarch64 dosfstools mtools binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu + + - name: Install arm GNU toolchain + run: | + wget https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-aarch64-none-elf.tar.xz + tar -xf arm-gnu-toolchain-15.2.rel1-x86_64-aarch64-none-elf.tar.xz + mv arm-gnu-toolchain-15.2.rel1-x86_64-aarch64-none-elf arm-gnu-toolchain + echo "${{ github.workspace }}/arm-gnu-toolchain/bin" >> $GITHUB_PATH + + - name: Build Image + run: | + wget https://github.com/arihant2math/prebuilt-musl/raw/refs/heads/main/aarch64-linux-musl-cross.tgz + mkdir build + mv aarch64-linux-musl-cross.tgz ./build/ + ls + ./scripts/build-deps.sh + ./scripts/create-image.sh + + - name: Upload Image + uses: actions/upload-artifact@v6 + with: + name: image + path: moss.img + + - name: Run userspace testing + run: CARGO_TARGET_AARCH64_UNKNOWN_NONE_SOFTFLOAT_RUNNER=./scripts/qemu-test-runner.sh cargo run -r diff --git a/.gitignore b/.gitignore index 45b53673..d6ef3072 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.img .idea/ .vscode/ +test_output.log diff --git a/scripts/qemu-test-runner.sh b/scripts/qemu-test-runner.sh new file mode 100755 index 00000000..0fc04f77 --- /dev/null +++ b/scripts/qemu-test-runner.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -euo pipefail + +base="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )" + +elf="$1" +bin="${elf%.elf}.bin" + +# Locate a suitable objcopy implementation (prefer bare-metal, fall back to linux/llvm/rust versions) +OBJCOPY=${OBJCOPY:-$(command -v aarch64-none-elf-objcopy \ + || command -v aarch64-linux-gnu-objcopy \ + || command -v llvm-objcopy \ + || command -v rust-objcopy)} + +if [[ -z "$OBJCOPY" ]]; then + echo "Error: no compatible aarch64 objcopy found (looked for aarch64-none-elf-objcopy, aarch64-linux-gnu-objcopy, llvm-objcopy, rust-objcopy)." >&2 + exit 1 +fi + +# Convert to binary format +"$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 "--init=/usertest --rootfs=fat32fs --automount=/dev,devfs --automount=/tmp,tmpfs"