Skip to content

Commit

Permalink
Generalize parts of RVM for multiple platforms
Browse files Browse the repository at this point in the history
cwd hack

Add unit tests from apps directory to task_python_microtvm.sh

Generalize parts of RVM for multiple platforms
  • Loading branch information
guberti committed Aug 23, 2021
1 parent df35ad4 commit 6ba358b
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 84 deletions.
5 changes: 5 additions & 0 deletions apps/microtvm/arduino/template_project/microtvm_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class BoardAutodetectFailed(Exception):
"architecture": "esp32",
"board": "feathers2",
},
"metrom4": {
"package": "adafruit",
"architecture": "samd",
"board": "adafruit_metro_m4",
},
# Spresense only works as of its v2.3.0 sdk
"spresense": {
"package": "SPRESENSE",
Expand Down
19 changes: 14 additions & 5 deletions apps/microtvm/reference-vm/arduino/base-box/base_box_provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,20 @@ SPRESENSE_BOARDS_URL="https://github.com/sonydevworld/spresense-arduino-compatib
arduino-cli core update-index --additional-urls $ADAFRUIT_BOARDS_URL,$ESP32_BOARDS_URL,$SPARKFUN_BOARDS_URL,$SEEED_BOARDS_URL,$SPRESENSE_BOARDS_URL

# Install supported cores from those URLS
arduino-cli core install arduino:mbed_nano # Arduino Nano BLE
arduino-cli core install arduino:sam # Arduino Due
arduino-cli core install SPRESENSE:spresense --additional-urls $SPRESENSE_BOARDS_URL # Sony Spresense
arduino-cli core install adafruit:samd --additional-urls $ADAFRUIT_BOARDS_URL # Adafruit PyBadge
arduino-cli core install esp32:esp32 --additional-urls $ESP32_BOARDS_URL # Adafruit FeatherS2
arduino-cli core install arduino:mbed_nano
arduino-cli core install arduino:sam
arduino-cli core install adafruit:samd --additional-urls $ADAFRUIT_BOARDS_URL
arduino-cli core install esp32:esp32 --additional-urls $ESP32_BOARDS_URL
arduino-cli core install Seeeduino:samd --additional-urls $SEEED_BOARDS_URL
arduino-cli core install SPRESENSE:spresense --additional-urls $SPRESENSE_BOARDS_URL

# The Sony Spresense SDK has a major bug that breaks TVM. It's scheduled to be fixed in
# release 2.3.0, but until that's published we need to use the below hack. This ONLY
# fixes the bug in the main core release SDK - the subcore release SDK and both
# the main and subcore debug SDKs will continue to fail until an official fix is made.
# https://github.com/sonydevworld/spresense/issues/200
SPRESENSE_BUGFIX_PATH=~/.arduino15/packages/SPRESENSE/tools/spresense-sdk/2.2.1/spresense/release/nuttx/include/sys/types.h
sed -i 's/#ifndef CONFIG_WCHAR_BUILTIN/#if !defined(__cplusplus)/g' $SPRESENSE_BUGFIX_PATH

# Cleanup
rm -f *.sh
2 changes: 1 addition & 1 deletion apps/microtvm/reference-vm/arduino/provision_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set -ex
# NOTE: TVM is presumed to be mounted already by Vagrantfile.
cd "${TVM_HOME}"

apps/microtvm/reference-vm/arduino/rebuild-tvm.sh
apps/microtvm/reference-vm/rebuild-tvm.sh

# Build poetry
cd apps/microtvm/reference-vm/arduino
Expand Down
108 changes: 74 additions & 34 deletions apps/microtvm/reference-vm/base-box-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,46 @@
"vmware_desktop",
)

# List of microTVM platforms for testing.
ALL_MICROTVM_PLATFORMS = (
"stm32f746xx_nucleo",
"stm32f746xx_disco",
"nrf5340dk",
"mps2_an521",
# List of supported electronics platforms. Each must correspond
# to a sub-directory of this directory.
ALL_PLATFORMS = (
"arduino",
"zephyr",
)

# List of identifying strings for microTVM platforms for testing.
# Must match PLATFORMS as defined in tvm/tests/micro/[platform]/conftest.py
# TODO add a way to declare supported platforms to ProjectAPI
ALL_MICROTVM_PLATFORMS = {
"arduino": (
"due",
"feathers2",
"metrom4",
"nano33ble",
"pybadge",
"spresense",
"teensy40",
"teensy41",
"wioterminal",
),
"zephyr": (
"stm32f746xx_nucleo",
"stm32f746xx_disco",
"nrf5340dk",
"mps2_an521",
),
}

# Extra scripts required to execute on provisioning
# in [platform]/base-box/base_box_provision.sh
EXTRA_SCRIPTS = {
"arduino": (),
"zephyr": (
"docker/install/ubuntu_init_zephyr_project.sh",
"docker/install/ubuntu_install_qemu.sh",
),
}

PACKER_FILE_NAME = "packer.json"


Expand Down Expand Up @@ -176,18 +208,6 @@ def attach_vmware(uuid, vid_hex=None, pid_hex=None, serial=None):
"vmware_desktop": attach_vmware,
}

# Extra scripts required to execute on provisioning
# in zephyr/base-box/base_box_provision.sh
EXTRA_SCRIPTS = {
"arduino": (
#"docker/install/ubuntu_install_arduino.sh",
"docker/install/ubuntu_install_qemu.sh",
),
"zephyr": (
"docker/install/ubuntu_init_zephyr_project.sh",
)
}


def generate_packer_config(platform, file_path, providers):
builders = []
Expand All @@ -207,7 +227,7 @@ def generate_packer_config(platform, file_path, providers):
)

