2010-03-30 14:46:26 +04:00
#!/usr/bin/env python
# Filter a subunit stream
2011-12-04 04:55:23 +04:00
# Copyright (C) 2009-2011 Jelmer Vernooij <jelmer@samba.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# NOTE: This script is a hack, meant as a placeholder until we can migrate
# to upstream subunit's filtering tools.
2010-03-30 14:46:26 +04:00
import optparse
import sys
import signal
2014-11-04 23:37:41 +03:00
sys.path.insert(0, "bin/python")
2010-03-31 06:51:05 +04:00
2010-03-31 06:52:13 +04:00
import subunithelper
2010-03-30 14:46:26 +04:00
parser = optparse.OptionParser("filter-subunit [options] < instream > outstream")
2017-06-01 06:26:48 +03:00
parser.add_option("--expected-failures", type="string", action="append",
help=("File or directory containing lists of regexes matching tests "
"to consider known failures"))
parser.add_option("--flapping", type="string", action="append",
help=("File or directory containing lists of flapping tests, "
"of which to ignore results."))
2011-12-04 03:23:02 +04:00
parser.add_option("--strip-passed-output", action="store_true",
2010-03-30 14:46:26 +04:00
help="Whether to strip output from tests that passed")
2011-12-04 03:23:02 +04:00
parser.add_option("--fail-immediately", action="store_true",
2010-09-27 05:56:50 +04:00
help="Whether to stop on the first error", default=False)
2016-08-02 02:00:27 +03:00
parser.add_option("--prefix", type="string", default='',
2014-10-26 21:31:38 +03:00
help="Add prefix to all test names")
2016-08-02 02:00:27 +03:00
parser.add_option("--suffix", type="string", default='',
2014-10-26 21:31:38 +03:00
help="Add suffix to all test names")
2010-11-03 18:30:40 +03:00
parser.add_option("--fail-on-empty", default=False,
2014-10-26 21:31:38 +03:00
action="store_true", help="Fail if there was no subunit output")
2010-12-11 20:21:27 +03:00
parser.add_option("--list", default=False,
2014-10-26 21:31:38 +03:00
action="store_true", help="Operate in list mode")
2016-08-17 01:56:50 +03:00
parser.add_option("--perf-test-output", default=False,
action="store_true", help="orientate output for performance measurement")
2010-03-30 14:46:26 +04:00
opts, args = parser.parse_args()
2010-12-11 20:21:27 +03:00
if opts.list:
2014-10-26 21:31:38 +03:00
for l in sys.stdin:
2016-08-02 02:00:27 +03:00
sys.stdout.write("%s%s%s\n" % (opts.prefix, l.rstrip(), opts.suffix))
2014-10-26 21:31:38 +03:00
sys.exit(0)
2010-12-11 20:21:27 +03:00
2016-08-17 01:56:50 +03:00
if opts.perf_test_output:
bad_options = []
for bad_opt in ('fail_immediately', 'strip_passed_output',
'flapping', 'expected_failures'):
if getattr(opts, bad_opt):
bad_options.append(bad_opt)
if bad_options:
print >>sys.stderr, ("--perf-test-output is incompatible with --%s" %
(', --'.join(x.replace('_', '-')
for x in bad_options)))
sys.exit(1)
2010-03-30 14:46:26 +04:00
if opts.expected_failures:
2017-06-01 06:26:48 +03:00
expected_failures = subunithelper.read_test_regexes(*opts.expected_failures)
2010-03-30 14:46:26 +04:00
else:
2014-10-26 21:31:38 +03:00
expected_failures = {}
2010-03-30 14:46:26 +04:00
2011-12-04 03:23:02 +04:00
if opts.flapping:
2017-06-01 06:26:48 +03:00
flapping = subunithelper.read_test_regexes(*opts.flapping)
2011-12-04 03:23:02 +04:00
else:
2014-10-26 21:31:38 +03:00
flapping = {}
2011-12-04 03:23:02 +04:00
2010-03-30 14:46:26 +04:00
statistics = {
2014-10-26 21:31:38 +03:00
'TESTS_UNEXPECTED_OK': 0,
'TESTS_EXPECTED_OK': 0,
'TESTS_UNEXPECTED_FAIL': 0,
'TESTS_EXPECTED_FAIL': 0,
'TESTS_ERROR': 0,
'TESTS_SKIP': 0,
2010-03-30 14:46:26 +04:00
}
def handle_sigint(sig, stack):
2014-10-26 21:31:38 +03:00
sys.exit(0)
2010-03-30 14:46:26 +04:00
signal.signal(signal.SIGINT, handle_sigint)
2010-09-13 23:17:05 +04:00
out = subunithelper.SubunitOps(sys.stdout)
2016-08-17 01:56:50 +03:00
if opts.perf_test_output:
msg_ops = subunithelper.PerfFilterOps(out, opts.prefix, opts.suffix)
else:
msg_ops = subunithelper.FilterOps(out, opts.prefix, opts.suffix,
expected_failures,
opts.strip_passed_output,
fail_immediately=opts.fail_immediately,
flapping=flapping)
2010-03-30 14:46:26 +04:00
2010-09-28 09:10:43 +04:00
try:
2014-10-26 21:31:38 +03:00
ret = subunithelper.parse_results(msg_ops, statistics, sys.stdin)
2010-09-28 09:10:43 +04:00
except subunithelper.ImmediateFail:
2014-10-26 21:31:38 +03:00
sys.stdout.flush()
sys.exit(1)
2010-11-03 18:30:40 +03:00
if opts.fail_on_empty and not msg_ops.seen_output:
2014-10-26 21:31:38 +03:00
sys.exit(1)
2010-11-03 18:30:40 +03:00
else:
2014-10-26 21:31:38 +03:00
sys.exit(ret)