[PATCH] osmo-gsm-tester[master]: junit result: also write for aborted runs

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Tue Jun 6 21:55:46 UTC 2017


Review at  https://gerrit.osmocom.org/2854

junit result: also write for aborted runs

Even if aborted due to signal, write a JUnit report XML, and make sure to
indicate the runs as erratic.

Change-Id: I7a334ef3463896c543c0fe592d3903c15e67d4c4
---
M src/osmo_gsm_tester/report.py
M src/osmo_gsm_tester/suite.py
M src/osmo_gsm_tester/trial.py
3 files changed, 29 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/54/2854/1

diff --git a/src/osmo_gsm_tester/report.py b/src/osmo_gsm_tester/report.py
index ae63408..f68f30b 100644
--- a/src/osmo_gsm_tester/report.py
+++ b/src/osmo_gsm_tester/report.py
@@ -38,8 +38,9 @@
     testsuite = et.Element('testsuite')
     testsuite.set('name', suite.name())
     testsuite.set('hostname', 'localhost')
-    testsuite.set('timestamp', datetime.fromtimestamp(round(suite.start_timestamp)).isoformat())
-    testsuite.set('time', str(math.ceil(suite.duration)))
+    if suite.start_timestamp:
+        testsuite.set('timestamp', datetime.fromtimestamp(round(suite.start_timestamp)).isoformat())
+        testsuite.set('time', str(math.ceil(suite.duration)))
     testsuite.set('tests', str(len(suite.tests)))
     testsuite.set('failures', str(suite.count_test_results()[2]))
     for test in suite.tests:
@@ -60,6 +61,9 @@
         if test.fail_tb:
             system_err = et.SubElement(testcase, 'system-err')
             system_err.text = test.fail_tb
+    else:
+        error = et.SubElement(testcase, 'error')
+        error.text = 'could not run'
     return testcase
 
 def trial_to_text(trial):
diff --git a/src/osmo_gsm_tester/suite.py b/src/osmo_gsm_tester/suite.py
index 638f0a4..d6f3db4 100644
--- a/src/osmo_gsm_tester/suite.py
+++ b/src/osmo_gsm_tester/suite.py
@@ -156,6 +156,8 @@
 
     trial = None
     status = None
+    start_timestamp = None
+    duration = None
     resources_pool = None
     reserved_resources = None
     objects_to_clean_up = None
@@ -169,6 +171,7 @@
         self.scenarios = scenarios
         self.set_name(suite_scenario_str)
         self.set_log_category(log.C_TST)
+        self.status = SuiteRun.UNKNOWN
         self.resources_pool = resource.ResourcesPool()
         self.load_tests()
 
diff --git a/src/osmo_gsm_tester/trial.py b/src/osmo_gsm_tester/trial.py
index a238e2f..b4d10c0 100644
--- a/src/osmo_gsm_tester/trial.py
+++ b/src/osmo_gsm_tester/trial.py
@@ -193,26 +193,26 @@
         self.suites.append(suite_run)
 
     def run_suites(self, names=None):
-        self.status = Trial.UNKNOWN
-        for suite_run in self.suites:
-            try:
-                suite_run.run_tests(names)
-            except Exception:
-                self.log_exn()
-            except:
-                # when the program is aborted by a signal (like Ctrl-C), escalate to abort all.
-                self.err('TEST RUN ABORTED.')
-                raise
-            finally:
-                if suite_run.status == suite.SuiteRun.FAIL:
-                    self.status = Trial.FAIL
-        if self.status == Trial.UNKNOWN:
-            self.status = Trial.PASS
-        self.log(self.status)
-        junit_path = self.get_run_dir().new_file(self.name()+'.xml')
-        self.log('Storing JUnit report in', junit_path)
-        report.trial_to_junit_write(self, junit_path)
-        return self.status
+        try:
+            self.status = Trial.UNKNOWN
+            for suite_run in self.suites:
+                try:
+                    suite_run.run_tests(names)
+                except Exception:
+                    self.log_exn()
+                except BaseException as e:
+                    # when the program is aborted by a signal (like Ctrl-C), escalate to abort all.
+                    self.err('TRIAL RUN ABORTED: %s' % type(e).__name__)
+                    raise
+                finally:
+                    if suite_run.status == suite.SuiteRun.FAIL:
+                        self.status = Trial.FAIL
+            if self.status == Trial.UNKNOWN:
+                self.status = Trial.PASS
+        finally:
+            junit_path = self.get_run_dir().new_file(self.name()+'.xml')
+            report.trial_to_junit_write(self, junit_path)
+            self.log('Wrote JUnit report to', junit_path)
 
     def log_report(self):
         log.large_separator('%s Results' % self.name())

-- 
To view, visit https://gerrit.osmocom.org/2854
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7a334ef3463896c543c0fe592d3903c15e67d4c4
Gerrit-PatchSet: 1
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list