[Libreoffice-commits] online.git: loolwsd/LOOLForKit.cpp loolwsd/LOOLKit.cpp loolwsd/test loolwsd/Unit.hpp

Michael Meeks michael.meeks at collabora.com
Sat Apr 9 17:29:42 UTC 2016


 loolwsd/LOOLForKit.cpp       |    4 ++++
 loolwsd/LOOLKit.cpp          |    6 +++++-
 loolwsd/Unit.hpp             |   18 ++++++++++++++++--
 loolwsd/test/UnitPrefork.cpp |   14 ++++++++++++++
 4 files changed, 39 insertions(+), 3 deletions(-)

New commits:
commit 5b8f49423ddb14bfda5ca0590e9579918d006cc0
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Sat Apr 9 18:26:33 2016 +0100

    More kit unit testing tentacles.

diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp
index 5529bc7..66f313c 100644
--- a/loolwsd/LOOLForKit.cpp
+++ b/loolwsd/LOOLForKit.cpp
@@ -94,6 +94,8 @@ static int createLibreOfficeKit(const std::string& childRoot,
         // (but pipeFd is a pipe, not a socket...?)
         close(pipeFd);
 
+        UnitKit::get().postFork();
+
         // child
         if (std::getenv("SLEEPKITFORDEBUGGER"))
         {
@@ -238,6 +240,8 @@ int main(int argc, char** argv)
 
     while (!TerminationFlag)
     {
+        UnitKit::get().invokeForKitTest();
+
         if (!childDispatcher.pollAndDispatch())
         {
             Log::info("Child dispatcher flagged for termination.");
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 4591300..52083d4 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -47,6 +47,7 @@
 #include "LOKitHelper.hpp"
 #include "LOOLProtocol.hpp"
 #include "QueueHandler.hpp"
+#include "Unit.hpp"
 #include "Util.hpp"
 
 #define LIB_SOFFICEAPP  "lib" "sofficeapp" ".so"
@@ -1020,7 +1021,10 @@ void lokit_main(const std::string& childRoot,
         const std::string socketName = "ChildControllerWS";
         IoUtil::SocketProcessor(ws, response, [&socketName, &ws, &document, &loKit](const std::vector<char>& data)
                 {
-                    const std::string message(data.data(), data.size());
+                    std::string message(data.data(), data.size());
+
+                    UnitKit::get().kitMessage(message);
+
                     Log::debug(socketName + ": recv [" + message + "].");
                     StringTokenizer tokens(message, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
diff --git a/loolwsd/Unit.hpp b/loolwsd/Unit.hpp
index 7e11a33..658184d 100644
--- a/loolwsd/Unit.hpp
+++ b/loolwsd/Unit.hpp
@@ -35,6 +35,7 @@ class UnitBase
     friend UnitKit;
 
 protected:
+
     // ---------------- Helper API ----------------
     /// After this time we invoke 'timeout' default 30 seconds
     void setTimeout(int timeoutMilliSeconds);
@@ -93,9 +94,9 @@ public:
     /// Do we have hooks for the Kit too
     bool hasKitHooks() { return _hasKitHooks; }
     /// set in your unit if you want to be injected into the kit too.
-    void setHasKitHooks(bool hasHooks) { _hasKitHooks = hasHooks; }
+    void setHasKitHooks(bool hasHooks = true) { _hasKitHooks = hasHooks; }
 
-    // ---------------- Hooks ----------------
+    // ---------------- WSD hooks ----------------
 
     /// Main-loop reached, time for testing
     virtual void invokeTest() {}
@@ -122,6 +123,19 @@ public:
         assert (_global && _global->_type == UnitType::TYPE_KIT);
         return *static_cast<UnitKit *>(_global);
     }
+
+    // ---------------- ForKit hooks ----------------
+
+    /// main-loop reached, time for testing
+    virtual void invokeForKitTest() {}
+
+    // ---------------- Kit hooks ----------------
+
+    /// Post fork hook - just before we init the child kit
+    virtual void postFork() {}
+
+    /// Kit got a message
+    virtual void kitMessage(std::string &/* message */) {}
 };
 
 #endif
diff --git a/loolwsd/test/UnitPrefork.cpp b/loolwsd/test/UnitPrefork.cpp
index 6094b0c..a79e593 100644
--- a/loolwsd/test/UnitPrefork.cpp
+++ b/loolwsd/test/UnitPrefork.cpp
@@ -18,6 +18,7 @@
 #include <Poco/Timestamp.h>
 using Poco::Timestamp;
 
+// Inside the WSD process
 class UnitPrefork : public UnitWSD
 {
     int _numStarted;
@@ -28,6 +29,7 @@ public:
         : _numStarted(0),
           _numToPrefork(20)
     {
+        setHasKitHooks();
     }
     virtual void preSpawnCount(int &numPrefork) override
     {
@@ -48,9 +50,21 @@ public:
     }
 };
 
+// Inside the forkit & kit processes
+class UnitKitPrefork : public UnitKit
+{
+public:
+    UnitKitPrefork() {}
+};
+
 UnitBase *unit_create_wsd(void)
 {
     return new UnitPrefork();
 }
 
+UnitBase *unit_create_kit(void)
+{
+    return new UnitKitPrefork();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list