Add improvements to colorizing script
authorLukasz Kostyra <l.kostyra@partner.samsung.com>
Fri, 14 Mar 2014 10:47:49 +0000 (11:47 +0100)
committerJan Olszak <j.olszak@samsung.com>
Mon, 19 May 2014 11:47:14 +0000 (13:47 +0200)
[Issue#]        N/A
[Feature]       Adds following features to script colorizing test output:
                    * sc_tests_all now passes arguments to launched binaries.
                    * sc_test_launch now allows for absolute path to test binary.
                    * If any test case fails, script provides a command to launch any test case
                      explicitly.
                    * Minor corrections in test result display.
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, install, run:
                    * sc_tests_all - all tests should show up,
                    * sc_tests_all -t ContainerSuite - only ContainerSuite test suite should show,
                    * sc_test_launch /bin/security-containers-server-unit-tests - should launch
                      security-containers-server-unit-tests.

Change-Id: Ic01d8ced2caceb1ed9347ed86fd7417e375bc271

src/scripts/sc_test_launch.py
src/scripts/sc_test_parser.py
src/scripts/sc_tests_all.py

index f80fe59..81d6d62 100755 (executable)
@@ -15,14 +15,16 @@ _defLaunchArgs = ["--report_format=XML",
 log = Logger()
 
 def _checkIfBinExists(binary):
+    # Check if binary is accessible through PATH env and with no additional paths
     paths = [s + "/" for s in os.environ["PATH"].split(os.pathsep)]
-    exists = any([os.path.isfile(path + binary) and os.access(path + binary, os.X_OK)
+    paths.append('')
+    existsInPaths = any([os.path.isfile(path + binary) and os.access(path + binary, os.X_OK)
                   for path in paths])
 
-    if not exists:
+    if not existsInPaths:
         log.error(binary + " NOT FOUND.")
 
-    return exists
+    return existsInPaths
 
 
 
@@ -36,7 +38,7 @@ def launchTest(cmd=[], externalToolCmd=[], parsing=True):
     if externalToolCmd and not _checkIfBinExists(externalToolCmd[0]):
         return
 
-    log.info("Starting " + cmd[0] + "...")
+    log.info("Starting " + cmd[0] + " ...")
 
     if parsing:
         parser = Parser()
@@ -48,6 +50,7 @@ def launchTest(cmd=[], externalToolCmd=[], parsing=True):
         if testResult != "":
             domResult = minidom.parseString(testResult)
             log.XMLSummary(domResult)
+            log.failedTestSummary(cmd[0])
     else:
         # Launching process without coloring does not require report in XML form
         # Avoid providing --report_format=XML, redirect std* by default to system's std*
index 7fd13d4..df3f7f1 100644 (file)
@@ -17,6 +17,8 @@ ENDC = "\033[0m"
 
 
 class Logger(object):
+    __failedTests = []
+
     # Create summary of test providing DOM object with parsed XML
     def info(self, msg):
         print BOLD + msg + ENDC
@@ -32,13 +34,14 @@ class Logger(object):
 
 
     __indentChar = "    "
-    def testCaseSummary(self, testName, testResult, recLevel):
-        msg = self.__indentChar * recLevel + BOLD + "{:<50}".format(testName + ":")
+    def testCaseSummary(self, testSuite, testName, testResult, recLevel):
+        msg = self.__indentChar * recLevel + BOLD + "{:<50}".format(testName)
 
         if testResult == "passed":
             msg += GREEN
         else:
             msg += RED
+            self.__failedTests.append(testSuite + "/" + testName)
 
         print msg + testResult + ENDC
 
@@ -51,16 +54,16 @@ class Logger(object):
             if child.nodeName == "TestSuite":
                 self.testSuiteSummary(child, recLevel=recLevel + 1)
             elif child.nodeName == "TestCase":
-                self.testCaseSummary(child.attributes["name"].value,
+                self.testCaseSummary(suite.attributes["name"].value,
+                                     child.attributes["name"].value,
                                      child.attributes["result"].value,
                                      recLevel=recLevel + 1)
 
         if summarize:
             self.infoTitle(indPrefix + suite.attributes["name"].value + " summary:")
-            self.info(indPrefix + "Passed tests:  " + suite.attributes["test_cases_passed"].value)
-            self.info(indPrefix + "Failed tests:  " + suite.attributes["test_cases_failed"].value)
-            self.info(indPrefix + "Skipped tests: " + suite.attributes["test_cases_skipped"].value +
-                      "\n")
+            self.info(indPrefix + "Passed tests: " + suite.attributes["test_cases_passed"].value)
+            self.info(indPrefix + "Failed tests: " + suite.attributes["test_cases_failed"].value +
+                      '\n')
 
     def XMLSummary(self, dom):
         self.info("\n=========== SUMMARY ===========\n")
@@ -70,6 +73,15 @@ class Logger(object):
                 if child.nodeName == "TestSuite":
                     self.testSuiteSummary(child, summarize=True)
 
+    def failedTestSummary(self, bin):
+        if not self.__failedTests:
+            return
+
+        commandPrefix = "sc_test_launch " + bin + " -t "
+        self.infoTitle("Some tests failed. Use following command(s) to launch them explicitly:")
+        for test in self.__failedTests:
+            self.error(self.__indentChar + commandPrefix + test)
+
 
 
 class Colorizer(object):
index 85c0d55..bf52dad 100755 (executable)
@@ -1,9 +1,10 @@
 #!/usr/bin/env python
 
 import sc_test_launch
+import sys
 
 # insert other test binaries to this array
 _testCmdTable = ["security-containers-server-unit-tests"]
 
 for test in _testCmdTable:
-    sc_test_launch.launchTest([test])
+    sc_test_launch.launchTest([test] + sys.argv[1:])