"""单场景精准补跑器:只跑指定接口的指定场景(跳过日志已存在且达标的)"""
import argparse, os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import importlib.util
spec = importlib.util.spec_from_file_location("rc", os.path.join(os.path.dirname(__file__), "run_scenario_campaign.py"))
rc = importlib.util.module_from_spec(spec)
spec.loader.exec_module(rc)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--worker", required=True)
ap.add_argument("--device", required=True)
ap.add_argument("--fw", required=True)
ap.add_argument("--apis", required=True)
ap.add_argument("--scenarios", default="normal,non_contig,multithread,consistent,error,sample")
args = ap.parse_args()
fw = os.path.abspath(args.fw)
fw = fw if fw.endswith("aclnnAPI_fuzz") else os.path.join(fw, "aclnnAPI_fuzz")
apis = [l.strip() for l in open(args.apis) if l.strip()]
scns = [s.strip() for s in args.scenarios.split(",") if s.strip()]
state_path = os.path.join(rc.ROOT, "out_res", f"scenario_campaign_worker{args.worker}.json")
state = rc.load_state(state_path)
rc.logw(f"worker{args.worker} device{args.device} 单场景补跑: {len(apis)}接口 x {scns}")
LOGMAP = {"normal": "{a}_fuzz_output.log", "non_contig": "{a}_non_contig_fuzz_output.log",
"multithread": "{a}_multithread_fuzz_output.log", "consistent": "{a}_consistent_fuzz_output.log",
"error": "{a}_error_fuzz_output.log"}
CPPMAP = {"normal": "{a}.cpp", "non_contig": "{a}_non_contig.cpp", "multithread": "{a}_multithread.cpp",
"consistent": "{a}_consistent.cpp", "error": "{a}_error.cpp"}
for api in apis:
for scn in scns:
if scn == "sample":
scpp = os.path.join(fw, "src", "op_sample", f"{api}.cpp")
if os.path.isfile(scpp):
try:
rc.run_sample(fw, api, args.device, state)
except Exception as e:
state.setdefault(api, {})["sample"] = {"status": "error", "e": str(e)[:200]}
continue
logp = os.path.join(rc.ROOT, "output", api, "fuzz_logs", LOGMAP[scn].format(a=api))
if os.path.isfile(logp) and "FUZZ_RESULT" in open(logp, errors="ignore").read(20*1024*1024):
continue
cpp = os.path.join(rc.ROOT, "output", api, CPPMAP[scn].format(a=api))
if not os.path.isfile(cpp):
continue
rc.logw(f"worker{args.worker} >>> {api} [{scn}]")
try:
rc.run_scenario(fw, api, scn, args.device, state)
except Exception as e:
state.setdefault(api, {})[scn] = {"status": "error", "e": str(e)[:200]}
rc.logw(f" [{scn}] ERROR {e}")
rc.save_state(state_path, state)
rc.logw(f"worker{args.worker} SCN-ONLY DONE")
if __name__ == "__main__":
main()