loolwsd/Log.cpp             |   56 ++++++++++++++++++++-----
 loolwsd/Log.hpp             |    5 ++
 loolwsd/Util.cpp            |   39 ++++--------------
 loolwsd/configure.ac        |    1 
 loolwsd/test/Makefile.am    |   15 ++----
 loolwsd/test/run_test.sh.in |   50 -----------------------
 loolwsd/test/run_unit.sh.in |   95 ++++++++++++++++++++++++++++++++------------
 7 files changed, 133 insertions(+), 128 deletions(-)

New commits:
commit 448e25f6d81f2c143878a3e6eb269d44049af389
Author: Michael Meeks <michael.me...@collabora.com>
Date:   Fri Apr 15 20:46:44 2016 +0100

    Make logging signal safe again. snprintf: simpler, safer, faster.

diff --git a/loolwsd/Log.cpp b/loolwsd/Log.cpp
index 48fe800..fb85a48 100644
--- a/loolwsd/Log.cpp
+++ b/loolwsd/Log.cpp
@@ -41,7 +41,27 @@ namespace Log
     };
     static StaticNames Source;
 
-    std::string prefix()
+    // We need a signal safe means of writing messages
+    //   $ man 7 signal
+    void signalLog(const char *message)
+    {
+        while (true) {
+            int length = strlen(message);
+            int written = write (STDERR_FILENO, message, length);
+            if (written < 0)
+            {
+                if (errno == EINTR)
+                    continue; // ignore.
+                else
+                    break;
+            }
+            message += written;
+            if (message[0] == '\0')
+                break;
+        }
+    }
+
+    static void getPrefix(char *buffer)
     {
         Poco::Int64 usec = Poco::Timestamp().epochMicroseconds() - epochStart;
 
@@ -53,19 +73,31 @@ namespace Log
         const Poco::Int64 seconds = usec / (one_s);
         usec %= (one_s);
 
-        std::ostringstream stream;
-        stream << (Source.inited ? Source.id : std::string())
-               << '-' << std::setw(2) << std::setfill('0')
-               << (Poco::Thread::current() ? Poco::Thread::current()->id() : 
0) << ' '
-               << std::setw(2) << hours << ':' << std::setw(2) << minutes << 
':'
-               << std::setw(2) << seconds << "." << std::setw(6) << usec
-               << ' ';
+        char procName[32]; // we really need only 16
+        if (!prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(procName), 0, 
0, 0) == 0)
+            strcpy(procName, "<noid>");
+
+        const char *appName = (Source.inited ? Source.id.c_str() : 
"<shutdown>");
+        assert(strlen(appName) + 32 + 28 < 1024 - 1);
 
-        char buf[32]; // we really need only 16
-        if (prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(buf), 0, 0, 0) 
== 0)
-            stream << '[' << std::setw(15) << std::setfill(' ') << std::left 
<< buf << "] ";
+        snprintf(buffer, 4095, "%s-%.2d %.2d:%.2d:%.2d.%.6d [ %s ] ", appName,
+                 (Poco::Thread::current() ? Poco::Thread::current()->id() : 0),
+                 (int)hours, (int)minutes, (int)seconds, (int)usec,
+                 procName);
+    }
+
+    std::string prefix()
+    {
+        char buffer[1024];
+        getPrefix(buffer);
+        return std::string(buffer);
+    }
 
-        return stream.str();
+    void signalLogPrefix()
+    {
+        char buffer[1024];
+        getPrefix(buffer);
+        signalLog(buffer);
     }
 
     void initialize(const std::string& name)
diff --git a/loolwsd/Log.hpp b/loolwsd/Log.hpp
index b64f766..cc43baa 100644
--- a/loolwsd/Log.hpp
+++ b/loolwsd/Log.hpp
@@ -29,6 +29,11 @@ namespace Log
     void error(const std::string& msg);
     void syserror(const std::string& msg);
 
+    /// Signal safe prefix logging
+    void signalLogPrefix();
+    /// Signal safe logging
+    void signalLog(const char *message);
+
     /// The following is to write streaming logs.
     /// Log::info() << "Value: 0x" << std::hex << value
     ///             << ", pointer: " << this << Log::end;
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index 8952179..d30b31a 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -253,27 +253,6 @@ namespace Util
         }
     }
 
-    // We need a signal safe means of writing messages
-    //   $ man 7 signal
-    static
-    void log_signal(const char *message)
-    {
-        while (true) {
-            int length = strlen(message);
-            int written = write (STDERR_FILENO, message, length);
-            if (written < 0)
-            {
-                if (errno == EINTR)
-                    continue; // ignore.
-                else
-                    break;
-            }
-            message += written;
-            if (message[0] == '\0')
-                break;
-        }
-    }
-
     static
     void handleTerminationSignal(const int signal)
     {
@@ -281,10 +260,10 @@ namespace Util
         {
             TerminationFlag = true;
 
-            log_signal(Log::prefix().c_str());
-            log_signal(" Termination signal received: ");
-            log_signal(signalName(signal));
-            log_signal("\n");
+            Log::signalLogPrefix();
+            Log::signalLog(" Termination signal received: ");
+            Log::signalLog(signalName(signal));
+            Log::signalLog("\n");
         }
     }
 
