diff --git a/.github/workflows/example.yaml b/.github/workflows/example.yaml index c31b430..71f77e6 100644 --- a/.github/workflows/example.yaml +++ b/.github/workflows/example.yaml @@ -5,32 +5,87 @@ on: push: jobs: - build-qemu: - runs-on: ubuntu-20.04 - steps: - - name: Install dependencies - run: sudo apt -y install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \ - gawk build-essential bison flex texinfo gperf libtool patchutils bc \ - zlib1g-dev libexpat-dev pkg-config libglib2.0-dev libpixman-1-dev libsdl2-dev libslirp-dev \ - git tmux python3 python3-pip ninja-build - - name: Get QEMU Source Code - run: wget https://github.com/qemu/qemu/archive/refs/tags/v9.0.0.tar.gz - - name: extract qemu source code - run: tar zxvf v9.0.0.tar.gz - - name: build qemu 9.0 - run: mkdir v9.0.0/build && cd v9.0.0/build && ../configure --target-list=riscv64-softmmu,aarch64-softmmu,x86_64-softmmu,loongarch64-softmmu - - name: make qemu 9.0 - run: cd v9.0.0/build && make -j8 + # build-qemu: + # runs-on: ubuntu-latest + # steps: + # - run: sudo apt update + # - name: Install dependencies + # run: sudo apt -y install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \ + # build-essential bison flex texinfo gperf libtool patchutils bc \ + # libexpat-dev pkg-config libglib2.0-dev libpixman-1-dev libsdl2-dev libslirp-dev \ + # tmux python3 python3-pip ninja-build + # - name: Get QEMU Source Code + # run: wget https://github.com/qemu/qemu/archive/refs/tags/v9.0.0.tar.gz + # - name: extract qemu source code + # run: tar zxvf v9.0.0.tar.gz + # - name: build qemu 9.0 + # run: mkdir v9.0.0/build && cd v9.0.0/build && ../configure --target-list=riscv64-softmmu,aarch64-softmmu,x86_64-softmmu,loongarch64-softmmu + # - name: make qemu 9.0 + # run: cd v9.0.0/build && make -j8 + test: - runs-on: ubuntu-20.04 - needs: build-qemu + runs-on: ubuntu-latest + container: + image: archlinux:base + volumes: + - .:/code strategy: fail-fast: false matrix: arch: [x86_64, riscv64, aarch64, loongarch64] + include: + - arch: aarch64 + packages: qemu-system-aarch64 + - arch: riscv64 + packages: qemu-system-riscv + - arch: x86_64 + packages: qemu-system-x86 + - arch: loongarch64 + packages: qemu-system-loongarch64 steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@nightly + - name: Install generaic tools + run: yes | pacman -Syy make cmake rustup gcc + - name: setup rust toolchain + run: rustup default nightly && cargo install cargo-binutils - name: Test ${{ matrix.arch }} - run: cd example && make ARCH=${{ matrix.arch }} build + run: cd example && PATH=$PATH:~/.cargo/bin make ARCH=${{ matrix.arch }} build + - name: Install Qemu + run: yes | pacman -Syy ${{ matrix.packages }} + - name: Test run + run: cd example && PATH=$PATH:~/.cargo/bin make ARCH=${{ matrix.arch }} run timeout-minutes: 1 + + template: + runs-on: ubuntu-latest + container: + image: archlinux:base + volumes: + - .:/code + strategy: + fail-fast: false + matrix: + arch: [x86_64, riscv64, aarch64, loongarch64] + include: + - arch: aarch64 + packages: qemu-system-aarch64 + - arch: riscv64 + packages: qemu-system-riscv + - arch: x86_64 + packages: qemu-system-x86 + - arch: loongarch64 + packages: qemu-system-loongarch64 + steps: + - name: Install generaic tools + run: yes | pacman -Syy make cmake rustup gcc git libgit2 libgit2-glib pkgconf openssl + - name: Install Rust toolchain + run: rustup default stable && cargo install cargo-binutils && cargo install cargo-generate + - name: generate by template + run: USER=test cargo generate --git https://github.com/Byte-OS/polyhal-template.git -n test-polyhal + - name: Install Qemu + run: yes | pacman -Syy ${{ matrix.packages }} + - name: test run + run: cd test-polyhal && (PATH=$PATH:~/.cargo/bin timeout 60 make ARCH=${{ matrix.arch }} run > output.log) || echo "qemu exited!" + timeout-minutes: 2 + - name: test log + run: grep "\[kernel\] exited successfully" test-polyhal/output.log diff --git a/.github/workflows/test-extranel.yaml b/.github/workflows/test-extranel.yaml new file mode 100644 index 0000000..29b8901 --- /dev/null +++ b/.github/workflows/test-extranel.yaml @@ -0,0 +1,24 @@ +name: TestExternal + +on: + workflow_dispatch: + push: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: convictional/trigger-workflow-and-wait@v1.6.1 + with: + owner: yfblock + repo: rcore-tutorial-v3-with-hal-component + github_token: ${{ secrets.PERSONAL_TOKEN }} + github_user: yfblock + workflow_file_name: test-run.yml + ref: ch7 + wait_interval: 10 + client_payload: '{"commit": "${{ github.sha}}"}' + propagate_failure: true + trigger_workflow: true + wait_workflow: true diff --git a/example/Makefile b/example/Makefile index 3cec0a3..ac09207 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,7 +1,12 @@ # Building ARCH := riscv64 +QEMU_EXEC := timeout 40 + + ifeq ($(ARCH), x86_64) TARGET := x86_64-unknown-none + KERNEL_ELF := target/$(TARGET)/release/example + KERNEL_BIN := $(KERNEL_ELF).bin QEMU_EXEC += qemu-system-x86_64 \ -machine q35 \ -kernel $(KERNEL_ELF) \ @@ -9,17 +14,23 @@ ifeq ($(ARCH), x86_64) BUS := pci else ifeq ($(ARCH), riscv64) TARGET := riscv64gc-unknown-none-elf + KERNEL_ELF := target/$(TARGET)/release/example + KERNEL_BIN := $(KERNEL_ELF).bin QEMU_EXEC += qemu-system-$(ARCH) \ -machine virt \ -kernel $(KERNEL_BIN) else ifeq ($(ARCH), aarch64) TARGET := aarch64-unknown-none-softfloat + KERNEL_ELF := target/$(TARGET)/release/example + KERNEL_BIN := $(KERNEL_ELF).bin QEMU_EXEC += qemu-system-$(ARCH) \ -cpu cortex-a72 \ -machine virt \ -kernel $(KERNEL_BIN) else ifeq ($(ARCH), loongarch64) TARGET := loongarch64-unknown-none + KERNEL_ELF := target/$(TARGET)/release/example + KERNEL_BIN := $(KERNEL_ELF).bin QEMU_EXEC += qemu-system-$(ARCH) -kernel $(KERNEL_ELF) BUILD_ARGS += -Z build-std=core,alloc BUS := pci @@ -27,9 +38,6 @@ else $(error "ARCH" must be one of "x86_64", "riscv64", "aarch64" or "loongarch64") endif -KERNEL_ELF := target/$(TARGET)/release/example -KERNEL_BIN := $(KERNEL_ELF).bin - # Binutils OBJDUMP := rust-objdump --arch-name=riscv64 OBJCOPY := rust-objcopy --binary-architecture=riscv64 @@ -54,15 +62,16 @@ clean: run: run-inner -QEMU_EXEC += -nographic -smp 1 +QEMU_EXEC += -nographic -smp 1 >output.log 2>&1 run-inner: build - $(QEMU_EXEC) + $(QEMU_EXEC) || echo "QEMU exited" + grep "\[kernel\] Hello, world!" output.log test: make ARCH=aarch64 run make ARCH=riscv64 run make ARCH=x86_64 run -# make ARCH=loongarch64 run + make ARCH=loongarch64 run .PHONY: build env kernel clean run-inner