Skip to content

Commit

Permalink
Incorporate ProjectAPI changes
Browse files Browse the repository at this point in the history
Add Arduino tests to CI
  • Loading branch information
guberti committed Aug 10, 2021
1 parent 7fad760 commit 237a65e
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 118 deletions.
4 changes: 2 additions & 2 deletions apps/microtvm/arduino/example_project/src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tvm_workspace_t app_workspace;
// Blink code for debugging purposes
void TVMPlatformAbort(tvm_crt_error_t error) {
for (;;) {
#ifdef LED_BUILTIN
#ifdef LED_BUILTIN
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
digitalWrite(LED_BUILTIN, LOW);
Expand All @@ -24,7 +24,7 @@ void TVMPlatformAbort(tvm_crt_error_t error) {
delay(250);
digitalWrite(LED_BUILTIN, LOW);
delay(750);
#endif
#endif
}
}

Expand Down
10 changes: 3 additions & 7 deletions apps/microtvm/arduino/template_project/microtvm_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ class BoardAutodetectFailed(Exception):


BOARD_PROPERTIES = {
"due": {
"package": "arduino",
"architecture": "sam",
"board": "arduino_due_x"
},
"due": {"package": "arduino", "architecture": "sam", "board": "arduino_due_x"},
# Due to the way the Feather S2 bootloader works, compilation
# behaves fine but uploads cannot be done automatically
"feathers2": {
Expand Down Expand Up @@ -112,7 +108,7 @@ def __init__(self):
self._port = None
self._serial = None

def server_info_query(self):
def server_info_query(self, tvm_version):
return server.ServerInfo(
platform_name="arduino",
is_template=IS_TEMPLATE,
Expand Down Expand Up @@ -372,7 +368,7 @@ def flash(self, options):
]

if options.get("verbose"):
compile_cmd.append("--verbose")
upload_cmd.append("--verbose")

output = subprocess.check_call(upload_cmd)

Expand Down
1 change: 0 additions & 1 deletion python/tvm/target/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ def micro(model="unknown", options=None):
)

if (not options) or (options and not any("-executor=aot" in o for o in options)):
print("Adding system libs!")
opts = _merge_opts(opts, "--system-lib")

# NOTE: in the future, the default micro target will be LLVM except when
Expand Down
49 changes: 47 additions & 2 deletions tests/micro/arduino/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import datetime
import pathlib

import pytest

import tvm.target.target
Expand All @@ -14,10 +17,21 @@
"teensy41": ("imxrt1060", "teensy41"),
}

TEMPLATE_PROJECT_DIR = (
pathlib.Path(__file__).parent
/ ".."
/ ".."
/ ".."
/ "apps"
/ "microtvm"
/ "arduino"
/ "template_project"
).resolve()


def pytest_addoption(parser):
parser.addoption(
"--platforms",
"--microtvm-platforms",
default=["due"],
nargs="*",
choices=PLATFORMS.keys(),
Expand All @@ -33,12 +47,19 @@ def pytest_addoption(parser):
action="store_true",
help="Run tests that require physical hardware.",
)
parser.addoption(
"--tvm-debug",
action="store_true",
default=False,
help="If set true, enable a debug session while the test is running. Before running the test, in a separate shell, you should run: <python -m tvm.exec.microtvm_debug_shell>",
)


# We might do project generation differently for different boards in the future
# (to take advantage of multiple cores / external memory / etc.), so all tests
# are parameterized by board
def pytest_generate_tests(metafunc):
platforms = metafunc.config.getoption("platforms")
platforms = metafunc.config.getoption("microtvm_platforms")
metafunc.parametrize("platform", platforms, scope="session")


Expand All @@ -47,6 +68,30 @@ def arduino_cli_cmd(request):
return request.config.getoption("--arduino-cli-cmd")


@pytest.fixture(scope="session")
def tvm_debug(request):
return request.config.getoption("--tvm-debug")


@pytest.fixture(scope="session")
def run_hardware_tests(request):
return request.config.getoption("--run-hardware-tests")


def make_workspace_dir(test_name, platform):
_, arduino_board = PLATFORMS[platform]
filepath = pathlib.Path(__file__)
board_workspace = (
filepath.parent
/ f"workspace_{test_name}_{arduino_board}"
/ datetime.datetime.now().strftime("%Y-%m-%dT%H-%M-%S")
)

number = 0
while board_workspace.exists():
number += 1
board_workspace = pathlib.Path(str(board_workspace) + f"-{number}")
board_workspace.parent.mkdir(exist_ok=True, parents=True)
t = tvm.contrib.utils.tempdir(board_workspace)
# time.sleep(200)
return t
Loading

0 comments on commit 237a65e

Please sign in to comment.