Skip to content

Commit 154a259

Browse files
authored
CI Tests for Zephyr Integration (#12734)
### Summary Adding in CI tests to verify and maintain support for Zephyr projects that build executorch as a module. The main zephyr application source code is hosted externally for now, but the process to host an Executorch as an official module of zephyr is in progress. This PR runs the simple Add model as unit tests, and verifies that the output is `2.0` (1D tensor + 1D tensor, values filled with `1.0s`). This is intended to be a simple and fast test to exemplify how to use executorch to build an executor_runner for other models. ### Test plan Added a new CI test called `test-models-arm-zephyr` that exits with status 0 on success, and 1 on failure.
1 parent 7a96c41 commit 154a259

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

.ci/docker/common/install_zephyr.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
set -ex
1010

11+
# shellcheck source=/dev/null
12+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
13+
1114
# Double check if the NDK version is set
1215
[ -n "${ZEPHYR_SDK}" ]
1316

@@ -77,16 +80,8 @@ install_prerequiresites() {
7780
chmod +x kitware-archive.sh && \
7881
./kitware-archive.sh && \
7982
rm -f kitware-archive.sh
80-
useradd -d /home/zephyruser -m -s /bin/bash zephyruser
81-
}
82-
83-
install_sdk() {
84-
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/zephyr-sdk-0.16.0_linux-x86_64.tar.xz && \
85-
tar -xf zephyr-sdk-0.16.0_linux-x86_64.tar.xz && \
86-
rm -f zephyr-sdk-0.16.0_linux-x86_64.tar.xz && \
87-
cd zephyr-sdk-0.16.0/ && \
88-
./setup.sh -c -t arm-zephyr-eabi
83+
pip_install --no-cache-dir west
84+
pip_install pyelftools
8985
}
9086

9187
install_prerequiresites
92-
install_sdk

.ci/docker/ubuntu/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ ARG ARM_SDK
8686

8787
ARG ZEPHYR_SDK
8888
COPY ./common/install_zephyr.sh install_zephyr.sh
89+
COPY ./common/utils.sh utils.sh
8990
RUN if [ -n "${ZEPHYR_SDK}" ]; then bash ./install_zephyr.sh; fi
90-
RUN rm install_zephyr.sh
91+
RUN rm install_zephyr.sh utils.sh
9192

9293
ARG QNN_SDK
9394

.ci/scripts/zephyr-utils.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
download_arm_zephyr_sdk () {
9+
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.0/zephyr-sdk-0.16.0_linux-x86_64.tar.xz
10+
tar -xf zephyr-sdk-0.16.0_linux-x86_64.tar.xz
11+
rm -f zephyr-sdk-0.16.0_linux-x86_64.tar.xz
12+
}
13+
14+
setup_zephyr_et_module () {
15+
git clone --branch executorch-module-integration https://github.com/BujSet/zephyr.git
16+
west init -l zephyr
17+
west config manifest.project-filter -- +executorch
18+
west -v update
19+
}

.github/workflows/trunk.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,49 @@ jobs:
5555
# Build and test executorch
5656
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}"
5757
58+
test-models-arm-zephyr:
59+
name: test-models-arm-zephyr
60+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
61+
strategy:
62+
matrix:
63+
model: [add]
64+
fail-fast: false
65+
with:
66+
runner: linux.2xlarge
67+
docker-image: ci-image:executorch-ubuntu-22.04-zephyr-sdk
68+
submodules: 'recursive'
69+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
70+
timeout: 120
71+
script: |
72+
MODEL_NAME=${{ matrix.model }}
73+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
74+
conda activate "${CONDA_ENV}"
75+
76+
source .ci/scripts/utils.sh
77+
source .ci/scripts/zephyr-utils.sh
78+
mkdir -p zephyr_scratch/
79+
cd zephyr_scratch
80+
export ZEPHYR_PROJ_ROOT=$(realpath $(pwd))
81+
82+
download_arm_zephyr_sdk
83+
./zephyr-sdk-0.16.0/setup.sh -c -t arm-zephyr-eabi
84+
85+
cd $ZEPHYR_PROJ_ROOT
86+
setup_zephyr_et_module
87+
88+
cd $ZEPHYR_PROJ_ROOT/modules/lib/executorch
89+
install_executorch "--use-pt-pinned-commit"
90+
.ci/scripts/setup-arm-baremetal-tools.sh --target-toolchain zephyr
91+
source examples/arm/ethos-u-scratch/setup_path.sh
92+
source $ZEPHYR_PROJ_ROOT/zephyr/zephyr-env.sh
93+
cd $ZEPHYR_PROJ_ROOT/zephyr/samples/modules/executorch/arm/hello_world
94+
west build -p always -b mps3/corstone300/fvp
95+
FVP_Corstone_SSE-300_Ethos-U55 -a build/zephyr/zephyr.elf -C mps3_board.visualisation.disable-visualisation=1 -C mps3_board.telnetterminal0.start_telnet=0 -C mps3_board.uart0.out_file='sim.out' -C cpu0.CFGITCMSZ=15 -C cpu0.CFGDTCMSZ=15 --simlimit 120
96+
97+
grep -qF "Output[0][0]: (float) 2.000000" sim.out
98+
exit_status=$? #store 0 if found (success), 1 if not (failure)
99+
exit $exit_status
100+
58101
test-models-linux-aarch64:
59102
name: test-models-linux-aarch64
60103
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main

0 commit comments

Comments
 (0)