2018-10-18 20:23:12 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Copyright 2018 Oticon A/S
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
# Syntax run_parallel.sh [-h] [options]
|
|
|
|
|
|
|
|
set -u
|
|
|
|
|
2019-11-23 04:15:11 +08:00
|
|
|
start=$SECONDS
|
2018-10-18 20:23:12 +08:00
|
|
|
|
|
|
|
function display_help(){
|
|
|
|
echo "run_parallel.sh [-help] [options]"
|
|
|
|
echo " Execute all cases which do not start with an _ (underscore)"
|
|
|
|
echo " [options] will be passed directly to the scripts"
|
|
|
|
echo " The results will be saved to \${RESULTS_FILE}, by deault"
|
|
|
|
echo " ../RunResults.xml"
|
|
|
|
echo " Testcases are searched for in \${SEARCH_PATH}, by default this folder"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Parse command line
|
|
|
|
if [ $# -ge 1 ]; then
|
|
|
|
if grep -Eiq "(\?|-\?|-h|help|-help|--help)" <<< $1 ; then
|
|
|
|
display_help
|
2019-11-23 04:22:20 +08:00
|
|
|
exit 0
|
2018-10-18 20:23:12 +08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
err=0
|
|
|
|
i=0
|
|
|
|
|
|
|
|
SEARCH_PATH="${SEARCH_PATH:-`pwd`}"
|
|
|
|
|
|
|
|
#All the testcases we want to run:
|
2019-11-23 04:15:11 +08:00
|
|
|
all_cases=`find ${SEARCH_PATH} -name "*.sh" | \
|
2018-10-18 20:23:12 +08:00
|
|
|
grep -Ev "(/_|run_parallel|compile.sh)"`
|
|
|
|
#we dont run ourselves
|
|
|
|
|
|
|
|
RESULTS_FILE="${RESULTS_FILE:-`pwd`/../RunResults.xml}"
|
2019-11-23 04:15:11 +08:00
|
|
|
tmp_res_file=tmp.xml
|
2018-10-18 20:23:12 +08:00
|
|
|
|
2019-11-23 04:15:11 +08:00
|
|
|
all_cases_a=( $all_cases )
|
|
|
|
n_cases=$((${#all_cases_a[@]}))
|
2018-10-18 20:23:12 +08:00
|
|
|
touch ${RESULTS_FILE}
|
2019-11-23 04:15:11 +08:00
|
|
|
echo "Attempting to run ${n_cases} cases (logging to \
|
2018-10-18 20:23:12 +08:00
|
|
|
`realpath ${RESULTS_FILE}`)"
|
|
|
|
|
2019-11-23 04:15:11 +08:00
|
|
|
chmod +x $all_cases
|
2018-10-18 20:23:12 +08:00
|
|
|
|
2018-12-06 17:45:01 +08:00
|
|
|
export CLEAN_XML="sed -E -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g' \
|
|
|
|
-e 's/\"/"/g'"
|
|
|
|
|
2019-11-23 04:15:11 +08:00
|
|
|
echo -n "" > $tmp_res_file
|
2018-10-18 20:23:12 +08:00
|
|
|
|
|
|
|
if [ `command -v parallel` ]; then
|
|
|
|
parallel '
|
2019-11-23 04:22:20 +08:00
|
|
|
echo "<testcase name=\"{}\" time=\"0\">"
|
|
|
|
{} $@ &> {#}.log
|
2018-10-18 20:23:12 +08:00
|
|
|
if [ $? -ne 0 ]; then
|
2019-11-23 04:22:20 +08:00
|
|
|
(>&2 echo -e "\e[91m{} FAILED\e[39m")
|
|
|
|
(>&2 cat {#}.log)
|
|
|
|
echo "<failure message=\"failed\" type=\"failure\">"
|
|
|
|
cat {#}.log | eval $CLEAN_XML
|
|
|
|
echo "</failure>"
|
|
|
|
rm {#}.log
|
|
|
|
echo "</testcase>"
|
|
|
|
exit 1
|
2018-10-18 20:23:12 +08:00
|
|
|
else
|
2019-11-23 04:22:20 +08:00
|
|
|
(>&2 echo -e "{} PASSED")
|
|
|
|
rm {#}.log
|
|
|
|
echo "</testcase>"
|
|
|
|
fi
|
2019-11-23 04:15:11 +08:00
|
|
|
' ::: $all_cases >> $tmp_res_file ; err=$?
|
2018-10-18 20:23:12 +08:00
|
|
|
else #fallback in case parallel is not installed
|
2019-11-23 04:15:11 +08:00
|
|
|
for case in $all_cases; do
|
|
|
|
echo "<testcase name=\"$case\" time=\"0\">" >> $tmp_res_file
|
|
|
|
$case $@ &> $i.log
|
2018-10-18 20:23:12 +08:00
|
|
|
if [ $? -ne 0 ]; then
|
2019-11-23 04:15:11 +08:00
|
|
|
echo -e "\e[91m$case FAILED\e[39m"
|
2018-10-18 20:23:12 +08:00
|
|
|
cat $i.log
|
2019-11-23 04:15:11 +08:00
|
|
|
echo "<failure message=\"failed\" type=\"failure\">" >> $tmp_res_file
|
|
|
|
cat $i.log | eval $CLEAN_XML >> $tmp_res_file
|
|
|
|
echo "</failure>" >> $tmp_res_file
|
2018-10-18 20:23:12 +08:00
|
|
|
let "err++"
|
|
|
|
else
|
2019-11-23 04:15:11 +08:00
|
|
|
echo -e "$case PASSED"
|
2019-11-23 04:22:20 +08:00
|
|
|
fi
|
2019-11-23 04:15:11 +08:00
|
|
|
echo "</testcase>" >> $tmp_res_file
|
2018-10-18 20:23:12 +08:00
|
|
|
rm $i.log
|
|
|
|
let i=i+1
|
|
|
|
done
|
|
|
|
fi
|
2019-11-23 04:15:11 +08:00
|
|
|
echo -e "</testsuite>\n</testsuites>\n" >> $tmp_res_file
|
|
|
|
dur=$(($SECONDS - $start))
|
2018-10-18 20:23:12 +08:00
|
|
|
echo -e "<testsuites>\n<testsuite errors=\"0\" failures=\"$err\"\
|
2019-11-23 04:15:11 +08:00
|
|
|
name=\"bsim_bt tests\" skip=\"0\" tests=\"$n_cases\" time=\"$dur\">" \
|
|
|
|
| cat - $tmp_res_file > $RESULTS_FILE
|
|
|
|
rm $tmp_res_file
|
2018-10-18 20:23:12 +08:00
|
|
|
|
|
|
|
exit $err
|