[Unit-test] Run tests in parallel

This commit is contained in:
Andrey Volk 2020-01-22 16:36:53 +00:00
parent 78c7dd2a37
commit 893a3cdc1f
5 changed files with 82 additions and 39 deletions

View File

@ -1452,6 +1452,8 @@ SWITCH_DECLARE(void) switch_getcputime(switch_cputime *t);
SWITCH_DECLARE(char *)switch_html_strip(const char *str);
SWITCH_DECLARE(unsigned long) switch_getpid();
SWITCH_END_EXTERN_C
#endif
/* For Emacs:

View File

@ -70,6 +70,7 @@ static switch_status_t fst_init_core_and_modload(const char *confdir, const char
{
switch_status_t status;
const char *err;
unsigned long pid = switch_getpid();
// Let FreeSWITCH core pick these
//SWITCH_GLOBAL_dirs.base_dir = strdup("/usr/local/freeswitch");
//SWITCH_GLOBAL_dirs.mod_dir = strdup("/usr/local/freeswitch/mod");
@ -101,12 +102,12 @@ static switch_status_t fst_init_core_and_modload(const char *confdir, const char
SWITCH_GLOBAL_dirs.conf_dir = switch_mprintf("%s%sconf", basedir, SWITCH_PATH_SEPARATOR);
}
SWITCH_GLOBAL_dirs.log_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
SWITCH_GLOBAL_dirs.log_dir = switch_mprintf("%s%s%lu%s", basedir, SWITCH_PATH_SEPARATOR, pid, SWITCH_PATH_SEPARATOR);
SWITCH_GLOBAL_dirs.run_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
SWITCH_GLOBAL_dirs.recordings_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
SWITCH_GLOBAL_dirs.sounds_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
SWITCH_GLOBAL_dirs.cache_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
SWITCH_GLOBAL_dirs.db_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
SWITCH_GLOBAL_dirs.db_dir = switch_mprintf("%s%s%lu%s", basedir, SWITCH_PATH_SEPARATOR, pid, SWITCH_PATH_SEPARATOR);
SWITCH_GLOBAL_dirs.script_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
SWITCH_GLOBAL_dirs.htdocs_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);
SWITCH_GLOBAL_dirs.grammar_dir = switch_mprintf("%s%s", basedir, SWITCH_PATH_SEPARATOR);

View File

@ -39,6 +39,11 @@
#include <sys/time.h>
#include <sys/resource.h>
#endif
#include <sys/types.h>
#include <unistd.h>
#else
/* process.h is required for _getpid() */
#include <process.h>
#endif
#include "private/switch_core_pvt.h"
#define ESCAPE_META '\\'
@ -4529,6 +4534,16 @@ SWITCH_DECLARE(char *)switch_html_strip(const char *str)
return text;
}
SWITCH_DECLARE(unsigned long) switch_getpid()
{
#ifndef WIN32
pid_t pid = getpid();
#else
int pid = _getpid();
#endif
return (unsigned long)pid;
}
/* For Emacs:

View File

@ -1,51 +1,28 @@
#!/bin/bash
# All output will be collected here
TESTSUNITPATH=$PWD
# "print_tests" returns relative paths to all the tests
TESTS=$(make -s -C ../.. print_tests)
# All relative paths are based on the tree's root
FSBASEDIR=$(realpath "$PWD/../../")
echo "-----------------------------------------------------------------";
echo "Starting tests";
echo "Tests found: ${TESTS}";
echo "-----------------------------------------------------------------";
echo "Starting" > pids.txt
for i in $TESTS
do
echo "Testing $i" ;
# Change folder to where the test is
currenttestpath="$FSBASEDIR/$i"
cd $(dirname "$currenttestpath")
# Tests are unique per module, so need to distinguish them by their directory
relativedir=$(dirname "$i")
echo "Relative dir is $relativedir"
file=$(basename -- "$currenttestpath")
log="$TESTSUNITPATH/log_run-tests_${relativedir//\//!}!$file.html";
# Execute the test
$currenttestpath | tee >(ansi2html > $log) ;
exitstatus=${PIPESTATUS[0]} ;
if [ "0" -eq $exitstatus ] ; then
rm $log ;
else
echo "*** ./$i exit status is $exitstatus" ;
corefilesearch=/cores/core.*.!drone!src!${relativedir//\//!}!.libs!$file.* ;
echo $corefilesearch ;
if ls $corefilesearch 1> /dev/null 2>&1; then
echo "coredump found";
coredump=$(ls $corefilesearch) ;
echo $coredump;
echo "set logging file $TESTSUNITPATH/backtrace_${i//\//!}.txt" ;
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" /drone/src/$relativedir/.libs/$file $coredump ;
fi ;
echo "*** $log was saved" ;
fi ;
./test.sh "$i" &
pid=($!)
pids+=($pid)
echo "$pid $i" >> pids.txt
echo "----------------" ;
done
for pid in "${pids[@]}"
do
echo "$pid waiting" >> pids.txt
wait "$pid"
echo "$pid finished" >> pids.txt
done
echo "Done running tests!"

48
tests/unit/test.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
# All output will be collected here
TESTSUNITPATH=$PWD
# All relative paths are based on the tree's root
FSBASEDIR=$(realpath "$PWD/../../")
i=$1
echo "----------------------------------" ;
echo "Starting test: $i" ;
echo "----------------------------------" ;
# Change folder to where the test is
currenttestpath="$FSBASEDIR/$i"
cd $(dirname "$currenttestpath")
# Tests are unique per module, so need to distinguish them by their directory
relativedir=$(dirname "$i")
echo "Relative dir is $relativedir"
file=$(basename -- "$currenttestpath")
log="$TESTSUNITPATH/log_run-tests_${relativedir//\//!}!$file.html";
# Execute the test
echo "Start executing $currenttestpath"
$currenttestpath | tee >(ansi2html > $log) ;
exitstatus=${PIPESTATUS[0]} ;
echo "End executing $currenttestpath"
echo "Exit status is $exitstatus"
if [ "0" -eq $exitstatus ] ; then
rm $log ;
else
echo "*** ./$i exit status is $exitstatus" ;
corefilesearch=/cores/core.*.!drone!src!${relativedir//\//!}!.libs!$file.* ;
echo $corefilesearch ;
if ls $corefilesearch 1> /dev/null 2>&1; then
echo "coredump found";
coredump=$(ls $corefilesearch) ;
echo $coredump;
echo "set logging file $TESTSUNITPATH/backtrace_${i//\//!}.txt" ;
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" /drone/src/$relativedir/.libs/$file $coredump ;
fi ;
echo "*** $log was saved" ;
fi ;
echo "----------------" ;