[RFC,v1,02/10] dts: hello world cli parameters and env vars

Message ID 20220824162454.394285-3-juraj.linkes@pantheon.tech (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series dts: add hello world testcase |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Juraj Linkeš Aug. 24, 2022, 4:24 p.m. UTC
  Add command line arguments (and the corresponding env variables) that
specify DPDK build and test execution workflow.

Also split the configuration into two parts, one that can be changed
during runtime and one that can't. We will need to change the git
refspec to a DPDK tarball path when support is added for building DPDK
from the repo.

Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
---
 dts/framework/logger.py   |  9 ++--
 dts/framework/settings.py | 96 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 96 insertions(+), 9 deletions(-)
  

Patch

diff --git a/dts/framework/logger.py b/dts/framework/logger.py
index 920ce0fb15..15cae3e4f9 100644
--- a/dts/framework/logger.py
+++ b/dts/framework/logger.py
@@ -8,6 +8,8 @@ 
 import os.path
 from typing import TypedDict
 
+from .settings import SETTINGS
+
 """
 DTS logger module with several log level. DTS framework and TestSuite log
 will saved into different log files.
@@ -66,10 +68,9 @@  def __init__(self, logger: logging.Logger, node: str = "suite"):
         self.logger.addHandler(sh)
         self.sh = sh
 
-        if not os.path.exists("output"):
-            os.mkdir("output")
+        logging_file_prefix = os.path.join(SETTINGS.output_dir, node)
 
-        fh = logging.FileHandler(f"output/{node}.log")
+        fh = logging.FileHandler(f"{logging_file_prefix}.log")
         fh.setFormatter(
             logging.Formatter(
                 fmt="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
@@ -83,7 +84,7 @@  def __init__(self, logger: logging.Logger, node: str = "suite"):
 
         # This outputs EVERYTHING, intended for post-mortem debugging
         # Also optimized for processing via AWK (awk -F '|' ...)
-        verbose_handler = logging.FileHandler(f"output/{node}.verbose.log")
+        verbose_handler = logging.FileHandler(f"{logging_file_prefix}.verbose.log")
         verbose_handler.setFormatter(
             logging.Formatter(
                 fmt="%(asctime)s|%(name)s|%(levelname)s|%(pathname)s|%(lineno)d|%(funcName)s|"
diff --git a/dts/framework/settings.py b/dts/framework/settings.py
index c9621d4e3d..1ff3af4438 100644
--- a/dts/framework/settings.py
+++ b/dts/framework/settings.py
@@ -7,6 +7,7 @@ 
 import argparse
 import os
 from dataclasses import dataclass
+from enum import Enum, unique
 from typing import Any
 
 
@@ -38,10 +39,40 @@  def wrapper(**kwargs) -> _EnvironmentArgument:
 
 
 @dataclass(slots=True, frozen=True)
-class _Settings:
+class _EnvSettings:
     config_file_path: str
+    compile_timeout: int
     timeout: float
     verbose: bool
+    output_dir: str
+    skip_setup: bool
+    test_cases: list
+    re_run: int
+    remote_dpdk_dir: str
+
+
+@dataclass(slots=True)
+class _RuntimeSettings:
+    dpdk_ref: str
+
+
+class _Settings(_EnvSettings, _RuntimeSettings):
+    pass
+
+
+@unique
+class DTSRuntimeErrors(Enum):
+    NO_ERR = 0
+    GENERIC_ERR = 1
+    DPDK_BUILD_ERR = (2,)
+    SUT_SETUP_ERR = (3,)
+    TG_SETUP_ERR = (4,)
+    SUITE_SETUP_ERR = (5,)
+    SUITE_EXECUTE_ERR = 6
+
+
+# TODO singleton
+DTSRuntimeError: DTSRuntimeErrors = DTSRuntimeErrors.NO_ERR
 
 
 def _get_parser() -> argparse.ArgumentParser:
@@ -63,6 +94,14 @@  def _get_parser() -> argparse.ArgumentParser:
         help="[DTS_TIMEOUT] The default timeout for all DTS operations except for compiling DPDK.",
     )
 
+    parser.add_argument(
+        "--compile-timeout",
+        action=_env_arg("DTS_COMPILE_TIMEOUT"),
+        default=1200,
+        required=False,
+        help="[DTS_COMPILE_TIMEOUT] The timeout for compiling DPDK.",
+    )
+
     parser.add_argument(
         "-v",
         "--verbose",
@@ -72,15 +111,62 @@  def _get_parser() -> argparse.ArgumentParser:
         help="[DTS_VERBOSE] Set to 'Y' to enable verbose output, logging all messages to the console.",
     )
 
+    parser.add_argument(
+        "--dpdk-ref",
+        "--git",
+        "--snapshot",
+        action=_env_arg("DTS_DPDK_REF"),
+        default="dep/dpdk.tar.gz",
+        help="[DTS_DPDK_REF] Reference to DPDK source code, "
+        "can be either a path to a tarball or a git refspec. "
+        "In case of a tarball, it will be extracted in the same directory.",
+    )
+
+    parser.add_argument(
+        "--output-dir",
+        "--output",
+        action=_env_arg("DTS_OUTPUT_DIR"),
+        default="output",
+        help="[DTS_OUTPUT_DIR] Output directory where dts logs and results are saved.",
+    )
+
+    parser.add_argument(
+        "-s",
+        "--skip-setup",
+        action=_env_arg("DTS_SKIP_SETUP"),
+        help="[DTS_SKIP_SETUP] Set to 'Y' to skip all setup steps on SUT and TG nodes.",
+    )
+
+    parser.add_argument(
+        "--test-cases",
+        action=_env_arg("DTS_TESTCASES"),
+        help="[DTS_TESTCASES] Comma-separated list of testcases to execute",
+    )
+
+    parser.add_argument(
+        "--re-run",
+        "--re_run",
+        action=_env_arg("DTS_RERUN"),
+        default=0,
+        help="[DTS_RERUN] Re-run tests the specified amount of times if a test failure occurs",
+    )
+
     return parser
 
 
 def _get_settings() -> _Settings:
-    args = _get_parser().parse_args()
+    parsed_args = _get_parser().parse_args()
     return _Settings(
-        config_file_path=args.config_file,
-        timeout=float(args.timeout),
-        verbose=(args.verbose == "Y"),
+        config_file_path=parsed_args.config_file,
+        compile_timeout=parsed_args.compile_timeout,
+        timeout=parsed_args.timeout,
+        verbose=(parsed_args.verbose == "Y"),
+        output_dir=parsed_args.output_dir,
+        skip_setup=(parsed_args.skip_setup == "Y"),
+        test_cases=parsed_args.test_cases.split(","),
+        re_run=int(parsed_args.re_run),
+        remote_dpdk_dir="/tmp/",
+        dpdk_ref=parsed_args.dpdk_ref,
     )