Skip to content

Commit

Permalink
Add scripts for automated build and testing (apache#10194)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehrdadh authored and ylc committed Feb 16, 2022
1 parent 9da2da5 commit 65f6aa0
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 94 deletions.
36 changes: 27 additions & 9 deletions apps/microtvm/arduino/template_project/boards.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,75 @@
"package": "arduino",
"architecture": "sam",
"board": "arduino_due_x_dbg",
"model": "sam3x8e"
"model": "sam3x8e",
"vid_hex": "2341",
"pid_hex": "003d"
},
"feathers2": {
"package": "esp32",
"architecture": "esp32",
"board": "feathers2",
"model": "esp32",
"note": "Due to the way the Feather S2 bootloader works, compilation behaves fine but uploads cannot be done automatically."
"note": "Due to the way the Feather S2 bootloader works, compilation behaves fine but uploads cannot be done automatically.",
"vid_hex": "303a",
"pid_hex": "0002"
},
"metrom4": {
"package": "adafruit",
"architecture": "samd",
"board": "adafruit_metro_m4",
"model": "atsamd51"
"model": "atsamd51",
"vid_hex": "",
"pid_hex": ""
},
"spresense": {
"package": "SPRESENSE",
"architecture": "spresense",
"board": "spresense",
"model": "cxd5602gg",
"note": "Spresense only works as of its v2.3.0 sdk."
"note": "Spresense only works as of its v2.3.0 sdk.",
"vid_hex": "10c4",
"pid_hex": "ea60"
},
"nano33ble": {
"package": "arduino",
"architecture": "mbed_nano",
"board": "nano33ble",
"model": "nrf52840"
"model": "nrf52840",
"vid_hex": "2341",
"pid_hex": "805a"
},
"pybadge": {
"package": "adafruit",
"architecture": "samd",
"board": "adafruit_pybadge_m4",
"model": "atsamd51"
"model": "atsamd51",
"vid_hex": "",
"pid_hex": ""
},
"teensy40": {
"package": "teensy",
"architecture": "avr",
"board": "teensy40",
"model": "imxrt1060",
"note": "The Teensy boards are listed here for completeness, but they won't work until https://github.com/arduino/arduino-cli/issues/700 is finished."
"note": "The Teensy boards are listed here for completeness, but they won't work until https://github.com/arduino/arduino-cli/issues/700 is finished.",
"vid_hex": "16c0",
"pid_hex": "0478"
},
"teensy41": {
"package": "teensy",
"architecture": "avr",
"board": "teensy41",
"model": "imxrt1060"
"model": "imxrt1060",
"vid_hex": "16c0",
"pid_hex": "0478"
},
"wioterminal": {
"package": "Seeeduino",
"architecture": "samd",
"board": "seeed_wio_terminal",
"model": "atsamd51"
"model": "atsamd51",
"vid_hex": "2886",
"pid_hex": "802d"
}
}
30 changes: 0 additions & 30 deletions apps/microtvm/reference-vm/arduino/base-box/test-config.json

This file was deleted.

66 changes: 39 additions & 27 deletions apps/microtvm/reference-vm/base-box-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


import argparse
from ast import arg
import copy
import json
import logging
Expand All @@ -27,6 +28,7 @@
import shutil
import subprocess
import sys
import pathlib

_LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -61,25 +63,15 @@


# List of identifying strings for microTVM boards for testing.
# TODO add a way to declare supported boards to ProjectAPI
with open(pathlib.Path(THIS_DIR) / ".." / "zephyr" / "template_project" / "boards.json") as f:
zephyr_boards = json.load(f)

with open(pathlib.Path(THIS_DIR) / ".." / "arduino" / "template_project" / "boards.json") as f:
arduino_boards = json.load(f)

ALL_MICROTVM_BOARDS = {
"arduino": (
"due",
"feathers2",
"metrom4",
"nano33ble",
"pybadge",
"spresense",
"teensy40",
"teensy41",
"wioterminal",
),
"zephyr": (
"nucleo_f746zg",
"stm32f746g_disco",
"nrf5340dk_nrf5340_cpuapp",
"mps2_an521",
),
"arduino": arduino_boards.keys(),
"zephyr": zephyr_boards.keys(),
}


Expand Down Expand Up @@ -290,7 +282,9 @@ def build_command(args):
SKIP_COPY_PATHS = [".vagrant", "base-box"]


def do_build_release_test_vm(release_test_dir, user_box_dir, base_box_dir, provider_name):
def do_build_release_test_vm(
release_test_dir, user_box_dir: pathlib.Path, base_box_dir: pathlib.Path, provider_name
):
if os.path.exists(release_test_dir):
try:
subprocess.check_call(["vagrant", "destroy", "-f"], cwd=release_test_dir)
Expand Down Expand Up @@ -378,10 +372,10 @@ def _quote_cmd(cmd):


