loolwsd/LOOLForKit.cpp | 4 - loolwsd/Util.cpp | 27 ------- loolwsd/Util.hpp | 20 ----- loolwsd/configure.ac | 2 loolwsd/test/Makefile.am | 6 + loolwsd/test/UnitFonts.cpp | 168 ++++++++++++++++++++++++++++++++++++++++++++ loolwsd/test/data/hello.odt |binary loolwsd/test/run_test.sh.in | 2 loolwsd/test/run_unit.sh.in | 2 9 files changed, 180 insertions(+), 51 deletions(-)
New commits: commit b3f17462eb3da98a129634218c2142ef64dd36d5 Author: Michael Meeks <michael.me...@collabora.com> Date: Thu Apr 14 09:34:37 2016 +0100 Fix ENABLE_SSL AC_SUBST. diff --git a/loolwsd/configure.ac b/loolwsd/configure.ac index c16e242..28faacc 100644 --- a/loolwsd/configure.ac +++ b/loolwsd/configure.ac @@ -171,8 +171,10 @@ AS_IF([test "$enable_tests" != "no"], AS_IF([test "$enable_ssl" != "no"], [AC_DEFINE([ENABLE_SSL],1,[Enable SSL])]) +ENABLE_SSL= if test "$enable_ssl" != "no"; then ssl_msg="ssl enabled" + ENABLE_SSL=true else ssl_msg="insecure: ssl disabled" fi diff --git a/loolwsd/test/data/hello.odt b/loolwsd/test/data/hello.odt index fcd047a..3febe62 100644 Binary files a/loolwsd/test/data/hello.odt and b/loolwsd/test/data/hello.odt differ commit 35b27b352cdce3b2b486905f0462d9b938dd9a04 Author: Michael Meeks <michael.me...@collabora.com> Date: Wed Apr 13 15:10:02 2016 +0100 Initial font unit test. diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp index e3e8046..700273f 100644 --- a/loolwsd/LOOLForKit.cpp +++ b/loolwsd/LOOLForKit.cpp @@ -120,13 +120,13 @@ static int createLibreOfficeKit(const std::string& childRoot, } else { - UnitKit::get().launchedKit(pid); - // parent if (pid < 0) Log::syserror("Fork failed."); else Log::info("Forked kit [" + std::to_string(pid) + "]."); + + UnitKit::get().launchedKit(pid); } return pid; diff --git a/loolwsd/test/Makefile.am b/loolwsd/test/Makefile.am index f4c71fa..144b9e0 100644 --- a/loolwsd/test/Makefile.am +++ b/loolwsd/test/Makefile.am @@ -4,7 +4,9 @@ check_PROGRAMS = test AM_CXXFLAGS = $(CPPUNIT_CFLAGS) -lib_LTLIBRARIES = unit-timeout.la unit-prefork.la unit-storage.la +lib_LTLIBRARIES = \ + unit-timeout.la unit-prefork.la \ + unit-storage.la unit-fonts.la AM_CPPFLAGS = -pthread -I$(top_srcdir) @@ -13,6 +15,8 @@ test_SOURCES = httpposttest.cpp httpwstest.cpp test.cpp ../LOOLProtocol.cpp test_LDADD = $(CPPUNIT_LIBS) # unit test modules: +unit_fonts_la_SOURCES = UnitFonts.cpp +unit_fonts_la_LDFLAGS = -module unit_timeout_la_SOURCES = UnitTimeout.cpp unit_timeout_la_LDFLAGS = -module unit_prefork_la_SOURCES = UnitPrefork.cpp diff --git a/loolwsd/test/UnitFonts.cpp b/loolwsd/test/UnitFonts.cpp new file mode 100644 index 0000000..4ffb17a --- /dev/null +++ b/loolwsd/test/UnitFonts.cpp @@ -0,0 +1,168 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <dlfcn.h> +#include <ftw.h> +#include <cassert> +#include <iostream> + +#include "Common.hpp" +#include "Util.hpp" +#include "Unit.hpp" +#include "LOOLProtocol.hpp" +#include <dlfcn.h> + +#include <Poco/Timestamp.h> +#include <Poco/StringTokenizer.h> +#include <Poco/Net/HTTPResponse.h> +#include <Poco/Net/HTTPClientSession.h> +#include <Poco/Net/HTTPServerRequest.h> + +#define UNIT_URI "/loolwsd/unit-font" + +namespace { + // interrogate the vcl/ fontmanager for its hook ... + std::string getFontList() + { + void *me = dlopen(NULL,RTLD_NOW); + typedef const char *(GetFontsFn)(void); + GetFontsFn *fn = reinterpret_cast<GetFontsFn *>( + dlsym(me, "unit_online_get_fonts")); + if (fn) + return std::string(fn()); + else + return std::string("can't find unit_online_get_fonts hook"); + } + + std::string readFontList(const std::shared_ptr< Poco::Net::WebSocket > &socket) + { + int flags; + char buffer[100 * 1000]; + + int length = socket->receiveFrame(buffer, sizeof (buffer), flags); + if (length > 0) + { + assert(length<(int)sizeof(buffer)); + buffer[length] = '\0'; + return std::string(buffer); + } + else + return std::string("read failure"); + } +} + +// Inside the WSD process +class UnitPrefork : public UnitWSD +{ + std::string _fontsKit; + std::string _fontsBroker; +public: + UnitPrefork() + { + setHasKitHooks(); + } + + void check() + { + if (!_fontsKit.length() || !_fontsBroker.length()) + return; // defer till we have all the data. + if (_fontsKit != _fontsBroker) + { + std::cout << "Error - font list mismatch" << std::endl; + std::cerr << "Kit : '" << _fontsKit << "' vs. Broker : '" << _fontsBroker << "'" << std::endl; + exitTest(TestResult::TEST_FAILED); + } + else + { + Poco::StringTokenizer tokens(_fontsKit, "\n"); + if (tokens.count() > 0) + std::cout << " " << tokens[0] << std::endl; + + exitTest(TestResult::TEST_OK); + } + } + + virtual void newChild(const std::shared_ptr<Poco::Net::WebSocket> &socket) override + { + Log::info("Fetching font list from kit"); + socket->sendFrame("unit-getfontlist: \n", + sizeof("unit-getfontlist: \n") - 1); + _fontsKit = readFontList(socket); + check(); + } + + virtual bool filterHandleRequest( + TestRequest type, + Poco::Net::HTTPServerRequest& request, + Poco::Net::HTTPServerResponse& response) override + { + if (type == UnitWSD::TestRequest::TEST_REQ_PRISONER && + request.getURI().find(UNIT_URI) == 0) + { + auto ws = std::make_shared<Poco::Net::WebSocket>(request, response); + _fontsBroker = readFontList(ws); + check(); + return true; + } + + return false; + } +}; + +// Inside the forkit & kit processes +class UnitKitPrefork : public UnitKit +{ +public: + UnitKitPrefork() + { + } + + // Called in the forkit after forking the kit + virtual void launchedKit(int /* pid */) override + { + // Open websocket connection between the child process and WSD. + Poco::Net::HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER); + cs.setTimeout(0); + Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, + std::string(UNIT_URI)); + Poco::Net::HTTPResponse response; + auto ws = std::make_shared<Poco::Net::WebSocket>(cs, request, response); + ws->setReceiveTimeout(0); + Log::info("Fetching font list from forkit"); + std::string fontListMsg = getFontList() + "\n"; + ws->sendFrame(fontListMsg.c_str(), fontListMsg.length()); + } + + // Called from WSD and handled inside the kit. + virtual bool filterKitMessage(const std::shared_ptr<Poco::Net::WebSocket> &ws, + std::string &message) override + { + std::string token = LOOLProtocol::getFirstToken(message.c_str(), message.length()); + if (token == "unit-getfontlist:") + { + std::string fontListReply = getFontList() + "\n"; + ws->sendFrame(fontListReply.c_str(), fontListReply.length()); + return true; + } + + return false; + } +}; + +UnitBase *unit_create_wsd(void) +{ + return new UnitPrefork(); +} + +UnitBase *unit_create_kit(void) +{ + return new UnitKitPrefork(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/loolwsd/test/run_test.sh.in b/loolwsd/test/run_test.sh.in index b5678f9..c52034e 100755 --- a/loolwsd/test/run_test.sh.in +++ b/loolwsd/test/run_test.sh.in @@ -21,6 +21,8 @@ fi # result logging echo > $test_output +echo "Running cppunit test ..."; + ${abs_top_builddir}/loolwsd --systemplate="@SYSTEMPLATE_PATH@" --lotemplate="@LO_PATH@" \ --childroot="@JAILS_PATH@" --allowlocalstorage 2>$test_log_output/run_test.log & diff --git a/loolwsd/test/run_unit.sh.in b/loolwsd/test/run_unit.sh.in index 1e0ae15..5491640 100755 --- a/loolwsd/test/run_unit.sh.in +++ b/loolwsd/test/run_unit.sh.in @@ -23,7 +23,7 @@ fi # result logging echo > run_unit.sh.trs -for tst in timeout storage prefork; do +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@" \ commit c7d0067969259d1a1e08d16ff2a2252b5dd00db6 Author: Tor Lillqvist <t...@collabora.com> Date: Thu Apr 14 11:30:28 2016 +0300 Util::getChildStatus() is unused Good, now the odd LOOLExitCode can go away, too. diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index c6fae82..2162b26 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -491,33 +491,6 @@ namespace Util strncpy(FatalGdbString, streamStr.c_str(), sizeof(FatalGdbString)); } - int getChildStatus(const int code) - { - int retVal; - - switch (static_cast<const LOOLExitCode>(code)) - { - case LOOLExitCode::LOOL_SECOND_OFFICE: - case LOOLExitCode::LOOL_FATAL_ERROR: - case LOOLExitCode::LOOL_CRASH_WITH_RESTART: - case LOOLExitCode::LOOL_NORMAL_RESTART: - case LOOLExitCode::LOOL_EXIT_SOFTWARE: - retVal = EXIT_FAILURE; - break; - - case LOOLExitCode::LOOL_NO_ERROR: - retVal = EXIT_SUCCESS; - break; - - // Why are other non-zero exit codes interpreted as success? - default: - retVal = EXIT_SUCCESS; - break; - } - - return retVal; - } - int getSignalStatus(const int code) { int retVal; diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp index b47c4ca..e56528d 100644 --- a/loolwsd/Util.hpp +++ b/loolwsd/Util.hpp @@ -24,24 +24,6 @@ #define LOK_USE_UNSTABLE_API #include <LibreOfficeKit/LibreOfficeKitEnums.h> -// This is an odd mix of the EExitCodes enum in LibreOffice's desktop/source/inc/exithelper.h and -// then EX_SOFTWARE (= 70) from the (BSD origin) <sysexits.h>. - -enum class LOOLExitCode -{ - LOOL_NO_ERROR = 0, - /* pipe was detected - second office must terminate itself */ - LOOL_SECOND_OFFICE = 1, - /* an uno exception was catched during startup */ - LOOL_FATAL_ERROR = 77, /* Only the low 8 bits are significant 333 % 256 = 77 */ - /* user force automatic restart after crash */ - LOOL_CRASH_WITH_RESTART = 79, - /* the office restarts itself */ - LOOL_NORMAL_RESTART = 81, - /* internal software error */ - LOOL_EXIT_SOFTWARE = 70 -}; - /// Flag to stop pump loops. extern volatile bool TerminationFlag; @@ -120,8 +102,6 @@ namespace Util void setFatalSignals(); /// Returns EXIT_SUCCESS or EXIT_FAILURE from <stdlib.h> - int getChildStatus(const int code); - /// Returns EXIT_SUCCESS or EXIT_FAILURE from <stdlib.h> int getSignalStatus(const int code); void requestTermination(const Poco::Process::PID& pid); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits