From 65826087cf1c98c277e23efdf5ed071550344762 Mon Sep 17 00:00:00 2001 From: HowJMay Date: Tue, 7 Jul 2020 19:27:19 +0800 Subject: [PATCH] refactor: Format shell scripts Using 'shfmt' to format shell scripts See: https://github.com/mvdan/sh for more information --- README.md | 9 ++ endpoint/build-legato.sh | 32 +++--- endpoint/unit-test/driver.sh | 67 ++++++------ hooks/autohook.sh | 148 ++++++++++++-------------- hooks/ci_format_check | 18 ++-- hooks/formatter | 14 +-- hooks/scripts/format_check | 18 ++-- hooks/scripts/function_check | 17 ++- tests/coverity_analysis.sh | 1 - tests/endpoint/common.sh | 45 ++++---- tests/endpoint/test-WP77.sh | 11 +- tests/regression/common.sh | 94 ++++++++-------- tests/regression/router-sanitizer.sh | 65 ++++++----- tests/regression/run-api-with-mqtt.sh | 69 ++++++------ tests/regression/run-api.sh | 74 ++++++------- 15 files changed, 331 insertions(+), 351 deletions(-) diff --git a/README.md b/README.md index f0702b75..a14317e5 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ The codebase of this repository follows [Google's C++ guidelines](https://google * buildifier * clang-format +* [shfmt](https://github.com/mvdan/sh) ### Buildifier @@ -171,6 +172,14 @@ clang-format can be installed by command: * Debian/Ubuntu based systems: `$ sudo apt-get install clang-format` * macOS: `$ brew install clang-format` +### shfmt + +It requires Go 1.13 or above, and install it with following command. + +```shell +GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt +``` + ## Usage `Tangle-accelerator` currently supports two categories of APIs diff --git a/endpoint/build-legato.sh b/endpoint/build-legato.sh index 0bd13d57..da57d857 100755 --- a/endpoint/build-legato.sh +++ b/endpoint/build-legato.sh @@ -4,25 +4,21 @@ set -uo pipefail COMMON_FILE="tests/endpoint/common.sh" -if [ ! -f "$COMMON_FILE" ] -then - echo "$COMMON_FILE is not exists." - echo "Always execute this script in top-level directory." - exit 1 +if [ ! -f "$COMMON_FILE" ]; then + echo "$COMMON_FILE is not exists." + echo "Always execute this script in top-level directory." + exit 1 fi source $COMMON_FILE -if [ ! -d "legato" ] -then - if ! download_legato_repo; - then - echo "Download Legato AF failed. Try to download again..." - rm -rf legato/ .repo/ - if ! download_legato_repo; - then - echo "Failed to download the Legato AF. Please check your connection" - exit 1 - fi - fi - build_legato_repo +if [ ! -d "legato" ]; then + if ! download_legato_repo; then + echo "Download Legato AF failed. Try to download again..." + rm -rf legato/ .repo/ + if ! download_legato_repo; then + echo "Failed to download the Legato AF. Please check your connection" + exit 1 + fi + fi + build_legato_repo fi diff --git a/endpoint/unit-test/driver.sh b/endpoint/unit-test/driver.sh index cb4f3334..d719d05f 100755 --- a/endpoint/unit-test/driver.sh +++ b/endpoint/unit-test/driver.sh @@ -6,55 +6,52 @@ GREEN='\033[0;32m' NC='\033[0m' # No Color EP_TEST_CONFIG=(asan tsan ubsan) -function cleanup(){ - kill -9 "${TA}" +function cleanup() { + kill -9 "${TA}" } -function success(){ - cleanup - echo -e "${GREEN}ALL test passed${NC}" - exit 0 +function success() { + cleanup + echo -e "${GREEN}ALL test passed${NC}" + exit 0 } -function failed(){ - cleanup - echo -e "${RED}Unit-test: ${TEST_CASE} not passed${NC}" - exit 1 +function failed() { + cleanup + echo -e "${RED}Unit-test: ${TEST_CASE} not passed${NC}" + exit 1 } -function run_test_suite(){ - bazel test -c dbg --config "$1" //endpoint/unit-test/... - ret=$? - if [[ ret -ne 0 ]] - then - TEST_CASE="$1" - failed - fi +function run_test_suite() { + bazel test -c dbg --config "$1" //endpoint/unit-test/... + ret=$? + if [[ ret -ne 0 ]]; then + TEST_CASE="$1" + failed + fi } -function start_ta(){ - # Create tangle-accelerator for unit-test - bazel run accelerator & - TA=$! - # Wait until tangle-accelerator has been initialized - echo "==============Wait for TA starting==============" - while read -r line - do - if [[ "$line" == "TA-START" ]] - then - echo "$line" - fi - done <<< $(nc -U -l $socket | tr '\0' '\n') - echo "==============TA has successfully started==============" +function start_ta() { + # Create tangle-accelerator for unit-test + bazel run accelerator & + TA=$! + # Wait until tangle-accelerator has been initialized + echo "==============Wait for TA starting==============" + while read -r line; do + if [[ "$line" == "TA-START" ]]; then + echo "$line" + fi + done <<<$(nc -U -l $socket | tr '\0' '\n') + echo "==============TA has successfully started==============" } echo "Start unit-test for endpoint" start_ta # Run endpoint unit-test -for i in ${EP_TEST_CONFIG[*]}; do - run_test_suite "$i" +for i in ${EP_TEST_CONFIG[*]}; do + run_test_suite "$i" done -# Finish +# Finish success diff --git a/hooks/autohook.sh b/hooks/autohook.sh index 81614df1..e3a1ee70 100755 --- a/hooks/autohook.sh +++ b/hooks/autohook.sh @@ -5,22 +5,22 @@ # Author: Nik Kantar # Version: 2.1.1 # Website: https://github.com/nkantar/Autohook -# License: MIT - +# License: MIT - # MIT License -# +# # Copyright (c) 2017 Nikola Kantar -# +# # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -29,90 +29,78 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. - echo() { - builtin echo "[Autohook] $@"; + builtin echo "[Autohook] $@" } - install() { - hook_types=( - "applypatch-msg" - "commit-msg" - "post-applypatch" - "post-checkout" - "post-commit" - "post-merge" - "post-receive" - "post-rewrite" - "post-update" - "pre-applypatch" - "pre-auto-gc" - "pre-commit" - "pre-push" - "pre-rebase" - "pre-receive" - "prepare-commit-msg" - "update" - ) + hook_types=( + "applypatch-msg" + "commit-msg" + "post-applypatch" + "post-checkout" + "post-commit" + "post-merge" + "post-receive" + "post-rewrite" + "post-update" + "pre-applypatch" + "pre-auto-gc" + "pre-commit" + "pre-push" + "pre-rebase" + "pre-receive" + "prepare-commit-msg" + "update" + ) - repo_root=$(git rev-parse --show-toplevel) - hooks_dir="$repo_root/.git/hooks" - autohook_filename="$repo_root/hooks/autohook.sh" - autohook_path=$(realpath $autohook_filename) - for hook_type in "${hook_types[@]}" - do - hook_symlink="$hooks_dir/$hook_type" - ln -s $autohook_path $hook_symlink - done + repo_root=$(git rev-parse --show-toplevel) + hooks_dir="$repo_root/.git/hooks" + autohook_filename="$repo_root/hooks/autohook.sh" + autohook_path=$(realpath $autohook_filename) + for hook_type in "${hook_types[@]}"; do + hook_symlink="$hooks_dir/$hook_type" + ln -s $autohook_path $hook_symlink + done } - main() { - calling_file=$(basename $0) + calling_file=$(basename $0) - if [[ $calling_file == "autohook.sh" ]] - then - command=$1 - if [[ $command == "install" ]] - then - install - fi - else - repo_root=$(git rev-parse --show-toplevel) - hook_type=$calling_file - symlinks_dir="$repo_root/hooks/$hook_type" - files=("$symlinks_dir"/*) - number_of_symlinks="${#files[@]}" - tmpfile=$(mktemp) - if [[ $number_of_symlinks == 1 ]] - then - if [[ "$(basename ${files[0]})" == "*" ]] - then - number_of_symlinks=0 - fi - fi - echo "Looking for $hook_type scripts to run...found $number_of_symlinks!" - if [[ $number_of_symlinks -gt 0 ]] - then - for file in "${files[@]}" - do - scriptname=$(basename $file) - echo "BEGIN $scriptname" - eval $file > $tmpfile - ret=$? - if [[ $ret -ne 0 ]] - then - cat $tmpfile - rm $tmpfile - exit $ret - fi - echo "FINISH $scriptname" - done - fi - rm $tmpfile - fi + if [[ $calling_file == "autohook.sh" ]]; then + command=$1 + if [[ $command == "install" ]]; then + install + fi + else + repo_root=$(git rev-parse --show-toplevel) + hook_type=$calling_file + symlinks_dir="$repo_root/hooks/$hook_type" + files=("$symlinks_dir"/*) + number_of_symlinks="${#files[@]}" + tmpfile=$(mktemp) + if [[ $number_of_symlinks == 1 ]]; then + if [[ "$(basename ${files[0]})" == "*" ]]; then + number_of_symlinks=0 + fi + fi + echo "Looking for $hook_type scripts to run...found $number_of_symlinks!" + if [[ $number_of_symlinks -gt 0 ]]; then + for file in "${files[@]}"; do + scriptname=$(basename $file) + echo "BEGIN $scriptname" + eval $file >$tmpfile + ret=$? + if [[ $ret -ne 0 ]]; then + cat $tmpfile + rm $tmpfile + exit $ret + fi + echo "FINISH $scriptname" + done + fi + rm $tmpfile + fi } - main "$@" diff --git a/hooks/ci_format_check b/hooks/ci_format_check index 0fe8a121..30113133 100755 --- a/hooks/ci_format_check +++ b/hooks/ci_format_check @@ -2,15 +2,13 @@ root=$(git rev-parse --show-toplevel) status=0 -for file in $(find "${@}" -type f | grep -E "\.(c|cc|cpp|h|hh|hpp)\$" | grep -Ev "/third_party/") -do - filepath="$root/$file" - output=$(diff <(cat $filepath) <(clang-format -style=file -fallback-style=none $filepath)) - if [ $? -ne 0 ] - then - echo -e "\nFile \e[31m\""$file"\"\e[39m is not compliant with the coding style" - echo "$output" - status=1 - fi +for file in $(find "${@}" -type f | grep -E "\.(c|cc|cpp|h|hh|hpp)\$" | grep -Ev "/third_party/"); do + filepath="$root/$file" + output=$(diff <(cat $filepath) <(clang-format -style=file -fallback-style=none $filepath)) + if [ $? -ne 0 ]; then + echo -e "\nFile \e[31m\""$file"\"\e[39m is not compliant with the coding style" + echo "$output" + status=1 + fi done exit $status diff --git a/hooks/formatter b/hooks/formatter index 7c464e25..5ca24033 100755 --- a/hooks/formatter +++ b/hooks/formatter @@ -1,12 +1,14 @@ #!/bin/bash -for file in $(find $(git rev-parse --show-toplevel) | egrep "\.(c|cc|cpp|h|hh|hpp|m|mm)\$" | egrep -v -f hooks/format-exclude-list) -do - clang-format -style=file -fallback-style=none -i $file +for file in $(find $(git rev-parse --show-toplevel) | egrep "\.(c|cc|cpp|h|hh|hpp|m|mm)\$" | egrep -v "third_party|output_base"); do + clang-format -style=file -fallback-style=none -i $file done -for file in $(find $(git rev-parse --show-toplevel) | egrep "\BUILD\$" | egrep -v -f hooks/format-exclude-list ) -do - buildifier $file +for file in $(find $(git rev-parse --show-toplevel) | egrep "\BUILD\$" | egrep -v "third_party|output_base"); do + buildifier $file done buildifier WORKSPACE + +for file in $(find $(git rev-parse --show-toplevel) | egrep "\.sh\$" | egrep -v "third_party|output_base"); do + shfmt -w $file +done \ No newline at end of file diff --git a/hooks/scripts/format_check b/hooks/scripts/format_check index 7390692e..c55f47f1 100755 --- a/hooks/scripts/format_check +++ b/hooks/scripts/format_check @@ -2,15 +2,13 @@ root=$(git rev-parse --show-toplevel) status=0 -for file in $(git diff --staged --name-only | grep -E "\.(c|cc|cpp|h|hh|hpp)\$") -do - filepath="$root/$file" - output=$(diff <(cat $filepath) <(clang-format -style=file -fallback-style=none $filepath)) - if [ $? -ne 0 ] - then - echo -e "\nFile \""$file"\" is not compliant with the coding style" - echo "$output" - status=1 - fi +for file in $(git diff --staged --name-only | grep -E "\.(c|cc|cpp|h|hh|hpp)\$"); do + filepath="$root/$file" + output=$(diff <(cat $filepath) <(clang-format -style=file -fallback-style=none $filepath)) + if [ $? -ne 0 ]; then + echo -e "\nFile \""$file"\" is not compliant with the coding style" + echo "$output" + status=1 + fi done exit $status diff --git a/hooks/scripts/function_check b/hooks/scripts/function_check index a3e24b9c..2f143762 100755 --- a/hooks/scripts/function_check +++ b/hooks/scripts/function_check @@ -3,14 +3,13 @@ root=$(git rev-parse --show-toplevel) banned="([^f]gets\()|(sprintf\()|(strcpy\()" status=0 -for file in $(git diff --staged --name-only | grep -E "\.(c|cc|cpp|h|hh|hpp)\$") -do - filepath="${root}/${file}" - output=$(grep -nrE "${banned}" "${filepath}") - if [ ! -z "${output}" ]; then - echo "Dangerous function detected in ${filepath}" - echo "${output}" - status=1 - fi +for file in $(git diff --staged --name-only | grep -E "\.(c|cc|cpp|h|hh|hpp)\$"); do + filepath="${root}/${file}" + output=$(grep -nrE "${banned}" "${filepath}") + if [ ! -z "${output}" ]; then + echo "Dangerous function detected in ${filepath}" + echo "${output}" + status=1 + fi done exit $status diff --git a/tests/coverity_analysis.sh b/tests/coverity_analysis.sh index 1d469895..50cc128b 100644 --- a/tests/coverity_analysis.sh +++ b/tests/coverity_analysis.sh @@ -8,7 +8,6 @@ make bazel build --define db=enable //accelerator make clean - make MQTT bazel build --define mqtt=enable //accelerator make clean diff --git a/tests/endpoint/common.sh b/tests/endpoint/common.sh index 73261019..29925668 100644 --- a/tests/endpoint/common.sh +++ b/tests/endpoint/common.sh @@ -1,32 +1,31 @@ LEGATO_VERSION="20.04.0" -function download_legato_repo(){ - echo "Downloading Legato AF" - repo init -u git://github.com/legatoproject/manifest -m legato/releases/${LEGATO_VERSION}.xml - repo sync +function download_legato_repo() { + echo "Downloading Legato AF" + repo init -u git://github.com/legatoproject/manifest -m legato/releases/${LEGATO_VERSION}.xml + repo sync } -function build_legato_repo(){ - if [ ! -d "legato" ]; then - echo "Please download the Legato AF first" - exit 1 - fi +function build_legato_repo() { + if [ ! -d "legato" ]; then + echo "Please download the Legato AF first" + exit 1 + fi - if [ ! -f "legato/Makefile" ]; then - echo "The Makefile inside legato project is missing" - echo "Please remove the legato directory and download Legato AF again." - exit 1 - fi + if [ ! -f "legato/Makefile" ]; then + echo "The Makefile inside legato project is missing" + echo "Please remove the legato directory and download Legato AF again." + exit 1 + fi - echo "Building Legato AF" - make -C legato localhost + echo "Building Legato AF" + make -C legato localhost } -function setup_leaf(){ - if ! which "leaf" - then - echo "Please install Legato leaf first" - exit 1 - fi - leaf --non-interactive setup legato-latest -p "$1" +function setup_leaf() { + if ! which "leaf"; then + echo "Please install Legato leaf first" + exit 1 + fi + leaf --non-interactive setup legato-latest -p "$1" } diff --git a/tests/endpoint/test-WP77.sh b/tests/endpoint/test-WP77.sh index e8438c76..8145e6af 100755 --- a/tests/endpoint/test-WP77.sh +++ b/tests/endpoint/test-WP77.sh @@ -4,15 +4,14 @@ set -uo pipefail COMMON_FILE="tests/endpoint/common.sh" -if [ ! -f "$COMMON_FILE" ] -then - echo "$COMMON_FILE is not exists." - exit 1 +if [ ! -f "$COMMON_FILE" ]; then + echo "$COMMON_FILE is not exists." + exit 1 fi source $COMMON_FILE # setup WP77 leaf shell setup_leaf "swi-wp77_3.4.0" -make TESTS=true EP_TARGET=wp77xx EP_TA_HOST=node.deviceproof.org EP_TA_PORT=5566 legato && \ -tar zcf endpoint.tgz endpoint/_build_endpoint/wp77xx/app/endpoint/staging/read-only/ +make TESTS=true EP_TARGET=wp77xx EP_TA_HOST=node.deviceproof.org EP_TA_PORT=5566 legato && + tar zcf endpoint.tgz endpoint/_build_endpoint/wp77xx/app/endpoint/staging/read-only/ diff --git a/tests/regression/common.sh b/tests/regression/common.sh index 42fc0d1e..1046412e 100644 --- a/tests/regression/common.sh +++ b/tests/regression/common.sh @@ -1,67 +1,67 @@ # Build options setup_build_opts() { - # The options are separated by '|', the format is as follows - # | - OPTIONS=( - "|" - "|--node_host ${NODE_HOST}" - "|--node_port ${NODE_PORT}" - "|--ta_host ${TA_HOST}" - "|--db_host ${DB_HOST}" - "|--quiet" - "|--proxy_passthrough" - "--define db=enable|" - "--define build_type=debug|" - "--define build_type=profile|" - ) - success=() - fail=() + # The options are separated by '|', the format is as follows + # | + OPTIONS=( + "|" + "|--node_host ${NODE_HOST}" + "|--node_port ${NODE_PORT}" + "|--ta_host ${TA_HOST}" + "|--db_host ${DB_HOST}" + "|--quiet" + "|--proxy_passthrough" + "--define db=enable|" + "--define build_type=debug|" + "--define build_type=profile|" + ) + success=() + fail=() } # Set sanitizer options setup_sanitizer_opts() { - SAN_OPTIONS=( - "--config=asan" - "--config=tsan" - "--config=ubsan" - ) - success=() - fail=() + SAN_OPTIONS=( + "--config=asan" + "--config=tsan" + "--config=ubsan" + ) + success=() + fail=() } # Check environment variables check_env() { - ENV_NAME=( - "NODE_HOST" - "NODE_PORT" - "TA_HOST" - "TA_PORT" - "DB_HOST" - ) + ENV_NAME=( + "NODE_HOST" + "NODE_PORT" + "TA_HOST" + "TA_PORT" + "DB_HOST" + ) - echo "Checking environment variables" - echo "==============================" + echo "Checking environment variables" + echo "==============================" - for (( i = 0; i < ${#ENV_NAME[@]}; i++ )); do - name=${ENV_NAME[${i}]} - if [[ -z ${!name} ]]; then - echo "${name} not set" - fail=1 - else - echo "${name} is set to ${!name}" - fi - done + for ((i = 0; i < ${#ENV_NAME[@]}; i++)); do + name=${ENV_NAME[${i}]} + if [[ -z ${!name} ]]; then + echo "${name} not set" + fail=1 + else + echo "${name} is set to ${!name}" + fi + done - echo "==============================" + echo "==============================" - [ -z ${fail} ] || exit 1 + [ -z ${fail} ] || exit 1 } # Parse command line arguments -get_cli_args () { - socket=$1 - shift - remaining_args=$@ # Get the remaining arguments +get_cli_args() { + socket=$1 + shift + remaining_args=$@ # Get the remaining arguments } start_notification="TA-START" diff --git a/tests/regression/router-sanitizer.sh b/tests/regression/router-sanitizer.sh index 4d451422..68b1a2aa 100644 --- a/tests/regression/router-sanitizer.sh +++ b/tests/regression/router-sanitizer.sh @@ -17,44 +17,41 @@ pip3 install --user -r tests/regression/requirements.txt redis-server & # Iterate over all available build options -for (( i = 0; i < ${#SAN_OPTIONS[@]}; i++ )); do - option=${SAN_OPTIONS[${i}]} - - bazel run accelerator ${option} -c dbg -- --ta_port=${TA_PORT} & - TA=$! - trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA - - # Wait until tangle-accelerator has been initialized - echo "==============Wait for TA starting==============" - while read -r line - do - if [[ "$line" == "$start_notification" ]] - then - echo "$line" - fi - done <<< $(nc -U -l $socket | tr '\0' '\n') - echo "==============TA has successfully started==============" - - python3 tests/regression/runner.py ${remaining_args} --url localhost:${TA_PORT} - rc=$? - - if [ $rc -ne 0 ] - then - echo "Build sanitizer '${option}' failed" - fail+=("${option}") - else - success+=("${option}") - fi - - bazel clean - wait $(kill -9 ${TA}) +for ((i = 0; i < ${#SAN_OPTIONS[@]}; i++)); do + option=${SAN_OPTIONS[${i}]} + + bazel run accelerator ${option} -c dbg -- --ta_port=${TA_PORT} & + TA=$! + trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA + + # Wait until tangle-accelerator has been initialized + echo "==============Wait for TA starting==============" + while read -r line; do + if [[ "$line" == "$start_notification" ]]; then + echo "$line" + fi + done <<<$(nc -U -l $socket | tr '\0' '\n') + echo "==============TA has successfully started==============" + + python3 tests/regression/runner.py ${remaining_args} --url localhost:${TA_PORT} + rc=$? + + if [ $rc -ne 0 ]; then + echo "Build sanitizer '${option}' failed" + fail+=("${option}") + else + success+=("${option}") + fi + + bazel clean + wait $(kill -9 ${TA}) done echo "--------- Successful build options ---------" -for (( i = 0; i < ${#success[@]}; i++ )); do echo ${success[${i}]}; done +for ((i = 0; i < ${#success[@]}; i++)); do echo ${success[${i}]}; done echo "----------- Failed build options -----------" -for (( i = 0; i < ${#fail[@]}; i++ )); do echo ${fail[${i}]}; done +for ((i = 0; i < ${#fail[@]}; i++)); do echo ${fail[${i}]}; done if [ ${#fail[@]} -gt 0 ]; then - exit 1 + exit 1 fi diff --git a/tests/regression/run-api-with-mqtt.sh b/tests/regression/run-api-with-mqtt.sh index 3c1568a6..43977412 100755 --- a/tests/regression/run-api-with-mqtt.sh +++ b/tests/regression/run-api-with-mqtt.sh @@ -17,46 +17,43 @@ pip3 install --user -r tests/regression/requirements.txt redis-server & # Iterate over all available build options -for (( i = 0; i < ${#OPTIONS[@]}; i++ )); do - option=${OPTIONS[${i}]} - cli_arg=${option} | cut -d '|' -f 1 - build_arg=${option} | cut -d '|' -f 2 - - bazel run accelerator --define mqtt=enable ${build_arg} -- --quiet --ta_port=${TA_PORT} ${cli_arg} & - TA=$! - trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA - - # Wait until tangle-accelerator has been initialized - echo "==============Wait for TA starting==============" - while read -r line - do - if [[ "$line" == "$start_notification" ]] - then - echo "$line" - fi - done <<< $(nc -U -l $socket | tr '\0' '\n') - echo "==============TA has successfully started==============" - - python3 tests/regression/runner.py ${remaining_args} --url "localhost" --mqtt - rc=$? - - if [ $rc -ne 0 ] - then - echo "Build option '${option}' failed" - fail+=("${option}") - else - success+=("${option}") - fi - - bazel clean - wait $(kill -9 ${TA}) +for ((i = 0; i < ${#OPTIONS[@]}; i++)); do + option=${OPTIONS[${i}]} + cli_arg=${option} | cut -d '|' -f 1 + build_arg=${option} | cut -d '|' -f 2 + + bazel run accelerator --define mqtt=enable ${build_arg} -- --quiet --ta_port=${TA_PORT} ${cli_arg} & + TA=$! + trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA + + # Wait until tangle-accelerator has been initialized + echo "==============Wait for TA starting==============" + while read -r line; do + if [[ "$line" == "$start_notification" ]]; then + echo "$line" + fi + done <<<$(nc -U -l $socket | tr '\0' '\n') + echo "==============TA has successfully started==============" + + python3 tests/regression/runner.py ${remaining_args} --url "localhost" --mqtt + rc=$? + + if [ $rc -ne 0 ]; then + echo "Build option '${option}' failed" + fail+=("${option}") + else + success+=("${option}") + fi + + bazel clean + wait $(kill -9 ${TA}) done echo "--------- Successful build options ---------" -for (( i = 0; i < ${#success[@]}; i++ )); do echo ${success[${i}]}; done +for ((i = 0; i < ${#success[@]}; i++)); do echo ${success[${i}]}; done echo "----------- Failed build options -----------" -for (( i = 0; i < ${#fail[@]}; i++ )); do echo ${fail[${i}]}; done +for ((i = 0; i < ${#fail[@]}; i++)); do echo ${fail[${i}]}; done if [ ${#fail[@]} -gt 0 ]; then - exit 1 + exit 1 fi diff --git a/tests/regression/run-api.sh b/tests/regression/run-api.sh index 7f050c2e..73d02943 100755 --- a/tests/regression/run-api.sh +++ b/tests/regression/run-api.sh @@ -17,46 +17,48 @@ pip3 install --user -r tests/regression/requirements.txt redis-server & # Iterate over all available build options -for (( i = 0; i < ${#OPTIONS[@]}; i++ )); do - option=${OPTIONS[${i}]} - cli_arg=$(echo ${option} | cut -d '|' -f 2) - build_arg=$(echo ${option} | cut -d '|' -f 1) - - bazel run accelerator ${build_arg} -- --ta_port=${TA_PORT} ${cli_arg} & - TA=$! - trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA - - # Wait until tangle-accelerator has been initialized - echo "==============Wait for TA starting==============" - while read -r line - do - if [[ "$line" == "$start_notification" ]] - then - echo "$line" - fi - done <<< $(nc -U -l $socket | tr '\0' '\n') - echo "==============TA has successfully started==============" - - python3 tests/regression/runner.py ${remaining_args} --url localhost:${TA_PORT} - rc=$? - - if [ $rc -ne 0 ] - then - echo "Build option '${option}' failed" - fail+=("${option}") - else - success+=("${option}") - fi - - bazel clean - wait $(kill -9 ${TA}) +for ((i = 0; i < ${#OPTIONS[@]}; i++)); do + option=${OPTIONS[${i}]} + cli_arg=$(echo ${option} | cut -d '|' -f 2) + build_arg=$(echo ${option} | cut -d '|' -f 1) + + bazel run accelerator ${build_arg} -- --ta_port=${TA_PORT} ${cli_arg} & + TA=$! + trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA + + # Wait until tangle-accelerator has been initialized + echo "==============Wait for TA starting==============" + while read -r line; do + if [[ "$line" == "$start_notification" ]]; then + echo "$line" + fi + done <<<$(nc -U -l $socket | tr '\0' '\n') + echo "==============TA has successfully started==============" + + python3 tests/regression/runner.py ${remaining_args} --url localhost:${TA_PORT} + rc=$? + + trap "kill -9 ${TA};" INT # Trap SIGINT from Ctrl-C to stop TA + + python3 tests/regression/runner.py ${remaining_args} --url localhost:${TA_PORT} + rc=$? + + if [ $rc -ne 0 ]; then + echo "Build option '${option}' failed" + fail+=("${option}") + else + success+=("${option}") + fi + + bazel clean + wait $(kill -9 ${TA}) done echo "--------- Successful build options ---------" -for (( i = 0; i < ${#success[@]}; i++ )); do echo ${success[${i}]}; done +for ((i = 0; i < ${#success[@]}; i++)); do echo ${success[${i}]}; done echo "----------- Failed build options -----------" -for (( i = 0; i < ${#fail[@]}; i++ )); do echo ${fail[${i}]}; done +for ((i = 0; i < ${#fail[@]}; i++)); do echo ${fail[${i}]}; done if [ ${#fail[@]} -gt 0 ]; then - exit 1 + exit 1 fi