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 94E55A0561; Thu, 18 Mar 2021 10:31:18 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8FE9D140F2C; Thu, 18 Mar 2021 10:31:18 +0100 (CET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id E307A140F17 for ; Thu, 18 Mar 2021 10:31:16 +0100 (CET) IronPort-SDR: AFjW9EpV1ewD7qcIvzLCzsqHaH85TSsLLO55r9U5EUkynHaysb6wjBdIb184CRqps+llRa6yZV 2oDitJNbDEBg== X-IronPort-AV: E=McAfee;i="6000,8403,9926"; a="189731907" X-IronPort-AV: E=Sophos;i="5.81,258,1610438400"; d="scan'208";a="189731907" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2021 02:31:16 -0700 IronPort-SDR: 47zIuwYtjsd0T0weME49KiLkJ6sX+VJtuEb8Qvbu2QDAp2j6nNu+18uIQAKxI6mgRjJs9rhFkE r+JSoIhzQ8ew== X-IronPort-AV: E=Sophos;i="5.81,258,1610438400"; d="scan'208";a="413013393" Received: from unknown (HELO localhost.localdomain) ([10.240.183.57]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2021 02:31:14 -0700 From: Haiyang Zhao To: dts@dpdk.org Cc: lijuan.tu@intel.com, Haiyang Zhao Date: Thu, 18 Mar 2021 17:22:12 +0800 Message-Id: <20210318092215.27270-3-haiyangx.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210318092215.27270-1-haiyangx.zhao@intel.com> References: <20210318092215.27270-1-haiyangx.zhao@intel.com> Subject: [dts] [PATCH V2 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