#!/bin/sh
set -eu
TASK_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
python3 - "$TASK_DIR" <<'CHECK'
from pathlib import Path
import subprocess,sys
r=Path(sys.argv[1]);d=r/'firmware/固件/drill_driver'
cmd=['cc','-std=c11','-Wall','-Wextra','-Werror','-I'+str(d)]
subprocess.run(cmd+['-fsanitize=address,undefined',str(d/'drv8316.c'),str(d/'test_drv8316.c'),'-o',str(r/'test_drv8316')],check=True)
subprocess.run([str(r/'test_drv8316')],check=True)
subprocess.run(cmd+[str(d/'drv8316.c'),str(r/'test_healthy_header.c'),'-o',str(r/'healthy_probe')],check=True)
subprocess.run([str(r/'healthy_probe')],check=True)
old=r/'original_A32_drv8316.c'
if not old.exists():old=r.parent/'sleep_gpio_A32/firmware/固件/drill_driver/drv8316.c'
subprocess.run(cmd+[str(old),str(r/'test_healthy_header.c'),'-o',str(r/'old_negative')],check=True)
p=subprocess.run([str(r/'old_negative')],capture_output=True,text=True)
assert p.returncode!=0,'Old code must fail the same healthy NPOR assertion'
print('PASS: original A32 driver rejected by independent healthy NPOR poll assertion')
CHECK
