them big_tasks.md (roadmap G0-G4, danh dau G1.1-G1.5 hoan thanh) + debug scripts/probes cua phien lam viec G0.1-G1.5 (test_g13/test_g12/test_g15_stress, patch_g1x, deploy/build bridge, probe_g0x)
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
# G1.3 verification: pump gate removed, single UiThread.
|
||||
# Stress: resize (WM_SIZE) editor, LOAD replacing instrument while editor open,
|
||||
# close/reopen cycles, Option B, PLAY audio advancing throughout, no crash.
|
||||
import ctypes, ctypes.wintypes as w, struct, subprocess, sys, os, time, re
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
||||
|
||||
APP_PID = int(sys.argv[1])
|
||||
SHM_NAME = f"SonicForge_DAW_IPC_{APP_PID}".encode()
|
||||
APP_LOG = os.path.join(os.environ.get('APPDATA', '.'), 'SonicForgeDAW', 'logs', 'bridge.log')
|
||||
NEXUS = r"C:\Program Files\Common Files\VST3\Nexus.vst3"
|
||||
EZKEYS = r"C:\Program Files\Common Files\VST3\Toontrack\EZkeys 2.vst3"
|
||||
|
||||
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
|
||||
kernel32.OpenFileMappingA.argtypes = [ctypes.wintypes.DWORD, w.BOOL, ctypes.c_char_p]
|
||||
kernel32.OpenFileMappingA.restype = ctypes.c_void_p
|
||||
kernel32.MapViewOfFile.argtypes = [ctypes.c_void_p, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD, ctypes.c_size_t]
|
||||
kernel32.MapViewOfFile.restype = ctypes.c_void_p
|
||||
hMap = kernel32.OpenFileMappingA(0xF001F, False, SHM_NAME)
|
||||
if not hMap:
|
||||
print(f"OpenFileMapping failed err={ctypes.get_last_error()}"); sys.exit(1)
|
||||
ptr = kernel32.MapViewOfFile(hMap, 0xF001F, 0, 0, 0)
|
||||
user32 = ctypes.windll.user32
|
||||
|
||||
def w32(off, fmt, *args):
|
||||
ctypes.memmove(ptr + off, struct.pack(fmt, *args), struct.calcsize(fmt))
|
||||
def rd32(off):
|
||||
return ctypes.c_uint32.from_address(ptr + off).value
|
||||
|
||||
def write_control(ctype, arg0, arg1, ch, path):
|
||||
for i in range(8):
|
||||
off = 2836 + i * 1040
|
||||
if rd32(off) == 0:
|
||||
w32(off, 'IIII', ctype, arg0, arg1, ch)
|
||||
if path:
|
||||
b = path.encode('utf-8')[:1023] + b'\x00'
|
||||
ctypes.memmove(ptr + off + 16, b, len(b))
|
||||
return i
|
||||
raise RuntimeError("control queue full")
|
||||
|
||||
def push_controls(events):
|
||||
for i in range(8):
|
||||
w32(2836 + i * 1040, 'I', 0)
|
||||
for (ctype, arg0, arg1, ch, path) in events:
|
||||
write_control(ctype, arg0, arg1, ch, path)
|
||||
w32(11156, 'I', len(events))
|
||||
|
||||
def log_lines():
|
||||
try:
|
||||
with open(APP_LOG, 'r', encoding='utf-8', errors='replace') as f:
|
||||
return f.readlines()
|
||||
except FileNotFoundError:
|
||||
return []
|
||||
|
||||
def wait_log(pattern, timeout, since, verbose=True):
|
||||
end = time.time() + timeout
|
||||
while time.time() < end:
|
||||
lines = log_lines()
|
||||
for i in range(since, len(lines)):
|
||||
if pattern in lines[i]:
|
||||
if verbose: print(f" LOG: {lines[i].strip()}")
|
||||
return lines[i].strip()
|
||||
time.sleep(0.2)
|
||||
return None
|
||||
|
||||
def write_index():
|
||||
return rd32(4)
|
||||
|
||||
def bridge_alive(pid0):
|
||||
try:
|
||||
out = subprocess.run(["tasklist"], capture_output=True, text=True).stdout
|
||||
for line in out.splitlines():
|
||||
p = line.split()
|
||||
if len(p) >= 2 and p[0] == "daw_vst_bridge.exe" and p[1] == pid0:
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
bad = []
|
||||
def collect_bad(since):
|
||||
for l in log_lines()[since:]:
|
||||
if any(k in l for k in ("EXCEPTION", "FAILED", "restarted")):
|
||||
bad.append(l.strip())
|
||||
|
||||
def find_hwnd(ch):
|
||||
last = None
|
||||
for l in log_lines():
|
||||
if f"ch={ch}" in l and "GUI attached" in l:
|
||||
m = re.search(r'hwnd=([0-9A-Fa-f]+)', l)
|
||||
if m: last = int(m.group(1), 16)
|
||||
return last
|
||||
|
||||
since0 = len(log_lines())
|
||||
# LOAD 6 Nexus + EZkeys (state may differ per run; just LOAD the needed ones)
|
||||
for ch in range(6):
|
||||
since = len(log_lines())
|
||||
push_controls([(2, 0, 0, ch, NEXUS)])
|
||||
r = wait_log(f"instrument loaded ch={ch}", 60, since, verbose=False)
|
||||
if not r: print(f" WARN load ch={ch} timeout")
|
||||
print("LOAD 6 Nexus done")
|
||||
|
||||
# --- T1: OPEN_GUI ch5, wait attach ---
|
||||
since = len(log_lines())
|
||||
push_controls([(4, 0, 0, 5, "Nexus")])
|
||||
r = wait_log("GUI attached", 30, since)
|
||||
print("T1 attach ch5:", "OK" if r else "TIMEOUT")
|
||||
collect_bad(since)
|
||||
hwnd5 = find_hwnd(5)
|
||||
print("T1 hwnd5:", hex(hwnd5) if hwnd5 else "None")
|
||||
|
||||
# --- T2: resize (WM_SIZE) while attached ---
|
||||
since = len(log_lines())
|
||||
if hwnd5:
|
||||
user32.SendMessageW(hwnd5, 0x0005, 0, (900 << 16) | 600) # WM_SIZE w=900 h=600
|
||||
time.sleep(1.5)
|
||||
print("T2 resize sent; log tail:")
|
||||
for l in log_lines()[-4:]: print(" ", l.strip())
|
||||
collect_bad(since)
|
||||
|
||||
# --- T3: PLAY with editor open, audio advancing ---
|
||||
since = len(log_lines())
|
||||
push_controls([(3, 1, 0, 0, "")])
|
||||
r = wait_log("transport PLAY", 10, since)
|
||||
print("T3 transport:", r or "TIMEOUT")
|
||||
a, b = write_index(), 0
|
||||
time.sleep(3); b = write_index()
|
||||
print(f"T3 writeIndex {a}->{b} delta={b-a} ({'ADVANCING' if b > a else 'STALLED'})")
|
||||
if b <= a: bad.append("T3: writeIndex stalled with editor open")
|
||||
collect_bad(since)
|
||||
|
||||
# --- T4: LOAD EZkeys on ch5 WHILE editor open + PLAYING (replace inst with editor) ---
|
||||
since = len(log_lines())
|
||||
push_controls([(2, 0, 0, 5, EZKEYS)])
|
||||
r = wait_log("instrument loaded ch=5", 60, since)
|
||||
print("T4 load ch5 (EZkeys) while editor open:", "OK" if r else "TIMEOUT")
|
||||
collect_bad(since)
|
||||
a, b = write_index(), 0
|
||||
time.sleep(2); b = write_index()
|
||||
print(f"T4 writeIndex {a}->{b} delta={b-a} ({'ADVANCING' if b > a else 'STALLED'})")
|
||||
if b <= a: bad.append("T4: writeIndex stalled after LOAD while editor open")
|
||||
|
||||
# --- T5: STOP, close ch5 editor (WM_CLOSE), reopen ---
|
||||
since = len(log_lines())
|
||||
push_controls([(3, 0, 0, 0, "")])
|
||||
wait_log("transport STOP", 10, since)
|
||||
hwnd5b = find_hwnd(5)
|
||||
if hwnd5b:
|
||||
since = len(log_lines())
|
||||
user32.PostMessageW(hwnd5b, 0x0010, 0, 0) # WM_CLOSE
|
||||
r = wait_log("state restored ch=5", 40, since)
|
||||
print("T5 close ch5:", "OK" if r else "TIMEOUT")
|
||||
collect_bad(since)
|
||||
# reopen ch5 (now EZkeys)
|
||||
since = len(log_lines())
|
||||
push_controls([(4, 0, 0, 5, "EZkeys 2")])
|
||||
r = wait_log("GUI attached", 30, since)
|
||||
print("T5 reopen ch5:", "OK" if r else "TIMEOUT")
|
||||
collect_bad(since)
|
||||
|
||||
# --- T6: 3x close/reopen cycle ch5 ---
|
||||
for i in range(3):
|
||||
hwnd = find_hwnd(5)
|
||||
if not hwnd: print(f"T6 iter{i}: no hwnd"); break
|
||||
since = len(log_lines())
|
||||
user32.PostMessageW(hwnd, 0x0010, 0, 0)
|
||||
r = wait_log("state restored ch=5", 40, since, verbose=False)
|
||||
since = len(log_lines())
|
||||
push_controls([(4, 0, 0, 5, "EZkeys 2")])
|
||||
r2 = wait_log("GUI attached", 30, since, verbose=False)
|
||||
print(f"T6 iter{i}: close={'OK' if r else 'TIMEOUT'} reopen={'OK' if r2 else 'TIMEOUT'}")
|
||||
if not r or not r2:
|
||||
bad.append(f"T6 iter{i}: close/reopen fail"); break
|
||||
collect_bad(since)
|
||||
|
||||
# --- T7: watch 8s ---
|
||||
since = len(log_lines())
|
||||
end = time.time() + 8
|
||||
while time.time() < end:
|
||||
collect_bad(since)
|
||||
if not bridge_alive(str(APP_PID and 0)):
|
||||
pass
|
||||
time.sleep(0.2)
|
||||
print()
|
||||
if bad:
|
||||
print("G1.3 RESULT: FAIL")
|
||||
for x in bad[:20]: print(" -", x)
|
||||
else:
|
||||
print("G1.3 RESULT: PASS - resize OK, LOAD-while-editor OK, close/reopen x4 OK, no crash")
|
||||
Reference in New Issue
Block a user