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 62F92A0032; Mon, 11 Jul 2022 16:52:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3DA6542B82; Mon, 11 Jul 2022 16:51:41 +0200 (CEST) Received: from lb.pantheon.sk (lb.pantheon.sk [46.229.239.20]) by mails.dpdk.org (Postfix) with ESMTP id 7CCE942826 for ; Mon, 11 Jul 2022 16:51:37 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by lb.pantheon.sk (Postfix) with ESMTP id B53AE243CE2; Mon, 11 Jul 2022 16:51:36 +0200 (CEST) X-Virus-Scanned: amavisd-new at siecit.sk Received: from lb.pantheon.sk ([127.0.0.1]) by localhost (lb.pantheon.sk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Jqvw7E3Li-Gl; Mon, 11 Jul 2022 16:51:35 +0200 (CEST) Received: from entguard.lab.pantheon.local (unknown [46.229.239.141]) by lb.pantheon.sk (Postfix) with ESMTP id CB2E3243CE5; Mon, 11 Jul 2022 16:51:31 +0200 (CEST) From: =?UTF-8?q?Juraj=20Linke=C5=A1?= To: thomas@monjalon.net, david.marchand@redhat.com, jerinjacobk@gmail.com, ronan.randles@intel.com, Honnappa.Nagarahalli@arm.com, ohilyard@iol.unh.edu, lijuan.tu@intel.com Cc: dev@dpdk.org, =?UTF-8?q?Juraj=20Linke=C5=A1?= Subject: [PATCH v2 7/8] dts: add dts workflow module Date: Mon, 11 Jul 2022 14:51:25 +0000 Message-Id: <20220711145126.295427-8-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711145126.295427-1-juraj.linkes@pantheon.tech> References: <20220622121448.3304251-1-juraj.linkes@pantheon.tech> <20220711145126.295427-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 The module implements methods needed to run DTS. It handles the creation of objects and eventually the whole DTS workflow, such as running node setups, test gathering, setup and execution and various cleanups. Signed-off-by: Juraj Linkeš --- dts/framework/dts.py | 76 ++++++++++++++++++++++++++++++++++++++++++ dts/framework/utils.py | 35 +++++++++++++++++-- 2 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 dts/framework/dts.py diff --git a/dts/framework/dts.py b/dts/framework/dts.py new file mode 100644 index 0000000000..52ec0638df --- /dev/null +++ b/dts/framework/dts.py @@ -0,0 +1,76 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2010-2019 Intel Corporation +# Copyright(c) 2022 PANTHEON.tech s.r.o. +# Copyright(c) 2022 University of New Hampshire +# + +import sys +from typing import Iterable, Optional + +import framework.logger as logger + +from .config import Configuration, load_config +from .logger import getLogger +from .node import Node +from .utils import check_dts_python_version, create_parallel_locks + +log_handler: Optional[logger.DTSLOG] = None + + +def dts_nodes_exit(nodes: Iterable[Node]) -> None: + """ + Call SUT and TG exit function after execution finished + """ + for node in nodes: + node.node_exit() + + +def run_all( + config_file, + verbose, +) -> None: + """ + Main process of DTS, it will run all test suites in the config file. + """ + + global log_handler + + # check the python version of the server that run dts + check_dts_python_version() + + # init log_handler handler + if verbose is True: + logger.set_verbose() + + log_handler = getLogger("dts") + + # parse input config file + config: Configuration = load_config(config_file) + + # init global lock + create_parallel_locks(len(config.nodes)) + + nodes = [] + try: + nodes = [ + Node(node_config, sut_id=i) + for i, node_config in enumerate(config.nodes) + ] + dts_nodes_exit(nodes) + finally: + quit_execution(nodes) + + +def quit_execution(nodes: Iterable[Node]) -> None: + """ + Close session to SUT and TG before quit. + Return exit status when failure occurred. + """ + for node in nodes: + # close all session + node.node_exit() + + if log_handler is not None: + log_handler.info("DTS ended") + + sys.exit(0) diff --git a/dts/framework/utils.py b/dts/framework/utils.py index a637c4641e..1f7f28d0c5 100644 --- a/dts/framework/utils.py +++ b/dts/framework/utils.py @@ -4,15 +4,29 @@ # Copyright(c) 2022 University of New Hampshire # +import sys import threading from functools import wraps from typing import Any, Callable, TypeVar locks_info: list[dict[str, Any]] = list() -T = TypeVar("T") + +def create_parallel_locks(num_suts: int) -> None: + """ + Create thread lock dictionary based on SUTs number + """ + global locks_info + + locks_info = list() + for _ in range(num_suts): + lock_info = dict() + lock_info["update_lock"] = threading.RLock() + locks_info.append(lock_info) +T = TypeVar("T") + def parallel_lock(num: int = 1) -> Callable[[Callable[..., T]], Callable[..., T]]: """ Wrapper function for protect parallel threads, allow multiple threads @@ -21,7 +35,6 @@ def parallel_lock(num: int = 1) -> Callable[[Callable[..., T]], Callable[..., T] Parameter: num: Number of parallel threads for the lock """ - global locks_info def decorate(func: Callable[..., T]) -> Callable[..., T]: # mypy does not know how to handle the types of this function, so Any is required @@ -97,3 +110,21 @@ def RED(text: str) -> str: def GREEN(text: str) -> str: return f"\u001B[32;1m{str(text)}\u001B[0m" + + +def check_dts_python_version() -> None: + if ( + sys.version_info.major < 3 + or (sys.version_info.major == 3 and sys.version_info.minor < 10) + ): + print( + RED( + ( + "WARNING: Dts running node python version is lower than python 3.10, " + "it is deprecated for use in DTS, " + "and will not work in future releases." + ) + ), + file=sys.stderr, + ) + print(RED("Please use Python >= 3.10 instead"), file=sys.stderr) \ No newline at end of file -- 2.30.2