|
1 | 1 | #!/bin/bash |
| 2 | +# StarryOS test script – mirrors the structure of app-helloworld/scripts/test.sh. |
| 3 | +# |
| 4 | +# Usage: |
| 5 | +# ./scripts/test.sh [STEP] |
| 6 | +# |
| 7 | +# STEP (optional): run only the specified step (1–5). Omit to run all steps. |
| 8 | +# 1 – check required tools |
| 9 | +# 2 – code format check (cargo fmt --all) |
| 10 | +# 3 – per-architecture rootfs download + kernel build + QEMU boot test |
| 11 | +# 4 – publish readiness check (cargo publish --dry-run) |
| 12 | +# 5 – print test summary |
| 13 | +# |
| 14 | +# Environment variables: |
| 15 | +# SKIP_QEMU=true skip QEMU boot tests in step 3 (build only) |
| 16 | +# |
| 17 | +# Examples: |
| 18 | +# ./scripts/test.sh # run all five steps |
| 19 | +# ./scripts/test.sh 1 # tool check only |
| 20 | +# ./scripts/test.sh 3 # build + QEMU boot tests only |
| 21 | +# ./scripts/test.sh 4 # publish dry-run only |
| 22 | +# SKIP_QEMU=true ./scripts/test.sh 3 # build only, no QEMU |
| 23 | + |
2 | 24 | set -e |
3 | 25 |
|
4 | | -echo "=== StarryOS Test Script ===" |
5 | | -echo "" |
| 26 | +ARCHS=("riscv64" "aarch64" "loongarch64" "x86_64") |
6 | 27 |
|
7 | 28 | # -------------------------------------------------------------------------- |
8 | | -# [1/4] Check required tools |
| 29 | +# Step 1 – Check required tools |
9 | 30 | # -------------------------------------------------------------------------- |
10 | | -check_tools() { |
11 | | - echo "[1/4] Checking required tools..." |
| 31 | +step1_check_tools() { |
| 32 | + echo "[1/5] Checking required tools..." |
12 | 33 |
|
13 | 34 | local missing=false |
14 | 35 |
|
15 | 36 | for tool in make cargo python3; do |
16 | 37 | if ! command -v "$tool" &> /dev/null; then |
17 | | - echo "Error: '$tool' is not installed" |
| 38 | + echo " ERROR: '$tool' is not installed" |
18 | 39 | missing=true |
19 | 40 | fi |
20 | 41 | done |
21 | 42 |
|
22 | | - for arch in riscv64 aarch64 loongarch64 x86_64; do |
23 | | - qemu_cmd="qemu-system-${arch}" |
24 | | - if ! command -v "$qemu_cmd" &> /dev/null; then |
25 | | - echo "Warning: '$qemu_cmd' not found (QEMU test for $arch will be skipped)" |
| 43 | + for arch in "${ARCHS[@]}"; do |
| 44 | + if ! command -v "qemu-system-${arch}" &> /dev/null; then |
| 45 | + echo " WARNING: 'qemu-system-${arch}' not found (QEMU test for ${arch} will be skipped)" |
26 | 46 | fi |
27 | 47 | done |
28 | 48 |
|
29 | 49 | if [ "$missing" = "true" ]; then |
30 | | - echo "Error: missing required tools, aborting." |
| 50 | + echo "ERROR: missing required tools – aborting." |
31 | 51 | exit 1 |
32 | 52 | fi |
33 | 53 |
|
34 | | - echo "All required tools are available" |
| 54 | + echo " OK: all required tools are available" |
35 | 55 | echo "" |
36 | 56 | } |
37 | 57 |
|
38 | 58 | # -------------------------------------------------------------------------- |
39 | | -# [2/4] Code format check |
| 59 | +# Step 2 – Code format check |
40 | 60 | # -------------------------------------------------------------------------- |
41 | | -check_format() { |
42 | | - echo "[2/4] Checking code format..." |
| 61 | +step2_check_format() { |
| 62 | + echo "[2/5] Checking code format..." |
43 | 63 | cargo fmt --all -- --check |
44 | | - echo "Code format check passed" |
| 64 | + echo " OK: code format check passed" |
45 | 65 | echo "" |
46 | 66 | } |
47 | 67 |
|
48 | 68 | # -------------------------------------------------------------------------- |
49 | | -# [3/4] Per-architecture: rootfs download + build + QEMU boot test |
| 69 | +# Step 3 – Per-architecture: rootfs + build + QEMU boot test |
50 | 70 | # -------------------------------------------------------------------------- |
51 | | -run_arch_tests() { |
52 | | - echo "[3/4] Running architecture-specific build and boot tests..." |
| 71 | +step3_arch_tests() { |
| 72 | + local skip_qemu="${SKIP_QEMU:-false}" |
| 73 | + echo "[3/5] Running architecture-specific build and boot tests..." |
| 74 | + if [ "$skip_qemu" = "true" ]; then |
| 75 | + echo " NOTE: SKIP_QEMU=true – QEMU boot tests will be skipped" |
| 76 | + fi |
53 | 77 |
|
54 | | - local archs=("riscv64" "aarch64" "loongarch64" "x86_64") |
55 | 78 | local all_passed=true |
56 | 79 |
|
57 | | - for arch in "${archs[@]}"; do |
| 80 | + for arch in "${ARCHS[@]}"; do |
58 | 81 | echo "" |
59 | | - echo "--- Architecture: $arch ---" |
| 82 | + echo " --- Architecture: ${arch} ---" |
| 83 | + |
| 84 | + # Rootfs download (skipped by Makefile if image already exists) |
| 85 | + echo " [${arch}] Downloading rootfs..." |
| 86 | + cargo xtask rootfs --arch="${arch}" |
| 87 | + |
| 88 | + # Kernel build |
| 89 | + echo " [${arch}] Building kernel..." |
| 90 | + cargo xtask build --arch="${arch}" |
| 91 | + |
| 92 | + # QEMU boot test |
| 93 | + if [ "$skip_qemu" = "true" ]; then |
| 94 | + echo " [${arch}] Skipping QEMU boot test (SKIP_QEMU=true)" |
| 95 | + continue |
| 96 | + fi |
60 | 97 |
|
61 | | - # Check if QEMU is available for this arch |
62 | 98 | if ! command -v "qemu-system-${arch}" &> /dev/null; then |
63 | | - echo "Warning: qemu-system-${arch} not found, skipping $arch" |
| 99 | + echo " [${arch}] WARNING: qemu-system-${arch} not found, skipping boot test" |
64 | 100 | continue |
65 | 101 | fi |
66 | 102 |
|
67 | | - echo " Step 1: downloading rootfs for $arch..." |
68 | | - cargo xtask rootfs --arch="$arch" |
| 103 | + echo " [${arch}] Running QEMU boot test..." |
| 104 | + if cargo xtask test --arch="${arch}"; then |
| 105 | + echo " [${arch}] OK: boot test passed" |
| 106 | + else |
| 107 | + echo " [${arch}] ERROR: boot test FAILED" |
| 108 | + all_passed=false |
| 109 | + fi |
| 110 | + done |
| 111 | + |
| 112 | + echo "" |
| 113 | + if [ "$all_passed" = "true" ]; then |
| 114 | + echo " OK: all architecture tests passed" |
| 115 | + else |
| 116 | + echo "ERROR: one or more architecture tests failed" |
| 117 | + exit 1 |
| 118 | + fi |
| 119 | + echo "" |
| 120 | +} |
| 121 | + |
| 122 | +# -------------------------------------------------------------------------- |
| 123 | +# Step 4 – Publish readiness check |
| 124 | +# -------------------------------------------------------------------------- |
| 125 | +step4_publish() { |
| 126 | + echo "[4/5] Checking publish readiness (cargo publish --dry-run)..." |
69 | 127 |
|
70 | | - echo " Step 2: building kernel for $arch..." |
71 | | - cargo xtask build --arch="$arch" |
| 128 | + local all_passed=true |
72 | 129 |
|
73 | | - echo " Step 3: running boot test for $arch..." |
74 | | - if cargo xtask test --arch="$arch"; then |
75 | | - echo "$arch boot test passed" |
| 130 | + for arch in "${ARCHS[@]}"; do |
| 131 | + echo "" |
| 132 | + echo " --- Publish check: ${arch} ---" |
| 133 | + if cargo xtask publish --arch="${arch}"; then |
| 134 | + echo " [${arch}] OK: publish check passed" |
76 | 135 | else |
77 | | - echo "Error: $arch boot test FAILED" |
| 136 | + echo " [${arch}] ERROR: publish check FAILED" |
78 | 137 | all_passed=false |
79 | 138 | fi |
80 | 139 | done |
81 | 140 |
|
82 | 141 | echo "" |
83 | 142 | if [ "$all_passed" = "true" ]; then |
84 | | - echo "All architecture tests passed" |
| 143 | + echo " OK: all architecture publish checks passed" |
85 | 144 | else |
86 | | - echo "Error: one or more architecture tests failed" |
| 145 | + echo "ERROR: one or more publish checks failed" |
87 | 146 | exit 1 |
88 | 147 | fi |
89 | 148 | echo "" |
90 | 149 | } |
91 | 150 |
|
92 | 151 | # -------------------------------------------------------------------------- |
93 | | -# [4/4] Summary |
| 152 | +# Step 5 – Summary |
94 | 153 | # -------------------------------------------------------------------------- |
95 | | -print_summary() { |
96 | | - echo "[4/4] Test Summary" |
97 | | - echo "==================" |
98 | | - echo "All checks passed successfully!" |
| 154 | +step5_summary() { |
| 155 | + echo "[5/5] Test Summary" |
| 156 | + echo " ==============================" |
| 157 | + echo " OK: all requested steps completed successfully!" |
99 | 158 | echo "" |
100 | | - echo "The following checks were performed:" |
101 | | - echo " 1. Tool availability check (make, cargo, python3, qemu-system-*)" |
102 | | - echo " 2. Code format check (cargo fmt --all)" |
103 | | - echo " 3. Architecture build + boot tests (riscv64, aarch64, loongarch64, x86_64)" |
| 159 | + echo " Steps available in this script:" |
| 160 | + echo " 1 – tool availability check (make, cargo, python3, qemu-system-*)" |
| 161 | + echo " 2 – code format check (cargo fmt --all)" |
| 162 | + echo " 3 – per-arch build + boot (riscv64, aarch64, loongarch64, x86_64)" |
| 163 | + echo " 4 – publish readiness check (cargo publish --dry-run)" |
| 164 | + echo " 5 – summary" |
104 | 165 | echo "" |
105 | 166 | } |
106 | 167 |
|
| 168 | +# -------------------------------------------------------------------------- |
| 169 | +# Usage / help (prints only the leading comment block of this file) |
| 170 | +# -------------------------------------------------------------------------- |
| 171 | +usage() { |
| 172 | + # Print lines 2..N of this file that start with '#', stop at first blank |
| 173 | + # or non-comment line – those lines form the usage documentation block. |
| 174 | + tail -n +2 "$0" | while IFS= read -r line; do |
| 175 | + case "$line" in |
| 176 | + '#'*) printf '%s\n' "${line}" | sed 's/^#[[:space:]]*//' ;; |
| 177 | + *) break ;; |
| 178 | + esac |
| 179 | + done |
| 180 | + exit 0 |
| 181 | +} |
| 182 | + |
107 | 183 | # -------------------------------------------------------------------------- |
108 | 184 | # Main |
109 | 185 | # -------------------------------------------------------------------------- |
110 | 186 | main() { |
111 | | - local skip_qemu="${SKIP_QEMU:-false}" |
112 | | - |
113 | | - check_tools |
114 | | - check_format |
115 | | - |
116 | | - if [ "$skip_qemu" = "true" ]; then |
117 | | - echo "[3/4] Skipping architecture tests (SKIP_QEMU=true)" |
118 | | - echo "" |
119 | | - else |
120 | | - run_arch_tests |
121 | | - fi |
122 | | - |
123 | | - print_summary |
| 187 | + local step="${1:-all}" |
| 188 | + |
| 189 | + case "$step" in |
| 190 | + -h|--help) usage ;; |
| 191 | + all) |
| 192 | + echo "=== StarryOS Test Script (all steps) ===" |
| 193 | + echo "" |
| 194 | + step1_check_tools |
| 195 | + step2_check_format |
| 196 | + step3_arch_tests |
| 197 | + step4_publish |
| 198 | + step5_summary |
| 199 | + ;; |
| 200 | + 1) |
| 201 | + echo "=== StarryOS Test Script (step 1: tool check) ===" |
| 202 | + echo "" |
| 203 | + step1_check_tools |
| 204 | + ;; |
| 205 | + 2) |
| 206 | + echo "=== StarryOS Test Script (step 2: format check) ===" |
| 207 | + echo "" |
| 208 | + step2_check_format |
| 209 | + ;; |
| 210 | + 3) |
| 211 | + echo "=== StarryOS Test Script (step 3: arch build + boot tests) ===" |
| 212 | + echo "" |
| 213 | + step3_arch_tests |
| 214 | + ;; |
| 215 | + 4) |
| 216 | + echo "=== StarryOS Test Script (step 4: publish readiness check) ===" |
| 217 | + echo "" |
| 218 | + step4_publish |
| 219 | + ;; |
| 220 | + 5) |
| 221 | + echo "=== StarryOS Test Script (step 5: summary) ===" |
| 222 | + echo "" |
| 223 | + step5_summary |
| 224 | + ;; |
| 225 | + *) |
| 226 | + echo "ERROR: unknown step '${step}'. Valid values: 1, 2, 3, 4, 5, or omit for all." |
| 227 | + echo "Run '$0 --help' for usage." |
| 228 | + exit 1 |
| 229 | + ;; |
| 230 | + esac |
124 | 231 | } |
125 | 232 |
|
126 | 233 | main "$@" |
0 commit comments