Merge branch 'cynara' into tizen 38/37338/1
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Tue, 24 Mar 2015 19:32:02 +0000 (20:32 +0100)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Tue, 24 Mar 2015 19:55:06 +0000 (20:55 +0100)
Conflicts:
src/framework/include/dpl/test/test_runner.h
src/framework/src/test_runner.cpp

Change-Id: I7186c1d1e8f60e453ea5ffe4f7cfd1e1eca3a3bb

20 files changed:
src/framework/include/dpl/test/performance_result.h [new file with mode: 0644]
src/framework/include/dpl/test/statistic.h
src/framework/include/dpl/test/test_result.h [new file with mode: 0644]
src/framework/include/dpl/test/test_results_collector.h
src/framework/include/dpl/test/test_results_collector_commons.h
src/framework/include/dpl/test/test_results_collector_console.h
src/framework/include/dpl/test/test_results_collector_html.h
src/framework/include/dpl/test/test_results_collector_summary.h
src/framework/include/dpl/test/test_results_collector_xml.h
src/framework/include/dpl/test/test_runner.h
src/framework/include/dpl/test/test_runner_child.h
src/framework/src/test_results_collector_commons.cpp
src/framework/src/test_results_collector_console.cpp
src/framework/src/test_results_collector_html.cpp
src/framework/src/test_results_collector_summary.cpp
src/framework/src/test_results_collector_xml.cpp
src/framework/src/test_runner.cpp
src/framework/src/test_runner_child.cpp
src/security-tests-all.sh
src/security-tests.sh

diff --git a/src/framework/include/dpl/test/performance_result.h b/src/framework/include/dpl/test/performance_result.h
new file mode 100644 (file)
index 0000000..f15c0da
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * 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
index fe550bd..4990ffd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -27,7 +27,7 @@
 #include <cstddef>
 
 #include <dpl/assert.h>
