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 F223C45C79; Mon, 4 Nov 2024 19:49:01 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8FE0340281; Mon, 4 Nov 2024 19:49:01 +0100 (CET) Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by mails.dpdk.org (Postfix) with ESMTP id 4F72B4025F for ; Mon, 4 Nov 2024 19:48:59 +0100 (CET) Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-6e9ba45d67fso42246257b3.1 for ; Mon, 04 Nov 2024 10:48:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1730746138; x=1731350938; darn=dpdk.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7UB7L/nfgSXWTdyoHj2tZ6BNT56hnHgER2cdN3Y4OuI=; b=N8Rw+25DtUXCfdRZtsrzRV7STqyNc1W0SLQ965jHZro8Z7fHIrsDSmvSaTc4VfwBoE ktuCh+vfPTlpuZFbII+wCyTgfPzMQXgHbQwxtLOSoRdDyLSIx4e+byD1/l0XZGT9XeIy RFAsYfP+SWVjsLv4nJEcKi1MAr+gUeLll1h0o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730746138; x=1731350938; h=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=7UB7L/nfgSXWTdyoHj2tZ6BNT56hnHgER2cdN3Y4OuI=; b=Q0F3C/ESkkQfc7fYT/1T4tysbHrIksogyFwVUc5F+OTXPHFgEqh/SpNwNXWkqt4aaC VM7sQAeGPVK+hFdfdXGQe/Nr1zL9ZhiSQipniSznfIYYryUQrKG5Q/zZwLCgEfA2/L3w XvMhHD7FiR92Jfr3JW1SZibYDNER6dAGqlgA8r51fb/Rok/nLHzM1vPQHr750qWp8FTE 4PQ13vYu5STpHJToWi9w8vcwXRXff0FPIR3KON4pdWOgDSvtl0PxASkwBdA37jyLAbl+ HpFMolBGV5TkecUkb3dqFfqq2SUbzCwAVvVADNOgYyELFrqAMy9YiXMGHNtwoR0Sr2S4 ueJQ== X-Gm-Message-State: AOJu0YxTzjKXshmPbC3D1oILtH7odsgfYWJmkmmXZZmnPDw1UyEDJqI7 BA4QcITMYVEVD9DYOmizB+93MBP+Fi6U0QqNL/DjDe91Jc4wo1cNBiFOZHCyNExKrGizWH9Drhc i0uqV7IiMwHMeoHk+dTBxxfyCZV+nYQBCFOES+uA0TIdLyjTrgiM= X-Google-Smtp-Source: AGHT+IG5jmvgoXi2AY6XWDEKlaj90BNPvFpPzyUvV4a12b5Ry3aMytvW/6dc21hvKDnqI/TIURKCuDe7TdNZnuwDWbc= X-Received: by 2002:a05:690c:445:b0:6ea:9bca:9fdc with SMTP id 00721157ae682-6ea9bcaa343mr43675867b3.34.1730746138412; Mon, 04 Nov 2024 10:48:58 -0800 (PST) MIME-Version: 1.0 References: <20240930162601.30317-1-tomas.durovec@pantheon.tech> In-Reply-To: From: Dean Marx Date: Mon, 4 Nov 2024 13:49:11 -0500 Message-ID: Subject: Re: [PATCH] dts: improve statistics To: =?UTF-8?B?VG9tw6HFoSDEjnVyb3ZlYw==?= , Luca Vizzarro Cc: dev@dpdk.org Content-Type: multipart/alternative; boundary="000000000000c6e2a306261abce2" 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 --000000000000c6e2a306261abce2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Adding Luca to this thread because it applies to him as well: Hi Tom=C3=A1=C5=A1, This all looks great, one thing I did notice when running locally is that the "test_suites" section of results.json contains null values instead of the names of the suites that were run. Could just be something strange happening on my side, but I would double check on your end just in case. Otherwise: Reviewed-by: Dean Marx On Fri, Oct 25, 2024 at 1:59=E2=80=AFPM Dean Marx wrote= : > Hi Tom=C3=A1=C5=A1, > > This all looks great, one thing I did notice when running locally is that > the "test_suites" section of results.json contains null values instead of > the names of the suites that were run. Could just be something strange > happening on my side, but I would double check on your end just in case. > Otherwise: > > Reviewed-by: Dean Marx > > On Mon, Sep 30, 2024 at 12:26=E2=80=AFPM Tom=C3=A1=C5=A1 =C4=8Eurovec > wrote: > >> The previous version of statistics store only the last test run >> attribute and result. In this patch we are adding header for each >> test run and overall summary of test runs at the end. This is >> represented as textual summaries with basic information and json >> result with more detailed information. >> >> Signed-off-by: Tom=C3=A1=C5=A1 =C4=8Eurovec >> >> Depends-on: series-33184 ("DTS external DPDK build") >> --- >> dts/framework/runner.py | 7 +- >> dts/framework/test_result.py | 409 ++++++++++++++++++++++++++++------- >> 2 files changed, 332 insertions(+), 84 deletions(-) >> >> diff --git a/dts/framework/runner.py b/dts/framework/runner.py >> index 7d463c1fa1..be615ccace 100644 >> --- a/dts/framework/runner.py >> +++ b/dts/framework/runner.py >> @@ -84,7 +84,7 @@ def __init__(self): >> if not os.path.exists(SETTINGS.output_dir): >> os.makedirs(SETTINGS.output_dir) >> self._logger.add_dts_root_logger_handlers(SETTINGS.verbose, >> SETTINGS.output_dir) >> - self._result =3D DTSResult(self._logger) >> + self._result =3D DTSResult(SETTINGS.output_dir, self._logger) >> self._test_suite_class_prefix =3D "Test" >> self._test_suite_module_prefix =3D "tests.TestSuite_" >> self._func_test_case_regex =3D r"test_(?!perf_)" >> @@ -421,11 +421,12 @@ def _run_test_run( >> self._logger.info( >> f"Running test run with SUT '{ >> test_run_config.system_under_test_node.name}'." >> ) >> - test_run_result.add_sut_info(sut_node.node_info) >> + test_run_result.ports =3D sut_node.ports >> + test_run_result.sut_info =3D sut_node.node_info >> try: >> dpdk_location =3D SETTINGS.dpdk_location or >> test_run_config.dpdk_config.dpdk_location >> sut_node.set_up_test_run(test_run_config, dpdk_location) >> - >> test_run_result.add_dpdk_build_info(sut_node.get_dpdk_build_info()) >> + test_run_result.dpdk_build_info =3D >> sut_node.get_dpdk_build_info() >> tg_node.set_up_test_run(test_run_config, dpdk_location) >> test_run_result.update_setup(Result.PASS) >> except Exception as e: >> diff --git a/dts/framework/test_result.py b/dts/framework/test_result.py >> index 0a10723098..bf148a6b45 100644 >> --- a/dts/framework/test_result.py >> +++ b/dts/framework/test_result.py >> @@ -22,18 +22,19 @@ >> variable modify the directory where the files with results will be >> stored. >> """ >> >> -import os.path >> +import json >> from collections.abc import MutableSequence >> -from dataclasses import dataclass >> +from dataclasses import asdict, dataclass >> from enum import Enum, auto >> +from pathlib import Path >> from types import FunctionType >> -from typing import Union >> +from typing import Any, Callable, TypedDict >> >> from .config import DPDKBuildInfo, NodeInfo, TestRunConfiguration, >> TestSuiteConfig >> from .exception import DTSError, ErrorSeverity >> from .logger import DTSLogger >> -from .settings import SETTINGS >> from .test_suite import TestSuite >> +from .testbed_model.port import Port >> >> >> @dataclass(slots=3DTrue, frozen=3DTrue) >> @@ -85,6 +86,60 @@ def __bool__(self) -> bool: >> return self is self.PASS >> >> >> +class TestCaseResultDict(TypedDict): >> + """Represents the `TestCaseResult` results. >> + >> + Attributes: >> + test_case_name: The name of the test case. >> + result: The result name of the test case. >> + """ >> + >> + test_case_name: str >> + result: str >> + >> + >> +class TestSuiteResultDict(TypedDict): >> + """Represents the `TestSuiteResult` results. >> + >> + Attributes: >> + test_suite_name: The name of the test suite. >> + test_cases: A list of test case results contained in this test >> suite. >> + """ >> + >> + test_suite_name: str >> + test_cases: list[TestCaseResultDict] >> + >> + >> +class TestRunResultDict(TypedDict, total=3DFalse): >> + """Represents the `TestRunResult` results. >> + >> + Attributes: >> + compiler_version: The version of the compiler used for the DPDK >> build. >> + dpdk_version: The version of DPDK being tested. >> + ports: A list of ports associated with the test run. >> + test_suites: A list of test suite results included in this test >> run. >> + summary: A dictionary containing overall results, such as >> pass/fail counts. >> + """ >> + >> + compiler_version: str | None >> + dpdk_version: str | None >> + ports: list[dict[str, Any]] >> + test_suites: list[TestSuiteResultDict] >> + summary: dict[str, int | float] >> + >> + >> +class DtsRunResultDict(TypedDict): >> + """Represents the `DtsRunResult` results. >> + >> + Attributes: >> + test_runs: A list of test run results. >> + summary: A summary dictionary containing overall statistics for >> the test runs. >> + """ >> + >> + test_runs: list[TestRunResultDict] >> + summary: dict[str, int | float] >> + >> + >> class FixtureResult: >> """A record that stores the result of a setup or a teardown. >> >> @@ -198,14 +253,34 @@ def get_errors(self) -> list[Exception]: >> """ >> return self._get_setup_teardown_errors() + >> self._get_child_errors() >> >> - def add_stats(self, statistics: "Statistics") -> None: >> - """Collate stats from the whole result hierarchy. >> + def to_dict(self): >> + """Convert the results hierarchy into a dictionary >> representation.""" >> + >> + def add_result(self, results: dict[str, int]): >> + """Collate the test case result from the result hierarchy. >> >> Args: >> - statistics: The :class:`Statistics` object where the stats >> will be collated. >> + results: The dictionary to which results will be collated. >> """ >> for child_result in self.child_results: >> - child_result.add_stats(statistics) >> + child_result.add_result(results) >> + >> + def generate_pass_rate_dict(self, test_run_summary) -> dict[str, >> float]: >> + """Generate a dictionary with the FAIL/PASS ratio of all test >> cases. >> + >> + Args: >> + test_run_summary: The summary dictionary containing test >> result counts. >> + >> + Returns: >> + A dictionary with the FAIL/PASS ratio of all test cases. >> + """ >> + return { >> + "PASS_RATE": ( >> + float(test_run_summary[Result.PASS.name]) >> + * 100 >> + / sum(test_run_summary[result.name] for result in >> Result) >> + ) >> + } >> >> >> class DTSResult(BaseResult): >> @@ -220,31 +295,25 @@ class DTSResult(BaseResult): >> and as such is where the data form the whole hierarchy is collated >> or processed. >> >> The internal list stores the results of all test runs. >> - >> - Attributes: >> - dpdk_version: The DPDK version to record. >> """ >> >> - dpdk_version: str | None >> + _output_dir: str >> _logger: DTSLogger >> _errors: list[Exception] >> _return_code: ErrorSeverity >> - _stats_result: Union["Statistics", None] >> - _stats_filename: str >> >> - def __init__(self, logger: DTSLogger): >> + def __init__(self, output_dir: str, logger: DTSLogger): >> """Extend the constructor with top-level specifics. >> >> Args: >> + output_dir: The directory where DTS logs and results are >> saved. >> logger: The logger instance the whole result will use. >> """ >> super().__init__() >> - self.dpdk_version =3D None >> + self._output_dir =3D output_dir >> self._logger =3D logger >> self._errors =3D [] >> self._return_code =3D ErrorSeverity.NO_ERR >> - self._stats_result =3D None >> - self._stats_filename =3D os.path.join(SETTINGS.output_dir, >> "statistics.txt") >> >> def add_test_run(self, test_run_config: TestRunConfiguration) -> >> "TestRunResult": >> """Add and return the child result (test run). >> @@ -281,10 +350,8 @@ def process(self) -> None: >> for error in self._errors: >> self._logger.debug(repr(error)) >> >> - self._stats_result =3D Statistics(self.dpdk_version) >> - self.add_stats(self._stats_result) >> - with open(self._stats_filename, "w+") as stats_file: >> - stats_file.write(str(self._stats_result)) >> + TextSummary(self).save(Path(self._output_dir, >> "results_summary.txt")) >> + JsonResults(self).save(Path(self._output_dir, "results.json")) >> >> def get_return_code(self) -> int: >> """Go through all stored Exceptions and return the final DTS >> error code. >> @@ -302,6 +369,37 @@ def get_return_code(self) -> int: >> >> return int(self._return_code) >> >> + def to_dict(self) -> DtsRunResultDict: >> + """Convert DTS result into a dictionary format. >> + >> + The dictionary contains test runs and summary of test runs. >> + >> + Returns: >> + A dictionary representation of the DTS result >> + """ >> + >> + def merge_test_run_summaries(test_run_summaries: list[dict[str, >> int]]) -> dict[str, int]: >> + """Merge multiple test run summaries into one dictionary. >> + >> + Args: >> + test_run_summaries: List of test run summary >> dictionaries. >> + >> + Returns: >> + A merged dictionary containing the aggregated summary. >> + """ >> + return { >> + key.name: sum(test_run_summary[key.name] for >> test_run_summary in test_run_summaries) >> + for key in Result >> + } >> + >> + test_runs =3D [child.to_dict() for child in self.child_results] >> + test_run_summary =3D merge_test_run_summaries([test_run["summar= y"] >> for test_run in test_runs]) >> + >> + return { >> + "test_runs": test_runs, >> + "summary": test_run_summary | >> self.generate_pass_rate_dict(test_run_summary), >> + } >> + >> >> class TestRunResult(BaseResult): >> """The test run specific result. >> @@ -316,13 +414,11 @@ class TestRunResult(BaseResult): >> sut_kernel_version: The operating system kernel version of the >> SUT node. >> """ >> >> - compiler_version: str | None >> - dpdk_version: str | None >> - sut_os_name: str >> - sut_os_version: str >> - sut_kernel_version: str >> _config: TestRunConfiguration >> _test_suites_with_cases: list[TestSuiteWithCases] >> + _ports: list[Port] >> + _sut_info: NodeInfo | None >> + _dpdk_build_info: DPDKBuildInfo | None >> >> def __init__(self, test_run_config: TestRunConfiguration): >> """Extend the constructor with the test run's config. >> @@ -331,10 +427,11 @@ def __init__(self, test_run_config: >> TestRunConfiguration): >> test_run_config: A test run configuration. >> """ >> super().__init__() >> - self.compiler_version =3D None >> - self.dpdk_version =3D None >> self._config =3D test_run_config >> self._test_suites_with_cases =3D [] >> + self._ports =3D [] >> + self._sut_info =3D None >> + self._dpdk_build_info =3D None >> >> def add_test_suite( >> self, >> @@ -374,24 +471,96 @@ def test_suites_with_cases(self, >> test_suites_with_cases: list[TestSuiteWithCases >> ) >> self._test_suites_with_cases =3D test_suites_with_cases >> >> - def add_sut_info(self, sut_info: NodeInfo) -> None: >> - """Add SUT information gathered at runtime. >> + @property >> + def ports(self) -> list[Port]: >> + """Get the list of ports associated with this test run.""" >> + return self._ports >> + >> + @ports.setter >> + def ports(self, ports: list[Port]) -> None: >> + """Set the list of ports associated with this test run. >> + >> + Args: >> + ports: The list of ports to associate with this test run. >> + >> + Raises: >> + ValueError: If the ports have already been assigned to this >> test run. >> + """ >> + if self._ports: >> + raise ValueError( >> + "Attempted to assign `ports` to a test run result which >> already has `ports`." >> + ) >> + self._ports =3D ports >> + >> + @property >> + def sut_info(self) -> NodeInfo | None: >> + """Get the SUT node information associated with this test run."= "" >> + return self._sut_info >> + >> + @sut_info.setter >> + def sut_info(self, sut_info: NodeInfo) -> None: >> + """Set the SUT node information associated with this test run. >> >> Args: >> - sut_info: The additional SUT node information. >> + sut_info: The SUT node information to associate with this >> test run. >> + >> + Raises: >> + ValueError: If the SUT information has already been assigne= d >> to this test run. >> """ >> - self.sut_os_name =3D sut_info.os_name >> - self.sut_os_version =3D sut_info.os_version >> - self.sut_kernel_version =3D sut_info.kernel_version >> + if self._sut_info: >> + raise ValueError( >> + "Attempted to assign `sut_info` to a test run result >> which already has `sut_info`." >> + ) >> + self._sut_info =3D sut_info >> >> - def add_dpdk_build_info(self, versions: DPDKBuildInfo) -> None: >> - """Add information about the DPDK build gathered at runtime. >> + @property >> + def dpdk_build_info(self) -> DPDKBuildInfo | None: >> + """Get the DPDK build information associated with this test >> run.""" >> + return self._dpdk_build_info >> + >> + @dpdk_build_info.setter >> + def dpdk_build_info(self, dpdk_build_info: DPDKBuildInfo) -> None: >> + """Set the DPDK build information associated with this test run= . >> >> Args: >> - versions: The additional information. >> + dpdk_build_info: The DPDK build information to associate >> with this test run. >> + >> + Raises: >> + ValueError: If the DPDK build information has already been >> assigned to this test run. >> """ >> - self.compiler_version =3D versions.compiler_version >> - self.dpdk_version =3D versions.dpdk_version >> + if self._dpdk_build_info: >> + raise ValueError( >> + "Attempted to assign `dpdk_build_info` to a test run >> result which already " >> + "has `dpdk_build_info`." >> + ) >> + self._dpdk_build_info =3D dpdk_build_info >> + >> + def to_dict(self) -> TestRunResultDict: >> + """Convert the test run result into a dictionary. >> + >> + The dictionary contains test suites in this test run, and a >> summary of the test run and >> + information about the DPDK version, compiler version and >> associated ports. >> + >> + Returns: >> + TestRunResultDict: A dictionary representation of the test >> run result. >> + """ >> + results =3D {result.name: 0 for result in Result} >> + self.add_result(results) >> + >> + compiler_version =3D None >> + dpdk_version =3D None >> + >> + if self.dpdk_build_info: >> + compiler_version =3D self.dpdk_build_info.compiler_version >> + dpdk_version =3D self.dpdk_build_info.dpdk_version >> + >> + return { >> + "compiler_version": compiler_version, >> + "dpdk_version": dpdk_version, >> + "ports": [asdict(port) for port in self.ports], >> + "test_suites": [child.to_dict() for child in >> self.child_results], >> + "summary": results | self.generate_pass_rate_dict(results), >> + } >> >> def _block_result(self) -> None: >> r"""Mark the result as :attr:`~Result.BLOCK`\ed.""" >> @@ -436,6 +605,16 @@ def add_test_case(self, test_case_name: str) -> >> "TestCaseResult": >> self.child_results.append(result) >> return result >> >> + def to_dict(self) -> TestSuiteResultDict: >> + """Convert the test suite result into a dictionary. >> + >> + The dictionary contains a test suite name and test cases given >> in this test suite. >> + """ >> + return { >> + "test_suite_name": self.test_suite_name, >> + "test_cases": [child.to_dict() for child in >> self.child_results], >> + } >> + >> def _block_result(self) -> None: >> r"""Mark the result as :attr:`~Result.BLOCK`\ed.""" >> for test_case_method in self._test_suite_with_cases.test_cases: >> @@ -483,16 +662,23 @@ def _get_child_errors(self) -> list[Exception]: >> return [self.error] >> return [] >> >> - def add_stats(self, statistics: "Statistics") -> None: >> - r"""Add the test case result to statistics. >> + def to_dict(self) -> TestCaseResultDict: >> + """Convert the test case result into a dictionary. >> + >> + The dictionary contains a test case name and the result name. >> + """ >> + return {"test_case_name": self.test_case_name, "result": >> self.result.name} >> + >> + def add_result(self, results: dict[str, int]): >> + r"""Add the test case result to the results. >> >> The base method goes through the hierarchy recursively and this >> method is here to stop >> - the recursion, as the :class:`TestCaseResult`\s are the leaves >> of the hierarchy tree. >> + the recursion, as the :class:`TestCaseResult` are the leaves of >> the hierarchy tree. >> >> Args: >> - statistics: The :class:`Statistics` object where the stats >> will be added. >> + results: The dictionary to which results will be collated. >> """ >> - statistics +=3D self.result >> + results[self.result.name] +=3D 1 >> >> def _block_result(self) -> None: >> r"""Mark the result as :attr:`~Result.BLOCK`\ed.""" >> @@ -503,53 +689,114 @@ def __bool__(self) -> bool: >> return bool(self.setup_result) and bool(self.teardown_result) >> and bool(self.result) >> >> >> -class Statistics(dict): >> - """How many test cases ended in which result state along some other >> basic information. >> +class TextSummary: >> + """Generates and saves textual summaries of DTS run results. >> >> - Subclassing :class:`dict` provides a convenient way to format the >> data. >> + The summary includes: >> + * Results of test run test cases, >> + * Compiler version of the DPDK build, >> + * DPDK version of the DPDK source tree, >> + * Overall summary of results when multiple test runs are present. >> + """ >> >> - The data are stored in the following keys: >> + _dict_result: DtsRunResultDict >> + _summary: dict[str, int | float] >> + _text: str >> >> - * **PASS RATE** (:class:`int`) -- The FAIL/PASS ratio of all test >> cases. >> - * **DPDK VERSION** (:class:`str`) -- The tested DPDK version. >> - """ >> + def __init__(self, dts_run_result: DTSResult): >> + """Initializes with a DTSResult object and converts it to a >> dictionary format. >> >> - def __init__(self, dpdk_version: str | None): >> - """Extend the constructor with keys in which the data are store= d. >> + Args: >> + dts_run_result: The DTS result. >> + """ >> + self._dict_result =3D dts_run_result.to_dict() >> + self._summary =3D self._dict_result["summary"] >> + self._text =3D "" >> + >> + @property >> + def _outdent(self) -> str: >> + """Appropriate indentation based on multiple test run results."= "" >> + return "\t" if len(self._dict_result["test_runs"]) > 1 else "" >> + >> + def save(self, output_path: Path): >> + """Generate and save text statistics to a file. >> >> Args: >> - dpdk_version: The version of tested DPDK. >> + output_path: The path where the text file will be saved. >> """ >> - super().__init__() >> - for result in Result: >> - self[result.name] =3D 0 >> - self["PASS RATE"] =3D 0.0 >> - self["DPDK VERSION"] =3D dpdk_version >> + if self._dict_result["test_runs"]: >> + with open(f"{output_path}", "w") as fp: >> + >> self._add_test_runs_dict_decorator(self._add_test_run_dict) >> + fp.write(self._text) >> >> - def __iadd__(self, other: Result) -> "Statistics": >> - """Add a Result to the final count. >> + def _add_test_runs_dict_decorator(self, func: Callable): >> + """Handles multiple test runs and appends results to the summar= y. >> >> - Example: >> - stats: Statistics =3D Statistics() # empty Statistics >> - stats +=3D Result.PASS # add a Result to `stats` >> + Adds headers for each test run and overall result when multiple >> + test runs are provided. >> >> Args: >> - other: The Result to add to this statistics object. >> + func: Function to process and add results from each test ru= n. >> + """ >> + if len(self._dict_result["test_runs"]) > 1: >> + for idx, test_run_result in >> enumerate(self._dict_result["test_runs"]): >> + self._text +=3D f"TEST_RUN_{idx}\n" >> + func(test_run_result) >> >> - Returns: >> - The modified statistics object. >> + self._add_overall_results() >> + else: >> + func(self._dict_result["test_runs"][0]) >> + >> + def _add_test_run_dict(self, test_run_dict: TestRunResultDict): >> + """Adds the results and the test run attributes of a single tes= t >> run to the summary. >> + >> + Args: >> + test_run_dict: Dictionary containing the test run results. >> """ >> - self[other.name] +=3D 1 >> - self["PASS RATE"] =3D ( >> - float(self[Result.PASS.name]) * 100 / sum(self[result.name] >> for result in Result) >> + self._add_column( >> + DPDK_VERSION=3Dtest_run_dict["dpdk_version"], >> + COMPILER_VERSION=3Dtest_run_dict["compiler_version"], >> + **test_run_dict["summary"], >> ) >> - return self >> - >> - def __str__(self) -> str: >> - """Each line contains the formatted key =3D value pair.""" >> - stats_str =3D "" >> - for key, value in self.items(): >> - stats_str +=3D f"{key:<12} =3D {value}\n" >> - # according to docs, we should use \n when writing to text >> files >> - # on all platforms >> - return stats_str >> + self._text +=3D "\n" >> + >> + def _add_column(self, **rows): >> + """Formats and adds key-value pairs to the summary text. >> + >> + Handles cases where values might be None by replacing them with >> "N/A". >> + >> + Args: >> + **rows: Arbitrary key-value pairs representing the result >> data. >> + """ >> + rows =3D {k: "N/A" if v is None else v for k, v in rows.items()= } >> + max_length =3D len(max(rows, key=3Dlen)) >> + for key, value in rows.items(): >> + self._text +=3D f"{self._outdent}{key:<{max_length}} =3D >> {value}\n" >> + >> + def _add_overall_results(self): >> + """Add overall summary of test runs.""" >> + self._text +=3D "OVERALL\n" >> + self._add_column(**self._summary) >> + >> + >> +class JsonResults: >> + """Save DTS run result in JSON format.""" >> + >> + _dict_result: DtsRunResultDict >> + >> + def __init__(self, dts_run_result: DTSResult): >> + """Initializes with a DTSResult object and converts it to a >> dictionary format. >> + >> + Args: >> + dts_run_result: The DTS result. >> + """ >> + self._dict_result =3D dts_run_result.to_dict() >> + >> + def save(self, output_path: Path): >> + """Save the result to a file as JSON. >> + >> + Args: >> + output_path: The path where the JSON file will be saved. >> + """ >> + with open(f"{output_path}", "w") as fp: >> + json.dump(self._dict_result, fp, indent=3D4) >> -- >> 2.46.1 >> >> --000000000000c6e2a306261abce2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Adding Luca to this thread because it applies to him as we= ll:

Hi=C2=A0Tom=C3=A1=C5=A1,

This all looks great= , one thing I did notice when running locally is that the "test_suites= " section of results.json contains null values instead of the names of= the=C2=A0suites that were run. Could just be something strange happening o= n my side, but I would double check on your end just in case. Otherwise:

Reviewed-by: Dean Marx <dmarx@iol.unh.edu>

On Fri, Oct 25= , 2024 at 1:59=E2=80=AFPM Dean Marx <dmarx@iol.unh.edu> wrote:
Hi=C2=A0Tom=C3=A1=C5=A1,

=
This all looks great, one thing I did notice when running locally is t= hat the "test_suites" section of results.json contains null value= s instead of the names of the=C2=A0suites that were run. Could just be some= thing strange happening on my side, but I would double check on your end ju= st in case. Otherwise:

Reviewed-by: Dean Marx <= dmarx@iol.unh.edu>

On Mon, Sep 30, 2024 at 12:26=E2=80=AFPM Tom=C3=A1=C5=A1 =C4=8Eu= rovec <tomas.durovec@pantheon.tech> wrote:
The previous version of statistics store o= nly the last test run
attribute and result. In this patch we are adding header for each
test run and overall summary of test runs at the end. This is
represented as textual summaries with basic information and json
result with more detailed information.

Signed-off-by: Tom=C3=A1=C5=A1 =C4=8Eurovec <tomas.durovec@pantheon.tech= >

Depends-on: series-33184 ("DTS external DPDK build")
---
=C2=A0dts/framework/runner.py=C2=A0 =C2=A0 =C2=A0 |=C2=A0 =C2=A07 +-
=C2=A0dts/framework/test_result.py | 409 ++++++++++++++++++++++++++++------= -
=C2=A02 files changed, 332 insertions(+), 84 deletions(-)

diff --git a/dts/framework/runner.py b/dts/framework/runner.py
index 7d463c1fa1..be615ccace 100644
--- a/dts/framework/runner.py
+++ b/dts/framework/runner.py
@@ -84,7 +84,7 @@ def __init__(self):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if not os.path.exists(SETTINGS.output_dir= ):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0os.makedirs(SETTINGS.output= _dir)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._logger.add_dts_root_logger_handlers= (SETTINGS.verbose, SETTINGS.output_dir)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._result =3D DTSResult(self._logger)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._result =3D DTSResult(SETTINGS.output_dir= , self._logger)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._test_suite_class_prefix =3D "T= est"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._test_suite_module_prefix =3D "= tests.TestSuite_"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._func_test_case_regex =3D r"tes= t_(?!perf_)"
@@ -421,11 +421,12 @@ def _run_test_run(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._
logger.info(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0f"Running test run wit= h SUT '{test_run_config.system_under_test_node= .name}'."
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 test_run_result.add_sut_info(sut_node.node_inf= o)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 test_run_result.ports =3D sut_node.ports
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 test_run_result.sut_info =3D sut_node.node_inf= o
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0try:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0dpdk_location =3D SETTINGS.= dpdk_location or test_run_config.dpdk_config.dpdk_location
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sut_node.set_up_test_run(te= st_run_config, dpdk_location)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 test_run_result.add_dpdk_build_i= nfo(sut_node.get_dpdk_build_info())
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 test_run_result.dpdk_build_info = =3D sut_node.get_dpdk_build_info()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tg_node.set_up_test_run(tes= t_run_config, dpdk_location)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0test_run_result.update_setu= p(Result.PASS)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0except Exception as e:
diff --git a/dts/framework/test_result.py b/dts/framework/test_result.py index 0a10723098..bf148a6b45 100644
--- a/dts/framework/test_result.py
+++ b/dts/framework/test_result.py
@@ -22,18 +22,19 @@
=C2=A0variable modify the directory where the files with results will be st= ored.
=C2=A0"""

-import os.path
+import json
=C2=A0from collections.abc import MutableSequence
-from dataclasses import dataclass
+from dataclasses import asdict, dataclass
=C2=A0from enum import Enum, auto
+from pathlib import Path
=C2=A0from types import FunctionType
-from typing import Union
+from typing import Any, Callable, TypedDict

=C2=A0from .config import DPDKBuildInfo, NodeInfo, TestRunConfiguration, Te= stSuiteConfig
=C2=A0from .exception import DTSError, ErrorSeverity
=C2=A0from .logger import DTSLogger
-from .settings import SETTINGS
=C2=A0from .test_suite import TestSuite
+from .testbed_model.port import Port


=C2=A0@dataclass(slots=3DTrue, frozen=3DTrue)
@@ -85,6 +86,60 @@ def __bool__(self) -> bool:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return self is self.PASS


+class TestCaseResultDict(TypedDict):
+=C2=A0 =C2=A0 """Represents the `TestCaseResult` results. +
+=C2=A0 =C2=A0 Attributes:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 test_case_name: The name of the test case.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 result: The result name of the test case.
+=C2=A0 =C2=A0 """
+
+=C2=A0 =C2=A0 test_case_name: str
+=C2=A0 =C2=A0 result: str
+
+
+class TestSuiteResultDict(TypedDict):
+=C2=A0 =C2=A0 """Represents the `TestSuiteResult` results.<= br> +
+=C2=A0 =C2=A0 Attributes:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 test_suite_name: The name of the test suite. +=C2=A0 =C2=A0 =C2=A0 =C2=A0 test_cases: A list of test case results contai= ned in this test suite.
+=C2=A0 =C2=A0 """
+
+=C2=A0 =C2=A0 test_suite_name: str
+=C2=A0 =C2=A0 test_cases: list[TestCaseResultDict]
+
+
+class TestRunResultDict(TypedDict, total=3DFalse):
+=C2=A0 =C2=A0 """Represents the `TestRunResult` results. +
+=C2=A0 =C2=A0 Attributes:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 compiler_version: The version of the compiler = used for the DPDK build.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 dpdk_version: The version of DPDK being tested= .
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 ports: A list of ports associated with the tes= t run.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 test_suites: A list of test suite results incl= uded in this test run.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 summary: A dictionary containing overall resul= ts, such as pass/fail counts.
+=C2=A0 =C2=A0 """
+
+=C2=A0 =C2=A0 compiler_version: str | None
+=C2=A0 =C2=A0 dpdk_version: str | None
+=C2=A0 =C2=A0 ports: list[dict[str, Any]]
+=C2=A0 =C2=A0 test_suites: list[TestSuiteResultDict]
+=C2=A0 =C2=A0 summary: dict[str, int | float]
+
+
+class DtsRunResultDict(TypedDict):
+=C2=A0 =C2=A0 """Represents the `DtsRunResult` results.
+
+=C2=A0 =C2=A0 Attributes:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 test_runs: A list of test run results.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 summary: A summary dictionary containing overa= ll statistics for the test runs.
+=C2=A0 =C2=A0 """
+
+=C2=A0 =C2=A0 test_runs: list[TestRunResultDict]
+=C2=A0 =C2=A0 summary: dict[str, int | float]
+
+
=C2=A0class FixtureResult:
=C2=A0 =C2=A0 =C2=A0"""A record that stores the result of a = setup or a teardown.

@@ -198,14 +253,34 @@ def get_errors(self) -> list[Exception]:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return self._get_setup_teardown_errors() = + self._get_child_errors()

-=C2=A0 =C2=A0 def add_stats(self, statistics: "Statistics") ->= ; None:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Collate stats from the whole= result hierarchy.
+=C2=A0 =C2=A0 def to_dict(self):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Convert the results hierarch= y into a dictionary representation."""
+
+=C2=A0 =C2=A0 def add_result(self, results: dict[str, int]):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Collate the test case result= from the result hierarchy.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Args:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 statistics: The :class:`Statisti= cs` object where the stats will be collated.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 results: The dictionary to which= results will be collated.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for child_result in self.child_results: -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 child_result.add_stats(statistic= s)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 child_result.add_result(results)=
+
+=C2=A0 =C2=A0 def generate_pass_rate_dict(self, test_run_summary) -> di= ct[str, float]:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Generate a dictionary with t= he FAIL/PASS ratio of all test cases.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Args:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 test_run_summary: The summary di= ctionary containing test result counts.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Returns:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 A dictionary with the FAIL/PASS = ratio of all test cases.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "PASS_RATE": (
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 float(test_run_sum= mary[Result.PASS.name])
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * 100
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 / sum(test_run_sum= mary[re= sult.name] for result in Result)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 )
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }


=C2=A0class DTSResult(BaseResult):
@@ -220,31 +295,25 @@ class DTSResult(BaseResult):
=C2=A0 =C2=A0 =C2=A0and as such is where the data form the whole hierarchy = is collated or processed.

=C2=A0 =C2=A0 =C2=A0The internal list stores the results of all test runs.<= br> -
-=C2=A0 =C2=A0 Attributes:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 dpdk_version: The DPDK version to record.
=C2=A0 =C2=A0 =C2=A0"""

-=C2=A0 =C2=A0 dpdk_version: str | None
+=C2=A0 =C2=A0 _output_dir: str
=C2=A0 =C2=A0 =C2=A0_logger: DTSLogger
=C2=A0 =C2=A0 =C2=A0_errors: list[Exception]
=C2=A0 =C2=A0 =C2=A0_return_code: ErrorSeverity
-=C2=A0 =C2=A0 _stats_result: Union["Statistics", None]
-=C2=A0 =C2=A0 _stats_filename: str

-=C2=A0 =C2=A0 def __init__(self, logger: DTSLogger):
+=C2=A0 =C2=A0 def __init__(self, output_dir: str, logger: DTSLogger):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""Extend the constructor = with top-level specifics.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Args:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 output_dir: The directory where = DTS logs and results are saved.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0logger: The logger instance= the whole result will use.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__()
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.dpdk_version =3D None
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._output_dir =3D output_dir
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._logger =3D logger
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._errors =3D []
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._return_code =3D ErrorSeverity.NO_ER= R
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._stats_result =3D None
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._stats_filename =3D os.path.join(SETTINGS= .output_dir, "statistics.txt")

=C2=A0 =C2=A0 =C2=A0def add_test_run(self, test_run_config: TestRunConfigur= ation) -> "TestRunResult":
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""Add and return the chil= d result (test run).
@@ -281,10 +350,8 @@ def process(self) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for error in self._errors:<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._logger.= debug(repr(error))

-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._stats_result =3D Statistics(self.dpdk_ve= rsion)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.add_stats(self._stats_result)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 with open(self._stats_filename, "w+"= ) as stats_file:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 stats_file.write(str(self._stats= _result))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 TextSummary(self).save(Path(self._output_dir, = "results_summary.txt"))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 JsonResults(self).save(Path(self._output_dir, = "results.json"))

=C2=A0 =C2=A0 =C2=A0def get_return_code(self) -> int:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""Go through all stored E= xceptions and return the final DTS error code.
@@ -302,6 +369,37 @@ def get_return_code(self) -> int:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return int(self._return_code)

+=C2=A0 =C2=A0 def to_dict(self) -> DtsRunResultDict:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Convert DTS result into a di= ctionary format.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 The dictionary contains test runs and summary = of test runs.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Returns:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 A dictionary representation of t= he DTS result
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 def merge_test_run_summaries(test_run_summarie= s: list[dict[str, int]]) -> dict[str, int]:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 """Merge multiple= test run summaries into one dictionary.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Args:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 test_run_summaries= : List of test run summary dictionaries.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Returns:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 A merged dictionar= y containing the aggregated summary.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 key.name: sum(test_run_s= ummary[key= .name] for test_run_summary in test_run_summaries)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for key in Result<= br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 test_runs =3D [child.to_dict() for child in se= lf.child_results]
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 test_run_summary =3D merge_test_run_summaries(= [test_run["summary"] for test_run in test_runs])
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "test_runs": test_runs= ,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "summary": test_run_su= mmary | self.generate_pass_rate_dict(test_run_summary),
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+

=C2=A0class TestRunResult(BaseResult):
=C2=A0 =C2=A0 =C2=A0"""The test run specific result.
@@ -316,13 +414,11 @@ class TestRunResult(BaseResult):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sut_kernel_version: The operating system = kernel version of the SUT node.
=C2=A0 =C2=A0 =C2=A0"""

-=C2=A0 =C2=A0 compiler_version: str | None
-=C2=A0 =C2=A0 dpdk_version: str | None
-=C2=A0 =C2=A0 sut_os_name: str
-=C2=A0 =C2=A0 sut_os_version: str
-=C2=A0 =C2=A0 sut_kernel_version: str
=C2=A0 =C2=A0 =C2=A0_config: TestRunConfiguration
=C2=A0 =C2=A0 =C2=A0_test_suites_with_cases: list[TestSuiteWithCases]
+=C2=A0 =C2=A0 _ports: list[Port]
+=C2=A0 =C2=A0 _sut_info: NodeInfo | None
+=C2=A0 =C2=A0 _dpdk_build_info: DPDKBuildInfo | None

=C2=A0 =C2=A0 =C2=A0def __init__(self, test_run_config: TestRunConfiguratio= n):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""Extend the constructor = with the test run's config.
@@ -331,10 +427,11 @@ def __init__(self, test_run_config: TestRunConfigurat= ion):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0test_run_config: A test run= configuration.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__()
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.compiler_version =3D None
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.dpdk_version =3D None
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._config =3D test_run_config
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._test_suites_with_cases =3D []
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._ports =3D []
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._sut_info =3D None
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._dpdk_build_info =3D None

=C2=A0 =C2=A0 =C2=A0def add_test_suite(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self,
@@ -374,24 +471,96 @@ def test_suites_with_cases(self, test_suites_with_cas= es: list[TestSuiteWithCases
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._test_suites_with_cases =3D test_sui= tes_with_cases

-=C2=A0 =C2=A0 def add_sut_info(self, sut_info: NodeInfo) -> None:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Add SUT information gathered= at runtime.
+=C2=A0 =C2=A0 @property
+=C2=A0 =C2=A0 def ports(self) -> list[Port]:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Get the list of ports associ= ated with this test run."""
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return self._ports
+
+=C2=A0 =C2=A0 @ports.setter
+=C2=A0 =C2=A0 def ports(self, ports: list[Port]) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Set the list of ports associ= ated with this test run.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Args:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ports: The list of ports to asso= ciate with this test run.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Raises:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ValueError: If the ports have al= ready been assigned to this test run.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if self._ports:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 raise ValueError(
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "Attempted to= assign `ports` to a test run result which already has `ports`."
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 )
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._ports =3D ports
+
+=C2=A0 =C2=A0 @property
+=C2=A0 =C2=A0 def sut_info(self) -> NodeInfo | None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Get the SUT node information= associated with this test run."""
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return self._sut_info
+
+=C2=A0 =C2=A0 @sut_info.setter
+=C2=A0 =C2=A0 def sut_info(self, sut_info: NodeInfo) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Set the SUT node information= associated with this test run.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Args:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sut_info: The additional SUT nod= e information.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sut_info: The SUT node informati= on to associate with this test run.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Raises:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ValueError: If the SUT informati= on has already been assigned to this test run.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.sut_os_name =3D sut_info.os_name
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.sut_os_version =3D sut_info.os_version -=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.sut_kernel_version =3D sut_info.kernel_ve= rsion
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if self._sut_info:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 raise ValueError(
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "Attempted to= assign `sut_info` to a test run result which already has `sut_info`."=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 )
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._sut_info =3D sut_info

-=C2=A0 =C2=A0 def add_dpdk_build_info(self, versions: DPDKBuildInfo) ->= None:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Add information about the DP= DK build gathered at runtime.
+=C2=A0 =C2=A0 @property
+=C2=A0 =C2=A0 def dpdk_build_info(self) -> DPDKBuildInfo | None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Get the DPDK build informati= on associated with this test run."""
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return self._dpdk_build_info
+
+=C2=A0 =C2=A0 @dpdk_build_info.setter
+=C2=A0 =C2=A0 def dpdk_build_info(self, dpdk_build_info: DPDKBuildInfo) -&= gt; None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Set the DPDK build informati= on associated with this test run.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Args:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 versions: The additional informa= tion.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dpdk_build_info: The DPDK build = information to associate with this test run.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Raises:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ValueError: If the DPDK build in= formation has already been assigned to this test run.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.compiler_version =3D versions.compiler_ve= rsion
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.dpdk_version =3D versions.dpdk_version +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if self._dpdk_build_info:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 raise ValueError(
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "Attempted to= assign `dpdk_build_info` to a test run result which already "
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "has `dpdk_bu= ild_info`."
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 )
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._dpdk_build_info =3D dpdk_build_info
+
+=C2=A0 =C2=A0 def to_dict(self) -> TestRunResultDict:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Convert the test run result = into a dictionary.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 The dictionary contains test suites in this te= st run, and a summary of the test run and
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 information about the DPDK version, compiler v= ersion and associated ports.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Returns:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 TestRunResultDict: A dictionary = representation of the test run result.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 results =3D {result.name: 0 for result in Result}=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.add_result(results)
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 compiler_version =3D None
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 dpdk_version =3D None
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if self.dpdk_build_info:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 compiler_version =3D self.dpdk_b= uild_info.compiler_version
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dpdk_version =3D self.dpdk_build= _info.dpdk_version
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "compiler_version": co= mpiler_version,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "dpdk_version": dpdk_v= ersion,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "ports": [asdict(port)= for port in self.ports],
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "test_suites": [child.= to_dict() for child in self.child_results],
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "summary": results | s= elf.generate_pass_rate_dict(results),
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 =C2=A0def _block_result(self) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0r"""Mark the result as :at= tr:`~Result.BLOCK`\ed."""
@@ -436,6 +605,16 @@ def add_test_case(self, test_case_name: str) -> &qu= ot;TestCaseResult":
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.child_results.append(result)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return result

+=C2=A0 =C2=A0 def to_dict(self) -> TestSuiteResultDict:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Convert the test suite resul= t into a dictionary.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 The dictionary contains a test suite name and = test cases given in this test suite.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "test_suite_name": sel= f.test_suite_name,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "test_cases": [child.t= o_dict() for child in self.child_results],
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+
=C2=A0 =C2=A0 =C2=A0def _block_result(self) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0r"""Mark the result as :at= tr:`~Result.BLOCK`\ed."""
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for test_case_method in self._test_suite_= with_cases.test_cases:
@@ -483,16 +662,23 @@ def _get_child_errors(self) -> list[Exception]: =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return [self.error]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return []

-=C2=A0 =C2=A0 def add_stats(self, statistics: "Statistics") ->= ; None:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 r"""Add the test case result to= statistics.
+=C2=A0 =C2=A0 def to_dict(self) -> TestCaseResultDict:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Convert the test case result= into a dictionary.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 The dictionary contains a test case name and t= he result name.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return {"test_case_name": self.test_= case_name, "result": self.result.name}
+
+=C2=A0 =C2=A0 def add_result(self, results: dict[str, int]):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 r"""Add the test case result to= the results.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0The base method goes through the hierarch= y recursively and this method is here to stop
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 the recursion, as the :class:`TestCaseResult`\= s are the leaves of the hierarchy tree.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 the recursion, as the :class:`TestCaseResult` = are the leaves of the hierarchy tree.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Args:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 statistics: The :class:`Statisti= cs` object where the stats will be added.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 results: The dictionary to which= results will be collated.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 statistics +=3D self.result
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 results[self.result.name] +=3D 1

=C2=A0 =C2=A0 =C2=A0def _block_result(self) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0r"""Mark the result as :at= tr:`~Result.BLOCK`\ed."""
@@ -503,53 +689,114 @@ def __bool__(self) -> bool:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return bool(self.setup_result) and bool(s= elf.teardown_result) and bool(self.result)


-class Statistics(dict):
-=C2=A0 =C2=A0 """How many test cases ended in which result = state along some other basic information.
+class TextSummary:
+=C2=A0 =C2=A0 """Generates and saves textual summaries of D= TS run results.

-=C2=A0 =C2=A0 Subclassing :class:`dict` provides a convenient way to forma= t the data.
+=C2=A0 =C2=A0 The summary includes:
+=C2=A0 =C2=A0 * Results of test run test cases,
+=C2=A0 =C2=A0 * Compiler version of the DPDK build,
+=C2=A0 =C2=A0 * DPDK version of the DPDK source tree,
+=C2=A0 =C2=A0 * Overall summary of results when multiple test runs are pre= sent.
+=C2=A0 =C2=A0 """

-=C2=A0 =C2=A0 The data are stored in the following keys:
+=C2=A0 =C2=A0 _dict_result: DtsRunResultDict
+=C2=A0 =C2=A0 _summary: dict[str, int | float]
+=C2=A0 =C2=A0 _text: str

-=C2=A0 =C2=A0 * **PASS RATE** (:class:`int`) -- The FAIL/PASS ratio of all= test cases.
-=C2=A0 =C2=A0 * **DPDK VERSION** (:class:`str`) -- The tested DPDK version= .
-=C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 def __init__(self, dts_run_result: DTSResult):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Initializes with a DTSResult= object and converts it to a dictionary format.

-=C2=A0 =C2=A0 def __init__(self, dpdk_version: str | None):
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Extend the constructor with = keys in which the data are stored.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Args:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dts_run_result: The DTS result.<= br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._dict_result =3D dts_run_result.to_dict()=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._summary =3D self._dict_result["summ= ary"]
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._text =3D ""
+
+=C2=A0 =C2=A0 @property
+=C2=A0 =C2=A0 def _outdent(self) -> str:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Appropriate indentation base= d on multiple test run results."""
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return "\t" if len(self._dict_result= ["test_runs"]) > 1 else ""
+
+=C2=A0 =C2=A0 def save(self, output_path: Path):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Generate and save text stati= stics to a file.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Args:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dpdk_version: The version of tes= ted DPDK.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 output_path: The path where the = text file will be saved.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 super().__init__()
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 for result in Result:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self[result.name] =3D 0
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self["PASS RATE"] =3D 0.0
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self["DPDK VERSION"] =3D dpdk_versio= n
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if self._dict_result["test_runs"]: +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 with open(f"{output_path}&q= uot;, "w") as fp:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._add_test_run= s_dict_decorator(self._add_test_run_dict)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fp.write(self._tex= t)

-=C2=A0 =C2=A0 def __iadd__(self, other: Result) -> "Statistics&quo= t;:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Add a Result to the final co= unt.
+=C2=A0 =C2=A0 def _add_test_runs_dict_decorator(self, func: Callable):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Handles multiple test runs a= nd appends results to the summary.

-=C2=A0 =C2=A0 =C2=A0 =C2=A0 Example:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 stats: Statistics =3D Statistics= ()=C2=A0 # empty Statistics
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 stats +=3D Result.PASS=C2=A0 # a= dd a Result to `stats`
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Adds headers for each test run and overall res= ult when multiple
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 test runs are provided.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Args:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 other: The Result to add to this= statistics object.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 func: Function to process and ad= d results from each test run.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if len(self._dict_result["test_runs"= ]) > 1:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for idx, test_run_result in enum= erate(self._dict_result["test_runs"]):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._text +=3D f&= quot;TEST_RUN_{idx}\n"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 func(test_run_resu= lt)

-=C2=A0 =C2=A0 =C2=A0 =C2=A0 Returns:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 The modified statistics object.<= br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._add_overall_results()
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 else:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 func(self._dict_result["tes= t_runs"][0])
+
+=C2=A0 =C2=A0 def _add_test_run_dict(self, test_run_dict: TestRunResultDic= t):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Adds the results and the tes= t run attributes of a single test run to the summary.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Args:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 test_run_dict: Dictionary contai= ning the test run results.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"""
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self[other.name] +=3D 1
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self["PASS RATE"] =3D (
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 float(self[Result.PASS.name]) = * 100 / sum(self[result.name] for result in Result)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._add_column(
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 DPDK_VERSION=3Dtest_run_dict[&qu= ot;dpdk_version"],
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 COMPILER_VERSION=3Dtest_run_dict= ["compiler_version"],
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 **test_run_dict["summary&qu= ot;],
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 return self
-
-=C2=A0 =C2=A0 def __str__(self) -> str:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Each line contains the forma= tted key =3D value pair."""
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 stats_str =3D ""
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 for key, value in self.items():
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 stats_str +=3D f"{key:<1= 2} =3D {value}\n"
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # according to docs, we should u= se \n when writing to text files
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # on all platforms
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 return stats_str
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._text +=3D "\n"
+
+=C2=A0 =C2=A0 def _add_column(self, **rows):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Formats and adds key-value p= airs to the summary text.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Handles cases where values might be None by re= placing them with "N/A".
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Args:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 **rows: Arbitrary key-value pair= s representing the result data.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 rows =3D {k: "N/A" if v is None else= v for k, v in rows.items()}
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 max_length =3D len(max(rows, key=3Dlen))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 for key, value in rows.items():
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._text +=3D f"{self._ou= tdent}{key:<{max_length}} =3D {value}\n"
+
+=C2=A0 =C2=A0 def _add_overall_results(self):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Add overall summary of test = runs."""
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._text +=3D "OVERALL\n"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._add_column(**self._summary)
+
+
+class JsonResults:
+=C2=A0 =C2=A0 """Save DTS run result in JSON format."&= quot;"
+
+=C2=A0 =C2=A0 _dict_result: DtsRunResultDict
+
+=C2=A0 =C2=A0 def __init__(self, dts_run_result: DTSResult):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Initializes with a DTSResult= object and converts it to a dictionary format.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Args:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dts_run_result: The DTS result.<= br> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._dict_result =3D dts_run_result.to_dict()=
+
+=C2=A0 =C2=A0 def save(self, output_path: Path):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Save the result to a file as= JSON.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Args:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 output_path: The path where the = JSON file will be saved.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 with open(f"{output_path}", "w&= quot;) as fp:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 json.dump(self._dict_result, fp,= indent=3D4)
--
2.46.1

--000000000000c6e2a306261abce2--