|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# All rights reserved. |
| 4 | +# Copyright 2026 Arm Limited and/or its affiliates. |
| 5 | +# |
| 6 | +# This source code is licensed under the BSD-style license found in the |
| 7 | +# LICENSE file in the root directory of this source tree. |
| 8 | + |
| 9 | +set -euo pipefail |
| 10 | + |
| 11 | +SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" |
| 12 | +EXECUTORCH_PROJ_ROOT="$(realpath "${SCRIPT_DIR}/../..")" |
| 13 | +ZEPHYR_README_PATH="zephyr/README.md" |
| 14 | + |
| 15 | +ZEPHYR_SAMPLES_README_PATH="zephyr/samples/hello-executorch/README.md" |
| 16 | +TARGETS_ARG="${TARGET_LIST:-}" |
| 17 | + |
| 18 | +usage() { |
| 19 | + cat <<EOF |
| 20 | +Usage: $0 [options] |
| 21 | +
|
| 22 | +Options: |
| 23 | + --zephyr-samples-readme-path <path> README containing test_<TARGET>* command blocks |
| 24 | + --targets <list> Comma-separated target list, e.g. ethos-u55,cortex-m55,ethos-u85 |
| 25 | + -h, --help Show this help |
| 26 | +EOF |
| 27 | +} |
| 28 | + |
| 29 | +while [[ $# -gt 0 ]]; do |
| 30 | + case "$1" in |
| 31 | + --targets) |
| 32 | + TARGETS_ARG="$2" |
| 33 | + shift 2 |
| 34 | + ;; |
| 35 | + --zephyr-samples-readme-path) |
| 36 | + ZEPHYR_SAMPLES_README_PATH="$2" |
| 37 | + shift 2 |
| 38 | + ;; |
| 39 | + -h|--help) |
| 40 | + usage |
| 41 | + exit 0 |
| 42 | + ;; |
| 43 | + *) |
| 44 | + echo "ERROR: Unknown argument: $1" >&2 |
| 45 | + usage >&2 |
| 46 | + exit 1 |
| 47 | + ;; |
| 48 | + esac |
| 49 | +done |
| 50 | + |
| 51 | +if [[ -z "${TARGETS_ARG}" ]]; then |
| 52 | + echo "ERROR: --targets or TARGET_LIST must be set" >&2 |
| 53 | + usage >&2 |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +IFS=',' read -r -a TARGETS <<< "${TARGETS_ARG}" |
| 58 | + |
| 59 | +export EXECUTORCH_PROJ_ROOT |
| 60 | + |
| 61 | +cd "${EXECUTORCH_PROJ_ROOT}" |
| 62 | + |
| 63 | +# Source utility scripts. |
| 64 | +. .ci/scripts/utils.sh |
| 65 | +. .ci/scripts/zephyr-utils.sh |
| 66 | + |
| 67 | +run_target_test_blocks_from_readme() { |
| 68 | + local readme_path="$1" |
| 69 | + local target="$2" |
| 70 | + local resolved_readme_path marker markers |
| 71 | + |
| 72 | + resolved_readme_path="$(_utils_path_from_root "${readme_path}")" |
| 73 | + markers="$(awk -v target="${target}" ' |
| 74 | + { |
| 75 | + line = $0 |
| 76 | + while (match(line, /<!--[[:space:]]*RUN[[:space:]]+[^>]*-->/)) { |
| 77 | + marker = substr(line, RSTART, RLENGTH) |
| 78 | + if (index(marker, "<!-- RUN test_" target) == 1) { |
| 79 | + print marker |
| 80 | + } |
| 81 | + line = substr(line, RSTART + RLENGTH) |
| 82 | + } |
| 83 | + } |
| 84 | + ' "${resolved_readme_path}")" |
| 85 | + |
| 86 | + if [[ -z "${markers}" ]]; then |
| 87 | + echo "ERROR: No test blocks matching <!-- RUN test_${target}* --> in ${readme_path}" >&2 |
| 88 | + return 1 |
| 89 | + fi |
| 90 | + |
| 91 | + while IFS= read -r marker; do |
| 92 | + echo "---- ${target} ${marker} ----" |
| 93 | + run_command_block_from_readme "${readme_path}" "${marker}" |
| 94 | + done <<< "${markers}" |
| 95 | +} |
| 96 | + |
| 97 | +# Check that zephyr/README.md and zephyr/executorch.yaml are in sync. |
| 98 | +verify_zephyr_readme |
| 99 | + |
| 100 | +# Based on instructions in zephyr/README.md and the selected sample README. |
| 101 | +run_command_block_from_readme "${ZEPHYR_README_PATH}" "<!-- RUN install_reqs -->" |
| 102 | + |
| 103 | +# Make sure to backup the zephyr_scratch folder if it exists to allow for local |
| 104 | +# testing that does not lose code/data. |
| 105 | +if [[ -d "zephyr_scratch" ]]; then |
| 106 | + mv "zephyr_scratch" "zephyr_scratch.backup.$(date +%Y%m%d%H%M%S)" |
| 107 | +fi |
| 108 | +mkdir -p zephyr_scratch/ |
| 109 | + |
| 110 | +cd zephyr_scratch |
| 111 | +export ZEPHYR_PROJ_ROOT="$(realpath "$(pwd)")" |
| 112 | + |
| 113 | +echo "---- Zephyr SDK ----" |
| 114 | +# Use ZephyrSDK if on the disk (e.g. setup in the docker) |
| 115 | +# Check for a zephyr-sdk-0.17.4 directory and make a symlink if found in parent directories |
| 116 | +if sdk_dir=$(find ../../.. -maxdepth 4 -type d -name 'zephyr-sdk-0.17.4' -print -quit) && [ -n "${sdk_dir}" ]; then |
| 117 | + echo "---- Found pre downloaded Zephyr SDK in ${sdk_dir} ----" |
| 118 | + ln -s "${sdk_dir}" . |
| 119 | +fi |
| 120 | + |
| 121 | +# Download and setup Zephyr SDK 0.17.4 if not already present |
| 122 | +if [ ! -d "zephyr-sdk-0.17.4" ]; then |
| 123 | + echo "---- Downloading Zephyr SDK ----" |
| 124 | + wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.17.4/zephyr-sdk-0.17.4_linux-x86_64.tar.xz |
| 125 | + tar -xf zephyr-sdk-0.17.4_linux-x86_64.tar.xz |
| 126 | + rm -f zephyr-sdk-0.17.4_linux-x86_64.tar.xz* |
| 127 | +fi |
| 128 | + |
| 129 | +./zephyr-sdk-0.17.4/setup.sh -c -t arm-zephyr-eabi |
| 130 | +export ZEPHYR_SDK_INSTALL_DIR=$(realpath ./zephyr-sdk-0.17.4) |
| 131 | + |
| 132 | +cd ${ZEPHYR_PROJ_ROOT} |
| 133 | + |
| 134 | +run_command_block_from_readme "${ZEPHYR_README_PATH}" "<!-- RUN west_init -->" |
| 135 | + |
| 136 | +cp "${EXECUTORCH_PROJ_ROOT}/zephyr/executorch.yaml" zephyr/submanifests/ |
| 137 | + |
| 138 | +run_command_block_from_readme "${ZEPHYR_README_PATH}" "<!-- RUN west_config -->" |
| 139 | + |
| 140 | +# Switch to executorch in this PR e.g. replace modules/lib/executorch with the |
| 141 | +# root folder of this repo instead of doing a re-checkout and figuring out the |
| 142 | +# correct commit hash. |
| 143 | +rm -Rf modules/lib/executorch |
| 144 | +ln -s "${EXECUTORCH_PROJ_ROOT}" modules/lib/executorch |
| 145 | + |
| 146 | +# Setup git local user for Executorch git to allow |
| 147 | +# modules/lib/executorch/examples/arm/setup.sh to run inside CI later. |
| 148 | +if ! git config --get user.name >/dev/null 2>&1; then |
| 149 | + git config --global user.name "Github Executorch" |
| 150 | +fi |
| 151 | +if ! git config --get user.email >/dev/null 2>&1; then |
| 152 | + git config --global user.email "github_executorch@arm.com" |
| 153 | +fi |
| 154 | + |
| 155 | +run_command_block_from_readme "${ZEPHYR_README_PATH}" "<!-- RUN install_executorch -->" |
| 156 | +run_command_block_from_readme "${ZEPHYR_README_PATH}" "<!-- RUN install_arm_tools -->" |
| 157 | + |
| 158 | +for TARGET in "${TARGETS[@]}"; do |
| 159 | + TARGET="$(echo "${TARGET}" | xargs)" |
| 160 | + |
| 161 | + echo "---- ${TARGET} ----" |
| 162 | + rm -Rf build |
| 163 | + |
| 164 | + if [[ ${TARGET} == "ethos-u55" || ${TARGET} == "cortex-m55" ]]; then |
| 165 | + BOARD="corstone300" |
| 166 | + elif [[ ${TARGET} == "ethos-u85" ]]; then |
| 167 | + BOARD="corstone320" |
| 168 | + else |
| 169 | + echo "Fail unsupported target selection ${TARGET}" |
| 170 | + exit 1 |
| 171 | + fi |
| 172 | + |
| 173 | + echo "---- ${TARGET} Board ${BOARD} FVP setup ----" |
| 174 | + run_command_block_from_readme "${ZEPHYR_SAMPLES_README_PATH}" "<!-- RUN setup_${BOARD} -->" |
| 175 | + |
| 176 | + # Run all blocks that match <!-- RUN test_${target}* --> |
| 177 | + run_target_test_blocks_from_readme "${ZEPHYR_SAMPLES_README_PATH}" "${TARGET}" |
| 178 | +done |
0 commit comments