1#!/usr/bin/env bash 2# Copyright 2018 Oticon A/S 3# SPDX-License-Identifier: Apache-2.0 4 5# Compile with all permutations of a given set of KConfigs 6# Specifically for going through possible combinations of 7# optional control procedures 8 9#set -x #uncomment this line for debugging 10# set DEBUG_PERMUTATE to 'true' for extra debug output 11DEBUG_PERMUTATE=false 12 13: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}" 14: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}" 15: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\ 16 directory}" 17 18WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_out}" 19BOARD="${BOARD:-nrf52_bsim}" 20BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}" 21 22mkdir -p ${WORK_DIR} 23 24source ${ZEPHYR_BASE}/tests/bsim/compile.source 25 26 27declare -a list=( 28"CONFIG_BT_CENTRAL=" 29"CONFIG_BT_PERIPHERAL=" 30"CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG=" 31"CONFIG_BT_DATA_LEN_UPDATE=" 32"CONFIG_BT_PHY_UPDATE=" 33"CONFIG_BT_CTLR_MIN_USED_CHAN=" 34"CONFIG_BT_CTLR_LE_PING=" 35"CONFIG_BT_CTLR_LE_ENC=" 36"CONFIG_BT_CTLR_CONN_PARAM_REQ=" 37) 38 39perm_compile() { 40 local -a results=() 41 # We set a unique exe-name, so that we don't overwrite the executables 42 # created by the compile scripts since that may mess up other tests 43 # We also delete the executable to avoid having artifacts from 44 # a previous run 45 local exe_name="bs_nrf52_bsim_tests_kconfig_perm" 46 local executable_name=${exe_name} 47 local executable_name=${BSIM_OUT_PATH}/bin/$executable_name 48 49 rm -f ${executable_name} 50 51 let idx=$2 52 for (( j = 0; j < $1; j++ )); do 53 if (( idx % 2 )); then 54 results=("${results[@]}" "${list[$j]}n") 55 else 56 results=("${results[@]}" "${list[$j]}y") 57 fi 58 let idx\>\>=1 59 done 60 printf '%s\n' "${results[@]}" > $3 61 if test "$DEBUG_PERMUTATE" = "true"; then 62 echo "Compile with config overlay:" 63 cat $3 64 fi 65 local app=tests/bsim/bluetooth/ll/edtt/hci_test_app 66 local conf_file=prj_dut_llcp.conf 67 local conf_overlay=$3 68# Note: we need to call '_compile' instead of 'compile' because the latter starts 69# compilations in parallel, but here we need to do it in serial since we modify 70# the configuration file between each run 71 _compile 72 if [ ! -f ${executable_name} ]; then 73 compile_failures=$(expr $compile_failures + 1) 74 fi 75} 76let n=${#list[@]} 77temp_conf_file=$(mktemp -p ${WORK_DIR}) 78# compile_failures will be equal to the number of failed compilations 79let compile_failures=0 80 81for (( i = 0; i < 2**n; i++ )); do 82 ## don't compile for CENTRAL=n AND PERIPHERAL=n 83 if (( (i & 0x3) != 0x3 )); then 84 perm_compile $n $i ${temp_conf_file} 85 fi 86done 87 88# We set exit code based on type of failure 89# 0 means all configurations compiled w/o error 90 91trap "{ rm "${temp_conf_file}" ; exit 255; }" SIGINT 92trap "{ rm "${temp_conf_file}" ; exit 254; }" SIGTERM 93trap "{ rm "${temp_conf_file}" ; exit 253; }" ERR 94trap "{ rm "${temp_conf_file}" ; exit ${compile_failures}; }" EXIT 95