Debian Codegraph @

test/run-tests

raw symbols SCIP
1 #!/bin/bash
2 # run-tests — Multi-kernel test orchestrator
3 #
4 # Entry point for the quotatool test suite. Reads kernels.conf, boots
5 # each kernel in a VM, runs the full test suite inside it, collects
6 # results.
7 #
8 # Usage:
9 # ./run-tests # run all kernels
10 # ./run-tests --jobs 4 # run 4 kernels in parallel
11 # ./run-tests --tier 1 # run tier 1 only
12 # ./run-tests --kernel alma-8 # run one kernel
13 # ./run-tests --host-only # run on host kernel only (fast)
14 # ./run-tests --timeout 600 # per-kernel timeout (default: 300)
15
16 set -euo pipefail
17
18 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
19 CONF="$SCRIPT_DIR/kernels/kernels.conf"
20 RESULTS_DIR="$SCRIPT_DIR/results"
21
22 # Source boot layer (boot.sh enables set -e which we don't want —
23 # run-tests needs to continue after test failures)
24 source "$SCRIPT_DIR/lib/boot.sh"
25 set +e
26
27 # Colors (if terminal)
28 if [[ -t 1 ]]; then
29 RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[0;33m'
30 BLUE='\033[0;34m'; BOLD='\033[1m'; NC='\033[0m'
31 else
32 RED=''; GREEN=''; YELLOW=''; BLUE=''; BOLD=''; NC=''
33 fi
34
35 # ---------------------------------------------------------------------------
36 # Helpers
37 # ---------------------------------------------------------------------------
38
39 # Find the vmlinuz path for an extracted kernel.
40 find_vmlinuz() {
41 local name="$1"
42 local dir="$SCRIPT_DIR/kernels/$name/extracted"
43 ls "$dir"/boot/vmlinu* 2>/dev/null | grep -v '\.gz$' | head -1 && return
44 find "$dir/lib/modules" -maxdepth 2 -name "vmlinuz" 2>/dev/null | head -1 && return
45 find "$dir/usr/lib/modules" -maxdepth 2 -name "vmlinuz" 2>/dev/null | head -1
46 }
47
48 # Check if a kernel has 9p filesystem support (module or built-in).
49 has_9p() {
50 local name="$1"
51 local dir="$SCRIPT_DIR/kernels/$name/extracted"
52 # Check for 9p.ko module (any compression: .ko, .ko.xz, .ko.zst)
53 find "$dir" -name "9p.ko" -o -name "9p.ko.*" 2>/dev/null | grep -q . && return 0
54 # Check modules.builtin for 9p filesystem (not 9pnet)
55 local builtin
56 builtin=$(find "$dir" -name "modules.builtin" 2>/dev/null | head -1)
57 [[ -n "$builtin" ]] && grep -q '/9p\.ko' "$builtin" 2>/dev/null && return 0
58 return 1
59 }
60
61 # Check if a kernel version is below the host glibc floor.
62 # Returns 0 (true) if kernel_version < GLIBC_MIN_KVER.
63 _below_glibc_floor() {
64 local version="$1"
65 [[ -n "$GLIBC_MIN_KVER" ]] || return 1 # no floor detected = not below
66 # sort -V: if kernel comes first, it's lower than floor
67 [[ "$(printf '%s\n' "$version" "$GLIBC_MIN_KVER" | sort -V | head -1)" == "$version" \
68 && "$version" != "$GLIBC_MIN_KVER" ]]
69 }
70
71 # Check if a kernel needs the Alpine rootfs (below glibc floor OR no 9p).
72 # Returns 0 (true) if Alpine rootfs should be used.
73 _needs_alpine_rootfs() {
74 local name="$1" version="$2"
75 _below_glibc_floor "$version" && return 0
76 ! has_9p "$name" && return 0
77 return 1
78 }
79
80 # Check if a kernel has a cached pass result from a previous run.
81 # Returns 0 (true) if results/<name>.log exists and shows 0 failures.
82 _is_cached_pass() {
83 local name="$1"
84 local result_file="$RESULTS_DIR/${name}.log"
85 [[ -f "$result_file" ]] \
86 && grep -qE '^Results:.*0 failed' "$result_file" 2>/dev/null
87 }
88
89 # Print result line for a completed kernel test.
90 # Args: $1=name $2=version $3=boot_path $4=exit_code
91 _print_result() {
92 local name="$1" version="$2" actual_boot="$3" rc="$4"
93 local result_file="$RESULTS_DIR/${name}.log"
94
95 printf "%-20s %-8s %-12s " "$name" "$version" "$actual_boot"
96 if [[ $rc -eq 0 ]]; then
97 local summary
98 summary=$(grep -E '^Results:' "$result_file" 2>/dev/null | tail -1 || true)
99 echo -e "${GREEN}PASS${NC} $summary"
100 elif [[ $rc -eq 124 || $rc -eq 137 ]]; then
101 echo -e "${RED}TIMEOUT${NC} (${OPT_TIMEOUT}s)"
102 else
103 local failures
104 failures=$(grep -E '^ FAIL:' "$result_file" 2>/dev/null | head -5 || true)
105 echo -e "${RED}FAIL${NC} (exit $rc)"
106 [[ -n "$failures" ]] && echo "$failures" | sed 's/^/ /'
107 fi
108 }
109
110 # ---------------------------------------------------------------------------
111 # Main
112 # ---------------------------------------------------------------------------
113
114 usage() {
115 cat <<'EOF'
116 Usage: run-tests [OPTIONS]
117
118 Run the quotatool test suite across multiple kernels.
119
120 Options:
121 --all Run the full kernel matrix (all 25 kernels)
122 --setup Bootstrap test infrastructure: check deps, download
123 kernels, build initramfs/rootfs. Does not run tests.
124 --smoke Quick infrastructure check (~30s). Boots one kernel
125 per boot path (virtme, QEMU+9p, QEMU+rootfs) and
126 runs a minimal test on each.
127 --list Show all kernels with boot method, tier, and status
128 --jobs N Run N kernels in parallel (default: 1 = sequential)
129 --only-failed Only re-run kernels that failed in the previous run
130 --tier N Only run kernels of tier N (1, 2, or 3)
131 Tiers: 1=actively supported, 2=recently EOL, 3=historical
132 --kernel NAME Only run the named kernel
133 --quick Argument validation tests only (no root, no VM, instant)
134 --host-only Run tests on the host kernel only (no kernel matrix)
135 --interactive Boot a kernel with quota filesystems and drop to shell.
136 Use with --kernel NAME for a specific kernel, or alone
137 for the host kernel. Type 'exit' to tear down.
138 --timeout SECS Per-kernel timeout in seconds (default: 120)
139 -v, --verbose Verbose boot output (forces --jobs 1)
140 -h, --help Show this help
141 EOF
142 }
143
144 OPT_ALL=0
145 OPT_TIER=""
146 OPT_KERNEL=""
147 OPT_HOST_ONLY=0
148 OPT_QUICK=0
149 OPT_INTERACTIVE=0
150 OPT_SETUP=0
151 OPT_SMOKE=0
152 OPT_LIST=0
153 OPT_TIMEOUT="120"
154 OPT_VERBOSE="0"
155 OPT_JOBS=1
156 OPT_ONLY_FAILED=0
157
158 # No arguments: show help
159 if [[ $# -eq 0 ]]; then
160 usage
161 exit 0
162 fi
163
164 while [[ $# -gt 0 ]]; do
165 case "$1" in
166 --all) OPT_ALL=1; shift ;;
167 --setup) OPT_SETUP=1; shift ;;
168 --smoke) OPT_SMOKE=1; shift ;;
169 --list) OPT_LIST=1; shift ;;
170 --jobs) OPT_JOBS="$2"; shift 2 ;;
171 -j) OPT_JOBS="$2"; shift 2 ;;
172 --only-failed) OPT_ONLY_FAILED=1; shift ;;
173 --tier) OPT_TIER="$2"; shift 2 ;;
174 --kernel) OPT_KERNEL="$2"; shift 2 ;;
175 --quick) OPT_QUICK=1; shift ;;
176 --host-only) OPT_HOST_ONLY=1; shift ;;
177 --interactive) OPT_INTERACTIVE=1; shift ;;
178 --timeout) OPT_TIMEOUT="$2"; shift 2 ;;
179 -v|--verbose) OPT_VERBOSE="1"; shift ;;
180 -h|--help) usage; exit 0 ;;
181 *) echo "Unknown option: $1" >&2; exit 1 ;;
182 esac
183 done
184
185 # Verbose forces sequential (interleaved output is useless)
186 if [[ "$OPT_VERBOSE" == "1" && $OPT_JOBS -gt 1 ]]; then
187 OPT_JOBS=1
188 fi
189
190 PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
191 QUOTATOOL="$PROJECT_DIR/quotatool"
192 INITRAMFS_DIR="$SCRIPT_DIR/kernels/initramfs"
193 KERNELS_DIR="$SCRIPT_DIR/kernels"
194 GUEST_CMD="$SCRIPT_DIR/guest-run-all.sh"
195 HOST_TESTS_DIR="$SCRIPT_DIR/tests/host"
196
197 # Export boot options early — needed by --host-only which exits before
198 # the kernel matrix section where these were previously set.
199 export BOOT_TIMEOUT="$OPT_TIMEOUT"
200 export BOOT_VERBOSE="$OPT_VERBOSE"
201
202 # Detect glibc floor early — needed by --interactive which runs before pre-flight.
203 GLIBC_MIN_KVER=""
204 _glibc_min=$(file -L /bin/sh 2>/dev/null | sed -n 's/.*for GNU\/Linux \([0-9.]\+\).*/\1/p' || true)
205 [[ -n "$_glibc_min" ]] && GLIBC_MIN_KVER="$_glibc_min"
206
207 # ---------------------------------------------------------------------------
208 # Quick tests (no root, no VM — argument validation only)
209 # ---------------------------------------------------------------------------
210
211 _run_quick_tests() {
212 echo -e "${BOLD}Quick tests (argument validation, no VM)${NC}"
213 echo ""
214 if [[ ! -f "$HOST_TESTS_DIR/t-error-args.sh" ]]; then
215 echo -e "${RED}FAIL${NC}: $HOST_TESTS_DIR/t-error-args.sh not found"
216 return 1
217 fi
218 "$HOST_TESTS_DIR/t-error-args.sh" "$QUOTATOOL"
219 }
220
221 # ---------------------------------------------------------------------------
222 # Setup / bootstrap
223 # ---------------------------------------------------------------------------
224
225 _setup_step() {
226 echo -e "${BLUE}==> $1${NC}"
227 }
228
229 # Check quotatool binary exists (we don't build it — that's the user's job)
230 if [[ ! -x "$QUOTATOOL" ]]; then
231 echo -e "${RED}quotatool binary not found.${NC} Run: ${BOLD}./configure && make${NC}"
232 exit 1
233 fi
234
235 # Check for stale test image files owned by another user (e.g. root).
236 # These cause virtme overlay COW failures (ENOSPC) since the overlay
237 # must copy the entire file to its upper layer before writing.
238 for _img in /tmp/test-ext4.img /tmp/test-xfs.img; do
239 if [[ -f "$_img" ]] && [[ "$(stat -c %u "$_img")" != "$(id -u)" ]]; then
240 echo -e "${RED}Stale test image found: $_img (owned by $(stat -c %U "$_img"))${NC}"
241 echo -e "Remove it first: ${BOLD}sudo rm -f $_img${NC}"
242 exit 1
243 fi
244 done
245
246 if [[ $OPT_SETUP -eq 1 ]]; then
247 echo -e "${BOLD}Setting up test framework...${NC}"
248 echo ""
249
250 # Step 1: check host dependencies
251 _setup_step "Checking host dependencies..."
252 if ! "$SCRIPT_DIR/check-deps.sh"; then
253 echo ""
254 echo -e "${RED}Missing required dependencies. Install them and re-run.${NC}"
255 exit 1
256 fi
257 echo ""
258
259 # Step 2: busybox for initramfs
260 if [[ ! -f "$INITRAMFS_DIR/busybox-musl" ]]; then
261 _setup_step "Downloading busybox (musl-static)..."
262 "$INITRAMFS_DIR/build-busybox.sh"
263 echo ""
264 fi
265
266 # Step 3: build initramfs
267 if [[ ! -f "$INITRAMFS_DIR/initramfs.cpio.gz" ]]; then
268 _setup_step "Building initramfs..."
269 "$INITRAMFS_DIR/build.sh"
270 echo ""
271 fi
272
273 # Step 4: download kernels (idempotent — skips already-extracted kernels)
274 _setup_step "Checking/downloading vendor kernels..."
275 "$KERNELS_DIR/download.sh"
276 echo ""
277
278 # Step 5: build Alpine rootfs (musl-based, for RHEL + glibc-floor kernels)
279 local_alpine="$KERNELS_DIR/alpine-rootfs.img"
280 if [[ ! -f "$local_alpine" ]]; then
281 if [[ -x "$KERNELS_DIR/build-alpine-rootfs.sh" ]]; then
282 _setup_step "Building Alpine rootfs (musl-based, for old/RHEL kernels)..."
283 if ! "$KERNELS_DIR/build-alpine-rootfs.sh"; then
284 echo -e "${YELLOW}WARNING: Alpine rootfs build failed. Old/RHEL kernel tests will be skipped.${NC}"
285 fi
286 echo ""
287 fi
288 elif [[ "$QUOTATOOL" -nt "$local_alpine" ]]; then
289 _setup_step "Rebuilding Alpine rootfs (quotatool binary is newer)..."
290 "$KERNELS_DIR/build-alpine-rootfs.sh" --force || true
291 echo ""
292 fi
293
294 echo -e "${GREEN}Setup complete.${NC}"
295 echo -e " Verify: ${BOLD}test/run-tests --smoke${NC}"
296 echo -e " Run: ${BOLD}test/run-tests${NC}"
297 echo -e " Options: ${BOLD}test/run-tests --help${NC}"
298 exit 0
299 fi
300
301 # ---------------------------------------------------------------------------
302 # Quick mode: no infrastructure needed, run and exit
303 # ---------------------------------------------------------------------------
304
305 if [[ $OPT_QUICK -eq 1 ]]; then
306 _run_quick_tests
307 exit $?
308 fi
309
310 # ---------------------------------------------------------------------------
311 # Host-only mode: only needs host kernel, not full infrastructure
312 # ---------------------------------------------------------------------------
313
314 if [[ $OPT_HOST_ONLY -eq 1 ]]; then
315 # Quick tests first (no VM)
316 _run_quick_tests || { echo -e "\n${RED}Quick tests failed — aborting.${NC}"; exit 1; }
317 echo ""
318
319 # Host value tests (VM, host kernel)
320 if [[ -x "$HOST_TESTS_DIR/guest-run-host-tests.sh" ]]; then
321 echo -e "${BOLD}Host value tests (VM, host kernel $(uname -r))${NC}"
322 echo ""
323 boot_host_kernel "$HOST_TESTS_DIR/guest-run-host-tests.sh" || exit $?
324 echo ""
325 fi
326
327 # Full test suite on host kernel
328 echo -e "${BOLD}Full test suite (host kernel $(uname -r))${NC}"
329 echo ""
330 boot_host_kernel "$GUEST_CMD"
331 exit $?
332 fi
333
334 # ---------------------------------------------------------------------------
335 # Interactive mode: boot a kernel with quota filesystems, drop to shell
336 # ---------------------------------------------------------------------------
337
338 if [[ $OPT_INTERACTIVE -eq 1 ]]; then
339 INTERACTIVE_CMD="$SCRIPT_DIR/guest-interactive.sh"
340 if [[ ! -x "$INTERACTIVE_CMD" ]]; then
341 echo -e "${RED}guest-interactive.sh not found${NC}"
342 exit 1
343 fi
344
345 if [[ -z "$OPT_KERNEL" ]]; then
346 # No --kernel: use host kernel
347 echo -e "${BOLD}Interactive shell — host kernel $(uname -r)${NC}"
348 boot_kernel_interactive "/boot/vmlinuz-$(uname -r)" "$INTERACTIVE_CMD"
349 exit $?
350 else
351 # --kernel NAME: find and boot that kernel
352 vmlinuz=$(find_vmlinuz "$OPT_KERNEL" || true)
353 if [[ -z "$vmlinuz" ]]; then
354 echo -e "${RED}Kernel '$OPT_KERNEL' not found. Run --setup or check --list.${NC}"
355 exit 1
356 fi
357 version=$(boot_kernel_version "$vmlinuz" 2>/dev/null || echo "unknown")
358 echo -e "${BOLD}Interactive shell — $OPT_KERNEL (kernel $version)${NC}"
359
360 # Check if this kernel needs Alpine rootfs
361 if _needs_alpine_rootfs "$OPT_KERNEL" "$version"; then
362 alpine_rootfs="$KERNELS_DIR/alpine-rootfs.img"
363 if [[ ! -f "$alpine_rootfs" ]]; then
364 echo -e "${RED}Alpine rootfs needed but not built. Run --setup.${NC}"
365 exit 1
366 fi
367 BOOT_METHOD=qemu BOOT_ROOTFS="$alpine_rootfs" \
368 boot_kernel_interactive "$vmlinuz" "$INTERACTIVE_CMD"
369 else
370 boot_kernel_interactive "$vmlinuz" "$INTERACTIVE_CMD"
371 fi
372 exit $?
373 fi
374 fi
375
376 # ---------------------------------------------------------------------------
377 # Require --all (or --kernel/--tier/--only-failed) for kernel matrix
378 # ---------------------------------------------------------------------------
379
380 if [[ $OPT_ALL -eq 0 && -z "$OPT_KERNEL" && -z "$OPT_TIER" && $OPT_ONLY_FAILED -eq 0 && $OPT_LIST -eq 0 && $OPT_SMOKE -eq 0 ]]; then
381 echo -e "${RED}No test mode specified.${NC} Use ${BOLD}--all${NC} for full matrix, or see ${BOLD}--help${NC}."
382 exit 1
383 fi
384
385 # ---------------------------------------------------------------------------
386 # Pre-flight: bail if --setup hasn't been run (needed for kernel matrix)
387 # ---------------------------------------------------------------------------
388
389 if [[ ! -f "$INITRAMFS_DIR/initramfs.cpio.gz" ]]; then
390 echo -e "${RED}Test infrastructure not set up.${NC} Run: ${BOLD}test/run-tests --setup${NC}"
391 exit 1
392 fi
393
394 if [[ ! -f "$CONF" ]]; then
395 echo -e "${RED}No kernels.conf found.${NC} Run: ${BOLD}test/run-tests --setup${NC}"
396 exit 1
397 fi
398
399 # Check how many kernels are actually downloaded
400 mapfile -t _preflight_entries < <(grep -v '^\s*#' "$CONF" | grep -v '^\s*$')
401 _ready=0
402 _not_ready=0
403 for _entry in "${_preflight_entries[@]}"; do
404 IFS='|' read -r _n _v _b _t _s <<< "$_entry"
405 _n=$(echo "$_n" | xargs)
406 [[ -z "$_n" ]] && continue
407 _stype="${_s%%:*}"
408 [[ "$_stype" == "unavailable" ]] && continue
409 if [[ -n "$(find_vmlinuz "$_n" 2>/dev/null)" ]]; then
410 _ready=$((_ready + 1))
411 else
412 _not_ready=$((_not_ready + 1))
413 fi
414 done
415
416 if [[ $_ready -eq 0 ]]; then
417 echo -e "${RED}No kernels downloaded.${NC} Run: ${BOLD}test/run-tests --setup${NC}"
418 exit 1
419 fi
420
421 # ---------------------------------------------------------------------------
422 # Post-make maintenance
423 # ---------------------------------------------------------------------------
424
425 # Auto-rebuild Alpine rootfs if quotatool binary is newer (keeps tests in sync)
426 alpine_rootfs="$KERNELS_DIR/alpine-rootfs.img"
427 if [[ -f "$alpine_rootfs" && "$QUOTATOOL" -nt "$alpine_rootfs" ]]; then
428 if [[ -x "$KERNELS_DIR/build-alpine-rootfs.sh" ]]; then
429 _setup_step "Rebuilding Alpine rootfs (quotatool binary is newer)..."
430 "$KERNELS_DIR/build-alpine-rootfs.sh" --force || true
431 fi
432 fi
433
434 # GLIBC_MIN_KVER already detected early (before --interactive).
435
436 # Create results directory
437 mkdir -p "$RESULTS_DIR"
438
439 # ---------------------------------------------------------------------------
440 # List mode
441 # ---------------------------------------------------------------------------
442
443 if [[ $OPT_LIST -eq 1 ]]; then
444 printf "${BOLD}%-18s %-8s %-12s %-5s %-10s %s${NC}\n" \
445 "KERNEL" "VERSION" "BOOT" "TIER" "STATUS" "NOTES"
446 echo "------------------------------------------------------------------------"
447 while IFS='|' read -r name version boot tier source; do
448 name=$(echo "$name" | xargs)
449 version=$(echo "$version" | xargs)
450 boot=$(echo "$boot" | xargs)
451 tier=$(echo "$tier" | xargs)
452 local_status="" notes=""
453
454 # Determine boot path (Alpine rootfs overrides normal path)
455 if _needs_alpine_rootfs "$name" "$version"; then
456 boot_path="qemu+alpine"
457 elif [[ "$boot" == "qemu" ]]; then
458 if has_9p "$name" 2>/dev/null; then
459 boot_path="qemu+9p"
460 else
461 boot_path="qemu+alpine"
462 fi
463 elif [[ "$boot" == "virtme" ]]; then
464 boot_path="virtme"
465 else
466 boot_path="$boot"
467 fi
468
469 # Check download/extraction status
470 kdir="$KERNELS_DIR/$name/extracted"
471 if [[ -d "$kdir" ]] && find "$kdir" -name "vmlinu*" 2>/dev/null | grep -q .; then
472 local_status="${GREEN}ready${NC}"
473 else
474 local_status="${RED}not downloaded${NC}"
475 fi
476
477 # Note glibc floor impact
478 if _below_glibc_floor "$version"; then
479 notes="alpine rootfs (glibc floor >=$GLIBC_MIN_KVER)"
480 elif ! has_9p "$name" 2>/dev/null; then
481 notes="alpine rootfs (no 9p)"
482 fi
483
484 printf "%-18s %-8s %-12s %-5s " "$name" "$version" "$boot_path" "$tier"
485 echo -ne "$local_status"
486 [[ -n "$notes" ]] && echo -ne " ${YELLOW}$notes${NC}"
487 echo ""
488 done < <(grep -v '^\s*#' "$CONF" | grep -v '^\s*$')
489 exit 0
490 fi
491
492 # ---------------------------------------------------------------------------
493 # Smoke test mode
494 # ---------------------------------------------------------------------------
495
496 if [[ $OPT_SMOKE -eq 1 ]]; then
497 echo -e "${BOLD}Smoke test — one kernel per boot path${NC}"
498 echo ""
499
500 smoke_pass=0
501 smoke_fail=0
502 smoke_skip=0
503
504 # A quick command that tests basic boot + quotatool binary runs.
505 # Use absolute path — QEMU+9p chroot doesn't have quotatool in PATH.
506 SMOKE_CMD="$QUOTATOOL -V && uname -r && echo SMOKE_PASS"
507
508 _smoke_run() {
509 local label="$1" name="$2" method="$3"
510 local vmlinuz use_rootfs=0
511
512 vmlinuz=$(find_vmlinuz "$name")
513 if [[ -z "$vmlinuz" ]]; then
514 printf " %-12s %-16s " "$label" "$name"
515 echo -e "${YELLOW}SKIP${NC} (kernel not downloaded)"
516 smoke_skip=$((smoke_skip + 1))
517 return
518 fi
519
520 printf " %-12s %-16s " "$label" "$name"
521
522 local rc=0 out=""
523 if [[ "$method" == "rootfs" ]]; then
524 if [[ ! -f "$alpine_rootfs" ]]; then
525 echo -e "${YELLOW}SKIP${NC} (alpine-rootfs.img not built)"
526 smoke_skip=$((smoke_skip + 1))
527 return
528 fi
529 out=$(BOOT_METHOD=qemu BOOT_ROOTFS="$alpine_rootfs" BOOT_TIMEOUT=60 \
530 boot_kernel "$vmlinuz" "/test/guest-run-all.sh ext4 1" 2>&1) || rc=$?
531 else
532 out=$(BOOT_METHOD="$method" BOOT_TIMEOUT=60 \
533 boot_kernel "$vmlinuz" "$SMOKE_CMD" 2>&1) || rc=$?
534 fi
535
536 if [[ $rc -eq 0 ]]; then
537 echo -e "${GREEN}PASS${NC}"
538 smoke_pass=$((smoke_pass + 1))
539 elif [[ $rc -eq 124 ]]; then
540 echo -e "${RED}TIMEOUT${NC}"
541 smoke_fail=$((smoke_fail + 1))
542 else
543 echo -e "${RED}FAIL${NC} (exit $rc)"
544 smoke_fail=$((smoke_fail + 1))
545 if [[ "$OPT_VERBOSE" == "1" && -n "$out" ]]; then
546 echo "$out" | tail -20 | sed 's/^/ /'
547 fi
548 fi
549 }
550
551 # Pick one kernel per boot path:
552 # virtme: first available tier-1 virtme kernel
553 # qemu+9p: first available QEMU kernel with 9p
554 # qemu+rootfs: first available kernel without 9p
555
556 # Virtme path — try debian-12, then ubuntu-2404, then any virtme kernel
557 for k in debian-12 ubuntu-2404 debian-11 ubuntu-2204; do
558 if [[ -n "$(find_vmlinuz "$k" 2>/dev/null)" ]]; then
559 _smoke_run "virtme" "$k" "virtme"
560 break
561 fi
562 done
563
564 # QEMU+9p path — try debian-8, then debian-7, then ubuntu-1404
565 for k in debian-8 debian-7 ubuntu-1404; do
566 if [[ -n "$(find_vmlinuz "$k" 2>/dev/null)" ]]; then
567 _smoke_run "qemu+9p" "$k" "qemu"
568 break
569 fi
570 done
571
572 # QEMU+alpine path — try alma-9, then centos-7, then alma-8
573 for k in alma-9 centos-7 alma-8; do
574 if [[ -n "$(find_vmlinuz "$k" 2>/dev/null)" ]] && ! has_9p "$k"; then
575 _smoke_run "qemu+alpine" "$k" "rootfs"
576 break
577 fi
578 done
579
580 echo ""
581 printf "Smoke: ${GREEN}${smoke_pass} pass${NC}"
582 [[ $smoke_fail -gt 0 ]] && printf ", ${RED}${smoke_fail} fail${NC}"
583 [[ $smoke_skip -gt 0 ]] && printf ", ${YELLOW}${smoke_skip} skip${NC}"
584 echo ""
585
586 if [[ $smoke_fail -gt 0 || $smoke_skip -gt 0 ]]; then
587 echo ""
588 [[ $smoke_fail -gt 0 ]] && echo "Debug failures: run-tests --kernel <name> --verbose"
589 [[ $smoke_skip -gt 0 ]] && echo "Skipped kernels may need: run-tests --setup"
590 if [[ -n "$GLIBC_MIN_KVER" ]]; then
591 echo "Note: host glibc requires kernel >=$GLIBC_MIN_KVER (qemu+9p path affected)"
592 fi
593 fi
594
595 [[ $smoke_fail -gt 0 ]] && exit 1
596 exit 0
597 fi
598
599 # ---------------------------------------------------------------------------
600 # Multi-kernel mode
601 # ---------------------------------------------------------------------------
602
603 # Run quick tests first — bail if basic arg parsing is broken
604 _run_quick_tests || { echo -e "\n${RED}Quick tests failed — aborting kernel matrix.${NC}"; exit 1; }
605 echo ""
606
607 # Re-use pre-flight data (kernels.conf already parsed, _ready/_not_ready set)
608 entries=("${_preflight_entries[@]}")
609
610 passed=0
611 failed=0
612 skipped=0
613 cached=0
614 declare -a failed_names=()
615 declare -a skipped_names=()
616
617 _start_time=$SECONDS
618
619 echo -e "${BOLD}quotatool multi-kernel test suite${NC}"
620 if [[ $_not_ready -gt 0 ]]; then
621 echo -e "Kernels: ${_ready}/${#entries[@]} ready (${YELLOW}${_not_ready} not downloaded — run --setup to fetch${NC})"
622 else
623 echo -e "Kernels: ${#entries[@]} in matrix"
624 fi
625 echo -e "Tests: $(ls "$SCRIPT_DIR/tests"/t-*.sh 2>/dev/null | wc -l) test scripts × 2 filesystems"
626 [[ $OPT_JOBS -gt 1 ]] && echo -e "Jobs: ${OPT_JOBS} parallel"
627 [[ -n "$OPT_KERNEL" ]] && echo -e "\nRunning tests for kernel ${BOLD}${OPT_KERNEL}${NC}...\n" || echo ""
628
629 # Clear previous results unless --only-failed (which needs them to
630 # know what passed last time).
631 if [[ $OPT_ONLY_FAILED -eq 0 ]]; then
632 rm -f "$RESULTS_DIR"/*.log
633 fi
634
635 # ---------------------------------------------------------------------------
636 # Phase 1: Collect runnable kernels, handle skips
637 # ---------------------------------------------------------------------------
638
639 declare -a run_names=()
640 declare -A run_version=()
641 declare -A run_boot=()
642 declare -A run_vmlinuz=()
643 declare -A run_rootfs=()
644
645 for entry in "${entries[@]}"; do
646 IFS='|' read -r name version boot tier source <<< "$entry"
647
648 # Trim whitespace
649 name=$(echo "$name" | xargs)
650 version=$(echo "$version" | xargs)
651 boot=$(echo "$boot" | xargs)
652 tier=$(echo "$tier" | xargs)
653 source=$(echo "$source" | xargs)
654 [[ -z "$name" ]] && continue
655
656 # Filter by tier
657 if [[ -n "$OPT_TIER" && "$tier" != "$OPT_TIER" ]]; then
658 continue
659 fi
660
661 # Filter by kernel name
662 if [[ -n "$OPT_KERNEL" && "$name" != "$OPT_KERNEL" ]]; then
663 continue
664 fi
665
666 source_type="${source%%:*}"
667
668 # Skip unavailable
669 if [[ "$source_type" == "unavailable" ]]; then
670 skipped=$((skipped + 1))
671 skipped_names+=("$name(unavail)")
672 continue
673 fi
674
675 # Check if this kernel needs Alpine rootfs (no 9p, or below glibc floor)
676 use_rootfs=0
677 if _needs_alpine_rootfs "$name" "$version"; then
678 if [[ -f "$alpine_rootfs" ]]; then
679 use_rootfs=1
680 else
681 printf "%-20s %-8s %-12s " "$name" "$version" "qemu+alpine"
682 echo -e "${YELLOW}SKIP${NC} (needs Alpine rootfs — run --setup)"
683 skipped=$((skipped + 1))
684 skipped_names+=("$name(no-rootfs)")
685 continue
686 fi
687 fi
688
689 # Find vmlinuz
690 vmlinuz=$(find_vmlinuz "$name")
691 if [[ -z "$vmlinuz" ]]; then
692 printf "%-20s %-8s %-12s " "$name" "$version" "$boot"
693 echo -e "${YELLOW}SKIP${NC} (not downloaded)"
694 skipped=$((skipped + 1))
695 skipped_names+=("$name(missing)")
696 continue
697 fi
698
699 # Determine actual boot path for display (matches boot.sh auto-detection)
700 if [[ $use_rootfs -eq 1 ]]; then
701 actual_boot="qemu+alpine"
702 else
703 detected=$(boot_detect_method "$vmlinuz" 2>/dev/null || echo "unknown")
704 if [[ "$detected" == "qemu" ]]; then
705 actual_boot="qemu+9p"
706 else
707 actual_boot="$detected"
708 fi
709 fi
710
711 # Skip previously passed kernels (only with --only-failed)
712 if [[ $OPT_ONLY_FAILED -eq 1 ]] && _is_cached_pass "$name"; then
713 _cached_summary=$(grep -E '^Results:' "$RESULTS_DIR/${name}.log" | tail -1 || true)
714 printf "%-20s %-8s %-12s " "$name" "$version" "$actual_boot"
715 echo -e "${GREEN}PASS${NC} $_cached_summary ${BLUE}(cached)${NC}"
716 cached=$((cached + 1))
717 passed=$((passed + 1))
718 continue
719 fi
720
721 # Add to run list
722 run_names+=("$name")
723 run_version[$name]="$version"
724 run_boot[$name]="$actual_boot"
725 run_vmlinuz[$name]="$vmlinuz"
726 run_rootfs[$name]="$use_rootfs"
727 done
728
729 # ---------------------------------------------------------------------------
730 # Phase 2: Run tests
731 # ---------------------------------------------------------------------------
732
733 # Run a single kernel test, writing output to .log and exit code to .rc
734 _run_kernel() {
735 local name="$1"
736 local vmlinuz="${run_vmlinuz[$name]}"
737 local use_rootfs="${run_rootfs[$name]}"
738 local result_file="$RESULTS_DIR/${name}.log"
739 local rc=0
740
741 if [[ $use_rootfs -eq 1 ]]; then
742 BOOT_METHOD=qemu BOOT_ROOTFS="$alpine_rootfs" \
743 boot_kernel "$vmlinuz" "/test/guest-run-all.sh" > "$result_file" 2>&1 || rc=$?
744 else
745 boot_kernel "$vmlinuz" "$GUEST_CMD" > "$result_file" 2>&1 || rc=$?
746 fi
747 echo "$rc" > "$RESULTS_DIR/${name}.rc"
748 }
749
750 if [[ $OPT_JOBS -le 1 ]]; then
751 # --- Sequential mode: real-time output per kernel ---
752 for name in "${run_names[@]}"; do
753 result_file="$RESULTS_DIR/${name}.log"
754 rc=0
755 [[ "$OPT_VERBOSE" == "1" ]] && echo ""
756 if [[ ${run_rootfs[$name]} -eq 1 ]]; then
757 if [[ "$OPT_VERBOSE" == "1" ]]; then
758 BOOT_METHOD=qemu BOOT_ROOTFS="$alpine_rootfs" \
759 boot_kernel "${run_vmlinuz[$name]}" "/test/guest-run-all.sh" 2>&1 | tee "$result_file" || rc=${PIPESTATUS[0]}
760 else
761 BOOT_METHOD=qemu BOOT_ROOTFS="$alpine_rootfs" \
762 boot_kernel "${run_vmlinuz[$name]}" "/test/guest-run-all.sh" > "$result_file" 2>&1 || rc=$?
763 fi
764 else
765 if [[ "$OPT_VERBOSE" == "1" ]]; then
766 boot_kernel "${run_vmlinuz[$name]}" "$GUEST_CMD" 2>&1 | tee "$result_file" || rc=${PIPESTATUS[0]}
767 else
768 boot_kernel "${run_vmlinuz[$name]}" "$GUEST_CMD" > "$result_file" 2>&1 || rc=$?
769 fi
770 fi
771
772 _print_result "$name" "${run_version[$name]}" "${run_boot[$name]}" "$rc"
773
774 if [[ $rc -eq 0 ]]; then
775 passed=$((passed + 1))
776 else
777 failed=$((failed + 1))
778 failed_names+=("$name")
779 fi
780 done
781 else
782 # --- Parallel mode: launch up to N jobs, collect results after ---
783 declare -A job_pids=() # pid -> kernel_name
784 _completed=0
785 _total=${#run_names[@]}
786
787 # Clean up stale .rc files
788 rm -f "$RESULTS_DIR"/*.rc
789
790 for name in "${run_names[@]}"; do
791 # Throttle: wait for a slot if at job limit
792 while [[ $(jobs -rp | wc -l) -ge $OPT_JOBS ]]; do
793 # Wait for any one job to finish
794 wait -n 2>/dev/null || true
795 _completed=$(ls "$RESULTS_DIR"/*.rc 2>/dev/null | wc -l)
796 printf "\r Running: %d/%d completed" "$_completed" "$_total"
797 done
798
799 # Launch in background subshell (set +e so the subshell doesn't
800 # exit on boot_kernel failure — we capture rc in .rc file)
801 ( set +e; _run_kernel "$name" ) &
802 job_pids[$!]="$name"
803 done
804
805 # Wait for all remaining jobs
806 while [[ $(ls "$RESULTS_DIR"/*.rc 2>/dev/null | wc -l) -lt $_total ]]; do
807 wait -n 2>/dev/null || true
808 _completed=$(ls "$RESULTS_DIR"/*.rc 2>/dev/null | wc -l)
809 printf "\r Running: %d/%d completed" "$_completed" "$_total"
810 done
811 wait 2>/dev/null || true
812 printf "\r Running: %d/%d completed\n\n" "$_total" "$_total"
813
814 # Print results in matrix order
815 for name in "${run_names[@]}"; do
816 rc=1
817 if [[ -f "$RESULTS_DIR/${name}.rc" ]]; then
818 rc=$(cat "$RESULTS_DIR/${name}.rc")
819 fi
820
821 _print_result "$name" "${run_version[$name]}" "${run_boot[$name]}" "$rc"
822
823 if [[ $rc -eq 0 ]]; then
824 passed=$((passed + 1))
825 else
826 failed=$((failed + 1))
827 failed_names+=("$name")
828 fi
829 done
830
831 # Clean up .rc files
832 rm -f "$RESULTS_DIR"/*.rc
833 fi
834
835 # ---------------------------------------------------------------------------
836 # Summary
837 # ---------------------------------------------------------------------------
838
839 _elapsed=$(( SECONDS - _start_time ))
840 _min=$(( _elapsed / 60 ))
841 _sec=$(( _elapsed % 60 ))
842
843 echo ""
844 echo "========================================================================"
845 _summary="Results: ${GREEN}${passed} passed${NC}, ${RED}${failed} failed${NC}"
846 [[ $cached -gt 0 ]] && _summary+=", ${BLUE}${cached} cached${NC}"
847 [[ $skipped -gt 0 ]] && _summary+=", ${YELLOW}${skipped} skipped${NC}"
848 _summary+=" (${_min}m ${_sec}s)"
849 echo -e "$_summary"
850 [[ ${#failed_names[@]} -gt 0 ]] && echo -e "Failed: ${RED}${failed_names[*]}${NC}"
851 [[ ${#skipped_names[@]} -gt 0 ]] && echo -e "Skipped: ${YELLOW}${skipped_names[*]}${NC}"
852 echo ""
853 echo "Logs: $RESULTS_DIR/"
854
855 [[ $failed -gt 0 ]] && exit 1
856 exit 0