aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo_gsm_tester
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2020-06-15 14:27:50 +0200
committerpespin <pespin@sysmocom.de>2020-06-15 15:42:58 +0000
commite3d1b61175d3f177ff15679954785d5d72b7ad8e (patch)
tree1be6d6a8ccd70f8df952945f23b4e6451a2bce8a /src/osmo_gsm_tester
parentd4dc2ad3a2767bcebf4eb2bba2cefee0c26f6d6e (diff)
Add per-test KPI support
tests can now use 'tenv.test().set_kpis(some_dict)' to set any kind of data as KPIs, which will be presented in the junit report. The representation of KPIs in the xml file doesn't follow the junit format, mainly because it has no support for per-test properties. Change-Id: I00e976f65a202e82d440bf33708f06c8ce2643e2
Diffstat (limited to 'src/osmo_gsm_tester')
-rw-r--r--src/osmo_gsm_tester/core/report.py41
-rw-r--r--src/osmo_gsm_tester/core/test.py9
2 files changed, 50 insertions, 0 deletions
diff --git a/src/osmo_gsm_tester/core/report.py b/src/osmo_gsm_tester/core/report.py
index 5014bf5..d2c68c5 100644
--- a/src/osmo_gsm_tester/core/report.py
+++ b/src/osmo_gsm_tester/core/report.py
@@ -53,6 +53,46 @@ def hash_info_to_junit(testsuite, hash_info):
prop.set('name', 'ref:' + key)
prop.set('value', val)
+def dict_to_junit(parent, d):
+ for key, val in d.items():
+ if isinstance(val, dict):
+ node = et.SubElement(parent, 'kpi_node')
+ node.set('name', key)
+ dict_to_junit(node, val)
+ continue
+ if isinstance(val, (tuple, list)):
+ node = et.SubElement(parent, 'kpi_node')
+ node.set('name', key)
+ list_to_junit(node, val)
+ continue
+ # scalar:
+ node = et.SubElement(parent, 'property')
+ node.set('name', key)
+ node.set('value', str(val))
+
+def list_to_junit(parent, li):
+ for i in range(len(li)):
+ if isinstance(li[i], dict):
+ node = et.SubElement(parent, 'kpi_node')
+ node.set('name', str(i))
+ dict_to_junit(node, li[i])
+ continue
+ if isinstance(val, (tuple, list)):
+ node = et.SubElement(parent, 'kpi_node')
+ node.set('name', str(i))
+ list_to_junit(node, li[i])
+ continue
+ # scalar:
+ node = et.SubElement(parent, 'property')
+ node.set('name', str(i))
+ node.set('value', str(li[i]))
+
+def kpis_to_junit(parent, kpis):
+ if not kpis:
+ return
+ assert isinstance(kpis, dict)
+ knode = et.SubElement(parent, 'kpis')
+ dict_to_junit(knode, kpis)
def trial_to_junit_write(trial, junit_path):
elements = et.ElementTree(element=trial_to_junit(trial))
@@ -118,6 +158,7 @@ def test_to_junit(t):
elif t.status != test.Test.PASS:
error = et.SubElement(testcase, 'error')
error.text = 'could not run'
+ kpis_to_junit(testcase, t.kpis())
sout = et.SubElement(testcase, 'system-out')
sout.text = escape_xml_invalid_characters(t.report_stdout())
return testcase
diff --git a/src/osmo_gsm_tester/core/test.py b/src/osmo_gsm_tester/core/test.py
index c6d88e6..dfbd169 100644
--- a/src/osmo_gsm_tester/core/test.py
+++ b/src/osmo_gsm_tester/core/test.py
@@ -49,6 +49,7 @@ class Test(log.Origin):
self.fail_message = None
self.log_targets = []
self._report_stdout = None
+ self._kpis = None
self.timeout = int(config_test_specific['timeout']) if 'timeout' in config_test_specific else None
def module_name(self):
@@ -139,6 +140,14 @@ class Test(log.Origin):
def config_test_specific(self):
return self._config_test_specific
+ def set_kpis(self, kpis):
+ if not isinstance(kpis, dict):
+ raise log.Error('Expected dictionary in toplevel kpis')
+ self._kpis = kpis
+
+ def kpis(self):
+ return self._kpis
+
def set_report_stdout(self, text):
'Overwrite stdout text stored in report from inside a test'
self._report_stdout = text