Add summary view to all security tests.
authorMichal Witanowski <m.witanowski@samsung.com>
Wed, 20 Nov 2013 10:52:55 +0000 (11:52 +0100)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 23 Jan 2014 14:21:36 +0000 (15:21 +0100)
[Issue#]       SSDWSSP-522
[Bug/Feature]  Running security tests via security-tests-all.sh prints
               summary view (all tests results summed together).
[Cause]        N/A
[Solution]     A new results collector for WRT tests runner was created
               (SummaryCollector in summary_collector.h). The collector
               counts all the test cases results and appends a line to
               a temporary file containing: number of all test cases,
               succeeded, failed and ignored.
               Then, after the tests are executed, tests-summary.sh
               sums the columns and prints summary in the console.
[Verification] Build, install, run all security tests via
               security-tests-all.sh and wait for summary at the very
               end of script output.

Change-Id: Id44cfb90acbc426e17e1971807e6eef0496c7805

16 files changed:
packaging/security-tests.spec
tests/CMakeLists.txt
tests/common/CMakeLists.txt
tests/common/summary_collector.cpp [new file with mode: 0644]
tests/common/summary_collector.h [new file with mode: 0644]
tests/libprivilege-control-tests/libprivilege-control-test.cpp
tests/libsmack-tests/libsmack-test.cpp
tests/security-server-tests/security_server_measurer_API_speed.cpp
tests/security-server-tests/security_server_tests_client_smack.cpp
tests/security-server-tests/security_server_tests_dbus.cpp
tests/security-server-tests/security_server_tests_password.cpp
tests/security-server-tests/security_server_tests_stress.cpp
tests/security-server-tests/server.cpp
tests/security-tests-all.sh
tests/security-tests.sh
tests/tests-summary.sh [new file with mode: 0644]

index e86f39c3164d5224bc919e15d1ed7b07d7335578..a21c76e09008596b60fd30437cdedf38bfeb20d5 100644 (file)
@@ -75,6 +75,7 @@ osp-installer -u V5LKqDFBXm
 %defattr(-, root, root, -)
 /usr/bin/security-tests.sh
 /usr/bin/security-tests-all.sh
+/usr/bin/tests-summary.sh
 /usr/bin/test-performance-check.sh
 /usr/bin/perf
 
index 251ebed93688902eb3a9aa11a5a0019787c4c097..27b1f8b0e40e93ac64a803f0b2331d6665451381 100644 (file)
@@ -35,6 +35,17 @@ INSTALL(FILES ${PROJECT_SOURCE_DIR}/tests/security-tests-all.sh
                 WORLD_EXECUTE
     )
 
+INSTALL(FILES ${PROJECT_SOURCE_DIR}/tests/tests-summary.sh
+    DESTINATION bin
+    PERMISSIONS OWNER_READ
+                OWNER_WRITE
+                OWNER_EXECUTE
+                GROUP_READ
+                GROUP_EXECUTE
+                WORLD_READ
+                WORLD_EXECUTE
+    )
+
 INSTALL(FILES
     ${PROJECT_SOURCE_DIR}/tests/test-performance-check.sh
     ${PROJECT_SOURCE_DIR}/tests/perf
index 0727e76717fff64129fb1ab5537c8468994ccfa0..7f635852c68c151e59c3fdf8e553f238e5787b33 100644 (file)
@@ -13,6 +13,7 @@ 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
     )
 
 #header directories
diff --git a/tests/common/summary_collector.cpp b/tests/common/summary_collector.cpp
new file mode 100644 (file)
index 0000000..b4d69ac
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2013 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 <summary_collector.h>
+#include <fstream>
+
+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::Type status,
+                                      const std::string& /*reason = ""*/)
+{
+    switch (status) {
+        case FailStatus::IGNORED: ++m_ignored; break;
+        case FailStatus::INTERNAL: // internal error count as fail
+        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
new file mode 100644 (file)
index 0000000..3a1cdf9
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013 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 <dpl/test/test_results_collector.h>
+
+/*
+ * 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::Type status,
+                       const std::string& /*reason = ""*/);
+
+public:
+    static TestResultsCollectorBase* Constructor();
+    static void Register();
+};
+
+#endif
index 1f1f18fd8a118a4c49809b65317ab71cef031d84..57e978013273409d013c0c24780a05bf8f93da50 100644 (file)
 
 #include <dpl/test/test_runner.h>
 #include <dpl/log/log.h>
+#include <summary_collector.h>
 
 int main (int argc, char *argv[])
 {
     LogInfo("Starting libprivilege-control tests");
+
+    SummaryCollector::Register();
     int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
     return status;
 }
