Skip to content

Commit ac4b94d

Browse files
author
szy
committed
add test
1 parent aed2bfd commit ac4b94d

File tree

7 files changed

+284
-59
lines changed

7 files changed

+284
-59
lines changed

.axconfig.toml

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Architecture identifier.
2-
arch = "x86_64" # str
3-
# Platform Package.
4-
package = "axplat-x86-pc" # str
2+
arch = "riscv64" # str
3+
# Platform package.
4+
package = "axplat-riscv64-qemu-virt" # str
55
# Platform identifier.
6-
platform = "x86-pc" # str
6+
platform = "riscv64-qemu-virt" # str
77
# Stack size of each task.
88
task-stack-size = 0x40000 # uint
99
# Number of timer ticks per second (Hz). A timer tick may contain several timer
@@ -15,27 +15,67 @@ ticks-per-sec = 100 # uint
1515
#
1616
[devices]
1717
# IPI interrupt num
18-
ipi-irq = 0xf3 # uint
18+
ipi-irq = "0x8000_0000_0000_0001" # uint
1919
# MMIO ranges with format (`base_paddr`, `size`).
2020
mmio-ranges = [
21-
[0xb000_0000, 0x1000_0000],
22-
[0xfe00_0000, 0xc0_0000],
23-
[0xfec0_0000, 0x1000],
24-
[0xfed0_0000, 0x1000],
25-
[0xfee0_0000, 0x1000]
21+
[0x0010_1000, 0x1000],
22+
[0x0c00_0000, 0x21_0000],
23+
[0x1000_0000, 0x1000],
24+
[0x1000_1000, 0x8000],
25+
[0x3000_0000, 0x1000_0000],
26+
[0x4000_0000, 0x4000_0000]
2627
] # [(uint, uint)]
27-
# End PCI bus number.
28+
# End PCI bus number (`bus-range` property in device tree).
2829
pci-bus-end = 0xff # uint
29-
# Base physical address of the PCIe ECAM space (should read from ACPI 'MCFG' table).
30-
pci-ecam-base = 0xb000_0000 # uint
31-
# PCI device memory ranges (not used on x86).
32-
pci-ranges = [] # [(uint, uint)]
33-
# Timer interrupt frequency in Hz. (4.0GHz)
34-
timer-frequency = 4_000_000_000 # uint
30+
# Base physical address of the PCIe ECAM space.
31+
pci-ecam-base = 0x3000_0000 # uint
32+
# PCI device memory ranges (`ranges` property in device tree).
33+
pci-ranges = [
34+
[0x0300_0000, 0x1_0000],
35+
[0x4000_0000, 0x4000_0000],
36+
[0x4_0000_0000, 0x4_0000_0000]
37+
] # [(uint, uint)]
38+
# plic@c000000 {
39+
# phandle = <0x03>;
40+
# riscv,ndev = <0x5f>;
41+
# reg = <0x00 0xc000000 0x00 0x600000>;
42+
# interrupts-extended = <0x02 0x0b 0x02 0x09>;
43+
# interrupt-controller;
44+
# compatible = "sifive,plic-1.0.0\0riscv,plic0";
45+
# };
46+
plic-paddr = 0x0c00_0000 # uint
47+
# rtc@101000 {
48+
# interrupts = <0x0b>;
49+
# interrupt-parent = <0x03>;
50+
# reg = <0x00 0x101000 0x00 0x1000>;
51+
# compatible = "google,goldfish-rtc";
52+
# };
53+
# RTC (goldfish) Address
54+
rtc-paddr = 0x10_1000 # uint
55+
# Timer interrupt frequency in Hz.
56+
timer-frequency = 10_000_000 # uint
3557
# Timer interrupt num.
36-
timer-irq = 0xf0 # uint
58+
timer-irq = "0x8000_0000_0000_0005" # uint
59+
uart-irq = 0x0a # uint
60+
# serial@10000000 {
61+
# interrupts = <0x0a>;
62+
# interrupt-parent = <0x03>;
63+
# clock-frequency = "\08@";
64+
# reg = <0x00 0x10000000 0x00 0x100>;
65+
# compatible = "ns16550a";
66+
# };
67+
uart-paddr = 0x1000_0000 # uint
3768
# VirtIO MMIO ranges with format (`base_paddr`, `size`).
38-
virtio-mmio-ranges = [] # [(uint, uint)]
69+
virtio-mmio-ranges = [
70+
[0x1000_1000, 0x1000],
71+
[0x1000_2000, 0x1000],
72+
[0x1000_3000, 0x1000],
73+
[0x1000_4000, 0x1000],
74+
[0x1000_5000, 0x1000],
75+
[0x1000_6000, 0x1000],
76+
[0x1000_7000, 0x1000],
77+
[0x1000_8000, 0x1000]
78+
] # [(uint, uint)]
3979

