1 Star 0 Fork 0

jinqi zhang/riscv_istio_test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
count_test.py 3.48 KB
一键复制 编辑 原始数据 按行查看 历史
jinqi zhang 提交于 2024-12-02 12:20 . 1
import os
import pandas as pd
import re
print("start processing test results")
# 创建一个字典来统计每个 `a` 部分出现的次数
count={}
def process_txt_file(file_path,test_name):
data = []
with open(file_path, 'r',errors='ignore') as file:
lines=file.readlines()
# 修改判断状态为 Y 的条件:是否存在仅包含 'PASS' 的行(允许空格)
status = 'N' # 默认状态为失败
for line in lines:
if line.strip() == 'PASS': # 去掉两端空格后判断是否为 'PASS'
status = 'Y'
break
# 判断文件是否视为错误
if len(lines) < 5:
# 使用正则表达式匹配 "ok istio.io",中间允许任意数量的空格
has_ok_istio = any(re.match(r'^ok.*', line) for line in lines)
if not has_ok_istio:
print("\nTEST_NAME:", test_name, "\ngo test error \n",
"error_test_file_path:", lines[-1] if lines else "No lines",
"error_test_output_dir:", file_path)
status = 'N'
name = lines[-2].strip() + lines[-1].strip() if len(lines) >= 2 else "Unknown Test"
data.append([name, status, lines[0].strip() if lines else "No content"])
return data
else:
status = 'Y'
# 根据出现次数构造测试名
if(count[test_name]>1):
name=lines[-2].strip()+lines[-1].strip()
else:
name = lines[-2].strip()
flag=''
for i in range(len(lines)):
if lines[i].startswith("--- PASS"):
flag=lines[i].strip()
elif lines[i].startswith("--- FAIL"):
flag=lines[i].strip()
# 根据 status 动态决定最后一部分是 PASS 还是 FAIL
status_result = 'PASS' if status == 'Y' else 'FAIL'
if flag == '':
detail = "'" + status_result
else:
detail = "'" + lines[0].strip() + "\n" + flag + "\n" + status_result
data.append([name,status,detail])
return data
def count_a_occurrences(directory):
# 遍历目录中的所有文件
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.txt'):
parts = file.split('-', 1)
if len(parts) == 2:
test_name = parts[0]
if test_name in count:
count[test_name] += 1
else:
count[test_name] = 1
def main(input_directory, output_file):
count_a_occurrences(input_directory)
all_data = []
for file_name in os.listdir(input_directory):
if file_name.endswith('.txt'):
parts=file_name.split('-',1)
file_path = os.path.join(input_directory, file_name)
file_data = process_txt_file(file_path,parts[0])
if file_data:
for i in range(len(file_data)):
all_data.append(file_data[i])
# Create a DataFrame
columns = ['Test Name','Status','Run Details']
df = pd.DataFrame(all_data, columns=columns)
# Write DataFrame to an Excel file
df.to_excel(output_file, index=False)
print("success save test results to test_result.xlsx")
if __name__ == "__main__":
input_directory = 'test' # Change to your directory
output_file = 'test_result.xlsx'
main(input_directory, output_file)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jasonbus_admin/riscv_istio_test.git
git@gitee.com:jasonbus_admin/riscv_istio_test.git
jasonbus_admin
riscv_istio_test
riscv_istio_test
1.22.2-riscv

搜索帮助