Add PerformanceResult class
[platform/core/test/security-tests.git] / src / framework / src / test_results_collector_summary.cpp
1 /*
2  * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file        test_results_collector_summary.cpp
18  * @author      Marcin Niesluchowski (m.niesluchow@samsung.com)
19  * @author      Michal Witanowski (m.witanowski@samsung.com)
20  * @version     1.0
21  * @brief       Source file containing SummaryCollector class definition.
22  */
23
24 #include <dpl/availability.h>
25 #include <dpl/log/log.h>
26 #include <dpl/test/test_results_collector_commons.h>
27
28 #include "dpl/test/test_results_collector_summary.h"
29
30 namespace DPL {
31 namespace Test {
32
33 namespace {
34
35 const std::string DEFAULT_SUMMARY_FILE_NAME = "summary.txt";
36
37 }
38
39 SummaryCollector::SummaryCollector()
40     : m_filename(DEFAULT_SUMMARY_FILE_NAME)
41 {
42 }
43
44 TestResultsCollectorBase* SummaryCollector::Constructor()
45 {
46     return new SummaryCollector();
47 }
48
49 std::string SummaryCollector::CollectorSpecificHelp() const
50 {
51     return CollectorFileHelp(DEFAULT_SUMMARY_FILE_NAME);
52 }
53
54 bool SummaryCollector::ParseCollectorSpecificArg(const std::string& arg)
55 {
56     return ParseCollectorFileArg(arg, m_filename);
57 }
58
59 void SummaryCollector::Start()
60 {
61     writeStats(true);
62 }
63
64 void SummaryCollector::CollectResult(const std::string& id,
65                                      const FailStatus status,
66                                      const std::string& reason,
67                                      const ConstPerformanceResultPtr &performanceResult)
68 {
69     DPL_UNUSED_PARAM(id);
70     DPL_UNUSED_PARAM(reason);
71     DPL_UNUSED_PARAM(performanceResult);
72
73     m_stats.AddTest(status);
74     writeStats(true);
75 }
76
77 void SummaryCollector::Finish()
78 {
79     writeStats(false);
80 }
81
82 void SummaryCollector::writeStats(bool segfault)
83 {
84     m_output.open(m_filename.c_str(), std::ofstream::out | std::ofstream::trunc);
85     if (!m_output) {
86         LogPedantic("Could not open file " << m_filename << " for writing");
87         return;
88     }
89     m_output << m_stats.GetTotal() << ' '
90              << m_stats.GetPassed() << ' '
91              << m_stats.GetFailed() << ' '
92              << m_stats.GetIgnored() << (segfault ? " segfault" : "");
93     if (!m_output)
94         LogPedantic("Writing to " << m_filename << " file failed");
95     m_output.close();
96     if (!m_output)
97         LogPedantic("Failed to close " << m_filename << " file");
98 }
99
100 } // namespace Test
101 } // namespace DPL