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 163AC45C79; Mon, 4 Nov 2024 18:50:16 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 006DB4113C; Mon, 4 Nov 2024 18:50:15 +0100 (CET) Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by mails.dpdk.org (Postfix) with ESMTP id 074C44028F for ; Mon, 4 Nov 2024 18:50:15 +0100 (CET) Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-539d9bfc5d1so600181e87.0 for ; Mon, 04 Nov 2024 09:50:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1730742614; x=1731347414; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=92g0xQmDd4mZMY65/plxemMAaPx7kLdz1TjA/TIE/NY=; b=OyUIvupmHQJwM5ddomKZdYu8JaFRg4oRxejsj9xyFufhJBJuZi7fp6qgp0ehgFCUqo 3MXT4j/47m+84Zfvjke/IavBGjNMoOPkW5beQpxj1tq1r6iq+44TdF8kax5QEGQVo69+ gp/hZt+mbPnzN7fn/VybSoS8sm0HkJeMCIYDk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730742614; x=1731347414; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=92g0xQmDd4mZMY65/plxemMAaPx7kLdz1TjA/TIE/NY=; b=rgRyKmYMerAD1ZLJ+GVQgV7zy6ef6118Q5v+93cgNymi4ss1uirNOO11Lp5ssteFdj jq9hdR0qSRoT2/xJlzF4QOQMtmpvvUGhDgbtKjThoQt1PSSpKCiC87WIfRtLrOW1mlYb WEmdnIIcFUjW48huOdzWViws9lRbjLkonKPpEUDJDKjZzFBg/vsn6Y/o/KljaK0cqQba m020DQngHYPExNAOC47Y3mrM52rDEmtRrwUcxPdMl+959QdHDqTiMMisliWztx7fmABe /qqkRwuP4IpnOn1IwmuAnPVO63DRbS2RvjphBEkuk7dCWwLI1l7kxmI617Jmaxv7qQsS t5JA== X-Gm-Message-State: AOJu0YyPpRy5s4lTFoTiErjY0bQk7k07C8gSD0u+oulm2aQf3V6qkPA/ wjmcdf+/mHEqMEPxBSuGMLwTNYlEJetR8KsysS5Hb+xal/AMuBpWdxRXmS4N/NLUTKm8s28XV0l 7iKTKYMwKmbOHrwj6y2kiP7RiCKH2njvV8J+khQ== X-Google-Smtp-Source: AGHT+IGwHe/90sFEAisF9ZjhzhJWC86nEH5Mm+emuHzElxqbxlmufetTe1oOe8nqaK9tIBo0f7+QynndjuV4jrfAk+s= X-Received: by 2002:a05:6512:234b:b0:539:cc4e:76e0 with SMTP id 2adb3069b0e04-53b348b9909mr5174500e87.2.1730742614190; Mon, 04 Nov 2024 09:50:14 -0800 (PST) MIME-Version: 1.0 References: <20240822163941.1390326-1-luca.vizzarro@arm.com> <20241028174949.3283701-1-luca.vizzarro@arm.com> <20241028174949.3283701-9-luca.vizzarro@arm.com> In-Reply-To: <20241028174949.3283701-9-luca.vizzarro@arm.com> From: Nicholas Pratte Date: Mon, 4 Nov 2024 12:50:02 -0500 Message-ID: Subject: Re: [PATCH v4 8/8] dts: use TestSuiteSpec class imports To: Luca Vizzarro Cc: dev@dpdk.org, Paul Szczepanek , Patrick Robb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Reviewed-by: Nicholas Pratte On Mon, Oct 28, 2024 at 1:51=E2=80=AFPM Luca Vizzarro wrote: > > The introduction of TestSuiteSpec adds auto-discovery of test suites, > which are also automatically imported. This causes double imports as the > runner loads the test suites. This changes the behaviour of the runner > to load the imported classes from TestSuiteSpec instead of importing > them again. > > Signed-off-by: Luca Vizzarro > Reviewed-by: Paul Szczepanek > --- > dts/framework/runner.py | 84 ++++------------------------------------- > 1 file changed, 7 insertions(+), 77 deletions(-) > > diff --git a/dts/framework/runner.py b/dts/framework/runner.py > index c3d9a27a8c..5f5837a132 100644 > --- a/dts/framework/runner.py > +++ b/dts/framework/runner.py > @@ -2,6 +2,7 @@ > # Copyright(c) 2010-2019 Intel Corporation > # Copyright(c) 2022-2023 PANTHEON.tech s.r.o. > # Copyright(c) 2022-2023 University of New Hampshire > +# Copyright(c) 2024 Arm Limited > > """Test suite runner module. > > @@ -17,8 +18,6 @@ > and the test case stage runs test cases individually. > """ > > -import importlib > -import inspect > import os > import random > import sys > @@ -39,12 +38,7 @@ > TGNodeConfiguration, > load_config, > ) > -from .exception import ( > - BlockingTestSuiteError, > - ConfigurationError, > - SSHTimeoutError, > - TestCaseVerifyError, > -) > +from .exception import BlockingTestSuiteError, SSHTimeoutError, TestCase= VerifyError > from .logger import DTSLogger, DtsStage, get_dts_logger > from .settings import SETTINGS > from .test_result import ( > @@ -215,11 +209,10 @@ def _get_test_suites_with_cases( > func: bool, > perf: bool, > ) -> list[TestSuiteWithCases]: > - """Test suites with test cases discovery. > + """Get test suites with selected cases. > > - The test suites with test cases defined in the user configuratio= n are discovered > - and stored for future use so that we don't import the modules tw= ice and so that > - the list of test suites with test cases is available for recordi= ng right away. > + The test suites with test cases defined in the user configuratio= n are selected > + and the corresponding functions and classes are gathered. > > Args: > test_suite_configs: Test suite configurations. > @@ -227,12 +220,12 @@ def _get_test_suites_with_cases( > perf: Whether to include performance test cases in the final= list. > > Returns: > - The discovered test suites, each with test cases. > + The test suites, each with test cases. > """ > test_suites_with_cases =3D [] > > for test_suite_config in test_suite_configs: > - test_suite_class =3D self._get_test_suite_class(test_suite_c= onfig.test_suite_name) > + test_suite_class =3D test_suite_config.test_suite_spec.class= _obj > test_cases: list[type[TestCase]] =3D [] > func_test_cases, perf_test_cases =3D test_suite_class.filter= _test_cases( > test_suite_config.test_cases_names > @@ -245,71 +238,8 @@ def _get_test_suites_with_cases( > test_suites_with_cases.append( > TestSuiteWithCases(test_suite_class=3Dtest_suite_class, = test_cases=3Dtest_cases) > ) > - > return test_suites_with_cases > > - def _get_test_suite_class(self, module_name: str) -> type[TestSuite]= : > - """Find the :class:`TestSuite` class in `module_name`. > - > - The full module name is `module_name` prefixed with `self._test_= suite_module_prefix`. > - The module name is a standard filename with words separated with= underscores. > - Search the `module_name` for a :class:`TestSuite` class which st= arts > - with `self._test_suite_class_prefix`, continuing with CamelCase = `module_name`. > - The first matching class is returned. > - > - The CamelCase convention applies to abbreviations, acronyms, ini= tialisms and so on:: > - > - OS -> Os > - TCP -> Tcp > - > - Args: > - module_name: The module name without prefix where to search = for the test suite. > - > - Returns: > - The found test suite class. > - > - Raises: > - ConfigurationError: If the corresponding module is not found= or > - a valid :class:`TestSuite` is not found in the module. > - """ > - > - def is_test_suite(object) -> bool: > - """Check whether `object` is a :class:`TestSuite`. > - > - The `object` is a subclass of :class:`TestSuite`, but not :c= lass:`TestSuite` itself. > - > - Args: > - object: The object to be checked. > - > - Returns: > - :data:`True` if `object` is a subclass of `TestSuite`. > - """ > - try: > - if issubclass(object, TestSuite) and object is not TestS= uite: > - return True > - except TypeError: > - return False > - return False > - > - testsuite_module_path =3D f"{self._test_suite_module_prefix}{mod= ule_name}" > - try: > - test_suite_module =3D importlib.import_module(testsuite_modu= le_path) > - except ModuleNotFoundError as e: > - raise ConfigurationError( > - f"Test suite module '{testsuite_module_path}' not found.= " > - ) from e > - > - camel_case_suite_name =3D "".join( > - [suite_word.capitalize() for suite_word in module_name.split= ("_")] > - ) > - full_suite_name_to_find =3D f"{self._test_suite_class_prefix}{ca= mel_case_suite_name}" > - for class_name, class_obj in inspect.getmembers(test_suite_modul= e, is_test_suite): > - if class_name =3D=3D full_suite_name_to_find: > - return class_obj > - raise ConfigurationError( > - f"Couldn't find any valid test suites in {test_suite_module.= __name__}." > - ) > - > def _connect_nodes_and_run_test_run( > self, > sut_nodes: dict[str, SutNode], > -- > 2.43.0 >