Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[microTVM] Replace static fixtures with parameterization #12530

Merged
merged 6 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions python/tvm/micro/testing/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@

from tvm.contrib.utils import tempdir

from .utils import get_supported_boards
from .utils import get_supported_platforms, get_supported_boards


def pytest_addoption(parser):
"""Adds more pytest arguments"""
parser.addoption(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this force every test to have --platform as an argument? In that case we don't want this for tests that are specific to Zephyr/Arduino

Copy link
Member Author

@guberti guberti Aug 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! Only tests that include the platform fixture will require the --platform argument, and likewise for board. This is done by the if argument in metafunc.fixturenames line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, thanks for clarification!

"--platform",
choices=get_supported_platforms(),
help=("microTVM platform for tests."),
)
parser.addoption(
"--board",
required=True,
choices=list(get_supported_boards("zephyr").keys())
+ list(get_supported_boards("arduino").keys()),
help=(
Expand All @@ -58,9 +62,25 @@ def pytest_addoption(parser):
)


@pytest.fixture(scope="session")
def board(request):
return request.config.getoption("--board")
def pytest_generate_tests(metafunc):
"""Hooks into pytest to add platform and board fixtures to tests that
require them. To make sure that "platform" and "board" are treated as
parameters for the appropriate tests (and included in the test names),
we add them as function level parametrizations. This prevents data
from being overwritten in Junit XML files if multiple platforms
or boards are tested."""

for argument in ["platform", "board"]:
if argument in metafunc.fixturenames:
value = metafunc.config.getoption(f"--{argument}", default=None)

if not value:
raise ValueError(
f"Test {metafunc.function.__name__} in module {metafunc.module.__name__} "
f"requires a --{argument} argument, but none was given."
)

metafunc.parametrize(argument, [metafunc.config.getoption(f"--{argument}")])


@pytest.fixture(scope="session")
Expand Down
5 changes: 5 additions & 0 deletions python/tvm/micro/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
TIMEOUT_SEC = 10


@lru_cache(maxsize=None)
def get_supported_platforms():
return ["arduino", "zephyr"]


@lru_cache(maxsize=None)
def get_supported_boards(platform: str):
template = Path(tvm.micro.get_microtvm_template_projects(platform))
Expand Down
13 changes: 9 additions & 4 deletions tests/micro/arduino/test_arduino_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@
"""

# Since these tests are sequential, we'll use the same project/workspace
# directory for all tests in this file
# directory for all tests in this file. Note that --board can't be loaded
# from the fixture, since the fixture is function scoped (it has to be
# for the tests to be named correctly via parameterization).
@pytest.fixture(scope="module")
def workflow_workspace_dir(request, board):
def workflow_workspace_dir(request):
board = request.config.getoption("--board")
return test_utils.make_workspace_dir("arduino_workflow", board)


Expand All @@ -48,9 +51,11 @@ def project_dir(workflow_workspace_dir):
return workflow_workspace_dir / "project"


# We MUST pass workspace_dir, not project_dir, or the workspace will be dereferenced too soon
# We MUST pass workspace_dir, not project_dir, or the workspace will be dereferenced
# too soon. We can't use the board fixture either for the reason mentioned above.
@pytest.fixture(scope="module")
def project(board, arduino_cli_cmd, microtvm_debug, workflow_workspace_dir):
def project(request, arduino_cli_cmd, microtvm_debug, workflow_workspace_dir):
board = request.config.getoption("--board")
return test_utils.make_kws_project(
board, arduino_cli_cmd, microtvm_debug, workflow_workspace_dir
)
Expand Down
16 changes: 0 additions & 16 deletions tests/micro/common/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,3 @@
pytest_plugins = [
"tvm.micro.testing.pytest_plugin",
]

import pytest


def pytest_addoption(parser):
parser.addoption(
"--platform",
required=True,
choices=["arduino", "zephyr"],
help="Platform to run tests with",
)


@pytest.fixture
def platform(request):
return request.config.getoption("--platform")