--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file performance_result.h
+ * @author Marcin Niesluchowski (m.niesluchow@samsung.com)
+ * @version 1.0
+ * @brief Header file with declaration of PerformanceResult class
+ */
+
+#ifndef DPL_TEST_PERFORMANCE_RESULT_H
+#define DPL_TEST_PERFORMANCE_RESULT_H
+
+#include <dpl/binary_queue.h>
+
+#include <chrono>
+#include <memory>
+
+namespace DPL {
+namespace Test {
+
+class PerformanceResult;
+
+typedef std::shared_ptr<PerformanceResult> PerformanceResultPtr;
+typedef std::shared_ptr<const PerformanceResult> ConstPerformanceResultPtr;
+
+class PerformanceResult
+{
+public:
+ PerformanceResult(const std::chrono::system_clock::duration& maxDuration)
+ : m_startTime(std::chrono::system_clock::now())
+ , m_duration(std::chrono::microseconds::zero())
+ , m_maxDuration(maxDuration < std::chrono::microseconds::zero()
+ ? std::chrono::microseconds::zero()
+ : maxDuration) {}
+
+ PerformanceResult(BinaryQueue &queue)
+ : m_startTime(std::chrono::system_clock::now())
+ , m_duration(std::chrono::microseconds::zero())
+ , m_maxDuration(std::chrono::microseconds::zero()) {
+ queue.FlattenConsume(const_cast<std::chrono::system_clock::time_point*>(&m_startTime),
+ sizeof(std::chrono::system_clock::time_point));
+ queue.FlattenConsume(const_cast<std::chrono::system_clock::duration*>(&m_duration),
+ sizeof(std::chrono::system_clock::duration));
+ queue.FlattenConsume(const_cast<std::chrono::system_clock::duration*>(&m_maxDuration),
+ sizeof(std::chrono::system_clock::duration));
+ }
+
+ bool IsMaxDuration() const {
+ return m_maxDuration > std::chrono::microseconds::zero();
+ }
+
+ bool IsDurationOk() const {
+ return m_duration <= m_maxDuration;
+ }
+
+ const std::chrono::system_clock::duration &GetDuration() const {
+ return m_duration;
+ }
+
+ const std::chrono::system_clock::duration &GetMaxDuration() const {
+ return m_maxDuration;
+ }
+
+ void Finish() {
+ if (m_duration == std::chrono::microseconds::zero())
+ m_duration = std::chrono::system_clock::now() - m_startTime;
+ }
+
+ const std::string ToBinaryString() const {
+ std::string strStartTime(reinterpret_cast<const char*>(&m_startTime), sizeof(m_startTime));
+ std::string strDuration(reinterpret_cast<const char*>(&m_duration), sizeof(m_duration));
+ std::string strMaxDuration(reinterpret_cast<const char*>(&m_maxDuration),
+ sizeof(m_maxDuration));
+ return strStartTime + strDuration + strMaxDuration;
+ }
+
+private:
+ const std::chrono::system_clock::time_point m_startTime;
+ std::chrono::system_clock::duration m_duration;
+ const std::chrono::system_clock::duration m_maxDuration;
+};
+
+} // namespace Test
+} // namespace DPL
+
+#endif // DPL_TEST_PERFORMANCE_RESULT_H
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#define DPL_TEST_RESULTS_COLLECTOR_H
#include <dpl/noncopyable.h>
+#include <dpl/test/performance_result.h>
+
#include <vector>
#include <list>
#include <map>
-#include <chrono>
#include <string>
#include <memory>
virtual void CollectResult(const std::string& id,
const FailStatus status = FailStatus::NONE,
const std::string& reason = "",
- const bool& isPerformanceTest = false,
- const std::chrono::system_clock::duration& performanceTime = std::chrono::microseconds::zero(),
- const std::chrono::system_clock::duration& performanceMaxTime = std::chrono::microseconds::zero()) = 0;
+ const ConstPerformanceResultPtr &performanceResult = nullptr) = 0;
virtual std::string CollectorSpecificHelp() const
{
return "";
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
virtual void CollectResult(const std::string& id,
const FailStatus status = FailStatus::NONE,
const std::string& reason = "",
- const bool& isPerformanceTest = true,
- const std::chrono::system_clock::duration& performanceTime
- = std::chrono::microseconds::zero(),
- const std::chrono::system_clock::duration& performanceMaxTime
- = std::chrono::microseconds::zero());
+ const ConstPerformanceResultPtr &performanceResult = nullptr);
virtual void Finish();
void PrintfErrorMessage(const char* type, const std::string& message);
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
virtual void CollectResult(const std::string& id,
const FailStatus status = FailStatus::NONE,
const std::string& reason = "",
- const bool& isPerformanceTest = false,
- const std::chrono::system_clock::duration& performanceTime
- = std::chrono::microseconds::zero(),
- const std::chrono::system_clock::duration& performanceMaxTime
- = std::chrono::microseconds::zero());
+ const ConstPerformanceResultPtr &performanceResult = nullptr);
virtual void Finish();
void PrintfErrorMessage(const char* type, const std::string& message);
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
virtual void CollectResult(const std::string& id,
const FailStatus status = FailStatus::NONE,
const std::string& reason = "",
- const bool& isPerformanceTest = false,
- const std::chrono::system_clock::duration& performanceTime
- = std::chrono::microseconds::zero(),
- const std::chrono::system_clock::duration& performanceMaxTime
- = std::chrono::microseconds::zero());
+ const ConstPerformanceResultPtr &performanceResult = nullptr);
virtual void Finish();
void writeStats(bool segfault);
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
virtual void CollectResult(const std::string& id,
const FailStatus status = FailStatus::NONE,
const std::string& reason = "",
- const bool& isPerformanceTest = false,
- const std::chrono::system_clock::duration& performanceTime
- = std::chrono::microseconds::zero(),
- const std::chrono::system_clock::duration& performanceMaxTime
- = std::chrono::microseconds::zero());
+ const ConstPerformanceResultPtr &performanceResult = nullptr);
virtual void Finish();
void GroupStart(const std::size_t pos, const std::string& name);
#include <dpl/colors.h>
#include <dpl/gdbbacktrace.h>
#include <dpl/singleton.h>
+#include <dpl/test/performance_result.h>
#include <dpl/test/test_results_collector.h>
namespace DPL {
, m_allowChildLogs(false)
{}
- void beginPerformanceTestTime(std::chrono::system_clock::duration maxTimeInMicroseconds);
- void endPerformanceTestTime();
- void getCurrentTestCasePerformanceResult(bool& isPerformanceTest,
- std::chrono::system_clock::duration& result,
- std::chrono::system_clock::duration& resultMax);
- void setCurrentTestCasePerformanceResult(bool isPerformanceTest,
- std::chrono::system_clock::duration result,
- std::chrono::system_clock::duration resultMax);
+ void beginPerformance(std::chrono::system_clock::duration maxDurationInMicroseconds);
+ void endPerformance();
+ void setCurrentTestCasePerformanceResult(const PerformanceResultPtr &performance);
+ ConstPerformanceResultPtr getCurrentTestCasePerformanceResult();
void addFailReason(const std::string &reason);
{
std::string name;
TestCase proc;
-
- bool m_isPerformanceTest;
- std::chrono::system_clock::time_point m_performanceTestStartTime;
- std::chrono::system_clock::duration m_performanceTestDurationTime;
- std::chrono::system_clock::duration m_performanceMaxTime;
+ PerformanceResultPtr performance;
bool operator <(const TestCaseStruct &other) const
{
TestCaseStruct(const std::string &n, TestCase p) :
name(n),
- proc(p),
- m_isPerformanceTest(false)
+ proc(p)
{}
};
const TestResultsCollectorBase::FailStatus status
= TestResultsCollectorBase::FailStatus::NONE,
const std::string& reason = std::string(),
- const bool& isPerformanceTest = false,
- const std::chrono::system_clock::duration& performanceTime = std::chrono::microseconds::zero(),
- const std::chrono::system_clock::duration& performanceMaxTime = std::chrono::microseconds::zero());
-
+ const ConstPerformanceResultPtr &performance = nullptr);
public:
class TestFailed
{
#define RUNNER_PERF_TEST_BEGIN(maxTime) \
do { \
- DPL::Test::TestRunnerSingleton::Instance().beginPerformanceTestTime( \
+ DPL::Test::TestRunnerSingleton::Instance().beginPerformance( \
std::chrono::microseconds{static_cast<long long int>(maxTime*1000000.0)}); \
} while (0)
-#define RUNNER_PERF_TEST_END() \
- do { \
- DPL::Test::TestRunnerSingleton::Instance().endPerformanceTestTime(); \
+#define RUNNER_PERF_TEST_END() \
+ do { \
+ DPL::Test::TestRunnerSingleton::Instance().endPerformance(); \
} while (0)
/**
/*
- * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2013-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
virtual ~PipeWrapper();
Status send(int code, std::string &message);
- Status sendTime(int code,
- std::chrono::system_clock::duration time,
- std::chrono::system_clock::duration timeMax);
+ Status sendPerformance(const ConstPerformanceResultPtr &performance);
Status receive(int &code,
- int &msgType,
std::string &data,
- std::chrono::system_clock::duration &time,
- std::chrono::system_clock::duration &timeMax,
+ PerformanceResultPtr &performance,
time_t deadline);
void closeAll();
protected:
std::string toBinaryString(int data);
- std::string toBinaryString(std::chrono::system_clock::duration data);
void closeHelp(int desc);
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void ConsoleCollector::CollectResult(const std::string& id,
const FailStatus status,
const std::string& reason,
- const bool& isPerformanceTest,
- const std::chrono::system_clock::duration& performanceTime,
- const std::chrono::system_clock::duration& performanceMaxTime)
+ const ConstPerformanceResultPtr &performanceResult)
{
using namespace DPL::Colors::Text;
std::string tmp = "'" + id + "' ...";
printf("Running test case %-60s", tmp.c_str());
switch (status) {
case FailStatus::NONE:
- if (isPerformanceTest) {
- if (performanceMaxTime <= std::chrono::microseconds::zero()) {
- printf(GREEN_RESULT_OK_TIME,
- get_milliseconds(performanceTime));
- break;
- }
- else {
- if (performanceTime > performanceMaxTime)
- printf(GREEN_RESULT_OK_TIME_TOO_LONG(
- get_milliseconds(performanceTime),
- get_milliseconds(performanceMaxTime)));
- else
- printf(GREEN_RESULT_OK_TIME_MAX(
- get_milliseconds(performanceTime),
- get_milliseconds(performanceMaxTime)));
- break;
- }
+ if (!performanceResult) {
+ printf(GREEN_RESULT_OK);
+ break;
}
- printf(GREEN_RESULT_OK);
+ if (!performanceResult->IsMaxDuration()) {
+ printf(GREEN_RESULT_OK_TIME,
+ get_milliseconds(performanceResult->GetDuration()));
+ break;
+ }
+ if (!performanceResult->IsDurationOk()) {
+ printf(GREEN_RESULT_OK_TIME_TOO_LONG(
+ get_milliseconds(performanceResult->GetDuration()),
+ get_milliseconds(performanceResult->GetMaxDuration())));
+ break;
+ }
+ printf(GREEN_RESULT_OK_TIME_MAX(
+ get_milliseconds(performanceResult->GetDuration()),
+ get_milliseconds(performanceResult->GetMaxDuration())));
break;
case FailStatus::FAILED:
PrintfErrorMessage(" FAILED ", reason);
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void HtmlCollector::CollectResult(const std::string& id,
const FailStatus status,
const std::string& reason,
- const bool& isPerformanceTest,
- const std::chrono::system_clock::duration& performanceTime,
- const std::chrono::system_clock::duration& performanceMaxTime)
+ const ConstPerformanceResultPtr &performanceResult)
{
using namespace DPL::Colors::Html;
std::string tmp = "'" + id + "' ...";
fprintf(m_fp.Get(), "Running test case %-100s", tmp.c_str());
switch (status) {
case FailStatus::NONE:
- if (isPerformanceTest) {
- if (performanceMaxTime <= std::chrono::microseconds::zero()) {
- fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME,
- get_milliseconds(performanceTime));
- break;
- } else {
- if (performanceTime > performanceMaxTime)
- fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME_TOO_LONG(
- get_milliseconds(performanceTime),
- get_milliseconds(performanceMaxTime)));
- else
- fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME_MAX(
- get_milliseconds(performanceTime),
- get_milliseconds(performanceMaxTime)));
- break;
- }
+ if (!performanceResult) {
+ fprintf(m_fp.Get(), GREEN_RESULT_OK);
+ break;
}
- fprintf(m_fp.Get(), GREEN_RESULT_OK);
+ if (!performanceResult->IsMaxDuration()) {
+ fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME,
+ get_milliseconds(performanceResult->GetDuration()));
+ break;
+ }
+ if (!performanceResult->IsDurationOk()) {
+ fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME_TOO_LONG(
+ get_milliseconds(performanceResult->GetDuration()),
+ get_milliseconds(performanceResult->GetMaxDuration())));
+ break;
+ }
+ fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME_MAX(
+ get_milliseconds(performanceResult->GetDuration()),
+ get_milliseconds(performanceResult->GetMaxDuration())));
break;
case FailStatus::FAILED:
PrintfErrorMessage(" FAILED ", reason);
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void SummaryCollector::CollectResult(const std::string& id,
const FailStatus status,
const std::string& reason,
- const bool& isPerformanceTest,
- const std::chrono::system_clock::duration& performanceTime,
- const std::chrono::system_clock::duration& performanceMaxTime)
+ const ConstPerformanceResultPtr &performanceResult)
{
DPL_UNUSED_PARAM(id);
DPL_UNUSED_PARAM(reason);
- DPL_UNUSED_PARAM(isPerformanceTest);
- DPL_UNUSED_PARAM(performanceTime);
- DPL_UNUSED_PARAM(performanceMaxTime);
+ DPL_UNUSED_PARAM(performanceResult);
m_stats.AddTest(status);
writeStats(true);
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void XmlCollector::CollectResult(const std::string& id,
const FailStatus status,
const std::string& reason,
- const bool& isPerformanceTest,
- const std::chrono::system_clock::duration& performanceTime,
- const std::chrono::system_clock::duration& performanceMaxTime)
+ const ConstPerformanceResultPtr &performanceResult)
{
m_resultBuffer.erase();
m_resultBuffer.append("\t\t<testcase name=\"");
m_resultBuffer.append(EscapeSpecialCharacters(id));
m_resultBuffer.append("\"");
+
+ std::ostringstream ostr;
switch (status) {
case FailStatus::NONE:
- if (isPerformanceTest) {
- if (performanceMaxTime <= std::chrono::microseconds::zero()) {
- m_resultBuffer.append(" status=\"OK\" time=\"");
- std::ostringstream ostr;
- ostr << performanceTime.count();
- m_resultBuffer.append(ostr.str());
- m_resultBuffer.append("\"/>\n");
- break;
- } else {
- m_resultBuffer.append(" status=\"OK\" time=\"");
- std::ostringstream ostr;
- ostr << performanceTime.count();
- m_resultBuffer.append(ostr.str());
- m_resultBuffer.append("\" time_expected=\"");
- ostr.str("");
- ostr << performanceMaxTime.count();
- m_resultBuffer.append(ostr.str());
- m_resultBuffer.append("\"/>\n");
- break;
- }
+ if (!performanceResult) {
+ m_resultBuffer.append(" status=\"OK\"/>\n");
+ break;
+ }
+ if (!performanceResult->IsMaxDuration()) {
+ m_resultBuffer.append(" status=\"OK\" time=\"");
+ ostr << performanceResult->GetDuration().count();
+ m_resultBuffer.append(ostr.str());
+ m_resultBuffer.append("\"/>\n");
+ break;
}
- m_resultBuffer.append(" status=\"OK\"/>\n");
+ m_resultBuffer.append(" status=\"OK\" time=\"");
+ ostr << performanceResult->GetDuration().count();
+ m_resultBuffer.append(ostr.str());
+ m_resultBuffer.append("\" time_expected=\"");
+ ostr.str("");
+ ostr << performanceResult->GetMaxDuration().count();
+ m_resultBuffer.append(ostr.str());
+ m_resultBuffer.append("\"/>\n");
break;
case FailStatus::FAILED:
m_resultBuffer.append(" status=\"FAILED\">\n");
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
CollectResult(testCase.name,
TestResultsCollectorBase::FailStatus::NONE,
- "",
- testCase.m_isPerformanceTest,
- testCase.m_performanceTestDurationTime,
- testCase.m_performanceMaxTime);
+ std::string(),
+ testCase.performance);
setCurrentTestCase(nullptr);
// Everything OK
m_currentTestCase = testCase;
}
-void TestRunner::beginPerformanceTestTime(std::chrono::system_clock::duration maxTimeInMicroseconds)
+void TestRunner::beginPerformance(std::chrono::system_clock::duration maxDurationInMicroseconds)
{
TestCaseStruct* testCase = getCurrentTestCase();
if (!testCase)
return;
- testCase->m_isPerformanceTest = true;
- testCase->m_performanceMaxTime = maxTimeInMicroseconds;
- testCase->m_performanceTestStartTime = std::chrono::system_clock::now();
-
- // Set result to 0 microseconds. Display 0ms result when end macro is missing.
- testCase->m_performanceTestDurationTime = std::chrono::microseconds::zero();
+ if (!testCase->performance)
+ testCase->performance.reset(new PerformanceResult(maxDurationInMicroseconds));
}
-void TestRunner::endPerformanceTestTime()
+void TestRunner::endPerformance()
{
TestCaseStruct* testCase = getCurrentTestCase();
if (!testCase)
return;
- testCase->m_performanceTestDurationTime = std::chrono::system_clock::now() -
- testCase->m_performanceTestStartTime;
+ testCase->performance->Finish();
}
-void TestRunner::getCurrentTestCasePerformanceResult(bool& isPerformanceTest,
- std::chrono::system_clock::duration& result,
- std::chrono::system_clock::duration& resultMax)
+ConstPerformanceResultPtr TestRunner::getCurrentTestCasePerformanceResult()
{
TestCaseStruct* testCase = getCurrentTestCase();
- if (!testCase || !(testCase->m_isPerformanceTest)){
- isPerformanceTest = false;
- return;
- }
+ if (!testCase)
+ return nullptr;
- isPerformanceTest = testCase->m_isPerformanceTest;
- result = testCase->m_performanceTestDurationTime;
- resultMax = testCase->m_performanceMaxTime;
+ return testCase->performance;
}
-void TestRunner::setCurrentTestCasePerformanceResult(bool isPerformanceTest,
- std::chrono::system_clock::duration result,
- std::chrono::system_clock::duration resultMax)
+void TestRunner::setCurrentTestCasePerformanceResult(const PerformanceResultPtr &performance)
{
TestCaseStruct* testCase = getCurrentTestCase();
if (!testCase)
return;
- testCase->m_isPerformanceTest = isPerformanceTest;
- testCase->m_performanceTestDurationTime = result;
- testCase->m_performanceMaxTime = resultMax;
+ testCase->performance = performance;
}
void TestRunner::addFailReason(const std::string &reason)
const std::string& id,
const TestResultsCollectorBase::FailStatus status,
const std::string& reason,
- const bool& isPerformanceTest,
- const std::chrono::system_clock::duration& performanceTestDurationTime,
- const std::chrono::system_clock::duration& performanceMaxTime)
+ const ConstPerformanceResultPtr &performance)
{
std::for_each(m_collectors.begin(),
m_collectors.end(),
collector.second->CollectResult(id,
status,
reason,
- isPerformanceTest,
- performanceTestDurationTime,
- performanceMaxTime);
+ performance);
});
}
/*
- * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2013-2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
const int CHILD_TEST_PASS = 1;
const int CHILD_TEST_IGNORED = 2;
-const int MSG_TYPE_MESSAGE = 0; // sizeof(Message) + Message
-const int MSG_TYPE_PERF_TIME = 1; // perfTime + maxTime
-
int closeOutput() {
int devnull;
int retcode = -1;
std::ostringstream output;
output << toBinaryString(code);
- output << toBinaryString(MSG_TYPE_MESSAGE);
output << toBinaryString(static_cast<int>(message.size()));
output << message;
return SUCCESS;
}
-PipeWrapper::Status PipeWrapper::sendTime(int code,
- std::chrono::system_clock::duration time,
- std::chrono::system_clock::duration timeMax)
+PipeWrapper::Status PipeWrapper::sendPerformance(const ConstPerformanceResultPtr &performance)
{
+ int foo = 0;
if (m_pipefd[1] == PIPE_CLOSED) {
return ERROR;
}
+ if (!performance)
+ return writeHelp(&foo, sizeof(int));
- std::ostringstream output;
- output << toBinaryString(code);
- output << toBinaryString(MSG_TYPE_PERF_TIME);
- output << toBinaryString(time);
- output << toBinaryString(timeMax);
-
- std::string binary = output.str();
+ std::string binary = performance->ToBinaryString();
int size = binary.size();
if ((writeHelp(&size,
}
PipeWrapper::Status PipeWrapper::receive(int &code,
- int &msgType,
std::string &data,
- std::chrono::system_clock::duration &time,
- std::chrono::system_clock::duration &timeMax,
+ PerformanceResultPtr &performance,
time_t deadline)
{
if (m_pipefd[0] == PIPE_CLOSED) {
queue.AppendCopy(&buffer[0], size);
queue.FlattenConsume(&code, sizeof(int));
- queue.FlattenConsume(&msgType, sizeof(int));
-
- switch (msgType) {
- case MSG_TYPE_MESSAGE:
- queue.FlattenConsume(&size, sizeof(int));
-
- buffer.resize(size);
-
- queue.FlattenConsume(&buffer[0], size);
- data.assign(buffer.begin(), buffer.end());
- break;
- case MSG_TYPE_PERF_TIME:
- queue.FlattenConsume(&time, sizeof(std::chrono::system_clock::duration));
- queue.FlattenConsume(&timeMax, sizeof(std::chrono::system_clock::duration));
- break;
- default:
- return ERROR;
+ queue.FlattenConsume(&size, sizeof(int));
+
+ buffer.resize(size);
+
+ queue.FlattenConsume(&buffer[0], size);
+ data.assign(buffer.begin(), buffer.end());
+
+ if (code != CHILD_TEST_PASS)
+ return SUCCESS;
+
+ if ((ret = readHelp(&size, sizeof(int), deadline)) != SUCCESS) {
+ return ret;
+ }
+
+ if (size == 0) {
+ performance = nullptr;
+ return SUCCESS;
+ }
+
+ buffer.resize(size);
+
+ if ((ret = readHelp(buffer.data(), size, deadline)) != SUCCESS) {
+ return ret;
}
+
+ queue.AppendCopy(buffer.data(), size);
+
+ performance.reset(new PerformanceResult(queue));
} catch (DPL::BinaryQueue::Exception::Base &e) {
return ERROR;
}
return std::string(buffer, buffer + sizeof(int));
}
-std::string PipeWrapper::toBinaryString(std::chrono::system_clock::duration data)
-{
- char buffer[sizeof(std::chrono::system_clock::duration)];
- memcpy(buffer, &data, sizeof(std::chrono::system_clock::duration));
- return std::string(buffer, buffer + sizeof(std::chrono::system_clock::duration));
-}
-
void PipeWrapper::closeHelp(int desc)
{
if (m_pipefd[desc] != PIPE_CLOSED) {
pipe.setUsage(PipeWrapper::READONLY);
int code;
- int msgType;
- std::chrono::system_clock::duration time_m;
- std::chrono::system_clock::duration timeMax_m;
std::string message;
+ PerformanceResultPtr performance;
- int pipeReturn = pipe.receive(code, msgType, message, time_m, timeMax_m, time(0) + 10);
+ int pipeReturn = pipe.receive(code, message, performance, time(0) + 10);
if (pipeReturn != PipeWrapper::SUCCESS) { // Timeout or reading error
pipe.closeAll();
throw TestRunner::TestFailed("Reading pipe error");
}
- if (code == CHILD_TEST_PASS && msgType == MSG_TYPE_PERF_TIME) {
- DPL::Test::TestRunnerSingleton::Instance().setCurrentTestCasePerformanceResult(true,
- time_m,
- timeMax_m);
- }
+ TestRunnerSingleton::Instance().setCurrentTestCasePerformanceResult(performance);
if (code == CHILD_TEST_FAIL) {
throw TestRunner::TestFailed(message);
int code = CHILD_TEST_PASS;
std::string msg;
- bool isPerformanceTest;
- std::chrono::system_clock::duration time_m;
- std::chrono::system_clock::duration timeMax_m;
bool allowLogs = TestRunnerSingleton::Instance().GetAllowChildLogs();
closeOutput();
}
- DPL::Test::TestRunnerSingleton::Instance().getCurrentTestCasePerformanceResult(isPerformanceTest,
- time_m,
- timeMax_m);
-
- if (code == CHILD_TEST_PASS && isPerformanceTest){
- pipe.sendTime(code,
- time_m,
- timeMax_m);
- } else {
- pipe.send(code, msg);
+ pipe.send(code, msg);
+ if (code == CHILD_TEST_PASS){
+ pipe.sendPerformance(TestRunnerSingleton::Instance() \
+ .getCurrentTestCasePerformanceResult());
}
}
}