4080
#
4181
# Platform configs
@@ -47,20 +87,20 @@ boot-stack-size = 0x40000 # uint
4787
# detection, it's also the number of CPUs to boot.
4888
max-cpu-num = 1
4989
# Kernel address space base.
50-
kernel-aspace-base = "0xffff_8000_0000_0000" # uint
90+
kernel-aspace-base = "0xffff_ffc0_0000_0000" # uint
5191
# Kernel address space size.
52-
kernel-aspace-size = "0x0000_7fff_ffff_f000" # uint
92+
kernel-aspace-size = "0x0000_003f_ffff_f000" # uint
5393
# Base physical address of the kernel image.
54-
kernel-base-paddr = 0x20_0000 # uint
94+
kernel-base-paddr = 0x8020_0000 # uint
5595
# Base virtual address of the kernel image.
56-
kernel-base-vaddr = "0xffff_8000_0020_0000" # uint
96+
kernel-base-vaddr = "0xffff_ffc0_8020_0000" # uint
5797
# Offset of bus address and phys address. some boards, the bus address is
5898
# different from the physical address.
5999
phys-bus-offset = 0 # uint
60100
# Base address of the whole physical memory.
61-
phys-memory-base = 0 # uint
101+
phys-memory-base = 0x8000_0000 # uint
62102
# Size of the whole physical memory. (128M)
63103
phys-memory-size = 0x800_0000 # uint
64104
# Linear mapping offset, for quick conversions between physical and virtual
65105
# addresses.
66-
phys-virt-offset = "0xffff_8000_0000_0000" # uint
106+
phys-virt-offset = "0xffff_ffc0_0000_0000" # uint

.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

payload/src/main.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,16 @@ use core::panic::PanicInfo;
1212
unsafe extern "C" fn _start() -> ! {
1313
unsafe {
1414
#[cfg(any(target_arch = "riscv64", target_arch = "riscv32"))]
15-
core::arch::asm!(
16-
"li a7, 93",
17-
"ecall",
18-
options(noreturn)
19-
);
15+
core::arch::asm!("li a7, 93", "ecall", options(noreturn));
2016

2117
#[cfg(target_arch = "aarch64")]
22-
core::arch::asm!(
23-
"mov x8, #93",
24-
"svc #0",
25-
options(noreturn)
26-
);
18+
core::arch::asm!("mov x8, #93", "svc #0", options(noreturn));
2719

2820
#[cfg(target_arch = "x86_64")]
29-
core::arch::asm!(
30-
"mov rax, 93",
31-
"syscall",
32-
options(noreturn)
33-
);
21+
core::arch::asm!("mov rax, 93", "syscall", options(noreturn));
3422

3523
#[cfg(target_arch = "loongarch64")]
36-
core::arch::asm!(
37-
"ori $a7, $zero, 93",
38-
"syscall 0",
39-
options(noreturn)
40-
);
24+
core::arch::asm!("ori $a7, $zero, 93", "syscall 0", options(noreturn));
4125
}
4226
}
4327

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" --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 -qF "monolithic kernel exit [0] normally!"; 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 --features "axstd" --allow-dirty --target="$target" --registry crates-io; 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/loader.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ pub fn load_user_app(fname: &str, uspace: &mut AddrSpace) -> Result<(), axio::Er
1313
.map_alloc(
1414
(APP_ENTRY).into(),
1515
axhal::mem::PAGE_SIZE_4K,
16-
MappingFlags::READ
17-
| MappingFlags::WRITE
18-
| MappingFlags::EXECUTE
19-
| MappingFlags::USER,
16+
MappingFlags::READ | MappingFlags::WRITE | MappingFlags::EXECUTE | MappingFlags::USER,
2017
true, // populate=true: allocate immediately
2118
)
2219
.map_err(|_| axio::Error::NoMemory)?;
@@ -35,6 +32,6 @@ fn load_file(fname: &str, buf: &mut [u8]) -> Result<usize, axio::Error> {
3532
ax_println!("app: {}", fname);
3633
let ctx = ROOT_FS_CONTEXT.get().expect("Root FS not initialized");
3734
let file = axfs::File::open(ctx, fname).map_err(|_| axio::Error::NotFound)?;
38-
let n = (&file).read(buf)?;
35+
let n = file.read(buf)?;
3936
Ok(n)
4037
}

0 commit comments

Comments
 (0)