summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2020-01-17 20:49:38 +0000
committerMichael Meeks <michael.meeks@collabora.com>2020-01-21 13:39:42 +0000
commit04f3460fd22f12b82fd606944f6d4c8433b36c42 (patch)
treeb3d8e87b33feb0140fadd4b05564b8b7e6b77870
parent1c6b4be2ce84e43a4646c52d8376c19af53d945c (diff)
test: switch to parallel tests based on Unit framework.
Increase a few timeouts, bin old-style standalone unit tests, fix a number of bugs. Change-Id: Ia3d59466ecb9a9443807ba3445d04dd5f77e3dba
-rw-r--r--common/Unit.cpp5
-rw-r--r--common/Unit.hpp8
-rw-r--r--test/Makefile.am41
-rw-r--r--test/UnitClient.cpp4
-rw-r--r--test/helpers.hpp8
-rw-r--r--test/test.cpp3
-rw-r--r--wsd/DocumentBroker.cpp6
-rw-r--r--wsd/LOOLWSD.cpp11
8 files changed, 57 insertions, 29 deletions
diff --git a/common/Unit.cpp b/common/Unit.cpp
index 5dc01d4ea..875c97686 100644
--- a/common/Unit.cpp
+++ b/common/Unit.cpp
@@ -26,7 +26,7 @@
#include <common/SigUtil.hpp>
UnitBase *UnitBase::Global = nullptr;
-
+char * UnitBase::UnitLibPath;
static std::thread TimeoutThread;
static std::atomic<bool> TimeoutThreadRunning(false);
std::timed_mutex TimeoutThreadMutex;
@@ -41,6 +41,9 @@ UnitBase *UnitBase::linkAndCreateUnit(UnitType type, const std::string &unitLibP
return nullptr;
}
+ // avoid std:string de-allocation during failure / exit.
+ UnitLibPath = strdup(unitLibPath.c_str());
+
const char *symbol = nullptr;
switch (type)
{
diff --git a/common/Unit.hpp b/common/Unit.hpp
index 63975514b..c403100c2 100644
--- a/common/Unit.hpp
+++ b/common/Unit.hpp
@@ -138,11 +138,17 @@ public:
return *Global;
}
+ static std::string getUnitLibPath() { return std::string(UnitLibPath); }
+
private:
- void setHandle(void *dlHandle) { _dlHandle = dlHandle; }
+ void setHandle(void *dlHandle)
+ {
+ _dlHandle = dlHandle;
+ }
static UnitBase *linkAndCreateUnit(UnitType type, const std::string& unitLibPath);
void *_dlHandle;
+ static char *UnitLibPath;
bool _setRetValue;
int _retValue;
int _timeoutMilliSeconds;
diff --git a/test/Makefile.am b/test/Makefile.am
index f1d4963b1..2b369465a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -13,9 +13,10 @@ AM_CXXFLAGS = $(CPPUNIT_CFLAGS) -DTDOC=\"$(abs_top_srcdir)/test/data\" \
-I${top_srcdir}/common -I${top_srcdir}/net -I${top_srcdir}/wsd -I${top_srcdir}/kit
noinst_LTLIBRARIES = \
+ unit-base.la unit-tiletest.la \
+ unit-integration.la unit-httpws.la unit-crash.la \
unit-convert.la unit-typing.la unit-copy-paste.la \
- unit-timeout.la unit-prefork.la \
- unit-storage.la unit-client.la \
+ unit-timeout.la unit-prefork.la unit-storage.la \
unit-admin.la unit-tilecache.la \
unit-fuzz.la unit-oob.la unit-http.la unit-oauth.la \
unit-wopi.la unit-wopi-saveas.la \
@@ -82,13 +83,6 @@ test_base_source = \
DeltaTests.cpp \
$(wsd_sources)
-test_all_source = \
- $(test_base_source) \
- TileCacheTests.cpp \
- integration-http-server.cpp \
- httpwstest.cpp \
- httpcrashtest.cpp
-
unittest_CPPFLAGS = -I$(top_srcdir) -DBUILDING_TESTS
unittest_SOURCES = $(test_base_source) test.cpp
unittest_LDADD = $(CPPUNIT_LIBS)
@@ -100,6 +94,18 @@ test_LDADD = $(CPPUNIT_LIBS)
fakesockettest_SOURCES = fakesockettest.cpp ../net/FakeSocket.cpp
fakesockettest_LDADD = $(CPPUNIT_LIBS)
+# old-style unit tests - bootstrapped via UnitClient
+unit_base_la_SOURCES = UnitClient.cpp ${test_base_source}
+unit_base_la_LIBADD = $(CPPUNIT_LIBS)
+unit_tiletest_la_SOURCES = UnitClient.cpp TileCacheTests.cpp
+unit_tiletest_la_LIBADD = $(CPPUNIT_LIBS)
+unit_integration_la_SOURCES = UnitClient.cpp integration-http-server.cpp
+unit_integration_la_LIBADD = $(CPPUNIT_LIBS)
+unit_httpws_la_SOURCES = UnitClient.cpp httpwstest.cpp
+unit_httpws_la_LIBADD = $(CPPUNIT_LIBS)
+unit_crash_la_SOURCES = UnitClient.cpp httpcrashtest.cpp
+unit_crash_la_LIBADD = $(CPPUNIT_LIBS)
+
# unit test modules:
unit_oob_la_SOURCES = UnitOOB.cpp
unit_http_la_SOURCES = UnitHTTP.cpp
@@ -107,8 +113,6 @@ unit_http_la_LIBADD = $(CPPUNIT_LIBS)
unit_fuzz_la_SOURCES = UnitFuzz.cpp
unit_admin_la_SOURCES = UnitAdmin.cpp
unit_admin_la_LIBADD = $(CPPUNIT_LIBS)
-unit_client_la_SOURCES = UnitClient.cpp ${test_all_source}
-unit_client_la_LIBADD = $(CPPUNIT_LIBS)
unit_typing_la_SOURCES = UnitTyping.cpp
unit_typing_la_LIBADD = $(CPPUNIT_LIBS)
unit_copy_paste_la_SOURCES = UnitCopyPaste.cpp
@@ -183,16 +187,20 @@ if HAVE_LO_PATH
check-local:
./fakesockettest
@fc-cache "@LO_PATH@"/share/fonts/truetype
- ./run_unit.sh --log-file test.log --trs-file test.trs
+
# FIXME 2: unit-oob.la fails with symbol undefined:
# UnitWSD::testHandleRequest(UnitWSD::TestRequest, UnitHTTPServerRequest&, UnitHTTPServerResponse&) ,
-TESTS = unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-tilecache.la unit-timeout.la \
+TESTS = \
+ unit-base.la unit-tiletest.la \
+ unit-integration.la unit-httpws.la unit-crash.la \
+ \
+ unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-tilecache.la unit-timeout.la \
unit-oauth.la unit-wopi.la unit-wopi-saveas.la \
unit-wopi-ownertermination.la unit-wopi-versionrestore.la \
unit-wopi-documentconflict.la unit_wopi_renamefile.la unit_wopi_watermark.la \
unit-http.la \
unit-tiff-load.la \
- unit-large-paste.la \
+ unit.large-paste.la \
unit-paste.la \
unit-load-torture.la \
unit-rendering-options.la \
@@ -209,9 +217,8 @@ TESTS = unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-t
unit-bad-doc-load.la \
unit-hosting.la \
unit-wopi-loadencoded.la unit-wopi-temp.la
-# TESTS = unit-client.la
-# TESTS += unit-admin.la
-# TESTS += unit-storage.la
+# TESTS += unit-admin.test
+# TESTS += unit-storage.test
else
TESTS = ${top_builddir}/test/test
endif
diff --git a/test/UnitClient.cpp b/test/UnitClient.cpp
index e3580f90e..03682fdc5 100644
--- a/test/UnitClient.cpp
+++ b/test/UnitClient.cpp
@@ -7,7 +7,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-// Runs client tests in their own thread inside a WSD process.
+// Runs old-style CPPUNIT tests in their own thread inside a WSD process.
+// Depending which cppunit objects this is linked with this runs different
+// tests.
#include <config.h>
diff --git a/test/helpers.hpp b/test/helpers.hpp
index f09de8bbb..dd638d191 100644
--- a/test/helpers.hpp
+++ b/test/helpers.hpp
@@ -390,8 +390,12 @@ inline
bool isDocumentLoaded(LOOLWebSocket& ws, const std::string& testname, bool isView = true)
{
const std::string prefix = isView ? "status:" : "statusindicatorfinish:";
- const auto message = getResponseString(ws, prefix, testname);
- return LOOLProtocol::matchPrefix(prefix, message);
+ // Allow 20 secs to load
+ const auto message = getResponseString(ws, prefix, testname, 30 * 1000);
+ bool success = LOOLProtocol::matchPrefix(prefix, message);
+ if (!success)
+ TST_LOG("ERR: Timed out loading document");
+ return success;
}
inline
diff --git a/test/test.cpp b/test/test.cpp
index cc00b2fde..4a5b0f6d0 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -183,7 +183,8 @@ bool runClientTests(bool standalone, bool verbose)
std::cerr << " (cd test; CPPUNIT_TEST_NAME=\"" << (*failures.begin())->failedTestName() << "\" gdb --args " << cmd << ")\n\n";
}
#else
- std::cerr << "(cd test; CPPUNIT_TEST_NAME=\"" << (*failures.begin())->failedTestName() << "\" make check)\n\n";
+ std::cerr << "(cd test; CPPUNIT_TEST_NAME=\"" << (*failures.begin())->failedTestName() <<
+ "\" ./run_unit.sh --test-name " << UnitBase::get().getUnitLibPath() << ")\n\n";
#endif
}
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 9bf7088c6..876436abe 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -309,9 +309,9 @@ void DocumentBroker::pollThread()
if (!_isLoaded && (limit_load_secs > 0) && (now > loadDeadline))
{
- LOG_WRN("Doc [" << _docKey << "] is taking too long to load. Will kill process ["
- << _childProcess->getPid() << "]. per_document.limit_load_secs set to "
- << limit_load_secs << " secs.");
+ LOG_ERR("Doc [" << _docKey << "] is taking too long to load. Will kill process ["
+ << _childProcess->getPid() << "]. per_document.limit_load_secs set to "
+ << limit_load_secs << " secs.");
broadcastMessage("error: cmd=load kind=docloadtimeout");
// Brutal but effective.
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index e39bfa9d0..4a4a61302 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -3283,14 +3283,19 @@ private:
std::shared_ptr<ServerSocket> socket = getServerSocket(
ClientListenAddr, port, WebServerPoll, factory);
+
+ while (!socket &&
#ifdef BUILDING_TESTS
- while (!socket)
+ true
+#else
+ UnitWSD::isUnitTesting()
+#endif
+ )
{
++port;
LOG_INF("Client port " << (port - 1) << " is busy, trying " << port << ".");
- socket = getServerSocket(port, WebServerPoll, factory);
+ socket = getServerSocket(ClientListenAddr, port, WebServerPoll, factory);
}
-#endif
if (!socket)
{