Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
78f92f8
num of cores
mehrdadh May 27, 2021
c2c8d74
add target list
mehrdadh May 28, 2021
daa572b
Merge branch 'ci_qemu' into rvm_update
mehrdadh May 28, 2021
30a2d79
extension
mehrdadh May 28, 2021
6750395
qemu
mehrdadh May 28, 2021
33fef63
Merge branch 'rvm_update' of github.com:mehrdadh/tvm into rvm_update
mehrdadh May 28, 2021
b2ad212
fix
mehrdadh May 28, 2021
560cce0
comments
mehrdadh May 28, 2021
bfb3b5c
Merge branch 'main' into rvm_update
mehrdadh May 28, 2021
4b3b232
add qemu to setup build
mehrdadh Jun 1, 2021
7e690a2
fix
mehrdadh Jun 1, 2021
7f62f78
add mps2 test
mehrdadh Jun 1, 2021
085ef28
Merge branch 'rvm_update' of github.com:mehrdadh/tvm into rvm_update
mehrdadh Jun 1, 2021
c04818b
Merge branch 'ci_qemu' into rvm_update
mehrdadh Jun 1, 2021
e14c83b
merge fix
mehrdadh Jun 1, 2021
9420eec
add commit option
mehrdadh Jun 1, 2021
30cc890
Merge branch 'main' into rvm_update
mehrdadh Jun 1, 2021
bfa7423
add log
mehrdadh Jun 1, 2021
f6d3498
fix
mehrdadh Jun 2, 2021
2332383
fix zephyr init
mehrdadh Jun 2, 2021
139dc8b
rename
mehrdadh Jun 2, 2021
5999db9
fix zephyr init
mehrdadh Jun 2, 2021
96cde66
uncomment
mehrdadh Jun 2, 2021
0ab5af2
fixed qemu isntall
mehrdadh Jun 2, 2021
05c0347
cleanup
mehrdadh Jun 2, 2021
91654d6
version
mehrdadh Jun 3, 2021
dd64216
add commit option
mehrdadh Jun 1, 2021
53a130f
fixed qemu isntall
mehrdadh Jun 1, 2021
38cc261
add docker import
mehrdadh Jun 4, 2021
b7dd894
merge
mehrdadh Jun 4, 2021
b8591f6
cleanup
mehrdadh Jun 4, 2021
76fe98c
fix
mehrdadh Jun 7, 2021
aa07329
cleanup
mehrdadh Jun 7, 2021
721a18a
fix
mehrdadh Jun 7, 2021
c4eb9cd
merge
mehrdadh Jun 7, 2021
5fd7f73
fix zephyr path
mehrdadh Jun 7, 2021
ed9f0c4
fix
mehrdadh Jun 7, 2021
153aeac
fix
mehrdadh Jun 8, 2021
b3dcdc8
address comments
mehrdadh Jun 9, 2021
3a14c49
Merge branch 'rvm_update' of github.com:mehrdadh/tvm into rvm_update
mehrdadh Jun 9, 2021
3a2af66
fix test
mehrdadh Jun 9, 2021
21c35df
fix
mehrdadh Jun 9, 2021
70f3c7d
add wait
mehrdadh Jun 8, 2021
87b4721
comments
mehrdadh Jun 10, 2021
ca9981a
changed test to script
mehrdadh Jun 10, 2021
510e4fa
add checks
mehrdadh Jun 10, 2021
635db46
fix zephyr
mehrdadh Jun 11, 2021
b535e84
Revert "add wait"
mehrdadh Jun 11, 2021
b43c3da
address comments
mehrdadh Jun 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/microtvm/reference-vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ Reference VMs are organized as follows:

## Creating Releases