repo_root = subprocess.check_output(
["git", "rev-parse", "--show-toplevel"], cwd=os.path.dirname(__file__), encoding="utf-8"
["git", "rev-parse", "--show-toplevel"], encoding="utf-8"
).strip()
for script in EXTRA_SCRIPTS[platform]:
script_path = os.path.join(repo_root, script)
Expand Down Expand Up @@ -247,7 +267,6 @@ def build_command(args):
packer_args += ["-debug"]

packer_args += [PACKER_FILE_NAME]
print(packer_args)
subprocess.check_call(
packer_args, cwd=os.path.join(THIS_DIR, args.platform, "base-box"), env=env
)
Expand Down Expand Up @@ -346,7 +365,7 @@ def _quote_cmd(cmd):
+ _quote_cmd(
[
f"apps/microtvm/reference-vm/{platform}/base-box/base_box_test.sh",
test_config["platform"],
test_config["microtvm_platform"],
]
)
)
Expand All @@ -361,7 +380,7 @@ def test_command(args):
test_config = json.load(f)

# select microTVM test platform
microtvm_test_platform = test_config["nano33ble"]
microtvm_test_platform = test_config[args.microtvm_platform]

for key, expected_type in REQUIRED_TEST_CONFIG_KEYS.items():
assert key in microtvm_test_platform and isinstance(
Expand All @@ -370,9 +389,10 @@ def test_command(args):

microtvm_test_platform["vid_hex"] = microtvm_test_platform["vid_hex"].lower()
microtvm_test_platform["pid_hex"] = microtvm_test_platform["pid_hex"].lower()
microtvm_test_platform["platform"] = args.platform
microtvm_test_platform["microtvm_platform"] = args.microtvm_platform

providers = args.provider
print(providers)
provider_passed = {p: False for p in providers}

release_test_dir = os.path.join(THIS_DIR, "release-test")
Expand All @@ -387,7 +407,11 @@ def test_command(args):
release_test_dir, user_box_dir, base_box_dir, provider_name
)
do_run_release_test(
release_test_dir, args.platform, provider_name, microtvm_test_platform, args.test_device_serial
release_test_dir,
args.platform,
provider_name,
microtvm_test_platform,
args.test_device_serial,
)
provider_passed[provider_name] = True

Expand Down Expand Up @@ -449,26 +473,27 @@ def parse_args():
"--provider",
choices=ALL_PROVIDERS,
action="append",
help="Name of the provider or providers to act on; if not specified, act on all.",
required=True,
help="Name of the provider or providers to act on",
)

parser.add_argument(
"platform",
help="Name of the platform VM to act on. Must be a sub-directory of this directory.",
)
# "test" has special options for different platforms, and "build", "release" might
# in the future, so we'll add the platform argument to each one individually.
platform_help_str = "Electronics platform to use (e.g. Arduino, Zephyr)"

# Options for build subcommand
parser_build = subparsers.add_parser("build", help="Build a base box.")
parser_build.set_defaults(func=build_command)
parser_test = subparsers.add_parser("test", help="Test a base box before release.")
parser_test.set_defaults(func=test_command)
parser_release = subparsers.add_parser("release", help="Release base box to cloud.")
parser_release.set_defaults(func=release_command)

parser_build.add_argument("platform", help=platform_help_str, choices=ALL_PLATFORMS)
parser_build.add_argument(
"--debug-packer",
action="store_true",
help=("Run packer in debug mode, and write log to the base-box directory."),
)

# Options for test subcommand
parser_test = subparsers.add_parser("test", help="Test a base box before release.")
parser_test.set_defaults(func=test_command)
parser_test.add_argument(
"--skip-build",
action="store_true",
Expand All @@ -485,6 +510,21 @@ def parse_args():
"iSerial field from `lsusb -v` output."
),
)
platform_subparsers = parser_test.add_subparsers(help=platform_help_str)
for platform in ALL_PLATFORMS:
platform_specific_parser = platform_subparsers.add_parser(platform)
platform_specific_parser.set_defaults(platform=platform)
platform_specific_parser.add_argument(
"--microtvm-platform",
choices=ALL_MICROTVM_PLATFORMS[platform],
required=True,
help="MicroTVM platfrom used for testing.",
)

# Options for release subcommand
parser_release = subparsers.add_parser("release", help="Release base box to cloud.")
parser_release.set_defaults(func=release_command)
parser_release.add_argument("platform", help=platform_help_str, choices=ALL_PLATFORMS)
parser_release.add_argument(
"--release-version",
required=True,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion apps/microtvm/reference-vm/zephyr/provision_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set -ex
# NOTE: TVM is presumed to be mounted already by Vagrantfile.
cd "${TVM_HOME}"

apps/microtvm/reference-vm/zephyr/rebuild-tvm.sh
apps/microtvm/reference-vm/rebuild-tvm.sh

# Build poetry
cd apps/microtvm/reference-vm/zephyr
Expand Down
43 changes: 0 additions & 43 deletions apps/microtvm/reference-vm/zephyr/rebuild-tvm.sh

This file was deleted.

1 change: 1 addition & 0 deletions tests/micro/arduino/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
PLATFORMS = {
"due": ("sam3x8e", "due"),
"feathers2": ("esp32", "feathers2"),
"metrom4": ("atsamd51", "metrom4"),
"nano33ble": ("nrf52840", "nano33ble"),
"pybadge": ("atsamd51", "pybadge"),
"spresense": ("cxd5602gg", "spresense"),
Expand Down

0 comments on commit 6ba358b

Please sign in to comment.