#!/bin/sh
set -eu
cd "$(dirname "$0")"
T=firmware/固件/lamp_target
C=firmware/固件/lamp_control
F="-std=c11 -g -O1 -Wall -Wextra -Werror -fsanitize=address,undefined -fno-omit-frame-pointer"
I="-Ihost -I$T/include -I$C"
cc $F $I test_runtime.c "$T/src/lamp_i2c_owner.c" "$T/src/lamp_i2c_clock.c" "$T/src/lamp_i2c_read.c" "$T/src/lamp_driver_diagnostics.c" "$T/src/lamp_diagnostic_runtime.c" "$T/src/lamp_output_pins.c" "$T/src/lamp_frame_stage.c" "$T/src/lamp_dark_init.c" "$T/src/lamp_i2c_write.c" "$C/pca9956b_async_bank.c" "$C/pca9956b_fault_monitor.c" -o host/runtime
./host/runtime
for phase in 100 200 300; do
 n=0; while [ "$n" -lt 30 ]; do ./host/runtime "$((phase+n))"; n=$((n+1)); done
done
for n in 400 401 402 403 404; do ./host/runtime "$n"; done
n=500; while [ "$n" -lt 524 ]; do ./host/runtime "$n"; n=$((n+1)); done
printf '%s\n' 'PASS 120 diagnostic runtime scenarios: two scans, 90 GPIO/config/alias faults across three phases, four scheduling/ownership faults, tick wrap, 24 NACK positions.'
for n in 600 601 602 603 604 605 606; do ./host/runtime "$n"; done
printf "%s\n" "PASS 127 runtime scenarios with explicit power/OE/WDOG/reset off-latch assertions"
