Kaynağa Gözat

Merge pull request #44 from greatbridf/pipeline

Pipeline build and test support
greatbridf 6 ay önce
ebeveyn
işleme
4bb09f5ef9
3 değiştirilmiş dosya ile 88 ekleme ve 1 silme
  1. 66 0
      .github/workflows/test-build.yaml
  2. 9 1
      Makefile.src
  3. 13 0
      script/test.sh

+ 66 - 0
.github/workflows/test-build.yaml

@@ -0,0 +1,66 @@
+name: Test Build
+
+on:
+  push:
+    branches-ignore:
+      - comp-and-judge
+  pull_request:
+    branches-ignore:
+      - comp-and-judge
+  workflow_dispatch:
+
+jobs:
+  build-and-run-test:
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        arch: [riscv64, loongarch64]
+        include:
+          - arch: riscv64
+            target: riscv64gc-unknown-none-elf
+          - arch: loongarch64
+            target: loongarch64-unknown-none-softfloat
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v4
+
+      - name: Setup rust nightly
+        run: rustup component add rust-src llvm-tools
+
+      - name: Setup QEMU
+        run: |
+          sudo apt-get install -y qemu-system-${{ matrix.arch }} qemu-kvm
+
+      - name: Configure
+        run: ./configure
+
+      - name: Run build for ${{ matrix.arch }} targets
+        run: |
+          make build ARCH=${{ matrix.arch }} MODE=release
+          zstd -k build/boot-${{ matrix.arch }}.img
+
+      - name: Upload build artifacts
+        uses: actions/upload-artifact@v4
+        with:
+          name: eonix-kernel-and-image-${{ matrix.arch }}
+          path: |
+            build/${{ matrix.target }}/release/eonix_kernel
+            build/boot-${{ matrix.arch }}.img.zst
+
+      - name: Test run for ${{ matrix.arch }}
+        run: |
+          echo "Fixing permissions for /dev/kvm..."
+          sudo adduser $USER kvm
+          sh script/test.sh
+        env:
+          ARCH: ${{ matrix.arch }}
+          QEMU_ACCEL: ''
+        timeout-minutes: 2
+        continue-on-error: true
+
+      - name: Upload run log
+        uses: actions/upload-artifact@v4
+        with:
+          name: test-${{ matrix.arch }}.log
+          path: build/test-*.log

+ 9 - 1
Makefile.src

@@ -21,15 +21,19 @@ KERNEL_SOURCES := $(shell find src macros crates -name '*.rs' -type f)
 KERNEL_CARGO_MANIFESTS += $(shell find src macros crates -name Cargo.toml -type f)
 KERNEL_DEPS := $(KERNEL_SOURCES) $(KERNEL_CARGO_MANIFESTS)
 
-QEMU_ARGS ?= -no-reboot -no-shutdown
+QEMU_ARGS ?= -no-reboot
 CARGO_FLAGS := --profile $(PROFILE) --features $(FEATURES)$(if $(SMP),$(COMMA)smp,)
 
 ifeq ($(HOST),darwin)
 QEMU_ACCEL ?= -accel tcg
 else ifeq ($(HOST),linux)
+
+ifeq ($(shell ls /dev/kvm),/dev/kvm)
 QEMU_ACCEL ?= -accel kvm
 endif
 
+endif
+
 QEMU_ARGS += $(QEMU_ACCEL)
 
 ifneq ($(DEBUG_TRAPS),)
@@ -122,6 +126,10 @@ run: build build/kernel.sym
 srun: build build/kernel.sym
 	$(QEMU) $(QEMU_ARGS) -display none -S -s -serial mon:stdio
 
+.PHONY: test-run
+test-run: build
+	$(QEMU) $(QEMU_ARGS) -display none -serial stdio
+
 .PHONY: clean
 clean:
 	-rm -rf build

+ 13 - 0
script/test.sh

@@ -0,0 +1,13 @@
+#!/bin/sh
+
+SUCCESS_MSG="###$RANDOM :SuCCeSS: $RANDOM###"
+
+if [ "$ARCH" = "" ]; then
+    echo "Error: ARCH environment variable is not set." >&2
+    exit 1
+fi
+
+printf "ls\necho \"$SUCCESS_MSG\"\npoweroff\n" \
+    | make test-run ARCH=$ARCH MODE=release QEMU=qemu-system-$ARCH \
+    | tee build/test-$$.log \
+    | grep "$SUCCESS_MSG" > /dev/null && echo TEST\ $$\ WITH\ ARCH=$ARCH\ PASSED