index 93c853dce47884773e429b85d993530f69c97b87..556e2a1679597f4ca6b48acafd03e96f2570a9ed 100644 (file)
  * @brief       libsmack test runer
  */
 #include <dpl/test/test_runner.h>
+#include <summary_collector.h>
 
 int main (int argc, char *argv[])
 {
+    SummaryCollector::Register();
     int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
     return status;
 }
index 3ea213026e36d9dab1635cc0a850704ed8b090d6..27d0aa310d90ceb0b1a8b940588e52a82c36efbf 100644 (file)
@@ -50,6 +50,7 @@
 #include <unistd.h>
 #include <memory>
 #include "security_server_mockup.h"
+#include <summary_collector.h>
 
 /*Number of calls in a single test*/
 #define NUMBER_OF_CALLS (5)
@@ -718,6 +719,7 @@ 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;
index 5d35cd75e13f59e0f2a45d329065c7ccc4e23f62..2f977f2f41fc41912bc5b55f0373418830e9ff63 100644 (file)
 #include "security_server_mockup.h"
 
 #include <security-server.h>
-
 #include <access_provider.h>
 #include <tracker.h>
-
 #include "tests_common.h"
+#include <summary_collector.h>
+
 
 #define PROPER_COOKIE_SIZE 20
 
@@ -952,6 +952,6 @@ RUNNER_TEST_NOSMACK(tc18_security_server_get_smacklabel_cookie_nosmack) {
 
 int main(int argc, char *argv[])
 {
-    return
-        DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
+    SummaryCollector::Register();
+    return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
 }
index be179dbaea1924498a320f24be83851af68a5ca8..cc8f32960682658fef5746b90e56ac4e1bbb010c 100644 (file)
@@ -7,6 +7,7 @@
 #include <dbus/dbus.h>
 #include <dbus-glib.h>
 #include <glib-object.h>
+#include <summary_collector.h>
 #include "tests_common.h"
 #include "security-server.h"
 #include "privilege-control.h"
@@ -348,7 +349,6 @@ RUNNER_MULTIPROCESS_TEST_NOSMACK(tc01_smack_context_from_DBus_nosmack)
 
 int main(int argc, char *argv[])
 {
-    int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
-
-    return status;
+    SummaryCollector::Register();
+    return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
 }
index 4074e1ecb9fa6cc56947ef088af3dae584939933..860f8dd41884c52b389188acd65c652c8c7319e0 100644 (file)
@@ -32,6 +32,7 @@
 #include <dlog.h>
 #include "security_server_clean_env.h"
 #include <tracker.h>
+#include <summary_collector.h>
 
 
 // security server retry timeout in microseconds
@@ -1493,7 +1494,6 @@ RUNNER_TEST(tc49_security_server_no_retry_timeout_set_pwd_max_challenge)
 
 int main(int argc, char *argv[])
 {
-    int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
-
-    return status;
+    SummaryCollector::Register();
+    return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
 }
index da3959bcc7921d5a645aa773249b5b971639bcea..dfa6996e90ac01724fb74df4484bb7f22fa856c5 100644 (file)
@@ -12,6 +12,7 @@
 #include <dpl/test/test_runner.h>
 #include <dpl/test/test_runner_multiprocess.h>
 #include <tests_common.h>
+#include <summary_collector.h>
 #include <iostream>
 #include <sys/smack.h>
 #include <cstddef>
@@ -21,7 +22,6 @@
 #include <sys/types.h>
 #include "security-server.h"
 
-
 std::mutex g_mutex;
 std::mutex g_msgMutex;
 size_t g_successes = 0;
@@ -213,7 +213,7 @@ RUNNER_CHILD_TEST_NOSMACK(tc_stress_cookie_api_no_smack)
 
 int main (int argc, char *argv[])
 {
-    int status = DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
-    return status;
+    SummaryCollector::Register();
+    return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
 }
 
index f86cb108f2d5b40aac0ddb7d15c3ef74beae0e92..76f733bb4291d51a531d0c9698c58cc0bbe62954 100644 (file)
@@ -34,6 +34,7 @@
 #include "tests_common.h"
 #include <smack_access.h>
 #include <access_provider.h>
+#include <summary_collector.h>
 
 const char *TEST03_SUBJECT = "subject_0f09f7cc";
 const char *TEST04_SUBJECT = "subject_57dfbfc5";
@@ -850,5 +851,6 @@ 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);
 }
