m_currentTestCase(nullptr)
, m_terminate(false)
, m_allowChildLogs(false)
+ , m_pipeTimeout(90)
, m_deferDeepness(0U)
, m_firstDeferredExceptionType(DeferredExceptionType::DEFERRED_FAILED)
{}
bool m_terminate;
bool m_allowChildLogs;
+ // Timeout for child test in seconds
+ int m_pipeTimeout;
+
void Banner();
void InvalidArgs(const std::string& message = "Invalid arguments!");
void Usage();
int ExecTestRunner(ArgsList args);
// The runner will terminate as soon as possible (after current test).
void Terminate();
- bool GetAllowChildLogs();
+ bool GetAllowChildLogs() const;
bool GetRunIgnored() const;
+ int GetTimeout() const;
void deferFailedException(const DPL::Test::TestFailed &ex);
void deferIgnoredException(const DPL::Test::TestIgnored &ex);
#include <exception>
#include <functional>
#include <memory>
+#include <stdexcept>
#include <string>
#include <unistd.h>
fprintf(stderr, " --allowchildlogs\t Allow to print logs from child process on screen.\n");
fprintf(stderr, " When active child process will be able to print logs on stdout and stderr.\n");
fprintf(stderr, " Both descriptors will be closed after test.\n");
+ fprintf(
+ stderr,
+ " --timeout=<timeout>\tTimeout for child test cases in seconds (default: 90)");
fprintf(stderr, " --help\t This help\n\n");
std::for_each(m_collectors.begin(),
m_collectors.end(),
const std::string listInGroup = "--listingroup=";
const std::string allowChildLogs = "--allowchildlogs";
const std::string onlyFromXML = "--only-from-xml=";
+ const std::string timeout = "--timeout=";
if (currentCollector) {
if (currentCollector->ParseCollectorSpecificArg(arg)) {
} else if (arg.find(allowChildLogs) == 0) {
arg.erase(0, allowChildLogs.length());
m_allowChildLogs = true;
+ } else if (arg.find(timeout) == 0) {
+ arg.erase(0, timeout.length());
+ try {
+ m_pipeTimeout = std::stoi(arg);
+ } catch (std::invalid_argument const &ex) {
+ InvalidArgs("Timeout is not a valid number\n");
+ Usage();
+ return -1;
+ } catch (std::out_of_range const &ex) {
+ InvalidArgs("Timeout is out of range\n");
+ Usage();
+ return -1;
+ }
+
+ if (m_pipeTimeout < 0) {
+ InvalidArgs("Timeout cannot be negative\n");
+ Usage();
+ return -1;
+ }
+
} else if (arg == "--help") {
showHelp = true;
} else if (arg.find(output) == 0) {
arg.erase(0, output.length());
if (m_collectors.find(arg) != m_collectors.end()) {
- InvalidArgs(
- "Multiple outputs of the same type are not supported!");
+ InvalidArgs("Multiple outputs of the same type are not supported!");
Usage();
return -1;
}
m_terminate = true;
}
-bool TestRunner::GetAllowChildLogs()
+bool TestRunner::GetAllowChildLogs() const
{
return m_allowChildLogs;
}
return m_runIgnored;
}
+int TestRunner::GetTimeout() const
+{
+ return m_pipeTimeout;
+}
+
void TestRunner::deferFailedException(const DPL::Test::TestFailed &ex)
{
if (m_deferDeepness <= 0)
throw TestFailed("Child creation failed");
}
+ int timeout = TestRunnerSingleton::Instance().GetTimeout();
+
if (pid != 0) {
// parent code
pipe.setUsage(PipeWrapper::READONLY);
std::string message;
PerformanceResultPtr performance;
- int pipeReturn = pipe.receive(code, message, performance, time(0) + 90);
+ int pipeReturn = pipe.receive(code, message, performance, time(0) + timeout);
if (pipeReturn != PipeWrapper::SUCCESS) { // Timeout or reading error
pipe.closeAll();