forked from redrsoe2100/os-autotest
137 lines
5.0 KiB
Python
137 lines
5.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
import os
|
|
import json
|
|
import csv
|
|
from pathlib import Path
|
|
import subprocess
|
|
import argparse
|
|
|
|
SOURCE_DIR = "./"
|
|
RESULT_DIR = "./"
|
|
# os.environ['LOG_DIR'] = os.path.join(os.getcwd(), "log")
|
|
os.environ['LOG_DIR'] = "./log"
|
|
os.environ['LOG_NAME'] = "os-autotest"
|
|
|
|
from log import log
|
|
|
|
def get_testsuite_info(testsuite):
|
|
json_file = os.path.join(SOURCE_DIR, "suite2cases", testsuite + ".json")
|
|
if os.path.exists(json_file):
|
|
with open(json_file, 'r', encoding='utf-8') as f:
|
|
suite_data = json.load(f)
|
|
return suite_data
|
|
else:
|
|
log.warning(f"{testsuite} not exists")
|
|
return None
|
|
|
|
def get_os_autotest_testsuite_result_data(testsuite):
|
|
log.info(f"begin to get testsuite {testsuite} result data...")
|
|
data=[]
|
|
all_cases = []
|
|
succeed_path = f"{RESULT_DIR}/results/{testsuite}/succeed"
|
|
failed_path = f"{RESULT_DIR}/results/{testsuite}/failed"
|
|
skipped_path = f"{RESULT_DIR}/results/{testsuite}/skipped"
|
|
if os.path.exists(succeed_path):
|
|
for file_name in os.listdir(succeed_path):
|
|
if file_name in all_cases:
|
|
continue
|
|
temp = [testsuite, file_name, "passed"]
|
|
data.append(temp)
|
|
all_cases.append(file_name)
|
|
else:
|
|
log.warning(f"{succeed_path} not exists")
|
|
if os.path.exists(failed_path):
|
|
for file_name in os.listdir(failed_path):
|
|
if file_name in all_cases:
|
|
continue
|
|
temp = [testsuite, file_name, "failed"]
|
|
data.append(temp)
|
|
all_cases.append(file_name)
|
|
else:
|
|
log.warning(f"{failed_path} not exists")
|
|
if os.path.exists(skipped_path):
|
|
for file_name in os.listdir(skipped_path):
|
|
if file_name in all_cases:
|
|
continue
|
|
temp = [testsuite, file_name, "skipped"]
|
|
data.append(temp)
|
|
all_cases.append(file_name)
|
|
else:
|
|
log.warning(f"{skipped_path} not exists")
|
|
suite_data=get_testsuite_info(testsuite)
|
|
if not suite_data:
|
|
log.warning(f"{testsuite} not found in mugen sources.")
|
|
return None
|
|
script_path_origin=suite_data["path"]
|
|
script_dir=SOURCE_DIR+ "/" +"/".join(script_path_origin.split("/")[1:])
|
|
for elem in suite_data["cases"]:
|
|
case_name=elem["name"]
|
|
result = subprocess.run(['find', script_dir, '-name', f"{case_name}.sh"], capture_output=True, text=True,
|
|
check=True)
|
|
found_files = result.stdout.splitlines()
|
|
if not found_files:
|
|
log.warning(f"{case_name}.sh not found in {script_dir}")
|
|
continue
|
|
if case_name not in all_cases:
|
|
if testsuite == "smoke_pkg_install" and "case_name" == "test_pkg_install_uninstall":
|
|
continue
|
|
temp = [testsuite, case_name, "not run or exception in running, please run manual"]
|
|
data.append(temp)
|
|
return data
|
|
|
|
def get_os_autotest_summary_results(testsuite_list):
|
|
summary_results_json_path = f"{RESULT_DIR}/summary_results.json"
|
|
summary_results_csv_path = f"{RESULT_DIR}/summary_results.csv"
|
|
header = ["testsuite", "testcase", "result"]
|
|
datas={
|
|
"head": header,
|
|
"data": []
|
|
}
|
|
for testsuite in testsuite_list:
|
|
data = get_os_autotest_testsuite_result_data(testsuite)
|
|
if data is not None:
|
|
datas["data"].extend(data)
|
|
with open(summary_results_json_path, "w+", encoding="utf-8") as f:
|
|
json.dump(datas, f, ensure_ascii=False, indent=4)
|
|
with open(summary_results_csv_path, "w+", encoding="utf-8") as f:
|
|
csv_writer = csv.writer(f)
|
|
csv_writer.writerow(header)
|
|
csv_writer.writerows(datas["data"])
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="整理测试结果")
|
|
parser.add_argument("--testsuits", required=True, help="测试套名称文件路径")
|
|
parser.add_argument("--result", required=True, help="测试结果存放目录路径")
|
|
parser.add_argument("--source", required=True, help="测试用例源码路径")
|
|
|
|
args = parser.parse_args()
|
|
testsuits_file = args.testsuits
|
|
global SOURCE_DIR
|
|
SOURCE_DIR = args.source
|
|
global RESULT_DIR
|
|
RESULT_DIR = args.result
|
|
|
|
with open(testsuits_file, 'r', encoding='utf-8') as f:
|
|
testsuit_names = f.read().splitlines()
|
|
|
|
print(testsuit_names)
|
|
get_os_autotest_summary_results(testsuit_names)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
# python summary.py --testsuits "./mugen/testsuits" --result "./mugen" --source "/home/xlab/workspaces/ruyi/mugen"
|
|
# path = "./mugen/testsuits"
|
|
# json_files = [f for f in os.listdir(path) if f.endswith('.json')]
|
|
# print(json_files)
|
|
|
|
# from pathlib import Path
|
|
# path = Path("./mugen/testsuits")
|
|
# testsuit_names = [f.stem for f in path.glob("*.json")]
|
|
# print(testsuit_names)
|
|
# with open('./mugen/testsuits', 'r', encoding='utf-8') as f:
|
|
# testsuit_names = f.read().splitlines()
|
|
|
|
# print(testsuit_names)
|
|
# get_os_autotest_summary_results(testsuit_names) |