-#include <dpl/test/test_results_collector.h>
+#include <dpl/test/test_result.h>
 
 namespace DPL {
 namespace Test {
@@ -42,15 +42,15 @@ class Statistic
         m_count(0)
     {}
 
-    void AddTest(TestResultsCollectorBase::FailStatus status)
+    void AddTest(TestResult::FailStatus status)
     {
         ++m_count;
         switch (status) {
-        case TestResultsCollectorBase::FailStatus::FAILED:   ++m_failed;
+        case TestResult::FailStatus::FAILED:   ++m_failed;
             break;
-        case TestResultsCollectorBase::FailStatus::IGNORED:  ++m_ignored;
+        case TestResult::FailStatus::IGNORED:  ++m_ignored;
             break;
-        case TestResultsCollectorBase::FailStatus::NONE:     ++m_passed;
+        case TestResult::FailStatus::NONE:     ++m_passed;
             break;
         default:
             Assert(false && "Bad FailStatus");
diff --git a/src/framework/include/dpl/test/test_result.h b/src/framework/include/dpl/test/test_result.h
new file mode 100644 (file)
index 0000000..e2810d6
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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        test_result.h
+ * @author      Marcin Niesluchowski (m.niesluchow@samsung.com)
+ * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version     1.0
+ * @brief       Header file with declaration of TestResult class
+ */
+
+#ifndef DPL_TEST_RESULT_H
+#define DPL_TEST_RESULT_H
+
+#include <dpl/test/performance_result.h>
+
+#include <string>
+
+namespace DPL {
+namespace Test {
+
+class TestResult
+{
+public:
+    enum class FailStatus
+    {
+        NONE,
+        FAILED,
+        IGNORED
+    };
+
+    TestResult(FailStatus status,
+               const std::string& reason = std::string(),
+               ConstPerformanceResultPtr performanceResult = nullptr)
+        : m_failStatus(status)
+        , m_reason(reason)
+        , m_performanceResult(performanceResult) {}
+
+    FailStatus GetFailStatus() const {
+        return m_failStatus;
+    }
+
+    const std::string& GetReason() const {
+        return m_reason;
+    }
+
+    ConstPerformanceResultPtr GetPerformanceResult() const {
+        return m_performanceResult;
+    }
+
+private:
+    const FailStatus m_failStatus;
+    const std::string m_reason;
+    ConstPerformanceResultPtr m_performanceResult;
+};
+
+} // namespace Test
+} // namespace DPL
+
+#endif // DPL_TEST_RESULT_H
index cfd9227..60a926f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -15,6 +15,7 @@
  */
 /*
  * @file        test_results_collector.h
+ * @author      Marcin Niesluchowski (m.niesluchow@samsung.com)
  * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
  * @version     1.0
  * @brief       Header file with declaration of TestResultsCollectorBase
 #define DPL_TEST_RESULTS_COLLECTOR_H
 
 #include <dpl/noncopyable.h>
+#include <dpl/test/test_result.h>
+
 #include <vector>
 #include <list>
 #include <map>
-#include <chrono>
 #include <string>
 #include <memory>
 
@@ -43,12 +45,6 @@ class TestResultsCollectorBase :
   public:
     typedef TestResultsCollectorBase* (*CollectorConstructorFunc)();
     typedef std::list<std::string> TestCaseIdList;
-    enum class FailStatus
-    {
-        NONE,
-        FAILED,
-        IGNORED
-    };
 
     virtual ~TestResultsCollectorBase() {}
 
@@ -61,13 +57,7 @@ class TestResultsCollectorBase :
     virtual void CollectCurrentTestGroupName(const std::string& /*groupName*/)
     {}
 
-    virtual void CollectTestsCasesList(const TestCaseIdList& /*list*/) {}
-    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;
+    virtual void CollectResult(const std::string& id, const TestResult &result) = 0;
     virtual std::string CollectorSpecificHelp() const
     {
         return "";
index 6961f4e..8fc98c1 100644 (file)
@@ -41,10 +41,14 @@ namespace Test {
     "[%s%s%s] %s[elapsed: %0.3fms, expected < %0.3fms]%s\n", BOLD_GREEN_BEGIN, \
     "   OK   ", BOLD_GREEN_END, BOLD_RED_BEGIN, elapsed, max, BOLD_RED_END
 
+extern const std::string COLLECTOR_NO_VERBOSE_HELP;
+
 // Get duration as a fraction of millisecond (max precision is 1 microsecond)
 double get_milliseconds (const std::chrono::system_clock::duration& performanceTime);
 
+std::string CollectorFileHelp(const std::string &defaultFilename);
 bool ParseCollectorFileArg(const std::string &arg, std::string &filename);
+bool ParseCollectorNoVerboseArg(const std::string &arg, bool &verbosity);
 
 } // namespace Test
 } // namespace DPL
index 332763b..8f43d75 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -40,28 +40,20 @@ public:
 private:
     ConsoleCollector();
 
+    virtual bool ParseCollectorSpecificArg(const std::string& arg);
+    virtual std::string CollectorSpecificHelp() const;
     virtual void CollectCurrentTestGroupName(const std::string& name);
-    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());
+    virtual void CollectResult(const std::string& id, const TestResult &result);
     virtual void Finish();
 
-    void PrintfErrorMessage(const char* type,
-                            const std::string& message,
-                            bool verbosity);
-    void PrintfIgnoredMessage(const char* type,
-                              const std::string& message,
-                              bool verbosity);
+    void PrintfErrorMessage(const char* type, const std::string& message);
+    void PrintfIgnoredMessage(const char* type, const std::string& message);
     void PrintStats(const std::string& title, const Statistic& stats);
 
     Statistic m_stats;
     std::map<std::string, Statistic> m_groupsStats;
     std::string m_currentGroup;
+    bool m_verbosity;
 };
 
 } // namespace Test
index 90d635e..122d3f9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -46,22 +46,11 @@ private:
     virtual bool Configure();
     virtual void Start();
     virtual void CollectCurrentTestGroupName(const std::string& name);
-    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());
+    virtual void CollectResult(const std::string& id, const TestResult &result);
     virtual void Finish();
 
-    void PrintfErrorMessage(const char* type,
-                            const std::string& message,
-                            bool verbosity);
-    void PrintfIgnoredMessage(const char* type,
-                              const std::string& message,
-                              bool verbosity);
+    void PrintfErrorMessage(const char* type, const std::string& message);
+    void PrintfIgnoredMessage(const char* type, const std::string& message);
     void PrintStats(const std::string& name, const Statistic& stats);
 
     std::string m_filename;
@@ -69,6 +58,7 @@ private:
     Statistic m_stats;
     std::string m_currentGroup;
     std::map<std::string, Statistic> m_groupsStats;
+    bool m_verbosity;
 };
 
 } // namespace Test
index f0edfcc..8f83a71 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -45,14 +45,7 @@ private:
     virtual std::string CollectorSpecificHelp() const;
     virtual bool ParseCollectorSpecificArg(const std::string& arg);
     virtual void Start();
