From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 16213A00C2; Wed, 17 Mar 2021 08:25:42 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 10AA3242B2E; Wed, 17 Mar 2021 08:25:42 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 2E6D7242B27 for ; Wed, 17 Mar 2021 08:25:40 +0100 (CET) IronPort-SDR: tqU78BUcjpFpKkiGfskQsQ4iNSn7moijdI2K5LGNR/t7Ky8KHaP883iERG3Gor+dSBbnq/r5an 7S4dM0rV+Hzg== X-IronPort-AV: E=McAfee;i="6000,8403,9925"; a="209369048" X-IronPort-AV: E=Sophos;i="5.81,255,1610438400"; d="scan'208";a="209369048" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 00:25:39 -0700 IronPort-SDR: RDZnSKFTZ5QVs7Qke8pw/JN1U6ZU0LSN6HzG2kT4Lw5ngQUAOsVmxi72VpN+w52YDG4uORGrZ/ AzosaitP48JA== X-IronPort-AV: E=Sophos;i="5.81,255,1610438400"; d="scan'208";a="405829295" Received: from unknown (HELO localhost.localdomain) ([10.240.183.57]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2021 00:25:38 -0700 From: Haiyang Zhao To: dts@dpdk.org Cc: Lijuan.Tu@intel.com, Haiyang Zhao Date: Wed, 17 Mar 2021 15:16:22 +0800 Message-Id: <20210317071625.13041-3-haiyangx.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210317071625.13041-1-haiyangx.zhao@intel.com> References: <20210317071625.13041-1-haiyangx.zhao@intel.com> Subject: [dts] [PATCH V1 2/5] framework/test_case: handle the VerifySkip exception and add some functions X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Sender: "dts" handle the VerfiySkip exception and mark the related case with N/A in result. add some functions to check if the nic or pkg support current case. Signed-off-by: Haiyang Zhao --- framework/test_case.py | 102 +++++++++++++++++++++++++++++++++++------ 1 file changed, 89 insertions(+), 13 deletions(-) diff --git a/framework/test_case.py b/framework/test_case.py index 57bea562..3347adad 100644 --- a/framework/test_case.py +++ b/framework/test_case.py @@ -38,7 +38,7 @@ import traceback import signal import time -from exception import VerifyFailure, TimeoutException +from exception import VerifyFailure, VerifySkip, TimeoutException from settings import DRIVERS, NICS, get_nic_name, load_global_setting from settings import PERF_SETTING, FUNC_SETTING, DEBUG_SETTING from settings import DEBUG_CASE_SETTING, HOST_DRIVER_SETTING @@ -48,6 +48,7 @@ from test_result import ResultTable, Result from logger import getLogger from config import SuiteConf from utils import BLUE, RED +from functools import wraps class TestCase(object): @@ -68,15 +69,10 @@ class TestCase(object): self._check_and_reconnect(crb=self.tester) # convert netdevice to codename - self.nics = [] - for portid in range(len(self.dut.ports_info)): - nic_type = self.dut.ports_info[portid]['type'] - self.nics.append(get_nic_name(nic_type)) - if len(self.nics): - self.nic = self.nics[0] - else: - self.nic = '' - self.kdriver = self._get_nic_driver(self.nic) + self.nic = self.dut.nic.name + self.nic_obj = self.dut.nic + self.kdriver = self.dut.nic.default_driver + self.pkg = self.dut.nic.pkg # result object for save suite result self._suite_result = Result() @@ -168,6 +164,12 @@ class TestCase(object): print(RED("History dump finished.")) raise VerifyFailure(description) + def skip_case(self, passed, description): + if not passed: + if self._enable_debug: + print("skip case: \"%s\" " % RED(description)) + raise VerifySkip(description) + def _get_nic_driver(self, nic_name): if nic_name in list(DRIVERS.keys()): return DRIVERS[nic_name] @@ -257,17 +259,28 @@ class TestCase(object): try: self.set_up_all() return True - except Exception: + except VerifySkip as v: + self.logger.info('set_up_all SKIPPED:\n' + traceback.format_exc()) + # record all cases N/A + if self._enable_func: + for case_obj in self._get_functional_cases(): + self._suite_result.test_case = case_obj.__name__ + self._suite_result.test_case_skip(str(v)) + if self._enable_perf: + for case_obj in self._get_performance_cases(): + self._suite_result.test_case = case_obj.__name__ + self._suite_result.test_case_skip(str(v)) + except Exception as v: self.logger.error('set_up_all failed:\n' + traceback.format_exc()) # record all cases blocked if self._enable_func: for case_obj in self._get_functional_cases(): self._suite_result.test_case = case_obj.__name__ - self._suite_result.test_case_blocked('set_up_all failed') + self._suite_result.test_case_blocked('set_up_all failed: {}'.format(str(v))) if self._enable_perf: for case_obj in self._get_performance_cases(): self._suite_result.test_case = case_obj.__name__ - self._suite_result.test_case_blocked('set_up_all failed') + self._suite_result.test_case_blocked('set_up_all failed: {}'.format(str(v))) return False def _execute_test_case(self, case_obj): @@ -328,6 +341,10 @@ class TestCase(object): self._suite_result.test_case_failed(str(v)) self._rst_obj.write_result("FAIL") self.logger.error('Test Case %s Result FAILED: ' % (case_name) + str(v)) + except VerifySkip as v: + self._suite_result.test_case_skip(str(v)) + self._rst_obj.write_result("N/A") + self.logger.info('Test Case %s N/A: ' % (case_name)) except KeyboardInterrupt: self._suite_result.test_case_blocked("Skipped") self.logger.error('Test Case %s SKIPPED: ' % (case_name)) @@ -504,3 +521,62 @@ class TestCase(object): bitrate *= 100 return bitrate * num_ports / 8 / (frame_size + 20) + + +def skip_unsupported_pkg(pkgs): + """ + Skip case which are not supported by the input pkgs + """ + if isinstance(pkgs, str): + pkgs = [pkgs] + + def decorator(func): + @wraps(func) + def wrapper(*args, **kwargs): + test_case = args[0] + pkg_type = test_case.pkg.get('type') + pkg_version = test_case.pkg.get('version') + if not pkg_type or not pkg_version: + raise VerifyFailure('Failed due to pkg is empty'.format(test_case.pkg)) + for pkg in pkgs: + if pkg in pkg_type: + raise VerifySkip('{} {} do not support this case'.format(pkg_type, pkg_version)) + return func(*args, **kwargs) + return wrapper + return decorator + + +def skip_unsupported_nic(nics): + """ + Skip case which are not supported by the input nics + """ + if isinstance(nics, str): + nics = [nics] + + def decorator(func): + @wraps(func) + def wrapper(*args, **kwargs): + test_case = args[0] + if test_case.nic in nics: + raise VerifySkip('{} do not support this case'.format(test_case.nic)) + return func(*args, **kwargs) + return wrapper + return decorator + + +def check_supported_nic(nics): + """ + check if the test case is supported by the input nics + """ + if isinstance(nics, str): + nics = [nics] + + def decorator(func): + @wraps(func) + def wrapper(*args, **kwargs): + test_case = args[0] + if test_case.nic not in nics: + raise VerifySkip('{} do not support this case'.format(test_case.nic)) + return func(*args, **kwargs) + return wrapper + return decorator -- 2.17.1