-
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.
- Rename all examples so that they have underscores instead of hyphens. .py files with hyphens in their names can't be imported. - Add a test/hitl/ directory with one test (so far): cpy_test.py. This test makes sure that cpy_example.py runs successfully on a CircuitPython host connected to a Notecard. I tested using a Notecarrier F and a Swan. - cpy_test.py relies on pyboard.py from MicroPython. I have added that file from MicroPython's master branch here.
- Loading branch information
1 parent
b52e7bb
commit e3b1bb5
Showing
8 changed files
with
1,007 additions
and
42 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,55 @@ | ||
import argparse | ||
from pathlib import Path | ||
import shutil | ||
import pyboard | ||
|
||
def main(args): | ||
# 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')) | ||
circuitpy_dir = Path(args.circuitpy_dir) | ||
cpy_notecard_dir = circuitpy_dir / 'lib' / 'notecard' | ||
# Create the /lib/notecard directory on the CircuitPython host. | ||
cpy_notecard_dir.mkdir(exist_ok=True, parents=True) | ||
|
||
print(f'Copying notecard .py files to host...') | ||
for f in notecard_files: | ||
print(f' {f.name}') | ||
shutil.copy(f, cpy_notecard_dir / f.name) | ||
print('Done.') | ||
|
||
# Copy over cpy_example.py. We'll run this example code on the CircuitPython | ||
# 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. | ||
examples_dir = note_python_root_dir / 'examples' | ||
cpy_example_file = examples_dir / 'notecard-basics' / 'cpy_example.py' | ||
print(f'Copying over {cpy_example_file}...', end='') | ||
shutil.copy(cpy_example_file, circuitpy_dir / cpy_example_file.name) | ||
print('Done.') | ||
|
||
# We use pyboard from the MicroPython project to run code remotely on the | ||
# host: https://github.com/micropython/micropython/blob/master/tools/pyboard.py | ||
pyb = pyboard.Pyboard(args.port, 115200) | ||
for use_uart in [False, True]: | ||
pyb.enter_raw_repl() | ||
# Run the example code, with serial (use_uart True) and I2C | ||
# (use_uart False). | ||
cmd = f'from cpy_example import run_example; run_example("{args.product_uid}", {use_uart})' | ||
print(f"Running test command: {cmd}") | ||
output = pyb.exec(cmd) | ||
output = output.decode() | ||
print(output) | ||
if 'Example complete.' not in output: | ||
raise Exception(f'Test failed. See output above.') | ||
|
||
print('Tests passed!') | ||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description='Run hardware-in-the-loop test against a CircuitPython host.') | ||
parser.add_argument('--circuitpy-dir', '-c', required=True, help='The path to the CIRCUITPY directory.') | ||
parser.add_argument('--port', '-p', required=True, help='The serial port of the CircuitPython host (e.g. /dev/ttyACM0).') | ||
parser.add_argument('--product-uid', '-i', required=True, help='The ProductUID to set on the Notecard.') | ||
args = parser.parse_args() | ||
main(args) |
Oops, something went wrong.