index d1c4bab9f3b7452d72646d24f6e66c1777db3e21..32063c0e8cb4891e3c00c46796168b8b9a32dfe4 100644 (file)
@@ -1,6 +1,11 @@
 #!/bin/sh
 echo "[Trigerring all tests...]"
 
+summary_file="/tmp/security-tests-summary-file"
+
+#delete summary file
+rm -f $summary_file
+
 ign="--runignored"
 if [ $# -gt 0 ]; then
   if [ "$1" = "--noignored" ]; then
@@ -8,11 +13,17 @@ if [ $# -gt 0 ]; then
   fi
 fi
 
-security-tests.sh smack --output=text $ign
-security-tests.sh libprivilege-control --output=text $ign
-security-tests.sh ss-clientsmack --output=text $ign
-security-tests.sh ss-server --output=text $ign
-security-tests.sh ss-password --output=text $ign
-security-tests.sh ss-dbus --output=text $ign
-security-tests.sh ss-stress --output=text $ign
+# 'text' - console output
+# 'summary' - used for summary view
+security-tests.sh smack --output=text --output=summary $ign
+security-tests.sh libprivilege-control --output=text --output=summary $ign
+security-tests.sh ss-clientsmack --output=text --output=summary $ign
+security-tests.sh ss-server --output=text --output=summary $ign
+security-tests.sh ss-password --output=text --output=summary $ign
+security-tests.sh ss-dbus --output=text --output=summary $ign
+security-tests.sh ss-stress --output=text --output=summary $ign
+
+# print summary
+tests-summary.sh $summary_file
+
 echo "[Done]"
index 8d876e9560f44b7c5b9e114c8b63474a9ec3c483..2f87cbcdbc68534bbbf9846e6d62bafe36f9437f 100644 (file)
@@ -26,49 +26,49 @@ case $1 in
     echo "========================================================================="
     echo $1
     echo
-    libsmack-test $2 $3
+    libsmack-test "${@:2}" # propagate all remaining arguments (except first)
     ;;
 "libprivilege-control")
     echo "========================================================================="
     echo $1
     echo
-    libprivilege-control-test $2 $3
+    libprivilege-control-test "${@:2}"
     ;;
 "ss-clientsmack")
     echo "========================================================================="
     echo "SECURITY SERVER TEST CLIENT SMACK"
     echo
-    security-server-tests-client-smack $2 $3
+    security-server-tests-client-smack "${@:2}"
     ;;
 "ss-stress")
     echo "========================================================================="
     echo "SECURITY SERVER TEST STRESS"
     echo
-    security-server-tests-stress $2 $3
+    security-server-tests-stress "${@:2}"
     ;;
 "ss-server")
     echo "========================================================================="
     echo "SECURITY SERVER TEST SERVER"
     echo
-    security-server-tests-server $2 $3
+    security-server-tests-server "${@:2}"
     ;;
 "ss-api-speed")
     echo "========================================================================="
     echo "SECURITY SERVER MEASURER SERVER"
     echo
-    security-server-tests-api-speed  $2 $3
+    security-server-tests-api-speed "${@:2}"
     ;;
 "ss-password")
     echo "========================================================================="
     echo "SECURITY SERVER TEST PASSWORD"
     echo
-    security-server-tests-password $2 $3
+    security-server-tests-password "${@:2}"
     ;;
 "ss-dbus")
     echo "========================================================================="
     echo "SECURITY SERVER TEST DBUS"
     echo
-    security-server-tests-dbus $2 $3
+    security-server-tests-dbus "${@:2}"
     ;;
 *)
     echo "Correct using:"
diff --git a/tests/tests-summary.sh b/tests/tests-summary.sh
new file mode 100644 (file)
index 0000000..a6ece36
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# sum up columns
+total=$(awk '{counter += $1} END {print counter}' "$1" )
+succeeded=$(awk '{counter += $2} END {print counter}' "$1" )
+failed=$(awk '{counter += $3} END {print counter}' "$1" )
+ignored=$(awk '{counter += $4} END {print counter}' "$1" )
+
+#color constants
+COLOR_GREEN_START="\033[1;32m"
+COLOR_DARK_GREEN_START="\033[0;36m"
+COLOR_END="\033[m"
+
+printf $COLOR_GREEN_START
+printf "Summary\n"
+printf $COLOR_END
+
+printf $COLOR_DARK_GREEN_START
+printf "  Total:     %i\n" $total
+printf "  Succeeded: %i\n" $succeeded
+printf "  Failed:    %i\n" $failed
+printf "  Ignored:   %i\n" $ignored
+printf $COLOR_END
+
+printf "\n"