Skip to content

Commit a6c65f3

Browse files
committed
添加 CI 配置与自动化测试脚本
1 parent de36b2e commit a6c65f3

File tree

5 files changed

+227
-78
lines changed

5 files changed

+227
-78
lines changed

.axconfig.toml

Lines changed: 0 additions & 66 deletions
This file was deleted.

.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 Childtask 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" -- -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 "Multi-task 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 "$@"

src/main.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@
55
#[macro_use]
66
extern crate axstd as std;
77

8-
#[cfg(feature = "axstd")]
8+
#[cfg(all(feature = "axstd", feature = "multitask"))]
99
use std::os::arceos::modules::axhal::mem::phys_to_virt;
1010

1111
/// PFlash1 physical address on RISC-V 64 QEMU virt machine.
1212
/// pflash0 @ 0x20000000 (32MB), pflash1 @ 0x22000000 (32MB).
13-
#[cfg(all(feature = "axstd", target_arch = "riscv64"))]
13+
#[cfg(all(feature = "axstd", feature = "multitask", target_arch = "riscv64"))]
1414
const PFLASH_START: usize = 0x2200_0000;
1515

1616
/// PFlash1 physical address on AArch64 QEMU virt machine.
1717
/// pflash0 @ 0x00000000 (64MB), pflash1 @ 0x04000000 (64MB).
18-
#[cfg(all(feature = "axstd", target_arch = "aarch64"))]
18+
#[cfg(all(feature = "axstd", feature = "multitask", target_arch = "aarch64"))]
1919
const PFLASH_START: usize = 0x0400_0000;
2020

2121
/// PFlash0 physical address on x86_64 QEMU Q35 machine.
2222
/// 4MB flash image mapped at 4GB - 4MB = 0xFFC00000.
23-
#[cfg(all(feature = "axstd", target_arch = "x86_64"))]
23+
#[cfg(all(feature = "axstd", feature = "multitask", target_arch = "x86_64"))]
2424
const PFLASH_START: usize = 0xFFC0_0000;
2525

2626
/// PFlash1 physical address on LoongArch64 QEMU virt machine.
2727
/// VIRT_FLASH region starts at 0x1d000000. pflash0 is reserved for
2828
/// firmware, so we use pflash1. When pflash0 is absent, pflash1 maps
2929
/// at the base of the flash region: 0x1d000000.
30-
#[cfg(all(feature = "axstd", target_arch = "loongarch64"))]
30+
#[cfg(all(feature = "axstd", feature = "multitask", target_arch = "loongarch64"))]
3131
const PFLASH_START: usize = 0x1d00_0000;
3232

3333
#[cfg_attr(feature = "axstd", unsafe(no_mangle))]
@@ -47,7 +47,10 @@ fn main() {
4747
let va = phys_to_virt(PFLASH_START.into()).as_usize();
4848
let ptr = va as *const u32;
4949
let magic = unsafe {
50-
println!("Try to access pflash dev region [{:#X}], got {:#X}", va, *ptr);
50+
println!(
51+
"Try to access pflash dev region [{:#X}], got {:#X}",
52+
va, *ptr
53+
);
5154
(*ptr).to_ne_bytes()
5255
};
5356
if let Ok(s) = core::str::from_utf8(&magic) {
@@ -66,7 +69,9 @@ fn main() {
6669
}
6770
#[cfg(not(all(feature = "axstd", feature = "multitask")))]
6871
{
69-
println!("This application requires the 'axstd' and 'multitask' features for multi-task and PFlash access.");
72+
println!(
73+
"This application requires the 'axstd' and 'multitask' features for multi-task and PFlash access."
74+
);
7075
println!("Run with: cargo xtask run [--arch <ARCH>]");
7176
}
7277
}

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 childtask multi-architecture build & run tool
66
#[derive(Parser)]
7-
#[command(name = "xtask", about = "Build and run arceos-childtask on different architectures")]
7+
#[command(
8+
name = "xtask",
9+
about = "Build and run arceos-childtask 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)