@@ -307,14 +286,14 @@ namespace Util
     static
     void handleFatalSignal(const int signal)
     {
-        log_signal(Log::prefix().c_str());
-        log_signal(" Fatal signal received: ");
-        log_signal(signalName(signal));
-        log_signal("\n");
+        Log::signalLogPrefix();
+        Log::signalLog(" Fatal signal received: ");
+        Log::signalLog(signalName(signal));
+        Log::signalLog("\n");
 
         if (std::getenv("LOOL_DEBUG"))
         {
-            log_signal(FatalGdbString);
+            Log::signalLog(FatalGdbString);
             sleep(30);
         }
 
commit 65ee749ce1c90612d04d4aea44318cb53e713031
Author: Michael Meeks <michael.me...@collabora.com>
Date:   Fri Apr 15 16:39:05 2016 +0100

    Move new unit tests to custom test driver.
    
    Cleaner, and avoids bogus warnings during compile.
    Merge run_test.sh.in into a mode of run_unit.sh - gives the
    chance for nice debug output etc.

diff --git a/loolwsd/configure.ac b/loolwsd/configure.ac
index 48b2539..0083081 100644
--- a/loolwsd/configure.ac
+++ b/loolwsd/configure.ac
@@ -249,7 +249,6 @@ AC_CONFIG_FILES([Makefile
                  loolwsd.spec
                  loolwsd.xml])
 AC_CONFIG_FILES([test/run_unit.sh],[chmod +x test/run_unit.sh])
-AC_CONFIG_FILES([test/run_test.sh],[chmod +x test/run_test.sh])
 
 AC_OUTPUT
 
diff --git a/loolwsd/test/Makefile.am b/loolwsd/test/Makefile.am
index d44e787..721ec0c 100644
--- a/loolwsd/test/Makefile.am
+++ b/loolwsd/test/Makefile.am
@@ -28,19 +28,14 @@ else
 SYSTEM_STAMP =
 endif
 
-${top_builddir}/test/run_unit.sh.log ${top_builddir}/test/run_unit.sh.trs : \
-       $(SYSTEM_STAMP) @JAILS_PATH@ \
-       ${top_srcdir}/test/run_unit.sh \
-       ${top_builddir}/loolwsd ${top_builddir}/loolforkit \
-       $(wildcard *.la)
-       if ${top_srcdir}/test/run_unit.sh; then \
-          touch ${top_builddir}/test/run_unit.sh.log; \
-       fi
-
 if HAVE_LO_PATH
-TESTS = ${top_srcdir}/test/run_unit.sh ${top_srcdir}/test/run_test.sh
+TESTS = unit-timeout.la unit-fonts.la unit-storage.la unit-prefork.la 
run_test.sh
 else
 TESTS = ${top_builddir}/test/test
 endif
 
+TEST_EXTENSIONS = .la .sh
+LA_LOG_DRIVER = ${top_srcdir}/test/run_unit.sh
+SH_LOG_DRIVER = ${top_srcdir}/test/run_unit.sh
+
 EXTRA_DIST = data/hello.odt data/hello.txt $(test_SOURCES) run_unit.sh
diff --git a/loolwsd/test/run_test.sh.in b/loolwsd/test/run_test.sh.in
deleted file mode 100755
index f7895c7..0000000
--- a/loolwsd/test/run_test.sh.in
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/bin/sh
-#
-# DO NOT EDIT - this file is generated from run_test.sh.in.
-#
-
-abs_top_builddir="@abs_top_builddir@"
-test_build="${abs_top_builddir}/test"
-test_output="$test_build/run_test.sh.trs"
-test_log_output="$test_build/test_output"
-
-mkdir -p $test_log_output
-
-if test "z@ENABLE_DEBUG@" != "ztrue"; then
-    echo ""
-    echo "It is necessary to configure with --enable-debug for unit tests to 
pass"
-    echo ""
-    echo ":test-result: FAIL $tst" > $test_output
-    exit 1;
-fi
-
-echo "Running cppunit test ...";
-
-# result logging
-echo > $test_output
-
-${abs_top_builddir}/loolwsd --systemplate="@SYSTEMPLATE_PATH@" 
--lotemplate="@LO_PATH@" \
-           --childroot="@JAILS_PATH@" --allowlocalstorage 
2>$test_log_output/run_test.log &
-
-echo "  waiting for loolwsd to start"
-sleep 1 # sad - need to add a wait to the start of test.cpp ...
-
-echo "  executing test"
-
-cd $test_build
-if ./test; then
-       echo "Test run_test.sh passed."
-       echo ":test-result: PASS run_test.sh" >> $test_output
-       retval=0
-else
-       cat $test_log_output/run_test.log
-        echo "============================================================="
-       echo "Test failed on unit:"
-        echo "============================================================="
-       echo ":test-result: FAIL run_test.sh" >> $test_output
-       retval=1
-fi
-
-kill $!
-
-exit $retval
diff --git a/loolwsd/test/run_unit.sh.in b/loolwsd/test/run_unit.sh.in
index 5491640..7a929e7 100755
--- a/loolwsd/test/run_unit.sh.in
+++ b/loolwsd/test/run_unit.sh.in
@@ -3,16 +3,34 @@
 # DO NOT EDIT - this file is generated from run_unit.sh.in.
 #
 
-export LOOL_LOGLEVEL=trace
+# substituted variables in one place:
+abs_top_builddir="/opt/libreoffice/online/loolwsd"
+systemplate_path="@SYSTEMPLATE_PATH@"
+enable_debug="@ENABLE_DEBUG@"
+jails_path="@JAILS_PATH@"
+lo_path="@LO_PATH@"
 
-abs_top_builddir="@abs_top_builddir@"
-test_build="${abs_top_builddir}/test"
-test_output="$test_build/run_unit.sh.trs"
-test_log_output="$test_build/test_output"
+while test $# -gt 0; do
+  case $1 in
+      --test-name) tst=$2; shift;;
+      --log-file)  tst_log=$2; shift;;
+      --trs-file)  test_output=$2; shift;;
+  -*) ;; # ignore
+  esac
+  shift
+done
+
+test_mode=
+if test "z$tst" != "zrun_test.sh"; then
+    # drop .la suffix
+    tst=`echo $tst | sed s/\.la//`;
+else
+    test_mode=old
+fi
 
