Skip to content

Commit 3ce3ee1

Browse files
committed
fix: add local test script and ci workflow
1 parent 5c66f4c commit 3ce3ee1

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-0
lines changed

.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: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "=== ArceOS Lazymapping 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 by architecture
34+
check_clippy() {
35+
echo "[3/7] Running clippy lint checks..."
36+
37+
local archs=("riscv64" "x86_64" "aarch64" "loongarch64")
38+
local targets=("riscv64gc-unknown-none-elf" "x86_64-unknown-none" "aarch64-unknown-none-softfloat" "loongarch64-unknown-none")
39+
40+
for i in "${!archs[@]}"; do
41+
local arch="${archs[$i]}"
42+
local target="${targets[$i]}"
43+
44+
echo ""
45+
echo "Running clippy for architecture: $arch"
46+
47+
# Install config file for the architecture
48+
cp "configs/${arch}.toml" ".axconfig.toml"
49+
50+
if cargo clippy --target="$target" --features="axstd" -- -D warnings; then
51+
echo "$arch clippy check passed"
52+
else
53+
echo "Error: $arch clippy check failed"
54+
rm -f .axconfig.toml
55+
exit 1
56+
fi
57+
done
58+
59+
rm -f .axconfig.toml
60+
echo ""
61+
echo "✓ All architecture clippy checks passed"
62+
echo ""
63+
}
64+
65+
# Basic build check (no default features to avoid platform-specific issues)
66+
check_build() {
67+
echo "[4/7] Checking basic build (no default features)..."
68+
cargo check --no-default-features
69+
echo "✓ Basic build check passed"
70+
echo ""
71+
}
72+
73+
# Run tests for each architecture
74+
run_arch_tests() {
75+
echo "[5/7] Running architecture-specific tests..."
76+
77+
local archs=("riscv64" "x86_64" "aarch64" "loongarch64")
78+
local qemu_ok=true
79+
80+
for arch in "${archs[@]}"; do
81+
echo ""
82+
echo "Testing architecture: $arch"
83+
84+
# Check if QEMU is available
85+
qemu_cmd="qemu-system-$arch"
86+
if ! command -v "$qemu_cmd" &> /dev/null; then
87+
echo "Warning: $qemu_cmd not found, skipping run test for $arch"
88+
qemu_ok=false
89+
continue
90+
fi
91+
92+
# Build and run
93+
if cargo xtask run --arch="$arch" 2>&1 | grep -q "handle page fault OK!"; then
94+
echo "$arch test passed"
95+
else
96+
echo "Error: $arch test failed"
97+
exit 1
98+
fi
99+
done
100+
101+
if [ "$qemu_ok" = true ]; then
102+
echo ""
103+
echo "✓ All architecture tests passed"
104+
fi
105+
echo ""
106+
}
107+
108+
# Publish dry-run check by architecture
109+
check_publish() {
110+
echo "[6/7] Checking publish readiness..."
111+
112+
local archs=("riscv64" "x86_64" "aarch64" "loongarch64")
113+
local targets=("riscv64gc-unknown-none-elf" "x86_64-unknown-none" "aarch64-unknown-none-softfloat" "loongarch64-unknown-none")
114+
115+
for i in "${!archs[@]}"; do
116+
local arch="${archs[$i]}"
117+
local target="${targets[$i]}"
118+
119+
echo ""
120+
echo "Checking publish for architecture: $arch"
121+
122+
# Install config file for the architecture
123+
cp "configs/${arch}.toml" ".axconfig.toml"
124+
125+
if cargo publish --dry-run --allow-dirty --target="$target"; then
126+
echo "$arch publish check passed"
127+
else
128+
echo "Error: $arch publish check failed"
129+
rm -f .axconfig.toml
130+
exit 1
131+
fi
132+
done
133+
134+
rm -f .axconfig.toml
135+
echo ""
136+
echo "✓ All architecture publish checks passed"
137+
echo ""
138+
}
139+
140+
# Summary
141+
print_summary() {
142+
echo "[7/7] Test Summary"
143+
echo "=================="
144+
echo "✓ All checks passed successfully!"
145+
echo ""
146+
echo "The following checks were performed:"
147+
echo " 1. Code format check (cargo fmt)"
148+
echo " 2. Lint check (cargo clippy)"
149+
echo " 3. Basic build check (cargo check)"
150+
echo " 4. Architecture tests (riscv64, x86_64, aarch64, loongarch64)"
151+
echo " 5. Publish readiness check (cargo publish --dry-run)"
152+
echo ""
153+
}
154+
155+
# Main execution
156+
main() {
157+
local skip_qemu=${SKIP_QEMU:-false}
158+
159+
check_tools
160+
check_format
161+
check_clippy
162+
check_build
163+
164+
if [ "$skip_qemu" = "true" ]; then
165+
echo "[5/7] Skipping architecture tests (SKIP_QEMU=true)"
166+
echo ""
167+
else
168+
run_arch_tests
169+
fi
170+
171+
check_publish
172+
print_summary
173+
}
174+
175+
# Run main function
176+
main "$@"

0 commit comments

Comments
 (0)