-    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());
+    virtual void CollectResult(const std::string& id, const TestResult &result);
     virtual void Finish();
 
     void writeStats(bool segfault);
index 01b9802..60e8aca 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -44,14 +44,7 @@ private:
     virtual bool Configure();
     virtual void Start();
     virtual void CollectCurrentTestGroupName(const std::string& name);
-    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());
+    virtual void CollectResult(const std::string& id, const TestResult &result);
     virtual void Finish();
 
     void GroupStart(const std::size_t pos, const std::string& name);
@@ -65,12 +58,8 @@ private:
                                 const std::string& value);
     std::string UIntToString(const unsigned int value);
     void GroupFinish(const std::size_t groupPosition);
-    void PrintfErrorMessage(const char* type,
-                            const std::string& message,
-                            bool verbosity);
-    void PrintfIgnoredMessage(const char* type,
-                              const std::string& message,
-                              bool verbosity);
+    void PrintfErrorMessage(const char* type, const std::string& message);
+    void PrintfIgnoredMessage(const char* type, const std::string& message);
     void FlushOutput();
     std::string EscapeSpecialCharacters(std::string s);
 
@@ -79,6 +68,7 @@ private:
     Statistic m_stats;
     std::string m_outputBuffer;
     std::string m_resultBuffer;
+    bool m_verbosity;
 };
 
 } // namespace Test
index 53764bf..9da89df 100644 (file)
 #include <dpl/colors.h>
 #include <dpl/gdbbacktrace.h>
 #include <dpl/singleton.h>
+#include <dpl/test/performance_result.h>
 #include <dpl/test/test_exception.h>
 #include <dpl/test/test_failed.h>
 #include <dpl/test/test_ignored.h>
+#include <dpl/test/test_result.h>
 #include <dpl/test/test_results_collector.h>
 
 namespace DPL {
@@ -69,14 +71,10 @@ class TestRunner
       , m_firstDeferredExceptionType(DeferredExceptionType::DEFERRED_FAILED)
     {}
 
-    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);
 
