All of lore.kernel.org
 help / color / mirror / Atom feed
* Enable xml output in OeTest class for report consumers
@ 2016-07-21 12:02 Benjamin Esquivel
  2016-07-21 12:02 ` [PATCH 1/2] oe-selftest: export test results via xmlrunner Benjamin Esquivel
  2016-07-21 12:02 ` [PATCH 2/2] oe-selftest: simplifying log filenames Benjamin Esquivel
  0 siblings, 2 replies; 3+ messages in thread
From: Benjamin Esquivel @ 2016-07-21 12:02 UTC (permalink / raw)
  To: openembedded-core


You can take a look at the bug 9682[1] where tests and sample logs are attached.
This patch assumes the xmlrunner[2] module in the system where oe-selftest will
run. if the xmlrunner is not there, it will default to unittest.

As it is now, it will change partially the text output format of the command
line but a bug will be filed for fixing that up. Reason being that is better
to fix it at the xmlrunner than recreating the functions to fix it. See the
summary of changes at the bug's attachments.

[1] https://bugzilla.yoctoproject.org/show_bug.cgi?id=9682
[2] https://github.com/xmlrunner/unittest-xml-reporting


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] oe-selftest: export test results via xmlrunner
  2016-07-21 12:02 Enable xml output in OeTest class for report consumers Benjamin Esquivel
@ 2016-07-21 12:02 ` Benjamin Esquivel
  2016-07-21 12:02 ` [PATCH 2/2] oe-selftest: simplifying log filenames Benjamin Esquivel
  1 sibling, 0 replies; 3+ messages in thread
From: Benjamin Esquivel @ 2016-07-21 12:02 UTC (permalink / raw)
  To: openembedded-core

if available, use the xmlrunner for exporting the test results to a
dir named the same than the log where the text results are stored.
this means creating a dir with the name of the log (without the .log)
and dumping there the xml files that indicate the results of each of
the tests.

if xmlrunner is not available then it will behave the same as before,
no xml exports.

[YOCTO#9682]

Signed-off-by: Benjamin Esquivel <benjamin.esquivel@linux.intel.com>
---
 scripts/oe-selftest | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index 303b1d5..3188a41 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -48,8 +48,19 @@ import oeqa.utils.ftools as ftools
 from oeqa.utils.commands import runCmd, get_bb_var, get_test_layer
 from oeqa.selftest.base import oeSelfTest, get_available_machines
 
+try:
+    import xmlrunner
+    from xmlrunner.result import _XMLTestResult as TestResult
+    from xmlrunner import XMLTestRunner as _TestRunner
+except ImportError:
+    # use the base runner instead
+    from unittest import TextTestResult as TestResult
+    from unittest import TextTestRunner as _TestRunner
+
+log_prefix = "oe-selftest-" + t.strftime("%Y-%m-%d_%H:%M:%S")
+
 def logger_create():
-    log_file = "oe-selftest-" + t.strftime("%Y-%m-%d_%H:%M:%S") + ".log"
+    log_file = log_prefix + ".log"
     if os.path.exists("oe-selftest.log"): os.remove("oe-selftest.log")
     os.symlink(log_file, "oe-selftest.log")
 
@@ -520,7 +531,8 @@ def main():
         suite = unittest.TestSuite()
         loader = unittest.TestLoader()
         loader.sortTestMethodsUsing = None
-        runner = unittest.TextTestRunner(verbosity=2, resultclass=buildResultClass(args))
+        runner = TestRunner(verbosity=2,
+                resultclass=buildResultClass(args))
         # we need to do this here, otherwise just loading the tests
         # will take 2 minutes (bitbake -e calls)
         oeSelfTest.testlayer_path = get_test_layer()
@@ -561,7 +573,7 @@ def buildResultClass(args):
     """Build a Result Class to use in the testcase execution"""
     import site
 
-    class StampedResult(unittest.TextTestResult):
+    class StampedResult(TestResult):
         """
         Custom TestResult that prints the time when a test starts.  As oe-selftest
         can take a long time (ie a few hours) to run, timestamps help us understand
@@ -631,6 +643,21 @@ def buildResultClass(args):
 
     return StampedResult
 
+class TestRunner(_TestRunner):
+    """Test runner class aware of exporting tests."""
+    def __init__(self, *args, **kwargs):
+        try:
+            exportdir = os.path.join(os.getcwd(), log_prefix)
+            kwargsx = dict(**kwargs)
+            # argument specific to XMLTestRunner, if adding a new runner then
+            # also add logic to use other runner's args.
+            kwargsx['output'] = exportdir
+            kwargsx['descriptions'] = False
+            # done for the case where telling the runner where to export
+            super(TestRunner, self).__init__(*args, **kwargsx)
+        except TypeError:
+            log.info("test runner init'ed like unittest")
+            super(TestRunner, self).__init__(*args, **kwargs)
 
 if __name__ == "__main__":
     try:
-- 
2.5.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] oe-selftest: simplifying log filenames
  2016-07-21 12:02 Enable xml output in OeTest class for report consumers Benjamin Esquivel
  2016-07-21 12:02 ` [PATCH 1/2] oe-selftest: export test results via xmlrunner Benjamin Esquivel
@ 2016-07-21 12:02 ` Benjamin Esquivel
  1 sibling, 0 replies; 3+ messages in thread
From: Benjamin Esquivel @ 2016-07-21 12:02 UTC (permalink / raw)
  To: openembedded-core

avoiding characters like ':' and making a clearer separation of the
fields that compose the filename. Changing from:

oe-selftest-2016-07-20_16:05:27.log

to:

oe-selftest-20160720-160527.log

Signed-off-by: Benjamin Esquivel <benjamin.esquivel@linux.intel.com>
---
 scripts/oe-selftest | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index 3188a41..72bf4dd 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -57,7 +57,7 @@ except ImportError:
     from unittest import TextTestResult as TestResult
     from unittest import TextTestRunner as _TestRunner
 
-log_prefix = "oe-selftest-" + t.strftime("%Y-%m-%d_%H:%M:%S")
+log_prefix = "oe-selftest-" + t.strftime("%Y%m%d-%H%M%S")
 
 def logger_create():
     log_file = log_prefix + ".log"
-- 
2.5.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-21 20:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-21 12:02 Enable xml output in OeTest class for report consumers Benjamin Esquivel
2016-07-21 12:02 ` [PATCH 1/2] oe-selftest: export test results via xmlrunner Benjamin Esquivel
2016-07-21 12:02 ` [PATCH 2/2] oe-selftest: simplifying log filenames Benjamin Esquivel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.