Skip to content

Commit edd52b2

Browse files
committed
test: add tests for the tool plugin system
Signed-off-by: James McCorrie <[email protected]>
1 parent 4c76c62 commit edd52b2

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

src/dvsim/tool/vcs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def get_cov_summary_table(cov_report_path: Path) -> tuple[Sequence[Sequence[str]
4949
raise SyntaxError(msg)
5050

5151
@staticmethod
52-
def get_job_runtime(log_text: list) -> tuple[float, str]:
52+
def get_job_runtime(log_text: Sequence[str]) -> tuple[float, str]:
5353
"""Return the job runtime (wall clock time) along with its units.
5454
5555
EDA tools indicate how long the job ran in terms of CPU time in the log
@@ -74,7 +74,7 @@ def get_job_runtime(log_text: list) -> tuple[float, str]:
7474
raise RuntimeError(msg)
7575

7676
@staticmethod
77-
def get_simulated_time(log_text: list) -> tuple[float, str]:
77+
def get_simulated_time(log_text: Sequence[str]) -> tuple[float, str]:
7878
"""Return the simulated time along with its units.
7979
8080
EDA tools indicate how long the design was simulated for in the log file.

src/dvsim/tool/xcelium.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_cov_summary_table(cov_report_path: Path) -> tuple[Sequence[Sequence[str]
7777
raise SyntaxError(msg)
7878

7979
@staticmethod
80-
def get_job_runtime(log_text: list) -> tuple[float, str]:
80+
def get_job_runtime(log_text: Sequence[str]) -> tuple[float, str]:
8181
"""Return the job runtime (wall clock time) along with its units.
8282
8383
EDA tools indicate how long the job ran in terms of CPU time in the log
@@ -103,7 +103,7 @@ def get_job_runtime(log_text: list) -> tuple[float, str]:
103103
raise RuntimeError(msg)
104104

105105
@staticmethod
106-
def get_simulated_time(log_text: list) -> tuple[float, str]:
106+
def get_simulated_time(log_text: Sequence[str]) -> tuple[float, str]:
107107
"""Return the simulated time along with its units.
108108
109109
EDA tools indicate how long the design was simulated for in the log file.

tests/tool/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
"""Tests for EDA tool plugins and the plug-in system."""

tests/tool/test_utils.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# copyright lowrisc contributors (opentitan project).
2+
# licensed under the apache license, version 2.0, see license for details.
3+
# spdx-license-identifier: apache-2.0
4+
5+
"""Test the EDA tool utilities."""
6+
7+
import pytest
8+
from hamcrest import assert_that, equal_to, instance_of
9+
10+
from dvsim.tool.sim import SimTool
11+
from dvsim.tool.utils import _SUPPORTED_SIM_TOOLS, get_sim_tool_plugin
12+
13+
__all__ = ("TestEDAToolPlugins",)
14+
15+
16+
class TestEDAToolPlugins:
17+
"""Test the EDA tool plug-ins."""
18+
19+
@staticmethod
20+
@pytest.mark.parametrize("tool", _SUPPORTED_SIM_TOOLS.keys())
21+
def test_get_sim_tool_plugin(tool: str) -> None:
22+
"""Test that sim plugins can be retrieved correctly."""
23+
assert_that(
24+
get_sim_tool_plugin(tool),
25+
equal_to(_SUPPORTED_SIM_TOOLS[tool]),
26+
)
27+
28+
@staticmethod
29+
@pytest.mark.parametrize("tool", _SUPPORTED_SIM_TOOLS.keys())
30+
def test_plugins_implement_simtool_protocol(tool: str) -> None:
31+
"""Test that all sim plugins implement the SimTool interface."""
32+
plugin = get_sim_tool_plugin(tool)
33+
34+
assert_that(plugin, instance_of(SimTool))

0 commit comments

Comments
 (0)