Skip to content

Commit

Permalink
Merge pull request #20 from opencomputeproject/feature/ocptv-output
Browse files Browse the repository at this point in the history
Added initial support for OCP-TV output format
  • Loading branch information
mimir-d authored Aug 21, 2024
2 parents 06a7fdc + 4659619 commit 0f2e04a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 35 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pylint>=2.17.5
mypy>=1.5.1
TestSlide>=2.7.1
bumpver>=2023.1126
ocptv>=0.1.7
66 changes: 34 additions & 32 deletions src/pci_lmt/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def collect_lane_margin_on_device_list(
receiver_number=ty.cast(int, self.receiver_number),
step=steps,
)
stepper = {}
if voltage_or_timing == "TIMING":
# FIXME: move this string construction in a separate method; or better make it
# into a typed enum
Expand Down Expand Up @@ -264,35 +265,36 @@ def run_lmt(args: argparse.Namespace, config: PlatformConfig, host: HostInfo, re
"""Runs LMT tests on all the interfaces listed in the platform_config."""

logger.info("Loading config: %s", config)

for group in config.lmt_groups:
args.annotation = args.annotation if args.annotation else group.name
left_right_none, up_down = group.margin_directions_tuple
# Loop through each step running LMT on all BDFs.
for step in group.margin_steps:
bdf_list = group.bdf_list
margin_type = group.margin_type
receiver_number = group.receiver_number
logger.info(
"Running %s margining test on %d BDFs Rx %d Step %d for %d seconds.",
margin_type,
len(bdf_list),
receiver_number,
step,
args.dwell_time,
)
results = collect_lmt_on_bdfs(
args=args,
hostname=host.hostname,
host_id=host.host_id,
model_name=host.model_name,
bdf_list=bdf_list,
receiver_number=receiver_number,
left_right_none=left_right_none,
up_down=up_down,
steps=step,
voltage_or_timing=margin_type,
)
for result in results:
logger.info(result)
reporter.write(result)
with reporter.start_run(host):
for group in config.lmt_groups:
args.annotation = args.annotation if args.annotation else group.name
left_right_none, up_down = group.margin_directions_tuple
# Loop through each step running LMT on all BDFs.
for step in group.margin_steps:
with reporter.start_step(name=f"Rcvr:{group.receiver_number} Step:{step} Ann:{args.annotation}"):
bdf_list = group.bdf_list
margin_type = group.margin_type
receiver_number = group.receiver_number
logger.info(
"Running %s margining test on %d BDFs Rx %d Step %d for %d seconds.",
margin_type,
len(bdf_list),
receiver_number,
step,
args.dwell_time,
)
results = collect_lmt_on_bdfs(
args=args,
hostname=host.hostname,
host_id=host.host_id,
model_name=host.model_name,
bdf_list=bdf_list,
receiver_number=receiver_number,
left_right_none=left_right_none,
up_down=up_down,
steps=step,
voltage_or_timing=margin_type,
)
for result in results:
logger.info(result)
reporter.write(result)
58 changes: 58 additions & 0 deletions src/pci_lmt/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import dataclasses as dc
import json
import typing as ty
from contextlib import contextmanager

import ocptv.output as tv
from ocptv.output import TestResult, TestRunError, TestStatus, TestStepError
from pci_lmt import __version__ as PCI_LMT_VERSION
from pci_lmt.host import HostInfo
from pci_lmt.pcie_lane_margining import LmtDeviceInfo


Expand Down Expand Up @@ -64,6 +69,19 @@ def to_csv(self) -> ty.Tuple[str, str]:


class Reporter:
def __init__(self):
pass

@contextmanager
def start_run(self, host: HostInfo):
# pylint: disable=unused-argument
yield

@contextmanager
def start_step(self, name: str):
# pylint: disable=unused-argument
yield

def write(self, _result: LmtLaneResult) -> None:
pass

Expand All @@ -84,3 +102,43 @@ def write(self, result: LmtLaneResult) -> None:
self.__emitted_header = True

print(row)


class OcptvReporter(Reporter):
def __init__(self):
self._run = tv.TestRun(name="pci_lmt", version=PCI_LMT_VERSION)
self._step = None

@contextmanager
def start_run(self, host: HostInfo):
# TODO(sksekar): Add support for HardwareInfo using PlatformConfig.
dut = tv.Dut(id=host.host_id, name=host.hostname)
try:
yield self._run.start(dut=dut)
except TestRunError as e:
self._run.end(status=e.status, result=e.result)
else:
self._run.end(status=TestStatus.COMPLETE, result=TestResult.PASS)

@contextmanager
def start_step(self, name: str):
if self._step:
raise RuntimeError("Cannot start a new step before ending the previous one.")

# TODO(sksekar): Add support for validators.
self._step = self._run.add_step(name=name)
try:
yield self._step.start()
except TestStepError as e:
self._step.end(status=e.status)
else:
self._step.end(status=TestStatus.COMPLETE)
finally:
self._step = None

def write(self, result: LmtLaneResult) -> None:
if not self._step:
raise RuntimeError("Cannot write results before starting a step.")

meas_name = f"BDF:{result.device_info.bdf} Lane:{result.lane}"
self._step.add_measurement(name=meas_name, value=result.ber)
13 changes: 10 additions & 3 deletions src/pci_lmt_bin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
from pci_lmt.args import add_common_args
from pci_lmt.config import read_platform_config
from pci_lmt.host import HostInfo
from pci_lmt.results import CsvStdoutReporter, JsonStdoutReporter, Reporter
from pci_lmt.results import (
CsvStdoutReporter,
JsonStdoutReporter,
OcptvReporter,
Reporter,
)


def parse_args() -> argparse.Namespace:
Expand All @@ -33,9 +38,9 @@ def parse_args() -> argparse.Namespace:
"-o",
dest="output",
type=str,
help="Output format. Supported formats: json, csv. Default: json",
help="Output format. Supported formats: json, csv, ocp. Default: json",
default="json",
choices=["json", "csv"],
choices=["json", "csv", "ocp"],
)
add_common_args(parser)

Expand All @@ -58,6 +63,8 @@ def main() -> None:
reporter = JsonStdoutReporter()
elif args.output == "csv":
reporter = CsvStdoutReporter()
elif args.output == "ocp":
reporter = OcptvReporter()

collector.run_lmt(
args=args,
Expand Down

0 comments on commit 0f2e04a

Please sign in to comment.