blob: 7892fc6eb36464e874546345f0878f7bd6c7aac2 [file] [log] [blame]
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +02001# osmo_gsm_tester: report: directory of binaries to be tested
2#
3# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
4#
5# Author: Pau Espin Pedrol <pespin@sysmocom.de>
6#
7# This program is free software: you can redistribute it and/or modify
Harald Welte27205342017-06-03 09:51:45 +02008# it under the terms of the GNU General Public License as
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +02009# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte27205342017-06-03 09:51:45 +020015# GNU General Public License for more details.
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020016#
Harald Welte27205342017-06-03 09:51:45 +020017# You should have received a copy of the GNU General Public License
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020018# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20import os
21import math
22from datetime import datetime
23import xml.etree.ElementTree as et
24from . import log, suite
25
26def trial_to_junit_write(trial, junit_path):
27 elements = et.ElementTree(element=trial_to_junit(trial))
28 elements.write(junit_path)
29
30def trial_to_junit(trial):
31 testsuites = et.Element('testsuites')
32 for suite in trial.suites:
33 testsuite = suite_to_junit(suite)
34 testsuites.append(testsuite)
35 return testsuites
36
37def suite_to_junit(suite):
38 testsuite = et.Element('testsuite')
39 testsuite.set('name', suite.name())
40 testsuite.set('hostname', 'localhost')
41 testsuite.set('timestamp', datetime.fromtimestamp(round(suite.start_timestamp)).isoformat())
42 testsuite.set('time', str(math.ceil(suite.duration)))
43 testsuite.set('tests', str(len(suite.tests)))
44 testsuite.set('failures', str(suite.test_failed_ctr))
45 for test in suite.tests:
46 testcase = test_to_junit(test)
47 testsuite.append(testcase)
48 return testsuite
49
50def test_to_junit(test):
51 testcase = et.Element('testcase')
52 testcase.set('name', test.name())
53 testcase.set('time', str(math.ceil(test.duration)))
54 if test.status == suite.Test.SKIP:
55 skip = et.SubElement(testcase, 'skipped')
56 elif test.status == suite.Test.FAIL:
57 failure = et.SubElement(testcase, 'failure')
58 failure.set('type', test.fail_type)
59 failure.text = test.fail_message
60 return testcase
61
62def trial_to_text(trial):
63 msg = '\n%s [%s]\n ' % (trial.status, trial.name())
64 msg += '\n '.join(suite_to_text(result) for result in trial.suites)
65 return msg
66
67def suite_to_text(suite):
68 if suite.test_failed_ctr:
69 return 'FAIL: [%s] %d failed out of %d tests run (%d skipped):\n %s' % (
70 suite.name(), suite.test_failed_ctr, len(suite.tests), suite.test_skipped_ctr,
71 '\n '.join([test_to_text(t) for t in suite.tests]))
72 if not suite.tests:
73 return 'no tests were run.'
74 return 'pass: all %d tests passed (%d skipped).' % (len(suite.tests), suite.test_skipped_ctr)
75
76def test_to_text(test):
77 ret = "%s: [%s]" % (test.status, test.name())
78 if test.status != suite.Test.SKIP:
79 ret += " (%s, %d sec)" % (datetime.fromtimestamp(round(test.start_timestamp)).isoformat(), test.duration)
80 if test.status == suite.Test.FAIL:
81 ret += " type:'%s' message: %s" % (test.fail_type, test.fail_message.replace('\n', '\n '))
82 return ret
83
84# vim: expandtab tabstop=4 shiftwidth=4