def test_command(args):
user_box_dir = os.path.join(THIS_DIR, args.platform)
base_box_dir = os.path.join(THIS_DIR, args.platform, "base-box")
test_config_file = os.path.join(base_box_dir, "test-config.json")
with open(test_config_file) as f:
user_box_dir = pathlib.Path(THIS_DIR) / args.platform
base_box_dir = user_box_dir / "base-box"
boards_file = pathlib.Path(THIS_DIR) / ".." / args.platform / "template_project" / "boards.json"
with open(boards_file) as f:
test_config = json.load(f)

# select microTVM test config
Expand All @@ -390,7 +384,7 @@ def test_command(args):
for key, expected_type in REQUIRED_TEST_CONFIG_KEYS.items():
assert key in microtvm_test_config and isinstance(
microtvm_test_config[key], expected_type
), f"Expected key {key} of type {expected_type} in {test_config_file}: {test_config!r}"
), f"Expected key {key} of type {expected_type} in {boards_file}: {test_config!r}"

microtvm_test_config["vid_hex"] = microtvm_test_config["vid_hex"].lower()
microtvm_test_config["pid_hex"] = microtvm_test_config["pid_hex"].lower()
Expand Down Expand Up @@ -443,7 +437,10 @@ def test_command(args):


def release_command(args):
vm_name = f"tlcpack/microtvm-{args.platform}-{args.platform_version}"
if args.release_full_name:
vm_name = args.release_full_name
else:
vm_name = f"tlcpack/microtvm-{args.platform}-{args.platform_version}"

if not args.skip_creating_release_version:
subprocess.check_call(
Expand Down Expand Up @@ -565,14 +562,29 @@ def parse_args():
)
parser_release.add_argument(
"--platform-version",
required=True,
required=False,
help=(
"For Zephyr, the platform version to release, in the form 'x.y'. "
"For Arduino, the version of arduino-cli that's being used, in the form 'x.y.z'."
),
)
parser_release.add_argument(
"--release-full-name",
required=False,
type=str,
default=None,
help=(
"If set, it will use this as the full release name and version for the box. "
"If this set, it will ignore `--platform-version` and `--release-version`."
),
)

args = parser.parse_args()

if args.action == "release" and not args.release_full_name:
parser.error("--platform-version is requireed.")

return parser.parse_args()
return args


def main():
Expand Down
34 changes: 34 additions & 0 deletions apps/microtvm/reference-vm/scripts/reference_vm_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Usage: apps/microtvm/reference-vm/scripts/reference_vm_build.sh <PLATFORM>
#

if [ "$#" -lt 1 -o "$1" == "--help" -o "$1" == "-h" ]; then
echo "Usage: apps/microtvm/reference-vm/scripts/reference_vm_build.sh <PLATFORM>"
exit -1
fi

PLATFORM=$1
shift

cd "$(dirname "$0")"
source "./utils.sh" || exit 2
cd ${RVM_BASE_PATH}

${BASE_BOX_TOOL} --provider=virtualbox build ${PLATFORM}
43 changes: 43 additions & 0 deletions apps/microtvm/reference-vm/scripts/reference_vm_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Usage: apps/microtvm/reference-vm/scripts/reference_vm_release.sh <PLATFORM> <RELEASE_NAME> <RELEASE_VERSION>
#

if [ "$#" -lt 3 -o "$1" == "--help" -o "$1" == "-h" ]; then
echo "Usage: apps/microtvm/reference-vm/scripts/reference_vm_release.sh <PLATFORM> <RELEASE_NAME> <RELEASE_VERSION>"
exit -1
fi

PLATFORM=$1
shift

RELEASE_NAME=$1
shift

RELEASE_VERSION=$1
shift

cd "$(dirname "$0")"
source "./utils.sh" || exit 2
cd ${RVM_BASE_PATH}

${BASE_BOX_TOOL} --provider=virtualbox release ${PLATFORM} \
--release-full-name=${RELEASE_NAME} \
--release-version=${RELEASE_VERSION} \
--skip-creating-release-version
37 changes: 37 additions & 0 deletions apps/microtvm/reference-vm/scripts/reference_vm_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Usage: apps/microtvm/reference-vm/scripts/reference_vm_test.sh <PLATFORM> <BOARD>
#

if [ "$#" -lt 2 -o "$1" == "--help" -o "$1" == "-h" ]; then
echo "Usage: apps/microtvm/reference-vm/scripts/reference_vm_test.sh <PLATFORM> <BOARD>"
exit -1
fi

PLATFORM=$1
shift

BOARD=$1
shift

cd "$(dirname "$0")"
source "./utils.sh" || exit 2
cd ${RVM_BASE_PATH}

${BASE_BOX_TOOL} --provider=virtualbox test ${PLATFORM} --microtvm-board=${BOARD}
26 changes: 26 additions & 0 deletions apps/microtvm/reference-vm/scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

SCRIPTS_DIR=$(dirname "${BASH_SOURCE[0]}")

function get_repo_root() {
cd "${SCRIPTS_DIR}" && git rev-parse --show-toplevel
}

BASE_BOX_TOOL="./base-box-tool.py"
RVM_BASE_PATH="$(get_repo_root)"/apps/microtvm/reference-vm
Loading

0 comments on commit 65f6aa0

Please sign in to comment.