#!/bin/bash # # Copyright (c) 2018, The OpenThread Authors. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. Neither the name of the copyright holder nor the # names of its contributors may be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # Description: # This file runs various tests of OpenThread. # set -euo pipefail readonly OT_BUILDDIR="$(pwd)/build" readonly OT_SRCDIR="$(pwd)" readonly COLOR_PASS='\033[0;32m' readonly COLOR_FAIL='\033[0;31m' readonly COLOR_NONE='\033[0m' readonly NODE_MODE="${NODE_MODE:-standalone}" readonly NODE_TYPE="${NODE_TYPE:-sim}" readonly OT_NATIVE_IP="${OT_NATIVE_IP:-0}" readonly THREAD_VERSION="${THREAD_VERSION:-1.1}" readonly VERBOSE="${VERBOSE:-0}" readonly VIRTUAL_TIME="${VIRTUAL_TIME:-1}" build_simulation() { local version="$1" local options=("-DOT_THREAD_VERSION=${version}") if [[ ${version} == "1.2" ]]; then options+=("-DOT_DUA=ON") fi if [[ ${VIRTUAL_TIME} == 1 ]]; then options+=("-DOT_SIMULATION_VIRTUAL_TIME=ON") if [[ ${NODE_MODE} == "rcp" ]]; then options+=("-DOT_SIMULATION_VIRTUAL_TIME_UART=ON") fi fi if [[ ${version} == "1.2" ]]; then options+=("-DOT_CSL_RECEIVER=ON") fi OT_CMAKE_BUILD_DIR="${OT_BUILDDIR}/cmake/openthread-simulation-${version}" "${OT_SRCDIR}"/script/cmake-build simulation "${options[@]}" "${ot_extra_options[@]}" if [[ ${version} == "1.2" ]]; then options+=("-DOT_BACKBONE_ROUTER=ON") OT_CMAKE_BUILD_DIR="${OT_BUILDDIR}/cmake/openthread-simulation-${version}-bbr" "${OT_SRCDIR}"/script/cmake-build simulation "${options[@]}" "${ot_extra_options[@]}" fi } build_posix() { local version="$1" local options=("-DOT_THREAD_VERSION=${version}") if [[ ${version} == "1.2" ]]; then options+=("-DOT_DUA=ON") fi if [[ ${VIRTUAL_TIME} == 1 ]]; then options+=("-DOT_POSIX_VIRTUAL_TIME=ON") fi if [[ ${OT_NATIVE_IP} == 1 ]]; then options+=("-DOT_PLATFORM_UDP=ON" "-DOT_PLATFORM_NETIF=ON") fi OT_CMAKE_BUILD_DIR="${OT_BUILDDIR}/cmake/openthread-posix-${version}" "${OT_SRCDIR}"/script/cmake-build posix "${options[@]}" "${ot_extra_options[@]}" if [[ ${version} == "1.2" ]]; then options+=("-DOT_BACKBONE_ROUTER=ON") OT_CMAKE_BUILD_DIR="${OT_BUILDDIR}/cmake/openthread-posix-${version}-bbr" "${OT_SRCDIR}"/script/cmake-build posix "${options[@]}" "${ot_extra_options[@]}" fi } do_build() { build_simulation "${THREAD_VERSION}" if [[ ${NODE_MODE} == "rcp" ]]; then build_posix "${THREAD_VERSION}" fi # Extra 1.1 build for 1.2 tests if [[ ${THREAD_VERSION} == "1.2" ]]; then build_simulation 1.1 if [[ ${NODE_MODE} == "rcp" ]]; then build_posix 1.1 fi fi } do_clean() { rm -rfv "${OT_BUILDDIR}" || sudo rm -rfv "${OT_BUILDDIR}" } do_unit() { local builddir="${OT_BUILDDIR}/cmake/openthread-simulation-${THREAD_VERSION}" if [[ ! -d ${builddir} ]]; then echo "Cannot find build directory!" exit 1 fi cd "${builddir}" ninja test } do_cert() { export top_builddir="${OT_BUILDDIR}/cmake/openthread-simulation-${THREAD_VERSION}" if [[ ${THREAD_VERSION} == "1.2" ]]; then export top_builddir_1_1="${OT_BUILDDIR}/cmake/openthread-simulation-1.1" export top_builddir_1_2_bbr="${OT_BUILDDIR}/cmake/openthread-simulation-1.2-bbr" fi [[ ! -d tmp ]] || rm -rvf tmp PYTHONUNBUFFERED=1 "$1" } do_cert_suite() { export top_builddir="${OT_BUILDDIR}/cmake/openthread-simulation-${THREAD_VERSION}" if [[ ${THREAD_VERSION} == "1.2" ]]; then export top_builddir_1_1="${OT_BUILDDIR}/cmake/openthread-simulation-1.1" export top_builddir_1_2_bbr="${OT_BUILDDIR}/cmake/openthread-simulation-1.2-bbr" fi local pass_count=0 local fail_count=0 [[ ! -f fail.log ]] || rm fail.log for test_case in "$@"; do rm -rf tmp || sudo rm -rf tmp if "${test_case}" &>test.log; then echo -e "${COLOR_PASS}PASS${COLOR_NONE} ${test_case}" pass_count=$((pass_count + 1)) else echo -e "${COLOR_FAIL}FAIL${COLOR_NONE} ${test_case}" fail_count=$((fail_count + 1)) { echo "==============================" echo "!!! FAIL:${test_case}" echo "==============================" cat test.log } >>fail.log fi done echo "==================================" echo " Test Summary" echo "==================================" echo "# TOTAL: $((pass_count + fail_count))" echo "# PASS: ${pass_count}" echo "# FAIL: ${fail_count}" if [[ ${fail_count} -gt 0 ]]; then tr -dc '[:print:]\r\n\t'