#!/usr/bin/env python3 """Clone a runtime scheduler fixture while patching TEST.ZTST in selected epochs. This is a diagnostic fixture transform. It leaves accepted generated assets untouched, creates cheap local aliases for the shared RTL harness, and rewrites only the selected feeder lists. Usage: patch_runtime_sched_test.py OUT IN --epochs START:END --ztst N """ import os import re import shutil import sys ROOT=os.path.normpath(os.path.join(os.path.dirname(__file__),"..")) DATA=os.path.join(ROOT,"sim","data","top_psmct32_raster_demo") def link_or_copy(src,dst): try: os.unlink(dst) except FileNotFoundError: pass try: os.link(src,dst) except OSError: shutil.copyfile(src,dst) def read_table(tag): path=os.path.join(DATA,f"sh3_{tag}_epochs.txt") comments=[]; meta=None; rows=[] for line in open(path): if line.startswith("META "): meta=line.strip() elif line and line[0].isdigit(): rows.append(line.split()) else: comments.append(line) if meta is None: raise ValueError(f"{path}: missing META") return comments,meta,rows def patch_list(src,dst,ztst): lines=open(src).readlines(); word_lines=[] for i,line in enumerate(lines): s=line.strip() if s and not s.startswith("//"): word_lines.append(i) if len(word_lines)<4: raise ValueError(f"{src}: feeder list shorter than TEST header") li=word_lines[3]; test=int(lines[li].strip(),16) test=(test&~(3<<17))|((ztst&3)<<17) lines[li]=f"{test:016x}\n" with open(dst,"w") as f: f.writelines(lines) def main(argv): if len(argv)<7 or argv[3]!="--epochs" or argv[5]!="--ztst": print(__doc__.strip()); return 2 out,src_tag=argv[1],argv[2] a,b=argv[4].split(":",1); start=int(a); end=int(b); ztst=int(argv[6],0) if ztst not in range(4): raise ValueError("ZTST must be 0..3") comments,meta,rows=read_table(src_tag) if start<0 or endlen(rows): raise ValueError(f"invalid epoch slice {start}:{end} for {len(rows)} rows") out_rows=[] for row in rows: k=int(row[0]); old=list(row) tex_src=os.path.join(DATA,old[4]); list_src=os.path.join(DATA,old[8]) tex_alias=f"sh3_{out}{k}_tex_lpddr.mem" list_alias=f"feeder_sh3_{out}{k}.mem" pal_alias=f"sh3_{out}{k}_pal.mem" link_or_copy(tex_src,os.path.join(DATA,tex_alias)) if start<=k {out}: epochs {start}:{end} ZTST={ztst}; {len(rows)} total") return 0 if __name__=="__main__": raise SystemExit(main(sys.argv))