s4:libcli:smb2: add support durable handle request v2 blob in smb2_create_send
[Samba/vl.git] / selftest / filter-subunit
blobbced14b101cedb00c9e613f2e3243d1a3d506480
1 #!/usr/bin/env python
2 # Filter a subunit stream
3 # Copyright (C) 2009-2011 Jelmer Vernooij <jelmer@samba.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # NOTE: This script is a hack, meant as a placeholder until we can migrate
19 # to upstream subunit's filtering tools.
21 import optparse
22 import os
23 import sys
24 import signal
26 sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../lib/subunit/python"))
27 sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../lib/testtools"))
29 import subunithelper
31 parser = optparse.OptionParser("filter-subunit [options] < instream > outstream")
32 parser.add_option("--expected-failures", type="string",
33 help="File containing list of regexes matching tests to consider known "
34 "failures")
35 parser.add_option("--flapping", type="string",
36 help="File containing list of flapping tests, of which to ignore results.")
37 parser.add_option("--strip-passed-output", action="store_true",
38 help="Whether to strip output from tests that passed")
39 parser.add_option("--fail-immediately", action="store_true",
40 help="Whether to stop on the first error", default=False)
41 parser.add_option("--prefix", type="string",
42 help="Add prefix to all test names")
43 parser.add_option("--fail-on-empty", default=False,
44 action="store_true", help="Fail if there was no subunit output")
45 parser.add_option("--list", default=False,
46 action="store_true", help="Operate in list mode")
47 opts, args = parser.parse_args()
49 if opts.list:
50 prefix = opts.prefix
51 if not prefix:
52 prefix = ""
53 for l in sys.stdin:
54 sys.stdout.write("%s%s\n" % (prefix, l.rstrip()))
55 sys.exit(0)
57 if opts.expected_failures:
58 expected_failures = subunithelper.read_test_regexes(opts.expected_failures)
59 else:
60 expected_failures = {}
63 if opts.flapping:
64 flapping = subunithelper.read_test_regexes(opts.flapping)
65 else:
66 flapping = {}
68 statistics = {
69 'TESTS_UNEXPECTED_OK': 0,
70 'TESTS_EXPECTED_OK': 0,
71 'TESTS_UNEXPECTED_FAIL': 0,
72 'TESTS_EXPECTED_FAIL': 0,
73 'TESTS_ERROR': 0,
74 'TESTS_SKIP': 0,
77 def handle_sigint(sig, stack):
78 sys.exit(0)
79 signal.signal(signal.SIGINT, handle_sigint)
81 out = subunithelper.SubunitOps(sys.stdout)
82 msg_ops = subunithelper.FilterOps(out, opts.prefix, expected_failures,
83 opts.strip_passed_output,
84 fail_immediately=opts.fail_immediately,
85 flapping=flapping)
87 try:
88 ret = subunithelper.parse_results(msg_ops, statistics, sys.stdin)
89 except subunithelper.ImmediateFail:
90 sys.stdout.flush()
91 sys.exit(1)
93 if opts.fail_on_empty and not msg_ops.seen_output:
94 sys.exit(1)
95 else:
96 sys.exit(ret)