1. Build the base box for the given platform: `$ ./base-box-tool.py build <platform>`
1. Build the base box for the given platform: `$ ./base-box-tool.py [--provider=<provider>] build <platform>`
2. Run release tests for each platform:
1. Connect any needed hardware to the VM host machine.
2. Run tests: `$ ./base-box-tool.py test <platform> [--test-device-serial=<serial>]`. This
2. Run tests: `$ ./base-box-tool.py [--provider=<provider>] test [--microtvm-platform=<platform>] <platform> [--test-device-serial=<serial>]`. This
command does the following for each provider:
1. Copies all files inside `./<platform>` except `.vagrant` and `base-box` to
`./release-test`. This is done to avoid reusing any VM the developer may have started.
2. Executes `$ vagrant up --provider=<provider>`.
2. Executes `$ vagrant up [--provider=<provider>]`.
3. Finds an attached USB device matching the VID and PID specified in `test-config.json`,
and if `--test-device-serial` was given, that serial number (as reported to USB). Creates
a rule to autoconnect this device to the VM, and also attaches it to the VM>
4. SSHs to the VM, `cd` to the TVM root directory, and runs `test_cmd` from
`test-config.json`. Nonzero status means failure.
3. If release tests fail, fix them and restart from step 1.
4. If release tests pass: `$ ./base-box-tool.py release <platform> <version>`. Be sure you've logged
4. If release tests pass: `$ ./base-box-tool.py [--provider=<provider>] release <--release-version=<version>> <--platform-version=<version>> <platform>`. Be sure you've logged
in to Vagrant Cloud using the `vagrant` tool.
72 changes: 55 additions & 17 deletions apps/microtvm/reference-vm/base-box-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

THIS_DIR = os.path.realpath(os.path.dirname(__file__) or ".")


