freeswitch/tests/unit/test.sh

90 lines
2.1 KiB
Bash
Raw Permalink Normal View History

2024-12-02 01:16:21 +00:00
#!/usr/bin/env bash
2020-01-22 16:36:53 +00:00
2024-12-02 01:16:21 +00:00
### shfmt -w -s -ci -sr -kp -fn tests/unit/run-tests.sh
#------------------------------------------------------------------------------
# Test Execution Script
# Executes unit tests and handles test logs and core dumps
#------------------------------------------------------------------------------
# Initialize timing
2024-07-25 17:47:30 +00:00
start_time=$(date +%s)
2020-01-22 16:36:53 +00:00
# All output will be collected here
TESTSUNITPATH=$PWD
# All relative paths are based on the tree's root
FSBASEDIR=$(realpath "$PWD/../../")
2024-12-02 01:16:21 +00:00
# Set system limits
2024-07-25 17:47:30 +00:00
ulimit -c unlimited
ulimit -a
2024-12-02 01:16:21 +00:00
# Get test identifier from argument
2020-01-22 16:36:53 +00:00
i=$1
2024-12-02 01:16:21 +00:00
echo ""
echo "Starting test: $i"
echo ""
2020-01-22 16:36:53 +00:00
# Change folder to where the test is
currenttestpath="$FSBASEDIR/$i"
2024-12-02 01:16:21 +00:00
cd "$(dirname "$currenttestpath")"
2020-01-22 16:36:53 +00:00
# Tests are unique per module, so need to distinguish them by their directory
relativedir=$(dirname "$i")
echo "Relative dir is $relativedir"
2024-12-02 01:16:21 +00:00
# Set up log file path
2020-01-22 16:36:53 +00:00
file=$(basename -- "$currenttestpath")
2024-12-02 01:16:21 +00:00
log="$TESTSUNITPATH/log_run-tests_${relativedir//\//!}!$file.html"
2020-01-22 16:36:53 +00:00
# Execute the test
echo "Start executing $currenttestpath"
2024-12-02 01:16:21 +00:00
$currenttestpath 2>&1 | tee >(ansi2html > "$log")
exitstatus=${PIPESTATUS[0]}
2020-01-22 16:36:53 +00:00
echo "End executing $currenttestpath"
2024-12-02 01:16:21 +00:00
# Record execution time
2024-07-25 17:47:30 +00:00
end_time=$(date +%s)
duration=$((end_time - start_time))
echo "Test $1 took $duration seconds" >> test_times.log
2020-01-22 16:36:53 +00:00
echo "Exit status is $exitstatus"
2024-12-02 01:16:21 +00:00
# Handle test results
if [ "0" -eq "$exitstatus" ]; then
rm "$log"
2020-01-22 16:36:53 +00:00
else
2024-12-02 01:16:21 +00:00
echo "*** ./$i exit status is $exitstatus"
# Search for core dumps
corefilesearch="/cores/core.*.!__w!freeswitch!freeswitch!${relativedir//\//!}!.libs!$file.*"
echo "$corefilesearch"
2020-01-22 16:36:53 +00:00
if ls $corefilesearch 1> /dev/null 2>&1; then
2024-12-02 01:16:21 +00:00
echo "coredump found"
coredump=$(ls $corefilesearch)
echo "$coredump"
# Generate backtrace using GDB
gdb \
-ex "set logging file $TESTSUNITPATH/backtrace_${i//\//!}.txt" \
-ex "set logging on" \
-ex "set pagination off" \
-ex "bt full" \
-ex "bt" \
-ex "info threads" \
-ex "thread apply all bt" \
-ex "thread apply all bt full" \
-ex "quit" \
"$FSBASEDIR/$relativedir/.libs/$file" \
"$coredump"
fi
echo "*** $log was saved"
exit $exitstatus
fi
echo ""