|
| 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 "$@" |
0 commit comments