-mkdir -p $test_log_output
+# export LOOL_LOGLEVEL=trace
 
-if test "z@ENABLE_DEBUG@" != "ztrue"; then
+if test "z$enable_debug" != "ztrue"; then
     echo ""
     echo "It is necessary to configure with --enable-debug for unit tests to 
pass"
     echo ""
@@ -21,25 +39,52 @@ if test "z@ENABLE_DEBUG@" != "ztrue"; then
 fi
 
 # result logging
-echo > run_unit.sh.trs
-
-for tst in fonts timeout storage prefork; do
-    tst_log="test_output/$tst.log"
-    echo "Running test: $tst | $tst_log ...";
-    if ${abs_top_builddir}/loolwsd --systemplate="@SYSTEMPLATE_PATH@" \
-                                   --lotemplate="@LO_PATH@" \
-                                   --childroot="@JAILS_PATH@" \
-                                   --unitlib=".libs/unit-$tst.so" 2> 
"$tst_log"; then
-       echo "Test $tst passed."
-       echo ":test-result: PASS $tst" >> $test_output
+echo > $test_output
+
+if test "z$test_mode" == "zold"; then
+     echo "executing external tests"
+     ${abs_top_builddir}/loolwsd --systemplate="$systemplate_path" \
+                                 --lotemplate="$lo_path" \
+                                 --childroot="$jails_path" \
+                                 --allowlocalstorage  2> "$tst_log" &
+
+     echo "  waiting for loolwsd to start"
+     sleep 1 # sad - need to add a wait to the start of test.cpp ...
+     echo "  executing test"
+
+     oldpath=`pwd`
+     cd "${abs_top_builddir}/test"
+     if ./test; then
+        echo "Test run_test.sh passed."
+        echo ":test-result: PASS run_test.sh" >> $oldpath/$test_output
+        retval=0
+     else
+         echo "============================================================="
+        echo "Test failed on unit:"
+         echo "============================================================="
+        echo ":test-result: FAIL run_test.sh" >> $oldpath/$test_output
+        retval=1
+     fi
+
+     kill $!
+
+     exit $retval
+
+else # newer unit tests.
+    echo "Running $tst | $tst_log ...";
+    if ${abs_top_builddir}/loolwsd --systemplate="$systemplate_path" \
+                                   --lotemplate="$lo_path" \
+                                   --childroot="$jails_path" \
+                                   --unitlib=".libs/$tst.so" 2> "$tst_log"; 
then
+        echo "Test $tst passed."
+        echo ":test-result: PASS $tst" >> $test_output
     else
-       cat "$tst_log"
-        echo "============================================================="
-       echo "Test failed on unit: $tst re-run with:"
-       echo "   $ gdb --args ../loolwsd --systemplate=\"@SYSTEMPLATE_PATH@\" 
--lotemplate=\"@LO_PATH@\" \\"
-       echo "         --childroot=\"@JAILS_PATH@\" 
--unitlib=\".libs/unit-$tst.so\""
+        cat "$tst_log"
         echo "============================================================="
+        echo "Test failed on unit: $tst re-run with:"
+       echo "   $ gdb --args ../loolwsd --systemplate=\"$systemplate_path\" 
--lotemplate=\"$lo_path\" \\"
+       echo "         --childroot=\"$jails_path\" --unitlib=\".libs/$tst.so\""
+       echo "============================================================="
        echo ":test-result: FAIL $tst" >> $test_output
     fi
-done
-
+fi
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to