# List of vagrant providers supported by this tool
ALL_PROVIDERS = (
"parallels",
Expand All @@ -46,8 +45,11 @@
ALL_MICROTVM_PLATFORMS = (
"stm32f746xx",
"nrf5340dk",
"mps2_an521",
)

PACKER_FILE_NAME = "packer.json"


def parse_virtualbox_devices():
output = subprocess.check_output(["VBoxManage", "list", "usbhost"], encoding="utf-8")
Expand Down Expand Up @@ -173,12 +175,21 @@ 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 = (
"docker/install/ubuntu_init_zephyr_project.sh",
"docker/install/ubuntu_install_qemu.sh",
)


def generate_packer_config(file_path, providers):
builders = []
provisioners = []
for provider_name in providers:
builders.append(
{
"name": f"{provider_name}",
"type": "vagrant",
"box_name": f"microtvm-base-{provider_name}",
"output_dir": f"output-packer-{provider_name}",
Expand All @@ -189,10 +200,26 @@ def generate_packer_config(file_path, providers):
}
)

repo_root = subprocess.check_output(
["git", "rev-parse", "--show-toplevel"], cwd=os.path.dirname(__file__), encoding="utf-8"
).strip()
for script in EXTRA_SCRIPTS:
script_path = os.path.join(repo_root, script)
filename = os.path.basename(script_path)
provisioners.append({"type": "file", "source": script_path, "destination": f"~/{filename}"})

provisioners.append(
{
"type": "shell",
"script": "base_box_provision.sh",
}
)

with open(file_path, "w") as f:
json.dump(
{
"builders": builders,
"provisioners": provisioners,
},
f,
sort_keys=True,
Expand All @@ -202,7 +229,7 @@ def generate_packer_config(file_path, providers):

def build_command(args):
generate_packer_config(
os.path.join(THIS_DIR, args.platform, "base-box", "packer.json"),
os.path.join(THIS_DIR, args.platform, "base-box", PACKER_FILE_NAME),
args.provider or ALL_PROVIDERS,
)
env = copy.copy(os.environ)
Expand All @@ -212,7 +239,7 @@ def build_command(args):
if args.debug_packer:
packer_args += ["-debug"]

packer_args += ["packer.json"]
packer_args += [PACKER_FILE_NAME]
subprocess.check_call(
packer_args, cwd=os.path.join(THIS_DIR, args.platform, "base-box"), env=env
)
Expand All @@ -221,7 +248,6 @@ def build_command(args):
REQUIRED_TEST_CONFIG_KEYS = {
"vid_hex": str,
"pid_hex": str,
"test_cmd": list,
}


Expand Down Expand Up @@ -284,7 +310,6 @@ def do_build_release_test_vm(release_test_dir, user_box_dir, base_box_dir, provi
return_code = subprocess.call(remove_args, cwd=release_test_dir)
assert return_code in (0, 1), f'{" ".join(remove_args)} returned exit code {return_code}'
subprocess.check_call(["vagrant", "up", f"--provider={provider_name}"], cwd=release_test_dir)

return True


Expand All @@ -293,18 +318,30 @@ def do_run_release_test(release_test_dir, provider_name, test_config, test_devic
os.path.join(release_test_dir, ".vagrant", "machines", "default", provider_name, "id")
) as f:
machine_uuid = f.read()
ATTACH_USB_DEVICE[provider_name](
machine_uuid,
vid_hex=test_config["vid_hex"],
pid_hex=test_config["pid_hex"],
serial=test_device_serial,
)

# Check if target is not QEMU
if test_config["vid_hex"] and test_config["pid_hex"]:
ATTACH_USB_DEVICE[provider_name](
machine_uuid,
vid_hex=test_config["vid_hex"],
pid_hex=test_config["pid_hex"],
serial=test_device_serial,
)
tvm_home = os.path.realpath(os.path.join(THIS_DIR, "..", "..", ".."))

def _quote_cmd(cmd):
return " ".join(shlex.quote(a) for a in cmd)

test_cmd = _quote_cmd(["cd", tvm_home]) + " && " + _quote_cmd(test_config["test_cmd"])
test_cmd = (
_quote_cmd(["cd", tvm_home])
+ " && "
+ _quote_cmd(
[
"apps/microtvm/reference-vm/zephyr/base-box/base_box_test.sh",
test_config["microtvm_platform"],
]
)
)
subprocess.check_call(["vagrant", "ssh", "-c", f"bash -ec '{test_cmd}'"], cwd=release_test_dir)


Expand All @@ -325,6 +362,7 @@ 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["microtvm_platform"] = args.microtvm_platform

providers = args.provider
provider_passed = {p: False for p in providers}
Expand Down Expand Up @@ -399,18 +437,18 @@ def parse_args():
description="Automates building, testing, and releasing a base box"
)
subparsers = parser.add_subparsers(help="Action to perform.")
parser.add_argument(
"platform",
help="Name of the platform VM to act on. Must be a sub-directory of this directory.",
)
parser.add_argument(
"--provider",
choices=ALL_PROVIDERS,
action="append",
default=list(ALL_PROVIDERS),
help="Name of the provider or providers to act on; if not specified, act on all.",
)

parser.add_argument(
"platform",
help="Name of the platform VM to act on. Must be a sub-directory of this directory.",
)

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.")
Expand Down
2 changes: 1 addition & 1 deletion apps/microtvm/reference-vm/zephyr/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Vagrant.configure("2") do |config|
end
end

config.vm.provision "shell", path: "setup.sh", env: {"TVM_HOME": dirs_to_mount[0]}, privileged: false
config.vm.provision "shell", path: "provision_setup.sh", env: {"TVM_HOME": dirs_to_mount[0]}, privileged: false

# Enable USB Controller on VirtualBox
vm_name = "microtvm-#{Time.now.tv_sec}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: "touch ~/skip_zeroing_disk", privileged: false
{{- end}}

# NOTE: setup.sh resides in the parent directory (../) because this template is expanded into a
# NOTE: base_box_setup.sh resides in the parent directory (../) because this template is expanded into a
# sub-directory of base-box (output-packer-*).
config.vm.provision "shell", path: "../setup.sh", privileged: false
config.vm.provision "shell", path: "../base_box_setup.sh", privileged: false
end
37 changes: 37 additions & 0 deletions apps/microtvm/reference-vm/zephyr/base-box/base_box_provision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash -e
# 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.
#
# Using this script we can reuse docker/install scripts to configure the reference
# virtual machine similar to CI QEMU setup.
#

set -e
set -x

source ~/.profile

# Init Zephyr
cd ~
# Using most recent commit that passes all the tests.
~/ubuntu_init_zephyr_project.sh ~/zephyr v2.5-branch --commit dabf23758417fd041fec2a2a821d8f526afac29d
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe comment if there is anything special about this commit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing special about it, this is just to show the most recent RVM build is using this commit and has been tested up to this point. I like this better because otherwise you have to download the RVM and check the commit.


# Build QEMU
sudo ~/ubuntu_install_qemu.sh --target-list arm-softmmu

# Cleanup
rm -f *.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# under the License.

set -e
set -x

skip_zeroing_disk=0
if [ -e "$HOME/skip_zeroing_disk" ]; then
Expand Down Expand Up @@ -81,8 +82,6 @@ pip3 install --user -U west
echo 'export PATH=$HOME/.local/bin:"$PATH"' >> ~/.profile
source ~/.profile
echo PATH=$PATH
REPO_ROOT=$(git rev-parse --show-toplevel)
${REPO_ROOT}/docker/install/ubuntu_init_zephyr_project.sh ~/zephyr v2.5.0

cd ~
echo "Downloading zephyr SDK..."
Expand Down
39 changes: 39 additions & 0 deletions apps/microtvm/reference-vm/zephyr/base-box/base_box_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash -e
# 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: base_box_test.sh <MICROTVM_PLATFORM>
# Execute microTVM Zephyr tests.
#

set -e
set -x

if [ "$#" -lt 1 ]; then
echo "Usage: base_box_test.sh <MICROTVM_PLATFORM>"
exit -1
fi

microtvm_platform=$1

pytest tests/micro/zephyr/test_zephyr.py --microtvm-platforms=${microtvm_platform}

if [ $microtvm_platform == "stm32f746xx" ]; then
echo "NOTE: skipped test_zephyr_aot.py on $microtvm_platform -- known failure"
else
pytest tests/micro/zephyr/test_zephyr_aot.py --microtvm-platforms=${microtvm_platform}
fi
10 changes: 6 additions & 4 deletions apps/microtvm/reference-vm/zephyr/base-box/test-config.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"stm32f746xx": {
"vid_hex": "0483",
"pid_hex": "374b",
"test_cmd": ["pytest", "tests/micro/zephyr/test_zephyr.py", "--microtvm-platforms=stm32f746xx"]
"pid_hex": "374b"
},
"nrf5340dk": {
"vid_hex": "1366",
"pid_hex": "1055",
"test_cmd": ["pytest", "tests/micro/zephyr/test_zephyr.py", "--microtvm-platforms=nrf5340dk"]
"pid_hex": "1055"
},
"mps2_an521": {
"vid_hex": "",
"pid_hex": ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cd "${TVM_HOME}"

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

# Build poetry
cd apps/microtvm/reference-vm/zephyr

poetry env use 3.6
Expand All @@ -41,7 +42,7 @@ echo "downloaded and cached for future use."
echo "------------------------------[ TVM Message ]------------------------------"
poetry lock -vvv
poetry install
poetry run pip3 install -r ~/zephyr/zephyr/scripts/requirements.txt
poetry run pip3 install -r ${ZEPHYR_BASE}/scripts/requirements.txt

echo "export TVM_LIBRARY_PATH=\"$TVM_HOME\"/build-microtvm" >>~/.profile
echo "VENV_PATH=\$((cd \"$TVM_HOME\"/apps/microtvm/reference-vm/zephyr && poetry env list --full-path) | sed -E 's/^(.*)[[:space:]]\(Activated\)\$/\1/g')" >>~/.profile
Expand Down
10 changes: 9 additions & 1 deletion apps/microtvm/reference-vm/zephyr/rebuild-tvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@

set -e

# Get number of cores for build
if [ -n "${TVM_CI_NUM_CORES}" ]; then
num_cores=${TVM_CI_NUM_CORES}
else
# default setup for Vagrantfile
num_cores=2
fi

cd "$(dirname $0)"
cd "$(git rev-parse --show-toplevel)"
BUILD_DIR=build-microtvm
Expand All @@ -32,4 +40,4 @@ sed -i 's/USE_GRAPH_EXECUTOR_DEBUG OFF/USE_GRAPH_EXECUTOR_DEBUG ON/' config.cmak
sed -i 's/USE_LLVM OFF/USE_LLVM ON/' config.cmake
cmake ..
rm -rf standalone_crt host_standalone_crt # remove stale generated files
make -j4
make -j${num_cores}
Loading