diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 21d4ae38ff..3e626c2065 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -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: diff --git a/src/include/test/switch_test.h b/src/include/test/switch_test.h index 3131d0b03d..b320e3fdca 100644 --- a/src/include/test/switch_test.h +++ b/src/include/test/switch_test.h @@ -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); diff --git a/src/switch_utils.c b/src/switch_utils.c index 64ceb39130..1dc0871b19 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -39,6 +39,11 @@ #include #include #endif +#include +#include +#else + /* process.h is required for _getpid() */ +#include #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: diff --git a/tests/unit/run-tests.sh b/tests/unit/run-tests.sh index deda30ffff..bda6a32571 100755 --- a/tests/unit/run-tests.sh +++ b/tests/unit/run-tests.sh @@ -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!" \ No newline at end of file diff --git a/tests/unit/test.sh b/tests/unit/test.sh new file mode 100755 index 0000000000..aebddc8cd2 --- /dev/null +++ b/tests/unit/test.sh @@ -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 "----------------" ;