]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[Unit-test] Run tests in parallel 258/head
authorAndrey Volk <andywolk@gmail.com>
Wed, 22 Jan 2020 16:36:53 +0000 (16:36 +0000)
committerAndrey Volk <andywolk@gmail.com>
Wed, 22 Jan 2020 22:29:57 +0000 (02:29 +0400)
src/include/switch_utils.h
src/include/test/switch_test.h
src/switch_utils.c
tests/unit/run-tests.sh
tests/unit/test.sh [new file with mode: 0755]

index 21d4ae38ff8eca57ad2727d463d8dd02e5efbaf9..3e626c2065d5bdaf8fcac7fc8055439b3c9d0f22 100644 (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:
index 3131d0b03ddb25a8c903cf177b3f772378f16a8a..b320e3fdca240d7f7549b982e00e2a9da4705704 100644 (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);
index 64ceb391306a1c9aa951fabe3ae348ea87887898..1dc0871b19350562c24a11e69fd4c66afb18b557 100644 (file)
 #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:
index deda30fffffbe3b4abe166a024895819ce6edfc2..bda6a3257151cd5a543f681367b61c70250df4fa 100755 (executable)
@@ -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 (executable)
index 0000000..aebddc8
--- /dev/null
@@ -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 "----------------" ;