Skip to content

Commit 970f1c2

Browse files
YanLienYanLien
authored andcommitted
add CI workflow and test script
1 parent ba6cfea commit 970f1c2

3 files changed

Lines changed: 167 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, dev, master]
6+
pull_request:
7+
branches: [main, dev, master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
container: ghcr.io/chyyuu/tangram-crates
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Verify tools
19+
run: |
20+
echo "=== Checking Rust version ==="
21+
rustc --version --verbose
22+
echo ""
23+
echo "=== Checking QEMU version ==="
24+
qemu-system-riscv64 --version
25+
qemu-system-x86_64 --version
26+
qemu-system-aarch64 --version
27+
qemu-system-loongarch64 --version
28+
echo ""
29+
30+
- name: Run tests
31+
run: ./scripts/test.sh

scripts/test.sh

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "=== ArceOS Helloworld Test Script ==="
5+
echo ""
6+
7+
# Check if required tools are installed
8+
check_tools() {
9+
echo "[1/7] Checking required tools..."
10+
11+
if ! command -v cargo &> /dev/null; then
12+
echo "Error: cargo is not installed"
13+
exit 1
14+
fi
15+
16+
if ! command -v rust-objcopy &> /dev/null; then
17+
echo "Warning: cargo-binutils not installed, installing..."
18+
cargo install cargo-binutils
19+
fi
20+
21+
echo "✓ All required tools are available"
22+
echo ""
23+
}
24+
25+
# Format check
26+
check_format() {
27+
echo "[2/7] Checking code format..."
28+
cargo fmt -- --check
29+
echo "✓ Code format check passed"
30+
echo ""
31+
}
32+
33+
# Clippy lint check
34+
check_clippy() {
35+
echo "[3/7] Running clippy lint checks..."
36+
cargo clippy -- -D warnings
37+
echo "✓ Clippy check passed"
38+
echo ""
39+
}
40+
41+
# Basic build check (no default features to avoid platform-specific issues)
42+
check_build() {
43+
echo "[4/7] Checking basic build (no default features)..."
44+
cargo check --no-default-features
45+
echo "✓ Basic build check passed"
46+
echo ""
47+
}
48+
49+
# Run tests for each architecture
50+
run_arch_tests() {
51+
echo "[5/7] Running architecture-specific tests..."
52+
53+
local archs=("riscv64" "x86_64" "aarch64" "loongarch64")
54+
local qemu_ok=true
55+
56+
for arch in "${archs[@]}"; do
57+
echo ""
58+
echo "Testing architecture: $arch"
59+
60+
# Check if QEMU is available
61+
qemu_cmd="qemu-system-$arch"
62+
if ! command -v "$qemu_cmd" &> /dev/null; then
63+
echo "Warning: $qemu_cmd not found, skipping run test for $arch"
64+
qemu_ok=false
65+
continue
66+
fi
67+
68+
# Build and run
69+
if cargo xtask run --arch="$arch" 2>&1 | grep -q "Multi-task message queue OK!"; then
70+
echo "$arch test passed"
71+
else
72+
echo "Error: $arch test failed"
73+
exit 1
74+
fi
75+
done
76+
77+
if [ "$qemu_ok" = true ]; then
78+
echo ""
79+
echo "✓ All architecture tests passed"
80+
fi
81+
echo ""
82+
}
83+
84+
# Publish dry-run check
85+
check_publish() {
86+
echo "[6/7] Checking publish readiness..."
87+
cargo publish --dry-run --allow-dirty
88+
echo "✓ Publish check passed"
89+
echo ""
90+
}
91+
92+
# Summary
93+
print_summary() {
94+
echo "[7/7] Test Summary"
95+
echo "=================="
96+
echo "✓ All checks passed successfully!"
97+
echo ""
98+
echo "The following checks were performed:"
99+
echo " 1. Code format check (cargo fmt)"
100+
echo " 2. Lint check (cargo clippy)"
101+
echo " 3. Basic build check (cargo check)"
102+
echo " 4. Architecture tests (riscv64, x86_64, aarch64, loongarch64)"
103+
echo " 5. Publish readiness check (cargo publish --dry-run)"
104+
echo ""
105+
}
106+
107+
# Main execution
108+
main() {
109+
local skip_qemu=${SKIP_QEMU:-false}
110+
111+
check_tools
112+
check_format
113+
check_clippy
114+
check_build
115+
116+
if [ "$skip_qemu" = "true" ]; then
117+
echo "[5/7] Skipping architecture tests (SKIP_QEMU=true)"
118+
echo ""
119+
else
120+
run_arch_tests
121+
fi
122+
123+
check_publish
124+
print_summary
125+
}
126+
127+
# Run main function
128+
main "$@"

xtask/src/main.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use std::process::{self, Command};
44

55
/// ArceOS msgqueue multi-architecture build & run tool
66
#[derive(Parser)]
7-
#[command(name = "xtask", about = "Build and run arceos-msgqueue on different architectures")]
7+
#[command(
8+
name = "xtask",
9+
about = "Build and run arceos-msgqueue on different architectures"
10+
)]
811
struct Cli {
912
#[command(subcommand)]
1013
command: Cmd,
@@ -168,10 +171,10 @@ fn find_seabios() -> PathBuf {
168171
/// - loongarch64: pflash1 size is flexible (we use 4MB)
169172
fn pflash_size(arch: &str) -> usize {
170173
match arch {
171-
"riscv64" => 32 * 1024 * 1024, // 32MB - fixed by QEMU virt machine
172-
"aarch64" => 64 * 1024 * 1024, // 64MB - fixed by QEMU virt machine
173-
"x86_64" => 4 * 1024 * 1024, // 4MB
174-
"loongarch64" => 4 * 1024 * 1024, // 4MB
174+
"riscv64" => 32 * 1024 * 1024, // 32MB - fixed by QEMU virt machine
175+
"aarch64" => 64 * 1024 * 1024, // 64MB - fixed by QEMU virt machine
176+
"x86_64" => 4 * 1024 * 1024, // 4MB
177+
"loongarch64" => 4 * 1024 * 1024, // 4MB
175178
_ => 4 * 1024 * 1024,
176179
}
177180
}

0 commit comments

Comments
 (0)