From: Marcin Niesluchowski Date: Mon, 13 Oct 2014 16:39:53 +0000 (+0200) Subject: Move Summary collector to test framework X-Git-Tag: security-manager_5.5_testing~122^2~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fa0f1cefd2f74d875becd497feb402b271ba1ea7;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Move Summary collector to test framework Change-Id: Ief5a3b837382651bd030642c262d3c69c408a4bb --- diff --git a/README b/README index 9caea478..c92cbb28 100644 --- a/README +++ b/README @@ -153,8 +153,8 @@ Collectors are classes which collect test results. Each class does it differentl Collectors can be registered by --output parameter (see HOW TO RUN section) but there is also another collector created to write summary. -tests-common - summary_collector.h +dpl-test-framework + test_results_collector_summary.h SummaryCollector Collector writing tests summary. Call SummaryCollector::Register() to register it diff --git a/tests/common/CMakeLists.txt b/tests/common/CMakeLists.txt index 0fa83054..c595bf72 100644 --- a/tests/common/CMakeLists.txt +++ b/tests/common/CMakeLists.txt @@ -17,7 +17,6 @@ SET(COMMON_TARGET_TEST_SOURCES ${PROJECT_SOURCE_DIR}/tests/common/tests_common.cpp ${PROJECT_SOURCE_DIR}/tests/common/access_provider.cpp ${PROJECT_SOURCE_DIR}/tests/common/smack_access.cpp - ${PROJECT_SOURCE_DIR}/tests/common/summary_collector.cpp ${PROJECT_SOURCE_DIR}/tests/common/dbus_access.cpp ${PROJECT_SOURCE_DIR}/tests/common/memory.cpp ${PROJECT_SOURCE_DIR}/tests/common/db_sqlite.cpp diff --git a/tests/common/summary_collector.cpp b/tests/common/summary_collector.cpp deleted file mode 100644 index 3af81576..00000000 --- a/tests/common/summary_collector.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2014 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 summary_collector.cpp - * @author Michal Witanowski (m.witanowski@samsung.com) - * @version 1.0 - * @brief Implementation of custom test results collector needed by summary view. - */ - -#include -#include - -namespace { - const char* summaryFileName = "/tmp/security-tests-summary-file"; - const char* summaryCollectorName = "summary"; -}; - -SummaryCollector::SummaryCollector() -{ - Start(); -} - - -// Overrides DPL::Test::TestResultsCollectorBase::Start() virtual method. -void SummaryCollector::Start() -{ - m_total = m_succeeded = m_failed = m_ignored = 0; -} - -// append results to the file -void SummaryCollector::Finish() -{ - std::ofstream outputFile; - outputFile.open(summaryFileName, std::ofstream::out | std::ofstream::app); - if (!outputFile) - return; //failed to open file - - outputFile << m_total << ' ' - << m_succeeded << ' ' - << m_failed << ' ' - << m_ignored << std::endl; - outputFile.close(); -} - -void SummaryCollector::CollectResult(const std::string& /*id*/, - const std::string& /*description*/, - 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)isPerformanceTest; - (void)performanceTime; - (void)performanceMaxTime; - switch (status) { - case FailStatus::IGNORED: ++m_ignored; break; - case FailStatus::FAILED: ++m_failed; break; - case FailStatus::NONE: ++m_succeeded; break; - }; - ++m_total; -} - -void SummaryCollector::CollectResult(const std::string& /*id*/, - const std::string& /*description*/, - const FailStatus status, - const std::string& /*reason = ""*/) -{ - switch (status) { - case FailStatus::IGNORED: ++m_ignored; break; - case FailStatus::FAILED: ++m_failed; break; - case FailStatus::NONE: ++m_succeeded; break; - }; - ++m_total; -} - -DPL::Test::TestResultsCollectorBase* SummaryCollector::Constructor() -{ - return new SummaryCollector(); -} - -void SummaryCollector::Register() -{ - //register custom results collector - DPL::Test::TestResultsCollectorBase::RegisterCollectorConstructor(summaryCollectorName, - &SummaryCollector::Constructor); -} diff --git a/tests/common/summary_collector.h b/tests/common/summary_collector.h deleted file mode 100644 index f04b2c28..00000000 --- a/tests/common/summary_collector.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2014 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 summary_collector.h - * @author Michal Witanowski (m.witanowski@samsung.com) - * @version 1.0 - * @brief Implementation of custom test results collector needed by summary view. - */ - -#ifndef _RAW_RESULTS_COLLECTOR_H_ -#define _RAW_RESULTS_COLLECTOR_H_ - -#include -#include - -/* - * Custom test runner results collector. The results (total test cases, failed, etc.) are - * appended to a file, wihich is parsed after execution of all tests in oreder to - * display summary view. - */ -class SummaryCollector : public DPL::Test::TestResultsCollectorBase -{ - unsigned int m_total, m_succeeded, m_failed, m_ignored; // counters - - SummaryCollector(); - void Start(); - void Finish(); - void CollectResult(const std::string& /*id*/, - const std::string& /*description*/, - const FailStatus status, - const std::string& /*reason = ""*/); - void CollectResult(const std::string& /*id*/, - const std::string& /*description*/, - const FailStatus status, - 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()); - -public: - static TestResultsCollectorBase* Constructor(); - static void Register(); -}; - -#endif diff --git a/tests/cynara-tests/cynara-test.cpp b/tests/cynara-tests/cynara-test.cpp index af98c775..2ff40841 100644 --- a/tests/cynara-tests/cynara-test.cpp +++ b/tests/cynara-tests/cynara-test.cpp @@ -15,11 +15,9 @@ */ #include -#include int main (int argc, char *argv[]) { - SummaryCollector::Register(); int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); return status; } diff --git a/tests/framework/config.cmake b/tests/framework/config.cmake index 23352984..a2cb0ffe 100644 --- a/tests/framework/config.cmake +++ b/tests/framework/config.cmake @@ -36,6 +36,7 @@ SET(DPL_FRAMEWORK_TEST_SOURCES ${PROJECT_SOURCE_DIR}/tests/framework/src/test_results_collector_commons.cpp ${PROJECT_SOURCE_DIR}/tests/framework/src/test_results_collector_console.cpp ${PROJECT_SOURCE_DIR}/tests/framework/src/test_results_collector_html.cpp + ${PROJECT_SOURCE_DIR}/tests/framework/src/test_results_collector_summary.cpp ${PROJECT_SOURCE_DIR}/tests/framework/src/test_results_collector_xml.cpp ${PROJECT_SOURCE_DIR}/tests/framework/src/test_runner_child.cpp ${PROJECT_SOURCE_DIR}/tests/framework/src/test_runner.cpp diff --git a/tests/framework/include/dpl/test/test_results_collector_summary.h b/tests/framework/include/dpl/test/test_results_collector_summary.h new file mode 100644 index 00000000..617c17ff --- /dev/null +++ b/tests/framework/include/dpl/test/test_results_collector_summary.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2014 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_results_collector_summary.h + * @author Marcin Niesluchowski (m.niesluchow@samsung.com) + * @author Michal Witanowski (m.witanowski@samsung.com) + * @version 1.0 + * @brief Header file containing SummaryCollector class declaration. + */ + +#ifndef DPL_TEST_RESULTS_COLLECTOR_SUMMARY_H +#define DPL_TEST_RESULTS_COLLECTOR_SUMMARY_H + +#include + +namespace DPL { +namespace Test { + +/* + * Custom test runner results collector. The results (total test cases, failed, etc.) are + * appended to a file, wihich is parsed after execution of all tests in oreder to + * display summary view. + */ +class SummaryCollector : public TestResultsCollectorBase +{ + unsigned int m_total, m_succeeded, m_failed, m_ignored; // counters + + SummaryCollector(); + void Start(); + void Finish(); + void CollectResult(const std::string& /*id*/, + const std::string& /*description*/, + const FailStatus status, + const std::string& /*reason = ""*/); + void CollectResult(const std::string& /*id*/, + const std::string& /*description*/, + const FailStatus status, + 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()); + +public: + static TestResultsCollectorBase* Constructor(); +}; + +} // namespace Test +} // namespace DPL + +#endif // DPL_TEST_RESULTS_COLLECTOR_SUMMARY_H diff --git a/tests/framework/src/test_results_collector.cpp b/tests/framework/src/test_results_collector.cpp index 48cc93b6..a0eb74f0 100644 --- a/tests/framework/src/test_results_collector.cpp +++ b/tests/framework/src/test_results_collector.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace DPL { @@ -73,6 +74,9 @@ int RegisterCollectorConstructors() TestResultsCollectorBase::RegisterCollectorConstructor( "html", &HtmlCollector::Constructor); + TestResultsCollectorBase::RegisterCollectorConstructor( + "summary", + &SummaryCollector::Constructor); TestResultsCollectorBase::RegisterCollectorConstructor( "xml", &XmlCollector::Constructor); diff --git a/tests/framework/src/test_results_collector_summary.cpp b/tests/framework/src/test_results_collector_summary.cpp new file mode 100644 index 00000000..e478112d --- /dev/null +++ b/tests/framework/src/test_results_collector_summary.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2014 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_results_collector_summary.cpp + * @author Marcin Niesluchowski (m.niesluchow@samsung.com) + * @author Michal Witanowski (m.witanowski@samsung.com) + * @version 1.0 + * @brief Source file containing SummaryCollector class definition. + */ + +#include + +#include "dpl/test/test_results_collector_summary.h" + +namespace DPL { +namespace Test { + +namespace { + + const char* summaryFileName = "/tmp/security-tests-summary-file"; + +} + +SummaryCollector::SummaryCollector() +{ + Start(); +} + + +// Overrides TestResultsCollectorBase::Start() virtual method. +void SummaryCollector::Start() +{ + m_total = m_succeeded = m_failed = m_ignored = 0; +} + +// append results to the file +void SummaryCollector::Finish() +{ + std::ofstream outputFile; + outputFile.open(summaryFileName, std::ofstream::out | std::ofstream::app); + if (!outputFile) + return; //failed to open file + + outputFile << m_total << ' ' + << m_succeeded << ' ' + << m_failed << ' ' + << m_ignored << std::endl; + outputFile.close(); +} + +void SummaryCollector::CollectResult(const std::string& /*id*/, + const std::string& /*description*/, + 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)isPerformanceTest; + (void)performanceTime; + (void)performanceMaxTime; + switch (status) { + case FailStatus::IGNORED: ++m_ignored; break; + case FailStatus::FAILED: ++m_failed; break; + case FailStatus::NONE: ++m_succeeded; break; + }; + ++m_total; +} + +void SummaryCollector::CollectResult(const std::string& /*id*/, + const std::string& /*description*/, + const FailStatus status, + const std::string& /*reason = ""*/) +{ + switch (status) { + case FailStatus::IGNORED: ++m_ignored; break; + case FailStatus::FAILED: ++m_failed; break; + case FailStatus::NONE: ++m_succeeded; break; + }; + ++m_total; +} + +TestResultsCollectorBase* SummaryCollector::Constructor() +{ + return new SummaryCollector(); +} + +} // namespace Test +} // namespace DPL diff --git a/tests/libprivilege-control-tests/libprivilege-control-test.cpp b/tests/libprivilege-control-tests/libprivilege-control-test.cpp index 57e97801..dbec70c8 100644 --- a/tests/libprivilege-control-tests/libprivilege-control-test.cpp +++ b/tests/libprivilege-control-tests/libprivilege-control-test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014 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. @@ -22,13 +22,11 @@ #include #include -#include int main (int argc, char *argv[]) { LogInfo("Starting libprivilege-control tests"); - SummaryCollector::Register(); int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); return status; } diff --git a/tests/libsmack-tests/libsmack-test.cpp b/tests/libsmack-tests/libsmack-test.cpp index 556e2a16..ccbb00e8 100644 --- a/tests/libsmack-tests/libsmack-test.cpp +++ b/tests/libsmack-tests/libsmack-test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014 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. @@ -20,11 +20,9 @@ * @brief libsmack test runer */ #include -#include int main (int argc, char *argv[]) { - SummaryCollector::Register(); int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); return status; } diff --git a/tests/security-manager-tests/security_manager_tests.cpp b/tests/security-manager-tests/security_manager_tests.cpp index ab6c0cd2..fe90f8e5 100644 --- a/tests/security-manager-tests/security_manager_tests.cpp +++ b/tests/security-manager-tests/security_manager_tests.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -619,6 +618,5 @@ RUNNER_CHILD_TEST(security_manager_05_drop_process_capabilities) int main(int argc, char *argv[]) { - SummaryCollector::Register(); return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); } diff --git a/tests/security-server-tests/security_server_measurer_API_speed.cpp b/tests/security-server-tests/security_server_measurer_API_speed.cpp index f9da5132..213f9be2 100644 --- a/tests/security-server-tests/security_server_measurer_API_speed.cpp +++ b/tests/security-server-tests/security_server_measurer_API_speed.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved * * Contact: Bumjin Im * @@ -49,7 +49,6 @@ #include #include #include "security_server_mockup.h" -#include #include IMPLEMENT_SAFE_SINGLETON(DPL::Log::LogSystem); @@ -723,7 +722,6 @@ RUNNER_TEST(m170_security_server_check_privilege_by_pid) { int main(int argc, char *argv[]) { - SummaryCollector::Register(); securityClientEnableLogSystem(); DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); return 0; diff --git a/tests/security-server-tests/security_server_tests_client_smack.cpp b/tests/security-server-tests/security_server_tests_client_smack.cpp index 194584e9..fa7c13ba 100644 --- a/tests/security-server-tests/security_server_tests_client_smack.cpp +++ b/tests/security-server-tests/security_server_tests_client_smack.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved */ /* * @file security_server_tests_client_smack.cpp @@ -31,7 +31,6 @@ #include #include #include "tests_common.h" -#include #include #define PROPER_COOKIE_SIZE 20 @@ -545,6 +544,5 @@ RUNNER_TEST_NOSMACK(tc18_security_server_get_smacklabel_cookie_nosmack) { int main(int argc, char *argv[]) { - SummaryCollector::Register(); return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); } diff --git a/tests/security-server-tests/security_server_tests_password.cpp b/tests/security-server-tests/security_server_tests_password.cpp index d914e5d4..b9f05842 100644 --- a/tests/security-server-tests/security_server_tests_password.cpp +++ b/tests/security-server-tests/security_server_tests_password.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved */ /* * @file security_server_tests_password.cpp @@ -33,7 +33,6 @@ #include #include "security_server_clean_env.h" #include "security_server_tests_common.h" -#include // the maximum time (in seconds) passwords can expire in @@ -1523,6 +1522,5 @@ RUNNER_TEST(tc53_security_server_is_pwd_valid) int main(int argc, char *argv[]) { - SummaryCollector::Register(); return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); } diff --git a/tests/security-server-tests/security_server_tests_privilege.cpp b/tests/security-server-tests/security_server_tests_privilege.cpp index 4b0ac72a..c7e698ff 100644 --- a/tests/security-server-tests/security_server_tests_privilege.cpp +++ b/tests/security-server-tests/security_server_tests_privilege.cpp @@ -1,7 +1,5 @@ #include -#include - #include #include @@ -123,6 +121,5 @@ RUNNER_TEST(sstp_01_security_server_app_has_privilege) int main(int argc, char *argv[]) { - SummaryCollector::Register(); return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); } diff --git a/tests/security-server-tests/security_server_tests_stress.cpp b/tests/security-server-tests/security_server_tests_stress.cpp index 9b74a625..b8f7e128 100644 --- a/tests/security-server-tests/security_server_tests_stress.cpp +++ b/tests/security-server-tests/security_server_tests_stress.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved */ /* * @file security_server_tests_stress.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -185,7 +184,6 @@ RUNNER_CHILD_TEST_NOSMACK(tc_stress_cookie_api_no_smack) int main (int argc, char *argv[]) { - SummaryCollector::Register(); return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); } diff --git a/tests/security-server-tests/server.cpp b/tests/security-server-tests/server.cpp index d7929ebd..e7d94b73 100644 --- a/tests/security-server-tests/server.cpp +++ b/tests/security-server-tests/server.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved */ /* * @file security_server_tests_server.cpp @@ -33,7 +33,6 @@ #include "tests_common.h" #include #include -#include const char *TEST03_SUBJECT = "subject_0f09f7cc"; const char *TEST04_SUBJECT = "subject_57dfbfc5"; @@ -429,6 +428,5 @@ int main(int argc, char *argv[]) { printf("Error: %s must be executed by root\n", argv[0]); exit(1); } - SummaryCollector::Register(); return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); } diff --git a/tests/smack-dbus-tests/smack_dbus_tests.cpp b/tests/smack-dbus-tests/smack_dbus_tests.cpp index 080e5b09..233994e8 100644 --- a/tests/smack-dbus-tests/smack_dbus_tests.cpp +++ b/tests/smack-dbus-tests/smack_dbus_tests.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "tests_common.h" #define DBUS_SERVER_NAME "test.method.server" @@ -302,6 +301,5 @@ RUNNER_MULTIPROCESS_TEST_NOSMACK(tc01_smack_context_from_DBus_nosmack) int main(int argc, char *argv[]) { - SummaryCollector::Register(); return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv); }