@@ -87,11 +85,7 @@ class TestRunner
     {
         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
         {
@@ -105,8 +99,7 @@ class TestRunner
 
         TestCaseStruct(const std::string &n, TestCase p) :
             name(n),
-            proc(p),
-            m_isPerformanceTest(false)
+            proc(p)
         {}
     };
 
@@ -138,9 +131,7 @@ class TestRunner
     bool filterByXML(std::map<std::string, bool> & casesMap);
     void normalizeXMLTag(std::string& str, const std::string& testcase);
 
-    enum Status { FAILED, IGNORED, PASS };
-
-    Status RunTestCase(const TestCaseStruct& testCase);
+    void RunTestCase(const TestCaseStruct& testCase);
 
     void setCurrentTestCase(TestCaseStruct* testCase);
     TestCaseStruct *getCurrentTestCase();
@@ -149,13 +140,7 @@ class TestRunner
 
     std::string getConcatedFailReason(const std::string &reason);
 
-    void CollectResult(const std::string& id,
-                       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());
+    void CollectResult(const std::string& id, const TestResult &result);
 
   public:
     void MarkAssertion();
@@ -305,13 +290,13 @@ typedef DPL::Singleton<TestRunner> TestRunnerSingleton;
 
 #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)
 
 /**
index d1e4b1c..8c52600 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -50,15 +50,11 @@ class PipeWrapper : DPL::Noncopyable
     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();
@@ -66,7 +62,6 @@ class PipeWrapper : DPL::Noncopyable
   protected:
 
     std::string toBinaryString(int data);
-    std::string toBinaryString(std::chrono::system_clock::duration data);
 
     void closeHelp(int desc);
 
index e821f16..013bde2 100644 (file)
 namespace DPL {
 namespace Test {
 
+namespace {
+
+const std::string NO_VERBOSE_ARG = "--no-verbose";
+
+} // namespace
+
+const std::string COLLECTOR_NO_VERBOSE_HELP =
+        NO_VERBOSE_ARG                          + " - turns off verbosity\n" +
+        std::string(NO_VERBOSE_ARG.size(), ' ') + "   verbosity turned on by default\n";
+
 double get_milliseconds (const std::chrono::system_clock::duration& performanceTime)
 {
     return (static_cast<double>(std::chrono::duration_cast<std::chrono::microseconds>
             (performanceTime).count()))/1000.0;
 }
 
+std::string CollectorFileHelp(const std::string &defaultFilename)
+{
+    return "--file=<filename> - name of file for output\n"
+           "                    default - " + defaultFilename + "\n";
+}
+
 bool ParseCollectorFileArg(const std::string &arg, std::string &filename)
 {
     const std::string argname = "--file=";
@@ -43,6 +59,14 @@ bool ParseCollectorFileArg(const std::string &arg, std::string &filename)
     return false;
 }
 
+bool ParseCollectorNoVerboseArg(const std::string &arg, bool &verbosity)
+{
+    if (arg != NO_VERBOSE_ARG)
+        return false;
+    verbosity=false;
+    return true;
+}
+
 } // namespace Test
 } // namespace DPL
 
index 09030a8..dab84f8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -34,6 +34,7 @@ namespace DPL {
 namespace Test {
 
 ConsoleCollector::ConsoleCollector()
+    : m_verbosity(true)
 {
 }
 
@@ -42,6 +43,16 @@ TestResultsCollectorBase* ConsoleCollector::Constructor()
     return new ConsoleCollector();
 }
 
+bool ConsoleCollector::ParseCollectorSpecificArg(const std::string& arg)
+{
+    return ParseCollectorNoVerboseArg(arg, m_verbosity);
+}
+
+std::string ConsoleCollector::CollectorSpecificHelp() const
+{
+    return COLLECTOR_NO_VERBOSE_HELP;
+}
+
 void ConsoleCollector::CollectCurrentTestGroupName(const std::string& name)
 {
     printf("Starting group %s\n", name.c_str());
@@ -59,92 +70,79 @@ void ConsoleCollector::Finish()
     PrintStats("All tests together", m_stats);
 }
 
-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)
+void ConsoleCollector::CollectResult(const std::string& id, const TestResult &result)
 {
     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;
-            }
+
+    ConstPerformanceResultPtr performanceResult;
+    switch (result.GetFailStatus()) {
+    case TestResult::FailStatus::NONE:
+        performanceResult = result.GetPerformanceResult();
+        if (!performanceResult) {
+            printf(GREEN_RESULT_OK);
+            break;
+        }
+        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);
+        printf(GREEN_RESULT_OK_TIME_MAX(
+                   get_milliseconds(performanceResult->GetDuration()),
+                   get_milliseconds(performanceResult->GetMaxDuration())));
         break;
-    case FailStatus::FAILED:
-        PrintfErrorMessage(" FAILED ", reason, true);
+    case TestResult::FailStatus::FAILED:
+        PrintfErrorMessage(" FAILED ", result.GetReason());
         break;
-    case FailStatus::IGNORED:
-        PrintfIgnoredMessage("Ignored ", reason, true);
+    case TestResult::FailStatus::IGNORED:
+        PrintfIgnoredMessage("Ignored ", result.GetReason());
         break;
     default:
         Assert(false && "Bad status");
     }
-    m_stats.AddTest(status);
-    m_groupsStats[m_currentGroup].AddTest(status);
+    m_stats.AddTest(result.GetFailStatus());
+    m_groupsStats[m_currentGroup].AddTest(result.GetFailStatus());
 }
 
-void ConsoleCollector::PrintfErrorMessage(const char* type,
-                                          const std::string& message,
-                                          bool verbosity)
+void ConsoleCollector::PrintfErrorMessage(const char* type, const std::string& message)
 {
     using namespace DPL::Colors::Text;
-    if (verbosity) {
-        printf("[%s%s%s] %s%s%s\n",
-               BOLD_RED_BEGIN,
-               type,
-               BOLD_RED_END,
+    printf("[%s%s%s]",
+           BOLD_RED_BEGIN,
+           type,
+           BOLD_RED_END);
+    if (m_verbosity) {
+        printf(" %s%s%s",
                BOLD_YELLOW_BEGIN,
                message.c_str(),
                BOLD_YELLOW_END);
-    } else {
-        printf("[%s%s%s]\n",
-               BOLD_RED_BEGIN,
-               type,
-               BOLD_RED_END);
     }
+    printf("\n");
 }
 
-void ConsoleCollector::PrintfIgnoredMessage(const char* type,
-                                            const std::string& message,
-                                            bool verbosity)
+void ConsoleCollector::PrintfIgnoredMessage(const char* type, const std::string& message)
 {
     using namespace DPL::Colors::Text;
-    if (verbosity) {
-        printf("[%s%s%s] %s%s%s\n",
-               CYAN_BEGIN,
-               type,
-               CYAN_END,
+    printf("[%s%s%s]",
+           CYAN_BEGIN,
+           type,
+           CYAN_END);
+    if (m_verbosity) {
+        printf(" %s%s%s",
                BOLD_GOLD_BEGIN,
                message.c_str(),
                BOLD_GOLD_END);
-    } else {
-        printf("[%s%s%s]\n",
-               CYAN_BEGIN,
-               type,
-               CYAN_END);
     }
+    printf("\n");
 }
 
 void ConsoleCollector::PrintStats(const std::string& title, const Statistic& stats)
index 93698cc..86fce37 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -39,7 +39,8 @@ const char *DEFAULT_HTML_FILE_NAME = "index.html";
 }
 
 HtmlCollector::HtmlCollector()
-    : m_filename(DEFAULT_HTML_FILE_NAME)
+    : m_filename(DEFAULT_HTML_FILE_NAME),
+      m_verbosity(true)
 {
 }
 
@@ -66,8 +67,7 @@ bool HtmlCollector::Configure()
 
 std::string HtmlCollector::CollectorSpecificHelp() const
 {
-    return "--file=<filename> - name of file for output\n"
-           "                    default - index.html\n";
+    return CollectorFileHelp(DEFAULT_HTML_FILE_NAME) + COLLECTOR_NO_VERBOSE_HELP;
 }
 
 void HtmlCollector::Start()
@@ -102,99 +102,87 @@ void HtmlCollector::Finish()
 
 bool HtmlCollector::ParseCollectorSpecificArg(const std::string& arg)
 {
-    return ParseCollectorFileArg(arg, m_filename);
+    return ParseCollectorFileArg(arg, m_filename) || ParseCollectorNoVerboseArg(arg, m_verbosity);
 }
 
-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)
+void HtmlCollector::CollectResult(const std::string& id, const TestResult &result)
 {
     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;
-            }
+
+    ConstPerformanceResultPtr performanceResult;
+    switch (result.GetFailStatus()) {
+    case TestResult::FailStatus::NONE:
+        performanceResult = result.GetPerformanceResult();
+        if (!performanceResult) {
+            fprintf(m_fp.Get(), GREEN_RESULT_OK);
+            break;
+        }
+        if (!performanceResult->IsMaxDuration()) {
+            fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME,
+                    get_milliseconds(performanceResult->GetDuration()));
+            break;
         }
-        fprintf(m_fp.Get(), GREEN_RESULT_OK);
+        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, true);
+    case TestResult::FailStatus::FAILED:
+        PrintfErrorMessage(" FAILED ", result.GetReason());
         break;
-    case FailStatus::IGNORED:
-        PrintfIgnoredMessage("Ignored ", reason, true);
+    case TestResult::FailStatus::IGNORED:
+        PrintfIgnoredMessage("Ignored ", result.GetReason());
         break;
     default:
         Assert(false && "Bad status");
     }
-    m_groupsStats[m_currentGroup].AddTest(status);
-    m_stats.AddTest(status);
+    m_groupsStats[m_currentGroup].AddTest(result.GetFailStatus());
+    m_stats.AddTest(result.GetFailStatus());
 }
 
-void HtmlCollector::PrintfErrorMessage(const char* type,
-                                       const std::string& message,
-                                       bool verbosity)
+void HtmlCollector::PrintfErrorMessage(const char* type, const std::string& message)
 {
     using namespace DPL::Colors::Html;
-    if (verbosity) {
+    fprintf(m_fp.Get(),
+            "[%s%s%s]",
+            BOLD_RED_BEGIN,
+            type,
+            BOLD_RED_END);
+    if (m_verbosity) {
         fprintf(m_fp.Get(),
-                "[%s%s%s] %s%s%s\n",
-                BOLD_RED_BEGIN,
-                type,
-                BOLD_RED_END,
+                " %s%s%s",
                 BOLD_YELLOW_BEGIN,
                 message.c_str(),
                 BOLD_YELLOW_END);
-    } else {
-        fprintf(m_fp.Get(),
-                "[%s%s%s]\n",
-                BOLD_RED_BEGIN,
-                type,
-                BOLD_RED_END);
     }
+    fprintf(m_fp.Get(), "\n");
 }
 
-void HtmlCollector::PrintfIgnoredMessage(const char* type,
-                                         const std::string& message,
-                                         bool verbosity)
+void HtmlCollector::PrintfIgnoredMessage(const char* type, const std::string& message)
 {
     using namespace DPL::Colors::Html;
 
-    if (verbosity) {
+    fprintf(m_fp.Get(),
+            "[%s%s%s]",
+            CYAN_BEGIN,
+            type,
+            CYAN_END);
+    if (m_verbosity) {
         fprintf(m_fp.Get(),
-                "[%s%s%s] %s%s%s\n",
-                CYAN_BEGIN,
-                type,
-                CYAN_END,
+                " %s%s%s",
                 BOLD_GOLD_BEGIN,
                 message.c_str(),
                 BOLD_GOLD_END);
-    } else {
-        fprintf(m_fp.Get(),
-                "[%s%s%s]\n",
-                CYAN_BEGIN,
-                type,
-                CYAN_END);
     }
+    fprintf(m_fp.Get(), "\n");
 }
 
 void HtmlCollector::PrintStats(const std::string& name, const Statistic& stats)
index 74cb680..efcaa31 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -48,8 +48,7 @@ TestResultsCollectorBase* SummaryCollector::Constructor()
 
 std::string SummaryCollector::CollectorSpecificHelp() const
 {
-    return "--file=<filename> - name of file for output\n"
-           "                    default - " + DEFAULT_SUMMARY_FILE_NAME + "\n";
+    return CollectorFileHelp(DEFAULT_SUMMARY_FILE_NAME);
 }
 
 bool SummaryCollector::ParseCollectorSpecificArg(const std::string& arg)
@@ -62,20 +61,11 @@ void SummaryCollector::Start()
     writeStats(true);
 }
 
-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)
+void SummaryCollector::CollectResult(const std::string& id, const TestResult &result)
 {
     DPL_UNUSED_PARAM(id);
-    DPL_UNUSED_PARAM(reason);
-    DPL_UNUSED_PARAM(isPerformanceTest);
-    DPL_UNUSED_PARAM(performanceTime);
-    DPL_UNUSED_PARAM(performanceMaxTime);
 
-    m_stats.AddTest(status);
+    m_stats.AddTest(result.GetFailStatus());
     writeStats(true);
 }
 
index 7eea2b7..6ad2fce 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -42,7 +42,7 @@ const char *DEFAULT_XML_FILE_NAME = "results.xml";
 }
 
 XmlCollector::XmlCollector()
-    : m_filename(DEFAULT_XML_FILE_NAME)
+    : m_filename(DEFAULT_XML_FILE_NAME), m_verbosity(true)
 {
 }
 
@@ -99,8 +99,7 @@ bool XmlCollector::Configure()
 
 std::string XmlCollector::CollectorSpecificHelp() const
 {
-    return "--file=<filename> - name of file for output\n"
-           "                    default - results.xml\n";
+    return CollectorFileHelp(DEFAULT_XML_FILE_NAME) + COLLECTOR_NO_VERBOSE_HELP;
 }
 
 void XmlCollector::Start()
@@ -122,54 +121,49 @@ void XmlCollector::Finish()
 
 bool XmlCollector::ParseCollectorSpecificArg(const std::string& arg)
 {
-    return ParseCollectorFileArg(arg, m_filename);
+    return ParseCollectorFileArg(arg, m_filename) || ParseCollectorNoVerboseArg(arg, m_verbosity);
 }
 
-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)
+void XmlCollector::CollectResult(const std::string& id, const TestResult &result)
 {
     m_resultBuffer.erase();
     m_resultBuffer.append("\t\t<testcase name=\"");
     m_resultBuffer.append(EscapeSpecialCharacters(id));
     m_resultBuffer.append("\"");
-    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;
-            }
+
+    std::ostringstream ostr;
+    ConstPerformanceResultPtr performanceResult;
+    switch (result.GetFailStatus()) {
+    case TestResult::FailStatus::NONE:
+        performanceResult = result.GetPerformanceResult();
+        if (!performanceResult) {
+            m_resultBuffer.append(" status=\"OK\"/>\n");
+            break;
         }
-        m_resultBuffer.append(" status=\"OK\"/>\n");
+        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\" 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:
+    case TestResult::FailStatus::FAILED:
         m_resultBuffer.append(" status=\"FAILED\">\n");
-        PrintfErrorMessage("FAILED", EscapeSpecialCharacters(reason), true);
+        PrintfErrorMessage("FAILED", EscapeSpecialCharacters(result.GetReason()));
         m_resultBuffer.append("\t\t</testcase>\n");
         break;
-    case FailStatus::IGNORED:
+    case TestResult::FailStatus::IGNORED:
         m_resultBuffer.append(" status=\"Ignored\">\n");
-        PrintfIgnoredMessage("Ignored", EscapeSpecialCharacters(
-                                 reason), true);
+        PrintfIgnoredMessage("Ignored", EscapeSpecialCharacters(result.GetReason()));
         m_resultBuffer.append("\t\t</testcase>\n");
         break;
     default:
@@ -188,7 +182,7 @@ void XmlCollector::CollectResult(const std::string& id,
     }
     m_outputBuffer.insert(last_case_pos - 2, m_resultBuffer);
 
-    m_stats.AddTest(status);
+    m_stats.AddTest(result.GetFailStatus());
 
     UpdateGroupHeader(group_pos,
                       m_stats.GetTotal() + 1, // include SegFault
@@ -300,38 +294,26 @@ void XmlCollector::FlushOutput()
     }
 }
 
-void XmlCollector::PrintfErrorMessage(const char* type,
-                                      const std::string& message,
-                                      bool verbosity)
+void XmlCollector::PrintfErrorMessage(const char* type, const std::string& message)
 {
-    if (verbosity) {
-        m_resultBuffer.append("\t\t\t<failure type=\"");
-        m_resultBuffer.append(EscapeSpecialCharacters(type));
+    m_resultBuffer.append("\t\t\t<failure type=\"");
+    m_resultBuffer.append(EscapeSpecialCharacters(type));
+    if (m_verbosity) {
         m_resultBuffer.append("\" message=\"");
         m_resultBuffer.append(EscapeSpecialCharacters(message));
-        m_resultBuffer.append("\"/>\n");
-    } else {
-        m_resultBuffer.append("\t\t\t<failure type=\"");
-        m_resultBuffer.append(EscapeSpecialCharacters(type));
-        m_resultBuffer.append("\"/>\n");
     }
+    m_resultBuffer.append("\"/>\n");
 }
 
-void XmlCollector::PrintfIgnoredMessage(const char* type,
-                                        const std::string& message,
-                                        bool verbosity)
+void XmlCollector::PrintfIgnoredMessage(const char* type, const std::string& message)
 {
-    if (verbosity) {
-        m_resultBuffer.append("\t\t\t<skipped type=\"");
-        m_resultBuffer.append(EscapeSpecialCharacters(type));
+    m_resultBuffer.append("\t\t\t<skipped type=\"");
+    m_resultBuffer.append(EscapeSpecialCharacters(type));
+    if (m_verbosity) {
         m_resultBuffer.append("\" message=\"");
         m_resultBuffer.append(EscapeSpecialCharacters(message));
-        m_resultBuffer.append("\"/>\n");
-    } else {
-        m_resultBuffer.append("\t\t\t<skipped type=\"");
-        m_resultBuffer.append(EscapeSpecialCharacters(type));
-        m_resultBuffer.append("\"/>\n");
     }
+    m_resultBuffer.append("\"/>\n");
 }
 
 std::string XmlCollector::EscapeSpecialCharacters(std::string s)
index 0b4099c..726d434 100644 (file)
@@ -206,7 +206,7 @@ bool TestRunner::filterByXML(std::map<std::string, bool> & casesMap)
     return true;
 }
 
-TestRunner::Status TestRunner::RunTestCase(const TestCaseStruct& testCase)
+void TestRunner::RunTestCase(const TestCaseStruct& testCase)
 {
     setCurrentTestCase(&(const_cast<TestCaseStruct &>(testCase)));
     m_deferDeepness = 0U;
@@ -215,49 +215,41 @@ TestRunner::Status TestRunner::RunTestCase(const TestCaseStruct& testCase)
     } catch (const TestFailed &e) {
         // Simple test failure
         CollectResult(testCase.name,
-                      TestResultsCollectorBase::FailStatus::FAILED,
-                      getConcatedFailReason(e.GetMessage()));
+                      TestResult(TestResult::FailStatus::FAILED,
+                                 getConcatedFailReason(e.GetMessage())));
 
         setCurrentTestCase(nullptr);
-        return FAILED;
+        return;
     } catch (const TestIgnored &e) {
         if (m_runIgnored) {
             // Simple test have to be implemented
             CollectResult(testCase.name,
-                          TestResultsCollectorBase::FailStatus::IGNORED,
-                          e.GetMessage());
+                          TestResult(TestResult::FailStatus::IGNORED, e.GetMessage()));
         }
 
         setCurrentTestCase(nullptr);
-        return IGNORED;
+        return;
     } catch (const std::exception &) {
         // std exception failure
         CollectResult(testCase.name,
-                      TestResultsCollectorBase::FailStatus::FAILED,
-                      "std exception");
+                      TestResult(TestResult::FailStatus::FAILED, "std exception"));
 
         setCurrentTestCase(nullptr);
-        return FAILED;
+        return;
     } catch (...) {
         // Unknown exception failure
         CollectResult(testCase.name,
-                      TestResultsCollectorBase::FailStatus::FAILED,
-                      "unknown exception");
-
+                      TestResult(TestResult::FailStatus::FAILED, "unknown exception"));
         setCurrentTestCase(nullptr);
-        return FAILED;
+        return;
     }
 
+    // Everything OK
     CollectResult(testCase.name,
-                  TestResultsCollectorBase::FailStatus::NONE,
-                  "",
-                  testCase.m_isPerformanceTest,
-                  testCase.m_performanceTestDurationTime,
-                  testCase.m_performanceMaxTime);
+                  TestResult(TestResult::FailStatus::NONE,
+                             std::string(),
+                             testCase.performance));
     setCurrentTestCase(nullptr);
-
-    // Everything OK
-    return PASS;
 }
 
 void TestRunner::RunTests()
@@ -324,56 +316,41 @@ void TestRunner::setCurrentTestCase(TestCaseStruct* testCase)
     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)
@@ -392,24 +369,13 @@ std::string TestRunner::getConcatedFailReason(const std::string &reason)
     return reason + ret;
 }
 
-void TestRunner::CollectResult(
-    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)
+void TestRunner::CollectResult(const std::string& id, const TestResult& result)
 {
     std::for_each(m_collectors.begin(),
                   m_collectors.end(),
                   [&](const TestResultsCollectors::value_type & collector)
                   {
-                      collector.second->CollectResult(id,
-                                                      status,
-                                                      reason,
-                                                      isPerformanceTest,
-                                                      performanceTestDurationTime,
-                                                      performanceMaxTime);
+                      collector.second->CollectResult(id, result);
                   });
 }
 
index 816316a..e2efb02 100644 (file)
@@ -49,9 +49,6 @@ const int CHILD_TEST_FAIL    = 0;
 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;
@@ -115,7 +112,6 @@ PipeWrapper::Status PipeWrapper::send(int code, std::string &message)
 
     std::ostringstream output;
     output << toBinaryString(code);
-    output << toBinaryString(MSG_TYPE_MESSAGE);
     output << toBinaryString(static_cast<int>(message.size()));
     output << message;
 
@@ -131,21 +127,16 @@ PipeWrapper::Status PipeWrapper::send(int code, std::string &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,
@@ -158,10 +149,8 @@ PipeWrapper::Status PipeWrapper::sendTime(int code,
 }
 
 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) {
@@ -187,24 +176,34 @@ PipeWrapper::Status PipeWrapper::receive(int &code,
         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;
     }
@@ -224,13 +223,6 @@ std::string PipeWrapper::toBinaryString(int data)
     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) {
@@ -313,12 +305,10 @@ void RunChildProc(TestRunner::TestCase procChild)
         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();
@@ -336,11 +326,7 @@ void RunChildProc(TestRunner::TestCase procChild)
             throw 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 TestFailed(message);
@@ -355,9 +341,6 @@ void RunChildProc(TestRunner::TestCase procChild)
 
         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();
 
@@ -385,16 +368,10 @@ void RunChildProc(TestRunner::TestCase procChild)
             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());
         }
     }
 }
index a1fe677..653971a 100644 (file)
@@ -54,7 +54,7 @@ function printSummary
 
 runTest smack
 runTest smack-dbus
-#runTest libprivilege-control
+runTest libprivilege-control
 #runTest ss-clientsmack
 #runTest ss-server
 #runTest ss-password
@@ -62,6 +62,7 @@ runTest smack-dbus
 #runTest ss-stress
 runTest security-manager
 runTest cynara
+runTest ckm
 
 printSummary
 
index db3221c..f99127b 100644 (file)
@@ -88,13 +88,19 @@ case $1 in
     echo
     cynara-test "${@:2}"
     ;;
+"ckm")
+    echo "========================================================================="
+    echo "KEY MANAGER TESTS"
+    echo
+    ckm-tests "${@:2}"
+    ;;
 *)
     echo "Correct using:"
     echo "    security_test.sh <module> <args_for_module>"
     echo
     echo "modules: smack, smack-dbus, libprivilege-control, ss-clientsmack"
     echo "         ss-server, ss-api-speed, ss-password, ss-stress"
-    echo "         ss-privilege, security-manager, cynara"
+    echo "         ss-privilege, security-manager, cynara, ckm"
     ;;
 
 esac