#Copyright (c) 2025 Huawei Technologies Co., Ltd.
#This program is free software, you can redistribute it and/or modify it under the terms and conditions of
#CANN Open Software License Agreement Version 2.0 (the "License").
#Please refer to the License for details. You may not use this file except in compliance with the License.
#THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
#INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
#See LICENSE in the root of the software repository for the full text of the License.
import sys
sys.stdout.reconfigure(encoding='utf-8')
with open(r'D:\AI\Vector_error_testing_angent\output\RmsNormGrad\aclnnRmsNormGrad.cpp', 'rb') as f:
data = f.read()
# Find key lines and show hex
targets = [b'printf("end ', b'Scenario %3d', b'LOG_PRINT("aclnnRmsNormGrad error test']
for t in targets:
idx = data.find(t)
if idx >= 0:
# Go back to find start of this expression
start = max(0, idx - 20)
end = min(len(data), idx + 80)
chunk = data[start:end]
hex_str = ' '.join(f'{b:02x}' for b in chunk)
print(f'Target: {t[:30]}')
print(f' Hex: {hex_str}')
# Check: does it have 0x5c 0x6e (backslash-n = correct C++ escape)?
has_escape = b'\\n' in chunk # 0x5c 0x6e
has_literal_backslash_r = b'\\r' in chunk # 0x5c 0x72
print(f' Has \\n (0x5c 0x6e): {has_escape}')
print(f' Has \\r (0x5c 0x72): {has_literal_backslash_r}')
print()
# Also check: is there any line with literal \r\n inside a C++ string?
# This would be: bytes 0x5c 0x72 0x5c 0x6e inside quotes
count_rn = 0
idx = 0
while True:
idx = data.find(b'\\r\\n', idx) # 0x5c 0x72 0x5c 0x6e
if idx < 0:
break
count_rn += 1
idx += 4
print(f'Total \\r\\n (0x5c725c6e) in file: {count_rn}')
# vs just \\n (0x5c 0x6e)
count_n = 0
idx = 0
while True:
idx = data.find(b'\\n', idx) # 0x5c 0x6e
if idx < 0:
break
count_n += 1
idx += 2
print(f'Total \\n (0x5c6e) in file: {count_n}')