| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- #!/bin/bash
- #
- # Copyright (c) 2022-2023 Project CHIP Authors
- #
- # Licensed 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.
- #
- # Build and/or run Open IoT SDK examples.
- NAME="$(basename "$0")"
- HERE="$(dirname "$0")"
- CHIP_ROOT="$(realpath "$HERE"/../..)"
- COMMAND=build
- PLATFORM=corstone300
- CLEAN=0
- SCRATCH=0
- EXAMPLE_PATH=""
- BUILD_PATH=""
- TOOLCHAIN=arm-none-eabi-gcc
- DEBUG=false
- LWIP_DEBUG=false
- EXAMPLE=""
- FVP_BIN=FVP_Corstone_SSE-300_Ethos-U55
- GDB_PLUGIN="$FAST_MODEL_PLUGINS_PATH/GDBRemoteConnection.so"
- OIS_CONFIG="$CHIP_ROOT/config/openiotsdk"
- FVP_CONFIG_FILE="$OIS_CONFIG/fvp/cs300.conf"
- EXAMPLE_TEST_PATH="$CHIP_ROOT/src/test_driver/openiotsdk/integration-tests"
- TELNET_TERMINAL_PORT=5000
- TELNET_CONNECTION_PORT=""
- FAILED_TESTS=0
- IS_UNIT_TEST=0
- FVP_NETWORK="user"
- KVS_STORAGE_FILE=""
- NO_ACTIVATE=""
- CRYPTO_BACKEND="mbedtls"
- APP_VERSION="1"
- APP_VERSION_STR="0.0.1"
- declare -A ps_storage_param=([instance]=qspi_sram [memspace]=0 [address]=0x660000 [size]=0x12000)
- readarray -t SUPPORTED_APP_NAMES <"$CHIP_ROOT"/examples/platform/openiotsdk/supported_examples.txt
- SUPPORTED_APP_NAMES+=("unit-tests")
- readarray -t TEST_NAMES <"$CHIP_ROOT"/src/test_driver/openiotsdk/unit-tests/test_components.txt
- function show_usage() {
- cat <<EOF
- Usage: $0 [options] example [test_name]
- Build, run or test the Open IoT SDK examples and unit-tests.
- Options:
- -h,--help Show this help
- -c,--clean Clean target build
- -s,--scratch Remove build directory at all before building
- -C,--command <command> Action to execute <build-run | run | test | build - default>
- -d,--debug <debug_enable> Build in debug mode <true | false - default>
- -l,--lwipdebug <lwip_debug_enable> Build with LwIP debug logs support <true | false - default>
- -b,--backend <crypto_backend) Select crypto backend <psa | mbedtls - default>
- -p,--path <build_path> Build path <build_path - default is example_dir/build>
- -K,--kvsfile <kvs_storage_file> Path to KVS storage file which will be used to ensure persistence <kvs_storage_file - default is empty which means disable persistence>
- -n,--network <network_name> FVP network interface name <network_name - default is "user" which means user network mode>
- -v,--version <version_number> Application version number <version_number - default is 1>
- -V,--versionStr <version_str> Application version string <version_strr - default is "0.0.1">
- --no-activate Do not activate the chip build environment
- Examples:
- EOF
- for app in "${SUPPORTED_APP_NAMES[@]}"; do
- echo " $app"
- done
- cat <<EOF
- You run or test individual test suites of unit tests by using their names [test_name] with the specified command:
- EOF
- for test in "${TEST_NAMES[@]}"; do
- echo " $test"
- done
- cat <<EOF
- Use "test" command without a specific test name, runs all supported unit tests.
- EOF
- }
- function build_with_cmake() {
- CMAKE="$(which cmake)"
- if [[ ! -f "$CMAKE" ]]; then
- echo "$NAME: cmake is not in PATH" >&2
- exit 1
- fi
- set -e
- mkdir -p "$BUILD_PATH"
- if [[ $CLEAN -ne 0 ]]; then
- echo "Clean build" >&2
- if compgen -G "$BUILD_PATH/CMake*" >/dev/null; then
- cmake --build "$BUILD_PATH" --target clean
- find "$BUILD_PATH" -name 'CMakeCache.txt' -delete
- fi
- fi
- if [[ $SCRATCH -ne 0 ]]; then
- echo "Remove building directory" >&2
- rm -rf "$BUILD_PATH"
- fi
- BUILD_OPTIONS=(-DCMAKE_SYSTEM_PROCESSOR=cortex-m55)
- BUILD_OPTIONS+=(-DCONFIG_CHIP_OPEN_IOT_SDK_SOFTWARE_VERSION="$APP_VERSION")
- BUILD_OPTIONS+=(-DTFM_NS_APP_VERSION="$APP_VERSION_STR")
- if "$DEBUG"; then
- BUILD_OPTIONS+=(-DCMAKE_BUILD_TYPE=Debug)
- else
- BUILD_OPTIONS+=(-DCMAKE_BUILD_TYPE=Release)
- fi
- if "$LWIP_DEBUG"; then
- BUILD_OPTIONS+=(-DCONFIG_CHIP_OPEN_IOT_SDK_LWIP_DEBUG=YES)
- fi
- BUILD_OPTIONS+=(-DCONFIG_CHIP_CRYPTO="$CRYPTO_BACKEND")
- cmake -G Ninja -S "$EXAMPLE_PATH" -B "$BUILD_PATH" --toolchain="$TOOLCHAIN_PATH" "${BUILD_OPTIONS[@]}"
- cmake --build "$BUILD_PATH"
- }
- function run_fvp() {
- set -e
- # Check if FVP exists
- if ! [ -x "$(command -v "$FVP_BIN")" ]; then
- echo "Error: $FVP_BIN not installed." >&2
- exit 1
- fi
- # Check if executable file exists
- if ! [ -f "$EXAMPLE_EXE_PATH" ]; then
- echo "Error: $EXAMPLE_EXE_PATH does not exist." >&2
- exit 1
- fi
- # Check if FVP GDB plugin file exists
- if "$DEBUG" && ! [ -f "$GDB_PLUGIN" ]; then
- echo "Error: $GDB_PLUGIN does not exist." >&2
- exit 1
- fi
- RUN_OPTIONS=(-C mps3_board.telnetterminal0.start_port="$TELNET_TERMINAL_PORT")
- RUN_OPTIONS+=(--quantum=25)
- if "$DEBUG"; then
- RUN_OPTIONS+=(--allow-debug-plugin --plugin "$GDB_PLUGIN")
- fi
- if [[ $FVP_NETWORK == "user" ]]; then
- RUN_OPTIONS+=(-C mps3_board.hostbridge.userNetworking=1)
- else
- RUN_OPTIONS+=(-C mps3_board.hostbridge.interfaceName="$FVP_NETWORK")
- fi
- if [ -n "$KVS_STORAGE_FILE" ]; then
- declare -n storage_param=ps_storage_param
- if [ -f "$KVS_STORAGE_FILE" ]; then
- RUN_OPTIONS+=(--data "mps3_board.${storage_param[instance]}=$KVS_STORAGE_FILE@${storage_param[memspace]}:${storage_param[address]}")
- fi
- RUN_OPTIONS+=(--dump "mps3_board.${storage_param[instance]}=$KVS_STORAGE_FILE@${storage_param[memspace]}:${storage_param[address]},${storage_param[size]}")
- fi
- echo "Running $EXAMPLE_EXE_PATH with options: ${RUN_OPTIONS[@]}"
- # Run the FVP
- "$FVP_BIN" "${RUN_OPTIONS[@]}" -f "$FVP_CONFIG_FILE" --application "$EXAMPLE_EXE_PATH" 2>&1 >/tmp/FVP_run_$$ &
- FVP_PID=$!
- # Wait for FVP to start and exist the output file
- timeout=0
- while [ ! -e /tmp/FVP_run_$$ ]; do
- timeout=$((timeout + 1))
- if [ "$timeout" -ge 5 ]; then
- echo "Error: FVP start failed" >&2
- break
- fi
- sleep 1
- done
- while IFS= read -t 5 -r line; do
- if [[ $line == *"Listening for serial connection on port"* ]]; then
- TELNET_CONNECTION_PORT="${line##* }"
- break
- fi
- done </tmp/FVP_run_$$
- if [ -n "$TELNET_CONNECTION_PORT" ]; then
- # Connect FVP via telnet client
- telnet localhost "$TELNET_CONNECTION_PORT"
- else
- echo "Error: FVP start failed" >&2
- fi
- # Stop the FVP
- kill -SIGTERM "$FVP_PID"
- # Wait for the FVP stop
- while kill -0 "$FVP_PID"; do
- sleep 1
- done
- rm -rf /tmp/FVP_run_$$
- }
- function run_test() {
- # Check if executable file exists
- if ! [ -f "$EXAMPLE_EXE_PATH" ]; then
- echo "Error: $EXAMPLE_EXE_PATH does not exist." >&2
- exit 1
- fi
- # Check if FVP exists
- if ! [ -x "$(command -v "$FVP_BIN")" ]; then
- echo "Error: $FVP_BIN not installed." >&2
- exit 1
- fi
- # Check if pytest exists
- if ! [ -x "$(command -v pytest)" ]; then
- echo "Error: pytest not installed." >&2
- exit 1
- fi
- TEST_OPTIONS=()
- if [[ $FVP_NETWORK ]]; then
- TEST_OPTIONS+=(--networkInterface="$FVP_NETWORK")
- fi
- if [[ "$EXAMPLE" == "ota-requestor-app" ]]; then
- TEST_OPTIONS+=(--updateBinaryPath="${EXAMPLE_EXE_PATH/elf/"ota"}")
- # Check if OTA provider exists, if so get the path to it
- OTA_PROVIDER_APP=$(find . -type f -name "chip-ota-provider-app")
- if [ -z "$OTA_PROVIDER_APP" ]; then
- echo "Error: OTA provider application does not exist." >&2
- exit 1
- fi
- TEST_OPTIONS+=(--otaProvider="$OTA_PROVIDER_APP")
- TEST_OPTIONS+=(--softwareVersion="$APP_VERSION:$APP_VERSION_STR")
- fi
- if [[ -f $EXAMPLE_TEST_PATH/test_report_$EXAMPLE.json ]]; then
- rm -rf "$EXAMPLE_TEST_PATH/test_report_$EXAMPLE".json
- fi
- set +e
- pytest --log-level=INFO --json-report --json-report-summary --json-report-file="$EXAMPLE_TEST_PATH"/test_report_"$EXAMPLE".json --binaryPath="$EXAMPLE_EXE_PATH" --fvp="$FVP_BIN" --fvpConfig="$FVP_CONFIG_FILE" "${TEST_OPTIONS[@]}" "$EXAMPLE_TEST_PATH"/test_app.py
- set -e
- if [[ ! -f $EXAMPLE_TEST_PATH/test_report_$EXAMPLE.json ]]; then
- exit 1
- else
- if [[ $(jq '.summary | has("failed")' $EXAMPLE_TEST_PATH/test_report_$EXAMPLE.json) == true ]]; then
- FAILED_TESTS=$((FAILED_TESTS + $(jq '.summary.failed' "$EXAMPLE_TEST_PATH"/test_report_"$EXAMPLE".json)))
- fi
- fi
- }
- SHORT=C:,p:,d:,l:,b:,n:,k:,K:,v:,V:,c,s,h
- LONG=command:,path:,debug:,lwipdebug:,backend:,network:,kvsstore:,kvsfile:,version:,versionStr:,clean,scratch,help,no-activate
- OPTS=$(getopt -n build --options "$SHORT" --longoptions "$LONG" -- "$@")
- eval set -- "$OPTS"
- while :; do
- case "$1" in
- -h | --help)
- show_usage
- exit 0
- ;;
- -c | --clean)
- CLEAN=1
- shift
- ;;
- -s | --scratch)
- SCRATCH=1
- shift
- ;;
- -C | --command)
- COMMAND=$2
- shift 2
- ;;
- -d | --debug)
- DEBUG=$2
- shift 2
- ;;
- -l | --lwipdebug)
- LWIP_DEBUG=$2
- shift 2
- ;;
- -K | --kvsfile)
- KVS_STORAGE_FILE=$2
- shift 2
- ;;
- -b | --backend)
- CRYPTO_BACKEND=$2
- shift 2
- ;;
- -p | --path)
- BUILD_PATH=$CHIP_ROOT/$2
- shift 2
- ;;
- -n | --network)
- FVP_NETWORK=$2
- shift 2
- ;;
- --no-activate)
- NO_ACTIVATE='YES'
- shift
- ;;
- -v | --version)
- APP_VERSION=$2
- shift 2
- ;;
- -V | --versionStr)
- APP_VERSION_STR=$2
- shift 2
- ;;
- -* | --*)
- shift
- break
- ;;
- *)
- echo "Unexpected option: $1"
- show_usage
- exit 2
- ;;
- esac
- done
- if [[ $# -lt 1 ]]; then
- show_usage >&2
- exit 1
- fi
- EXAMPLE=$1
- if [[ ! " ${SUPPORTED_APP_NAMES[@]} " =~ " ${EXAMPLE} " ]]; then
- echo "Wrong example name"
- show_usage
- exit 2
- fi
- case "$COMMAND" in
- build | run | test | build-run) ;;
- *)
- echo "Wrong command definition"
- show_usage
- exit 2
- ;;
- esac
- if [[ "$EXAMPLE" == "unit-tests" ]]; then
- if [ ! -z "$2" ]; then
- if [[ " ${TEST_NAMES[*]} " =~ " $2 " ]]; then
- EXAMPLE=$2
- echo "Use specific unit test $EXAMPLE"
- elif [[ "$2" == "all" ]]; then
- echo "Use all unit tests"
- else
- echo " Wrong unit test name"
- show_usage
- exit 2
- fi
- else
- echo "Use all unit tests"
- fi
- EXAMPLE_PATH="$CHIP_ROOT/src/test_driver/openiotsdk/unit-tests"
- IS_UNIT_TEST=1
- else
- EXAMPLE_PATH="$CHIP_ROOT/examples/$EXAMPLE/openiotsdk"
- fi
- case "$CRYPTO_BACKEND" in
- psa | mbedtls) ;;
- *)
- echo "Wrong crypto type definition"
- show_usage
- exit 2
- ;;
- esac
- TOOLCHAIN_PATH="toolchains/toolchain-$TOOLCHAIN.cmake"
- if [ -z "$BUILD_PATH" ]; then
- BUILD_PATH="$EXAMPLE_PATH/build"
- fi
- if [ -z "$NO_ACTIVATE" ]; then
- # Activate Matter environment
- source "$CHIP_ROOT"/scripts/activate.sh
- fi
- if [[ $IS_UNIT_TEST -eq 0 ]]; then
- EXAMPLE_EXE_PATH="$BUILD_PATH/chip-openiotsdk-$EXAMPLE-example.elf"
- EXAMPLE_TEST_PATH+="/$EXAMPLE"
- else
- EXAMPLE_EXE_PATH="$BUILD_PATH/$EXAMPLE.elf"
- EXAMPLE_TEST_PATH+="/unit-tests"
- fi
- if [[ "$COMMAND" == *"build"* ]]; then
- build_with_cmake
- fi
- if [[ "$COMMAND" == *"run"* ]]; then
- if [[ "$EXAMPLE" == "unit-tests" ]]; then
- echo "You have to specify the test suites to run"
- show_usage
- exit 2
- else
- run_fvp
- fi
- fi
- if [[ "$COMMAND" == *"test"* ]]; then
- if [[ "$EXAMPLE" == "unit-tests" ]]; then
- for NAME in "${TEST_NAMES[@]}"; do
- EXAMPLE=$NAME
- EXAMPLE_EXE_PATH="$BUILD_PATH/$EXAMPLE.elf"
- echo "Test specific unit test $EXAMPLE"
- run_test
- done
- else
- run_test
- fi
- echo "Failed tests total: $FAILED_TESTS"
- exit "$FAILED_TESTS"
- fi
|