From c3b17f2991587010712255450ec22c363b0a108b Mon Sep 17 00:00:00 2001 From: liyl_kl Date: Mon, 26 Feb 2024 11:33:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BB=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kytuning/main.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/kytuning/main.py b/src/kytuning/main.py index 84e4d3e..6ebac77 100644 --- a/src/kytuning/main.py +++ b/src/kytuning/main.py @@ -1,25 +1,33 @@ __all__ = [ 'Main' ] -import sys +import sys, getopt, os, time from .logger import * -from .scheme import * +from .scheme import subproc_call, SchemeError, SchemeParserError, TestCaseError from .test import * from .error import * - +from .config import * class Main(object): def __init__(self): - self.test= None + # 载入配置文件 + self.config = KYConfig().load() - def run(self): + def __parse_argv(self): if len(sys.argv) < 2: print('input scheme path.') sys.exit() - path = sys.argv[1] - if path is None or len(path) == 0: - print('invalid scheme path : "%s"' % path) + opts, args = getopt.getopt(sys.argv[1:], "hf:", ["help", "report_path="]) + for o, a in opts: + if o in ("-h", "--help"): + sys.exit() + elif o in ("-f", "--report_path"): + self.config.add({'main':{'report_path': a}}) + pass + + if len(args) == 0: + print('input scheme path.') sys.exit() with open(path, 'r') as f: -- Gitee From 7e844edb341b98744547d3a32a7acb4c44428b0e Mon Sep 17 00:00:00 2001 From: liyl_kl Date: Mon, 26 Feb 2024 13:37:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kytuning/main.py | 48 ++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/kytuning/main.py b/src/kytuning/main.py index 6ebac77..1a4e672 100644 --- a/src/kytuning/main.py +++ b/src/kytuning/main.py @@ -30,25 +30,47 @@ class Main(object): print('input scheme path.') sys.exit() - with open(path, 'r') as f: + for file in args: + if file is None or len(file) == 0: + print('invalid scheme path : "%s"' % file) + sys.exit() + if not os.path.exists(file): + print("scheme not found: \"%s\"" % file) + sys.exit() + + return args + + def run(self): + # 解析参数 + paths = self.__parse_argv() + # do test + cpaths = len(paths) + for idx in range(cpaths): try: - scheme = SchemeParser().parse(f) - scheme.prepare() + test = TestFactory().get(paths[idx]) + test.prepare() + test.do_test() + test.export(self.config.report_path) except SchemeError as e: print(e) sys.exit() except SchemeParserError as e: print(e) - sys.exit() - try: - self.test = TestFactory().get_test_object(scheme.get_test_type(), scheme) - self.test.prepare() - except TestNotFound as e: - logging.error(e) - sys.exit() - except SchemeError as e: - logging.error(e) - sys.exit() + except TestNotFound as e: + logging.error(e) + except TestCaseError as e: + logging.error(e) + except Exception as e: + logging.error(e) + except BaseException as e: + logging.error(e) + finally: + if (cpaths > 1) and ((idx + 1) < cpaths): + subproc_call("echo 3 > /proc/sys/vm/drop_caches") + time.sleep(10) + pass + + logging.info('all tests are finshed.') try: self.test.collect_env() -- Gitee