提交 fe0195ee 编写于 作者: F felixhjh

split log with different test cases

上级 680e2f14
......@@ -30,12 +30,24 @@ import pytest
inference_test_cases = ["test_fit_a_line.py::TestFitALine::test_inference"]
cpp_test_cases = ["test_fit_a_line.py::TestFitALine::test_cpu", "test_fit_a_line.py::TestFitALine::test_gpu"]
pipeline_test_cases = ["test_uci_pipeline.py::TestUCIPipeline::test_cpu", "test_uci_pipeline.py::TestUCIPipeline::test_gpu"]
log_files = ["PipelineServingLogs", "log", "stderr.log", "stdout.log"]
def set_serving_log_path():
if 'SERVING_LOG_PATH' not in os.environ:
serving_log_path = os.path.expanduser(os.getcwd())
os.environ['SERVING_LOG_PATH']=serving_log_path
def mv_log_to_new_dir(dir_path):
import shutil
if not os.path.exists(dir_path):
os.mkdir(dir_path)
serving_log_path = os.environ['SERVING_LOG_PATH']
for file_name in log_files:
file_path = os.path.join(serving_log_path, file_name)
if os.path.exists(file_path):
shutil.move(file_path, dir_path)
def run_test_cases(cases_list, case_type, is_open_std):
old_stdout, old_stderr = sys.stdout, sys.stderr
real_path = os.path.dirname(os.path.realpath(__file__))
......@@ -48,6 +60,10 @@ def run_test_cases(cases_list, case_type, is_open_std):
res = pytest.main(args)
sys.stdout, sys.stderr = old_stdout, old_stderr
case_name = case.split('_')[-1]
serving_log_path = os.environ['SERVING_LOG_PATH']
dir_name = str(case_type) + '_' + case.split(':')[-1]
new_dir_path = os.path.join(serving_log_path, dir_name)
mv_log_to_new_dir(new_dir_path)
if res == 0:
print("{} {} environment running success".format(case_type, case_name))
elif res == 1:
......
......@@ -13,6 +13,7 @@ class ServingTest(object):
DATA_PATH: 数据集根目录
py_version: python版本 python3.6~3.8
"""
self.serving_log_path = os.environ['SERVING_LOG_PATH']
code_path = os.path.dirname(os.path.realpath(__file__))
self.data_path = f"{code_path}/{data_path}/"
self.example_path = f"{code_path}/{example_path}/"
......@@ -37,6 +38,9 @@ class ServingTest(object):
os.system(f"ln -s {abs_path} {file}")
def start_server_by_shell(self, cmd: str, sleep: int = 5, err="stderr.log", out="stdout.log", wait=False):
err = os.path.join(self.serving_log_path, err)
out = os.path.join(self.serving_log_path, out)
self.err = open(err, "w")
self.out = open(out, "w")
p = subprocess.Popen(cmd, shell=True, stdout=self.out, stderr=self.err)
......@@ -128,17 +132,16 @@ def diff_compare(array1, array2):
def print_log(file_list, iden=""):
serving_log_path = os.environ['SERVING_LOG_PATH']
for file in file_list:
print(f"======================{file} {iden}=====================")
if os.path.exists(file):
with open(file, "r") as f:
print(f"======================{file}=====================")
file_path = os.path.join(serving_log_path, file)
if os.path.exists(file_path):
with open(file_path, "r") as f:
print(f.read())
if file.startswith("log") or file.startswith("PipelineServingLogs"):
os.remove(file)
else:
pass
def parse_prototxt(file):
with open(file, "r") as f:
lines = [i.strip().split(":") for i in f.readlines()]
......
......@@ -480,10 +480,14 @@ class Check_Env_Shell(cmd.Cmd):
# ----- basic commands -----
def do_help(self, arg):
print("\nCommand list\t\tDescription\n"\
"check_all\t\tCheck Environment of Paddle Inference, Pipeline Serving, C++ Serving\n"\
"check_pipeline\t\tCheck Environment of Pipeline Serving\n"\
"check_cpp\t\tCheck Environment of C++ Serving\n"\
"check_inference\t\tCheck Environment of Paddle Inference\n"\
"check_all\t\tCheck Environment of Paddle Inference, Pipeline Serving, C++ Serving. "\
"If failed, using debug command to debug\n"\
"check_pipeline\t\tCheck Environment of Pipeline Serving. "\
"If failed, using debug command to debug\n"\
"check_cpp\t\tCheck Environment of C++ Serving. "\
"If failed, using debug command to debug\n"\
"check_inference\t\tCheck Environment of Paddle Inference. "\
"If failed, using debug command to debug\n"\
"debug\t\t\tWhen checking was failed, open log to debug\n"\
"exit\t\t\tExit Check Env Shell\n")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册