-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make changes to support HitL testing.
- Loading branch information
1 parent
b52e7bb
commit 25373cc
Showing
10 changed files
with
1,105 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
addopts = --ignore=test/hitl/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from pathlib import Path | ||
import shutil | ||
import sys | ||
|
||
# Add the 'deps' folder to the path so we can import the pyboard module from | ||
# it. | ||
deps_path = str(Path(__file__).parent / 'deps') | ||
sys.path.append(deps_path) | ||
import pyboard | ||
|
||
|
||
def mkdir_on_host(pyb, dir): | ||
pyb.enter_raw_repl() | ||
try: | ||
pyb.fs_mkdir(dir) | ||
except pyboard.PyboardError as e: | ||
already_exists = ["EEXIST", "File exists"] | ||
if any([keyword in str(e) for keyword in already_exists]): | ||
# If the directory already exists, that's fine. | ||
pass | ||
else: | ||
raise | ||
finally: | ||
pyb.exit_raw_repl() | ||
|
||
|
||
def copy_files_to_host(pyb, files, dest_dir): | ||
pyb.enter_raw_repl() | ||
try: | ||
for f in files: | ||
pyb.fs_put(f, f'{dest_dir}/{f.name}', chunk_size=4096) | ||
finally: | ||
pyb.exit_raw_repl() | ||
|
||
|
||
def copy_file_to_host(pyb, file, dest): | ||
pyb.enter_raw_repl() | ||
try: | ||
pyb.fs_put(file, dest, chunk_size=4096) | ||
finally: | ||
pyb.exit_raw_repl() | ||
|
||
def setup_host(port, platform): | ||
pyb = pyboard.Pyboard(port, 115200) | ||
# Get the path to the root of the note-python repository. | ||
note_python_root_dir = Path(__file__).parent.parent.parent | ||
notecard_dir = note_python_root_dir / 'notecard' | ||
# Get a list of all the .py files in note-python/notecard/. | ||
notecard_files = list(notecard_dir.glob('*.py')) | ||
|
||
mkdir_on_host(pyb, '/lib') | ||
mkdir_on_host(pyb, '/lib/notecard') | ||
copy_files_to_host(pyb, notecard_files, '/lib/notecard') | ||
|
||
# Copy over mpy_example.py. We'll run this example code on the MicroPython | ||
# host to 1) verify that the host is able to use note-python to communicate | ||
# with the Notecard and 2) verify that the example isn't broken. | ||
if platform == 'circuitpython': | ||
example_file = 'cpy_example.py' | ||
else: | ||
example_file = 'mpy_example.py' | ||
examples_dir = note_python_root_dir / 'examples' | ||
example_file_path = examples_dir / 'notecard-basics' / example_file | ||
copy_file_to_host(pyb, example_file_path, '/example.py') | ||
|
||
pyb.close() | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
'--port', | ||
required=True, | ||
help='The serial port of the CircuitPython host (e.g. /dev/ttyACM0).' | ||
) | ||
parser.addoption( | ||
'--platform', | ||
required=True, | ||
help='Choose the platform to run the tests on.', | ||
choices=["circuitpython", "micropython"] | ||
) | ||
parser.addoption( | ||
'--productuid', | ||
required=True, | ||
help='The ProductUID to set on the Notecard.' | ||
) | ||
parser.addoption( | ||
"--skipsetup", | ||
action="store_true", | ||
help="Skip host setup (copying over note-python, etc.) (default: False)" | ||
) | ||
|
||
|
||
def pytest_configure(config): | ||
config.port = config.getoption("port") | ||
config.platform = config.getoption("platform") | ||
config.product_uid = config.getoption("productuid") | ||
config.skip_setup = config.getoption("skipsetup") | ||
|
||
if not config.skip_setup: | ||
setup_host(config.port, config.platform) |
Oops, something went wrong.