2016-04-05 11:41:10 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <config.h>
|
2017-03-08 10:38:22 -06:00
|
|
|
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include "Unit.hpp"
|
|
|
|
|
2022-02-15 16:45:01 -06:00
|
|
|
#include <iostream>
|
2016-04-05 11:41:10 -05:00
|
|
|
#include <cassert>
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include <dlfcn.h>
|
2016-05-01 09:24:31 -05:00
|
|
|
#include <fstream>
|
2022-02-15 16:45:01 -06:00
|
|
|
#include <sstream>
|
2019-11-06 03:07:32 -06:00
|
|
|
#include <sysexits.h>
|
2019-11-06 07:03:53 -06:00
|
|
|
#include <thread>
|
2016-04-05 11:41:10 -05:00
|
|
|
|
2022-05-03 06:50:24 -05:00
|
|
|
#include <Poco/JSON/Object.h>
|
|
|
|
#include <Poco/JSON/Parser.h>
|
2019-11-06 03:07:32 -06:00
|
|
|
#include <Poco/Util/LayeredConfiguration.h>
|
2016-04-06 13:50:55 -05:00
|
|
|
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include "Log.hpp"
|
|
|
|
#include "Util.hpp"
|
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <common/SigUtil.hpp>
|
2022-06-18 09:32:49 -05:00
|
|
|
#include <common/Message.hpp>
|
2016-11-14 07:58:04 -06:00
|
|
|
|
2016-06-07 02:18:49 -05:00
|
|
|
UnitBase *UnitBase::Global = nullptr;
|
2021-09-14 10:05:31 -05:00
|
|
|
UnitKit *GlobalKit = nullptr;
|
|
|
|
UnitWSD *GlobalWSD = nullptr;
|
2021-09-28 04:21:45 -05:00
|
|
|
UnitTool *GlobalTool = nullptr;
|
2020-01-17 14:49:38 -06:00
|
|
|
char * UnitBase::UnitLibPath;
|
2019-11-06 07:03:53 -06:00
|
|
|
static std::thread TimeoutThread;
|
|
|
|
static std::atomic<bool> TimeoutThreadRunning(false);
|
|
|
|
std::timed_mutex TimeoutThreadMutex;
|
2016-04-08 11:36:08 -05:00
|
|
|
|
2022-03-17 07:25:43 -05:00
|
|
|
/// Controls whether experimental features/behavior is enabled or not.
|
|
|
|
bool EnableExperimental = false;
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
UnitBase *UnitBase::linkAndCreateUnit(UnitType type, const std::string &unitLibPath)
|
2016-04-05 11:41:10 -05:00
|
|
|
{
|
2019-02-12 05:16:40 -06:00
|
|
|
#if !MOBILEAPP
|
2016-04-05 11:41:10 -05:00
|
|
|
void *dlHandle = dlopen(unitLibPath.c_str(), RTLD_GLOBAL|RTLD_NOW);
|
|
|
|
if (!dlHandle)
|
|
|
|
{
|
2016-11-06 11:06:21 -06:00
|
|
|
LOG_ERR("Failed to load " << unitLibPath << ": " << dlerror());
|
2016-12-22 08:04:07 -06:00
|
|
|
return nullptr;
|
2016-04-05 11:41:10 -05:00
|
|
|
}
|
|
|
|
|
2020-01-17 14:49:38 -06:00
|
|
|
// avoid std:string de-allocation during failure / exit.
|
|
|
|
UnitLibPath = strdup(unitLibPath.c_str());
|
|
|
|
|
2016-12-22 08:04:07 -06:00
|
|
|
const char *symbol = nullptr;
|
2016-04-09 11:30:48 -05:00
|
|
|
switch (type)
|
|
|
|
{
|
2016-12-22 03:27:30 -06:00
|
|
|
case UnitType::Wsd:
|
2016-04-09 11:30:48 -05:00
|
|
|
symbol = "unit_create_wsd";
|
|
|
|
break;
|
2016-12-22 03:27:30 -06:00
|
|
|
case UnitType::Kit:
|
2016-04-09 11:30:48 -05:00
|
|
|
symbol = "unit_create_kit";
|
|
|
|
break;
|
2021-08-10 22:41:02 -05:00
|
|
|
case UnitType::Tool:
|
|
|
|
symbol = "unit_create_tool";
|
|
|
|
break;
|
2016-04-09 11:30:48 -05:00
|
|
|
}
|
2016-04-05 11:41:10 -05:00
|
|
|
CreateUnitHooksFunction* createHooks;
|
2016-04-09 11:30:48 -05:00
|
|
|
createHooks = reinterpret_cast<CreateUnitHooksFunction *>(dlsym(dlHandle, symbol));
|
2016-04-05 11:41:10 -05:00
|
|
|
if (!createHooks)
|
|
|
|
{
|
2016-11-06 11:06:21 -06:00
|
|
|
LOG_ERR("No " << symbol << " symbol in " << unitLibPath);
|
2016-12-22 08:04:07 -06:00
|
|
|
return nullptr;
|
2016-04-05 11:41:10 -05:00
|
|
|
}
|
2017-01-13 06:52:08 -06:00
|
|
|
UnitBase *hooks = createHooks();
|
2016-04-05 11:41:10 -05:00
|
|
|
|
2017-01-13 06:52:08 -06:00
|
|
|
if (hooks)
|
|
|
|
hooks->setHandle(dlHandle);
|
2016-04-05 11:41:10 -05:00
|
|
|
|
2017-01-13 06:52:08 -06:00
|
|
|
return hooks;
|
2018-09-13 11:16:00 -05:00
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
2016-04-05 11:41:10 -05:00
|
|
|
}
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
bool UnitBase::init(UnitType type, const std::string &unitLibPath)
|
2016-04-05 11:41:10 -05:00
|
|
|
{
|
2019-02-13 09:37:54 -06:00
|
|
|
#if !MOBILEAPP
|
2021-09-16 06:25:29 -05:00
|
|
|
assert(!get(type));
|
2019-02-13 09:37:54 -06:00
|
|
|
#else
|
2021-11-18 06:08:14 -06:00
|
|
|
// The COOLWSD initialization is called in a loop on mobile, allow reuse
|
2021-09-16 06:25:29 -05:00
|
|
|
if (get(type))
|
2019-02-13 09:37:54 -06:00
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
2016-04-05 11:41:10 -05:00
|
|
|
if (!unitLibPath.empty())
|
2016-04-08 11:36:08 -05:00
|
|
|
{
|
2021-09-16 06:25:29 -05:00
|
|
|
UnitBase* instance = linkAndCreateUnit(type, unitLibPath);
|
|
|
|
rememberInstance(type, instance);
|
2022-02-16 16:22:18 -06:00
|
|
|
LOG_DBG(instance->getTestname() << ": Initializing");
|
2021-09-14 10:05:31 -05:00
|
|
|
|
2021-09-16 06:25:29 -05:00
|
|
|
if (instance && type == UnitType::Kit)
|
2016-04-09 11:30:48 -05:00
|
|
|
{
|
2019-11-06 07:03:53 -06:00
|
|
|
TimeoutThreadMutex.lock();
|
2021-09-16 06:25:29 -05:00
|
|
|
TimeoutThread = std::thread([instance]{
|
2019-11-06 07:03:53 -06:00
|
|
|
TimeoutThreadRunning = true;
|
|
|
|
Util::setThreadName("unit timeout");
|
|
|
|
|
2021-09-16 06:25:29 -05:00
|
|
|
if (TimeoutThreadMutex.try_lock_for(instance->_timeoutMilliSeconds))
|
2019-11-06 07:03:53 -06:00
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
LOG_DBG(instance->getTestname() << ": Unit test finished in time");
|
2019-11-06 07:03:53 -06:00
|
|
|
TimeoutThreadMutex.unlock();
|
|
|
|
}
|
|
|
|
else
|
2016-04-09 11:30:48 -05:00
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
LOG_ERR(instance->getTestname()
|
|
|
|
<< ": Unit test timeout after " << instance->_timeoutMilliSeconds);
|
2021-09-16 06:25:29 -05:00
|
|
|
instance->timeout();
|
2016-04-09 11:30:48 -05:00
|
|
|
}
|
2019-11-06 07:03:53 -06:00
|
|
|
TimeoutThreadRunning = false;
|
2016-04-09 11:30:48 -05:00
|
|
|
});
|
|
|
|
}
|
2016-04-08 11:36:08 -05:00
|
|
|
}
|
2016-04-05 11:41:10 -05:00
|
|
|
else
|
2016-04-09 11:30:48 -05:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2016-12-22 03:27:30 -06:00
|
|
|
case UnitType::Wsd:
|
2022-04-21 18:14:16 -05:00
|
|
|
rememberInstance(UnitType::Wsd, new UnitWSD("UnitWSD"));
|
2016-04-09 11:30:48 -05:00
|
|
|
break;
|
2016-12-22 03:27:30 -06:00
|
|
|
case UnitType::Kit:
|
2022-04-21 18:14:16 -05:00
|
|
|
rememberInstance(UnitType::Kit, new UnitKit("UnitKit"));
|
2016-04-09 11:30:48 -05:00
|
|
|
break;
|
2021-08-10 22:41:02 -05:00
|
|
|
case UnitType::Tool:
|
2022-04-21 18:14:16 -05:00
|
|
|
rememberInstance(UnitType::Tool, new UnitTool("UnitTool"));
|
2021-08-10 22:41:02 -05:00
|
|
|
break;
|
2016-04-09 11:30:48 -05:00
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-16 06:25:29 -05:00
|
|
|
return get(type) != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase* UnitBase::get(UnitType type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case UnitType::Wsd:
|
|
|
|
return GlobalWSD;
|
|
|
|
break;
|
|
|
|
case UnitType::Kit:
|
|
|
|
return GlobalKit;
|
|
|
|
break;
|
2021-09-28 04:21:45 -05:00
|
|
|
case UnitType::Tool:
|
|
|
|
return GlobalTool;
|
|
|
|
break;
|
2021-09-16 06:25:29 -05:00
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
break;
|
|
|
|
}
|
2016-04-05 11:41:10 -05:00
|
|
|
|
2021-09-16 06:25:29 -05:00
|
|
|
return nullptr;
|
2016-04-05 11:41:10 -05:00
|
|
|
}
|
|
|
|
|
2021-09-16 06:25:29 -05:00
|
|
|
void UnitBase::rememberInstance(UnitType type, UnitBase* instance)
|
2021-09-14 10:05:31 -05:00
|
|
|
{
|
2021-09-16 06:25:29 -05:00
|
|
|
assert(instance->_type == type);
|
|
|
|
|
2021-09-14 10:05:31 -05:00
|
|
|
Global = instance;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case UnitType::Wsd:
|
|
|
|
GlobalWSD = static_cast<UnitWSD*>(instance);
|
|
|
|
break;
|
|
|
|
case UnitType::Kit:
|
|
|
|
GlobalKit = static_cast<UnitKit*>(instance);
|
|
|
|
break;
|
2021-09-28 04:21:45 -05:00
|
|
|
case UnitType::Tool:
|
|
|
|
GlobalTool = static_cast<UnitTool*>(instance);
|
|
|
|
break;
|
2021-09-14 10:05:31 -05:00
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-22 10:35:30 -05:00
|
|
|
bool UnitBase::isUnitTesting()
|
|
|
|
{
|
|
|
|
return Global && Global->_dlHandle;
|
|
|
|
}
|
|
|
|
|
2020-12-14 13:00:55 -06:00
|
|
|
void UnitBase::setTimeout(std::chrono::milliseconds timeoutMilliSeconds)
|
2016-04-08 11:36:08 -05:00
|
|
|
{
|
2019-11-06 07:03:53 -06:00
|
|
|
assert(!TimeoutThreadRunning);
|
2016-04-08 11:36:08 -05:00
|
|
|
_timeoutMilliSeconds = timeoutMilliSeconds;
|
2021-04-12 13:40:38 -05:00
|
|
|
LOG_TST(getTestname() << ": setTimeout: " << _timeoutMilliSeconds);
|
2016-04-08 11:36:08 -05:00
|
|
|
}
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
UnitBase::~UnitBase()
|
2016-04-05 11:41:10 -05:00
|
|
|
{
|
2022-07-19 21:22:54 -05:00
|
|
|
LOG_TST(getTestname() << ": ~UnitBase: " << (_retValue ? "FAILED" : "SUCCESS"));
|
2022-04-21 16:53:34 -05:00
|
|
|
|
2016-04-06 13:50:55 -05:00
|
|
|
// FIXME: we should really clean-up properly.
|
|
|
|
// if (_dlHandle)
|
|
|
|
// dlclose(_dlHandle);
|
2016-12-22 08:04:07 -06:00
|
|
|
_dlHandle = nullptr;
|
2021-04-12 23:48:47 -05:00
|
|
|
_socketPoll->joinThread();
|
2016-04-05 11:41:10 -05:00
|
|
|
}
|
|
|
|
|
2022-06-18 09:32:49 -05:00
|
|
|
bool UnitBase::filterLOKitMessage(const std::shared_ptr<Message>& message)
|
|
|
|
{
|
|
|
|
return onFilterLOKitMessage(message);
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:27:24 -05:00
|
|
|
bool UnitBase::filterSendWebSocketMessage(const char* data, const std::size_t len,
|
|
|
|
const WSOpCode code, const bool flush, int& unitReturn)
|
2022-05-03 06:50:24 -05:00
|
|
|
{
|
|
|
|
const std::string message(data, len);
|
|
|
|
if (Util::startsWith(message, "unocommandresult:"))
|
|
|
|
{
|
|
|
|
const std::size_t index = message.find_first_of('{');
|
|
|
|
if (index != std::string::npos)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const std::string stringJSON = message.substr(index);
|
|
|
|
Poco::JSON::Parser parser;
|
|
|
|
const Poco::Dynamic::Var parsedJSON = parser.parse(stringJSON);
|
|
|
|
const auto& object = parsedJSON.extract<Poco::JSON::Object::Ptr>();
|
|
|
|
if (object->get("commandName").toString() == ".uno:Save")
|
|
|
|
{
|
|
|
|
const bool success = object->get("success").toString() == "true";
|
|
|
|
std::string result;
|
|
|
|
if (object->has("result"))
|
|
|
|
{
|
|
|
|
const Poco::Dynamic::Var parsedResultJSON = object->get("result");
|
|
|
|
const auto& resultObj = parsedResultJSON.extract<Poco::JSON::Object::Ptr>();
|
|
|
|
if (resultObj->get("type").toString() == "string")
|
|
|
|
result = resultObj->get("value").toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onDocumentSaved(message, success, result))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::exception& exception)
|
|
|
|
{
|
|
|
|
LOG_TST("unocommandresult parsing failure: " << exception.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_TST("Expected json unocommandresult. Ignoring: " << message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Util::startsWith(message, "status:"))
|
|
|
|
{
|
|
|
|
if (onDocumentLoaded(message))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (message == "statechanged: .uno:ModifiedStatus=true")
|
|
|
|
{
|
|
|
|
if (onDocumentModified(message))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (Util::startsWith(message, "statechanged:"))
|
|
|
|
{
|
|
|
|
if (onDocumentStateChanged(message))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (Util::startsWith(message, "error:"))
|
|
|
|
{
|
|
|
|
if (onDocumentError(message))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-06-14 05:27:24 -05:00
|
|
|
return onFilterSendWebSocketMessage(data, len, code, flush, unitReturn);
|
2022-05-03 06:50:24 -05:00
|
|
|
}
|
|
|
|
|
2022-04-21 18:14:16 -05:00
|
|
|
UnitWSD::UnitWSD(const std::string& name)
|
|
|
|
: UnitBase(name, UnitType::Wsd)
|
2020-12-20 21:11:33 -06:00
|
|
|
, _hasKitHooks(false)
|
2016-04-09 11:30:48 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitWSD::~UnitWSD()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-21 15:25:23 -05:00
|
|
|
void UnitWSD::configure(Poco::Util::LayeredConfiguration &config)
|
|
|
|
{
|
2016-10-22 10:35:30 -05:00
|
|
|
if (isUnitTesting())
|
2016-10-21 15:25:23 -05:00
|
|
|
{
|
|
|
|
// Force HTTP - helps stracing.
|
|
|
|
config.setBool("ssl.enable", false);
|
2016-12-03 16:40:58 -06:00
|
|
|
// Use http:// everywhere.
|
|
|
|
config.setBool("ssl.termination", false);
|
2016-10-21 15:25:23 -05:00
|
|
|
// Force console output - easier to debug.
|
|
|
|
config.setBool("logging.file[@enable]", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-30 00:27:44 -05:00
|
|
|
void UnitWSD::lookupTile(int part, int mode, int width, int height, int tilePosX, int tilePosY,
|
2019-02-14 13:01:43 -06:00
|
|
|
int tileWidth, int tileHeight,
|
2021-11-13 05:49:35 -06:00
|
|
|
std::shared_ptr<TileData> &tile)
|
2016-05-01 09:24:31 -05:00
|
|
|
{
|
2021-04-29 05:15:36 -05:00
|
|
|
if (isUnitTesting())
|
|
|
|
{
|
|
|
|
if (tile)
|
2022-08-30 00:27:44 -05:00
|
|
|
onTileCacheHit(part, mode, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
|
2021-04-29 05:15:36 -05:00
|
|
|
else
|
2022-08-30 00:27:44 -05:00
|
|
|
onTileCacheMiss(part, mode, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
|
2021-04-29 05:15:36 -05:00
|
|
|
}
|
2016-05-01 09:24:31 -05:00
|
|
|
}
|
|
|
|
|
2021-09-14 10:05:31 -05:00
|
|
|
UnitWSD& UnitWSD::get()
|
|
|
|
{
|
2021-09-16 06:25:29 -05:00
|
|
|
assert(GlobalWSD);
|
2021-09-14 10:05:31 -05:00
|
|
|
return *GlobalWSD;
|
|
|
|
}
|
|
|
|
|
2022-04-21 18:14:16 -05:00
|
|
|
UnitKit::UnitKit(const std::string& name)
|
|
|
|
: UnitBase(name, UnitType::Kit)
|
2016-04-09 11:30:48 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitKit::~UnitKit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-14 10:05:31 -05:00
|
|
|
UnitKit& UnitKit::get()
|
|
|
|
{
|
|
|
|
#if MOBILEAPP
|
|
|
|
if (!GlobalKit)
|
2022-04-21 18:14:16 -05:00
|
|
|
GlobalKit = new UnitKit("UnitKit");
|
2021-09-14 10:05:31 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
assert(GlobalKit);
|
|
|
|
return *GlobalKit;
|
|
|
|
}
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
void UnitBase::exitTest(TestResult result)
|
2016-04-06 13:50:55 -05:00
|
|
|
{
|
2022-02-09 18:37:40 -06:00
|
|
|
if (isFinished())
|
2020-02-19 02:24:36 -06:00
|
|
|
{
|
2022-11-06 10:47:27 -06:00
|
|
|
if ((result == TestResult::Ok && _retValue != EX_OK) ||
|
|
|
|
(result != TestResult::Ok && _retValue == EX_OK))
|
|
|
|
LOG_TST(getTestname() << ": exitTest " << testResultAsString(result)
|
|
|
|
<< " but is already finished with a different result.");
|
2020-02-19 02:24:36 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-22 18:08:45 -06:00
|
|
|
if (result == TestResult::Ok)
|
2022-02-15 16:45:01 -06:00
|
|
|
LOG_TST(getTestname() << ": SUCCESS: exitTest: " << testResultAsString(result)
|
2021-04-12 13:40:38 -05:00
|
|
|
<< ". Flagging to shutdown.");
|
2020-12-22 18:08:45 -06:00
|
|
|
else
|
2022-02-15 16:45:01 -06:00
|
|
|
LOG_TST("ERROR " << getTestname() << ": FAILURE: exitTest: " << testResultAsString(result)
|
|
|
|
<< ". Flagging to shutdown.");
|
2020-12-22 18:08:45 -06:00
|
|
|
|
2016-04-06 13:50:55 -05:00
|
|
|
_setRetValue = true;
|
2019-11-06 03:07:32 -06:00
|
|
|
_retValue = result == TestResult::Ok ? EX_OK : EX_SOFTWARE;
|
2020-02-24 01:12:38 -06:00
|
|
|
#if !MOBILEAPP
|
2022-07-19 21:22:54 -05:00
|
|
|
LOG_INF("Setting ShutdownRequestFlag: " << getTestname() << " test has finished: "
|
|
|
|
<< (_retValue ? "FAILED" : "SUCCESS"));
|
2022-02-12 13:39:56 -06:00
|
|
|
SigUtil::setTerminationFlag(); // And wakupWorld.
|
2021-01-10 15:44:24 -06:00
|
|
|
#else
|
2017-03-16 13:52:49 -05:00
|
|
|
SocketPoll::wakeupWorld();
|
2021-01-10 15:44:24 -06:00
|
|
|
#endif
|
2016-04-06 13:50:55 -05:00
|
|
|
}
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
void UnitBase::timeout()
|
2016-04-08 11:36:08 -05:00
|
|
|
{
|
2020-12-26 14:37:57 -06:00
|
|
|
// Don't timeout if we had already finished.
|
2022-02-09 18:37:40 -06:00
|
|
|
if (isUnitTesting() && !isFinished())
|
2017-03-17 02:13:12 -05:00
|
|
|
{
|
2022-02-09 18:37:40 -06:00
|
|
|
LOG_TST("ERROR " << getTestname() << ": Timed out waiting for unit test to complete within "
|
|
|
|
<< _timeoutMilliSeconds);
|
2017-03-17 02:13:12 -05:00
|
|
|
exitTest(TestResult::TimedOut);
|
|
|
|
}
|
2016-04-08 11:36:08 -05:00
|
|
|
}
|
|
|
|
|
2016-04-09 11:30:48 -05:00
|
|
|
void UnitBase::returnValue(int &retValue)
|
2016-04-06 13:50:55 -05:00
|
|
|
{
|
|
|
|
if (_setRetValue)
|
|
|
|
retValue = _retValue;
|
|
|
|
|
2019-11-06 07:03:53 -06:00
|
|
|
// tell the timeout thread that the work has finished
|
|
|
|
TimeoutThreadMutex.unlock();
|
|
|
|
if (TimeoutThread.joinable())
|
|
|
|
TimeoutThread.join();
|
2016-04-08 11:36:08 -05:00
|
|
|
|
2016-06-07 02:18:49 -05:00
|
|
|
Global = nullptr;
|
2016-04-06 13:50:55 -05:00
|
|
|
}
|
|
|
|
|
2021-09-16 06:25:29 -05:00
|
|
|
void UnitKit::returnValue(int &retValue)
|
|
|
|
{
|
|
|
|
UnitBase::returnValue(retValue);
|
|
|
|
|
|
|
|
delete GlobalKit;
|
|
|
|
GlobalKit = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnitWSD::returnValue(int &retValue)
|
|
|
|
{
|
|
|
|
UnitBase::returnValue(retValue);
|
|
|
|
|
|
|
|
delete GlobalWSD;
|
|
|
|
GlobalWSD = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-05 11:41:10 -05:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|