#!/bin/bash
elapsed=0
cd ../../
PQCP_ROOT_DIR=`pwd`
paramList=$@
paramNum=$#
is_concurrent=1
need_run_all=1
if [[ "$(uname)" == "Darwin" ]]; then
threadsNum=$(sysctl -n hw.ncpu)
else
threadsNum=$(grep -c ^processor /proc/cpuinfo)
fi
testsuite_array=()
testcase_array=()
LIB_PATHS="$(realpath ${PQCP_ROOT_DIR}/build)"
if [[ "$(uname)" == "Darwin" ]]; then
if [ -n "${DYLD_LIBRARY_PATH}" ]; then
LIB_PATHS="${LIB_PATHS}:${DYLD_LIBRARY_PATH}"
fi
export DYLD_LIBRARY_PATH="${LIB_PATHS}"
export LD_LIBRARY_PATH="${LIB_PATHS}"
echo "[INFO] Final DYLD_LIBRARY_PATH: ${DYLD_LIBRARY_PATH}"
else
if [ -n "${LD_LIBRARY_PATH}" ]; then
LIB_PATHS="${LIB_PATHS}:${LD_LIBRARY_PATH}"
fi
export LD_LIBRARY_PATH="${LIB_PATHS}"
echo "[INFO] Final LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}"
fi
generate_asan_log() {
ASAN_LOG=$(find ../output -name "asan.log*")
if [ ! -z "$ASAN_LOG" ]; then
for i in $ASAN_LOG
do
if grep -q "ASan doesn't fully support makecontext/swapcontext" $i
then
line_count=$(wc -l < "$i")
if [ "$line_count" -eq 1 ]; then
echo "The ASAN log contains only ucontext warning content. Ignore it."
else
echo "ASAN ERROR. Exit with ucontext check failure."
cat ${i}
exit 1
fi
continue
else
echo "ASAN ERROR. Exit with failure."
cat ${i}
exit 1
fi
done
fi
}
run_test() {
cd ${PQCP_ROOT_DIR}/testcode/output
export ASAN_OPTIONS=detect_stack_use_after_return=1:strict_string_checks=1:detect_leaks=1:halt_on_error=0:detect_odr_violation=0:log_path=asan.log
echo ""
echo "Begin Test"
echo ".................................................."
start_time=$(date +%s)
if [ ${#testsuite_array[*]} -ne 0 ] && [ ${#testcase_array[*]} -eq 0 ];then
for i in ${testsuite_array[@]}
do
if [ "${i}" = "test_suite_sdv_eal_provider_load" ]; then
echo "Running ${i} with LD_LIBRARY_PATH set to ../testdata/provider/path1"
env LD_LIBRARY_PATH="../testdata/provider/path1:${LD_LIBRARY_PATH}" ./${i} NO_DETAIL
else
./${i} NO_DETAIL
fi
done
fi
if [ ${#testcase_array[*]} -ne 0 ];then
num=0
for i in ${testcase_array[@]}
do
./${testsuite_array[num]} ${i}
let num+=1
done
fi
end_time=$(date +%s)
elapsed=$((end_time - start_time))
generate_asan_log
}
gen_test_report()
{
cd ${PQCP_ROOT_DIR}/testcode/output
./gen_testcase GenReport
testcase_num=0
pass_num=0
skip_num=0
while read line
do
array=(${line})
last_index=$((${#array[@]}-1))
if [ "${array[last_index]}" = "PASS" ]; then
let pass_num+=1
elif [ "${array[last_index]}" = "SKIP" ]; then
let skip_num+=1
fi
let testcase_num+=1
done < result.log
fail_num=`expr $testcase_num - $pass_num - $skip_num`
SumTime=`echo "$elapsed 60" |awk '{printf("%.2f",$1/$2)}'`
echo "SumTime is ${SumTime} mintues TestCase Num is ${testcase_num} Pass is ${pass_num} Skip is ${skip_num} Fail is ${fail_num}"
if [ ${fail_num} -ne 0 ]; then
exit 1
fi
}
run_all() {
start_time=$(date +%s)
echo "Test: $1" >> ${PQCP_ROOT_DIR}/testcode/output/time.txt
echo "Start: $(date)" >> ${PQCP_ROOT_DIR}/testcode/output/time.txt
cd ${PQCP_ROOT_DIR}/testcode/output
SUITES=$(ls ./ | grep .datax | sed -e "s/.datax//")
export ASAN_OPTIONS=detect_stack_use_after_return=1:strict_string_checks=1:detect_leaks=1:halt_on_error=0:detect_odr_violation=0:log_path=asan.log
echo ""
echo "Begin Test"
echo ".................................................."
if [ $is_concurrent = 1 ]; then
mkfifo tmppipe
exec 5<>tmppipe
rm -f tmppipe
echo "threadsNum = $threadsNum"
for ((i=1;i<=$threadsNum;i++)); do
echo >&5
done
retPipe=$tmpPipe.ret
mkfifo $retPipe
exec 8<>$retPipe
rm -f $retPipe
echo "0" >&8
for i in $SUITES
do
read -u5
{
if [ "${i}" = "test_suite_sdv_eal_provider_load" ]; then
echo "Running ${i} with LD_LIBRARY_PATH set to ../testdata/provider/path1"
env LD_LIBRARY_PATH="../testdata/provider/path1:${LD_LIBRARY_PATH}" ./${i} NO_DETAIL || (read -u8 && echo "1 $i" >&8)
else
./${i} NO_DETAIL || (read -u8 && echo "1 $i" >&8)
fi
echo >&5
} &
done
wait
exec 5>&-
exec 5<&-
read -u8 ret
exec 8<&-
if [ "$ret" != "0" ];then
echo "some case failed $ret"
gen_test_report
generate_asan_log
exit 1
fi
else
for i in $SUITES
do
if [ "${i}" = "test_suite_sdv_eal_provider_load" ]; then
echo "Running ${i} with LD_LIBRARY_PATH set to ../testdata/provider/path1"
env LD_LIBRARY_PATH="../testdata/provider/path1:${LD_LIBRARY_PATH}" ./${i} NO_DETAIL
else
./${i} NO_DETAIL
fi
done
fi
end_time=$(date +%s)
echo "End: $(date)" >> time.txt
elapsed=$((end_time - start_time))
if [[ "$(uname)" == "Darwin" ]]; then
days=$((elapsed/86400)); hours=$(( (elapsed%86400)/3600 )); minutes=$(( (elapsed%3600)/60 )); seconds=$((elapsed%60))
echo "Elapsed time: $days days $(printf "%02d" $hours) hr $(printf "%02d" $minutes) min $(printf "%02d" $seconds) sec" >> time.txt
else
eval "echo Elapsed time: $(date -ud "@$elapsed" +'$((%s/3600/24)) days %H hr %M min %S sec') >> time.txt"
fi
generate_asan_log
}
parse_testsuite_testcase()
{
cd ${PQCP_ROOT_DIR}/testcode/output
testsuite_name="test_suite"
if [[ "$1" == *$testsuite_name* ]]; then
if [ -f "$1" ]; then
testsuite_array[${#testsuite_array[*]}]=$i
return 1
fi
return 0
else
testsuite=`grep -l $1 *.c`
if [ "${testsuite}" = "" ]; then
return 0
else
array=(${testsuite//./ })
testsuite_array[${#testcase_array[*]}]="${array[0]}"
testcase_array[${#testcase_array[*]}]="$1"
return 1
fi
fi
}
parse_option()
{
for i in $paramList
do
case "$i" in
"help")
printf "Note: Before Run <sh ${BASH_SOURCE[0]}>, Please Fisrt Run <sh build_hitls.sh && sh build_sdv.sh>"
printf "%-50s %-30s\n" "Run All Testsuites Of The Output" "sh ${BASH_SOURCE[0]}"
printf "%-50s %-30s\n" "Run The Specified Testsuite" "sh ${BASH_SOURCE[0]} test_suites_xxx test_suites_xxx"
printf "%-50s %-30s\n" "Run The Specified Testcase" "sh ${BASH_SOURCE[0]} UT_CRYPTO_xxx SDV_CRYPTO_xxx"
printf "%-50s %-30s\n" "Set Thread Pool Size" "sh ${BASH_SOURCE[0]} threads=N"
printf "%-50s %-30s\n" "Example: Run with 4 threads" "sh ${BASH_SOURCE[0]} threads=4"
exit 0
;;
"threads"*)
threads_num=${i#*=}
threadsNum=$threads_num
;;
*)
parse_testsuite_testcase $i
if [ $? -eq 0 ]; then
echo "Not Find This Testsuite or Testcase : ${i}"
exit 1
fi
need_run_all=0
;;
esac
done
}
clean()
{
rm -rf ${PQCP_ROOT_DIR}/testcode/output/log/*
rm -rf ${PQCP_ROOT_DIR}/testcode/output/result.log
rm -rf ${PQCP_ROOT_DIR}/testcode/output/*.sock*
rm -rf ${PQCP_ROOT_DIR}/testcode/output/asan*
}
clean
parse_option
if [ ${need_run_all} -eq 1 ]; then
run_all
else
run_test
fi
gen_test_report