-
Notifications
You must be signed in to change notification settings - Fork 18
Utilize GitHub Actions for building and running via QEMU #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
G36maid
wants to merge
1
commit into
sysprog21:main
Choose a base branch
from
G36maid:ci
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Check if at least one app is provided | ||
if [ $# -eq 0 ]; then | ||
echo "Usage: $0 <app1> [app2] [app3] ..." | ||
echo "Example: $0 hello echo cpubench" | ||
exit 1 | ||
fi | ||
|
||
APPS="$@" | ||
TIMEOUT=10 | ||
TOOLCHAIN_TYPE=${TOOLCHAIN_TYPE:-gnu} | ||
|
||
echo "[+] Will run apps: $APPS" | ||
echo "[+] Using toolchain: $TOOLCHAIN_TYPE" | ||
echo "" | ||
|
||
# Loop through each app | ||
for app in $APPS; do | ||
echo "=== Running $app ($TOOLCHAIN_TYPE) ===" | ||
|
||
# Build the app | ||
echo "[+] Building $app with $TOOLCHAIN_TYPE toolchain..." | ||
make clean >/dev/null 2>&1 | ||
if ! make "$app" TOOLCHAIN_TYPE="$TOOLCHAIN_TYPE" >/dev/null 2>&1; then | ||
echo "[!] Failed to build $app with $TOOLCHAIN_TYPE" | ||
echo "" | ||
continue | ||
fi | ||
|
||
# Run in QEMU with timeout | ||
echo "[+] Running $app in QEMU (timeout: ${TIMEOUT}s)..." | ||
set +e | ||
timeout ${TIMEOUT}s qemu-system-riscv32 -nographic -machine virt -bios none -kernel build/image.elf | ||
exit_code=$? | ||
set -e | ||
|
||
# Print result | ||
if [ $exit_code -eq 124 ]; then | ||
echo "[!] $app timed out" | ||
elif [ $exit_code -eq 0 ]; then | ||
echo "[✓] $app completed successfully" | ||
else | ||
echo "[!] $app failed with exit code $exit_code" | ||
fi | ||
echo "" | ||
done | ||
|
||
echo "[+] All apps tested with $TOOLCHAIN_TYPE toolchain" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Default to GNU if no toolchain specified | ||
TOOLCHAIN_TYPE=${1:-gnu} | ||
|
||
TOOLCHAIN_REPO=https://github.com/riscv-collab/riscv-gnu-toolchain | ||
TOOLCHAIN_VERSION=2025.05.30 | ||
TOOLCHAIN_OS=ubuntu-24.04 | ||
|
||
setup_gnu_toolchain() { | ||
echo "[+] Setting up GNU RISC-V toolchain..." | ||
|
||
local URL="${TOOLCHAIN_REPO}/releases/download/${TOOLCHAIN_VERSION}/riscv32-elf-${TOOLCHAIN_OS}-gcc-nightly-${TOOLCHAIN_VERSION}-nightly.tar.xz" | ||
|
||
echo "[+] Downloading RISC-V GNU toolchain..." | ||
wget -q "$URL" | ||
tar -xf "$(basename "$URL")" | ||
|
||
echo "[+] Exporting GNU toolchain path..." | ||
echo "$PWD/riscv/bin" >> "$GITHUB_PATH" | ||
|
||
# Set cross-compile prefix for GNU | ||
echo "CROSS_COMPILE=riscv32-unknown-elf-" >> "$GITHUB_ENV" | ||
echo "TOOLCHAIN_TYPE=gnu" >> "$GITHUB_ENV" | ||
} | ||
|
||
setup_llvm_toolchain() { | ||
echo "[+] Setting up LLVM RISC-V toolchain..." | ||
|
||
# upstream URL for LLVM toolchainzz2 | ||
local URL="${TOOLCHAIN_REPO}/releases/download/${TOOLCHAIN_VERSION}/riscv32-elf-${TOOLCHAIN_OS}-llvm-nightly-${TOOLCHAIN_VERSION}-nightly.tar.xz" | ||
|
||
echo "[+] Downloading RISC-V LLVM toolchain..." | ||
wget -q "$URL" | ||
tar -xf "$(basename "$URL")" | ||
|
||
echo "[+] Exporting LLVM toolchain path..." | ||
echo "$PWD/riscv/bin" >> "$GITHUB_PATH" | ||
|
||
# Set cross-compile prefix for LLVM | ||
echo "CROSS_COMPILE=riscv32-unknown-elf-" >> "$GITHUB_ENV" | ||
echo "TOOLCHAIN_TYPE=llvm" >> "$GITHUB_ENV" | ||
} | ||
|
||
case "$TOOLCHAIN_TYPE" in | ||
"gnu") | ||
setup_gnu_toolchain | ||
;; | ||
"llvm") | ||
setup_llvm_toolchain | ||
;; | ||
*) | ||
echo "Error: Unknown toolchain type '$TOOLCHAIN_TYPE'" | ||
echo "Usage: $0 [gnu|llvm]" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
echo "[+] Toolchain setup complete: $TOOLCHAIN_TYPE" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: Linmo CI | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
matrix-tests: | ||
runs-on: ubuntu-24.04 | ||
name: Test on ${{ matrix.toolchain }} toolchain | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
toolchain: [gnu, llvm] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install base dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y build-essential qemu-system-riscv32 wget | ||
|
||
- name: Setup ${{ matrix.toolchain }} toolchain | ||
run: .ci/setup-toolchain.sh ${{ matrix.toolchain }} | ||
|
||
- name: Verify toolchain installation | ||
run: | | ||
if [ "${{ matrix.toolchain }}" = "gnu" ]; then | ||
riscv32-unknown-elf-gcc --version | ||
else | ||
# LLVM toolchain fallback: try system llvm-objdump | ||
riscv32-unknown-elf-clang --version || clang --version | ||
riscv32-unknown-elf-llvm-objdump --version || llvm-objdump --version | ||
fi | ||
qemu-system-riscv32 --version | ||
|
||
- name: Build Kernel | ||
run: | | ||
make clean | ||
make | ||
env: | ||
TOOLCHAIN_TYPE: ${{ matrix.toolchain }} | ||
|
||
- name: Run Basic Apps | ||
id: test | ||
run: | | ||
output=$(.ci/run-qemu-tests.sh cpubench ) | ||
echo "TEST_OUTPUT<<EOF" >> $GITHUB_OUTPUT | ||
echo "$output" >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
env: | ||
TOOLCHAIN_TYPE: ${{ matrix.toolchain }} | ||
|
||
- name: Comment PR with results | ||
if: github.event_name == 'pull_request' | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const output = `${{ steps.test.outputs.TEST_OUTPUT }}`; | ||
const toolchain = `${{ matrix.toolchain }}`.toUpperCase(); | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `## Linmo QEMU App Test Result (${toolchain} Toolchain)\n\n\`\`\`\n${output}\n\`\`\`\n\n_This is an automated report from CI._` | ||
}); | ||
|
||
# Optional: Create a summary job that depends on all matrix jobs | ||
test-summary: | ||
runs-on: ubuntu-24.04 | ||
needs: matrix-tests | ||
if: always() | ||
|
||
steps: | ||
- name: Check test results | ||
run: | | ||
if [ "${{ needs.matrix-tests.result }}" = "success" ]; then | ||
echo "✅ All toolchain tests passed!" | ||
else | ||
echo "❌ Some toolchain tests failed" | ||
exit 1 | ||
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try Nightly: July 16, 2025