aboutsummaryrefslogtreecommitdiff
path: root/scripts/xunit/xunit.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/xunit/xunit.py')
-rw-r--r--scripts/xunit/xunit.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/scripts/xunit/xunit.py b/scripts/xunit/xunit.py
new file mode 100644
index 0000000..c636136
--- /dev/null
+++ b/scripts/xunit/xunit.py
@@ -0,0 +1,91 @@
+
+
+# Copyright (c) 2020, ARM Limited.
+#
+# 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.
+
+from __future__ import print_function
+import xml.etree.ElementTree as ET
+
+class xunit_results():
+ def __init__(self, name='Testsuites'):
+ self.name = name
+ self.suites = []
+ def create_suite(self, name):
+ s = xunit_suite(name)
+ self.suites.append(s)
+ return s
+ def write_results(self, filename):
+ suites = ET.Element(self.name)
+ tree = ET.ElementTree(suites)
+ for s in self.suites:
+ testsuite = ET.SubElement(suites, 'testsuite', {'name' : s.name, 'errors' : '0'})
+ tests = 0
+ failures = 0
+ skip = 0
+ for t in s.tests:
+ test = ET.SubElement(testsuite, 'testcase', {'name' : t.name, 'classname' : t.classname, 'time' : t.time})
+ tests += 1
+ if t.skip:
+ skip += 1
+ ET.SubElement(test, 'skipped', {'type' : 'Skipped test'})
+ if t.fail:
+ failures += 1
+ fail = ET.SubElement(test, 'failure', {'type' : 'Test failed'})
+ fail.text = t.fail
+ if t.sysout:
+ sysout = ET.SubElement(test, 'system-out')
+ sysout.text = t.sysout
+ if t.syserr:
+ syserr = ET.SubElement(test, 'system-err')
+ syserr.text = t.syserr
+ testsuite.attrib['tests'] = str(tests)
+ testsuite.attrib['failures'] = str(failures)
+ testsuite.attrib['skip'] = str(skip)
+ tree.write(filename, 'UTF-8', True)
+
+
+class xunit_suite():
+ def __init__(self, name):
+ self.name = name
+ self.tests = []
+
+class xunit_test():
+ def __init__(self, name, classname=None):
+ self.name = name
+ if classname:
+ self.classname = classname
+ else:
+ self.classname = name
+ self.time = '0.000'
+ self.fail = None
+ self.skip = False
+ self.sysout = None
+ self.syserr = None
+ def failed(self, text):
+ self.fail = text
+ def skipped(self):
+ self.skip = True
+
+
+if __name__ == '__main__':
+ r = xunit_results()
+ s = r.create_suite('selftest')
+ for i in range(0,10):
+ t = xunit_test('atest' + str(i))
+ if i == 3:
+ t.failed('Unknown failure foo')
+ if i == 7:
+ t.skipped()
+ s.tests.append(t)
+ r.write_results('foo.xml')