AAlice_zhouupdate
54847f2fAdd on Aug 1History
#!/usr/bin/env python3
"""Inject a simple [FUZZ_PARAM] print after [FUZZ_LOG] line for files that still lack it."""
import re
import os

SRC_DIR = "/home/30039325/Vector_fuzz_cpp_testing/turing_sec/aclnnAPI_fuzz/src/src_no_contiguous"

TARGET_FILES = [
    "aclnnIndex_non_contig.cpp", "aclnnIndexPutImpl_non_contig.cpp",
    "aclnnInplaceNormal_non_contig.cpp", "aclnnInplaceNormalTensor_non_contig.cpp",
    "aclnnInplaceRandomTensor_non_contig.cpp", "aclnnInplaceUniformTensor_non_contig.cpp",
    "aclnnLogSoftmaxBackward_non_contig.cpp", "aclnnLogSumExp_non_contig.cpp",
    "aclnnMean_non_contig.cpp", "aclnnMoeGatingTopK_non_contig.cpp",
    "aclnnMoeInitRouting_non_contig.cpp", "aclnnMoeInitRoutingV3_non_contig.cpp",
    "aclnnMseLoss_non_contig.cpp", "aclnnNormalFloatTensor_non_contig.cpp",
    "aclnnNormalTensorFloat_non_contig.cpp", "aclnnNormalTensorTensor_non_contig.cpp",
    "aclnnResize_non_contig.cpp", "aclnnScatterPaKvCache_non_contig.cpp",
    "aclnnSoftmaxBackward_non_contig.cpp", "aclnnSplitTensor_non_contig.cpp",
    "aclnnRmsNormQuant_non_contig.cpp",
]

for filename in TARGET_FILES:
    filepath = os.path.join(SRC_DIR, filename)
    if not os.path.exists(filepath):
        continue
    with open(filepath, 'r', encoding='utf-8', errors='replace') as f:
        content = f.read()

    if '[FUZZ_PARAM]' in content:
        print(f"SKIP (has FUZZ_PARAM): {filename}")
        continue

    # Find [FUZZ_LOG] line and add [FUZZ_PARAM] after it
    # Pattern: printf("[FUZZ_LOG] plog_file: xxx\n");
    pat = r'(printf\(\"\[FUZZ_LOG\] plog_file:[^\"]*\\"\\"\);\s*\n)'
    m = re.search(pat, content)
    if m:
        insert_line = '        printf("[FUZZ_PARAM] see CreateAclTensorByScene params above\\n");\n'
        content = content[:m.end()] + insert_line + content[m.end():]
        with open(filepath, 'w', encoding='utf-8') as f:
            f.write(content)
        print(f"FIXED: {filename}")
    else:
        print(f"SKIP (no FUZZ_LOG): {filename}")