2 # This script generates a list of testsuites that should be run as part of
3 # the Samba 4 test suite.
5 # The output of this script is parsed by selftest.pl, which then decides
6 # which of the tests to actually run. It will, for example, skip all tests
7 # listed in selftest/skip or only run a subset during "make quicktest".
9 # The idea is that this script outputs all of the tests of Samba 4, not
10 # just those that are known to pass, and list those that should be skipped
11 # or are known to fail in selftest/skip or selftest/knownfail. This makes it
12 # very easy to see what functionality is still missing in Samba 4 and makes
13 # it possible to run the testsuite against other servers, such as Samba 3 or
14 # Windows that have a different set of features.
16 # The syntax for a testsuite is "-- TEST --" on a single line, followed
17 # by the name of the test, the environment it needs and the command to run, all
18 # three separated by newlines. All other lines in the output are considered
26 return os
.path
.normpath(os
.getenv("SRCDIR", os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), "..")))
29 return os
.path
.normpath(os
.path
.join(srcdir(), "source4"))
32 return os
.path
.normpath(os
.getenv("BINDIR", "./bin"))
37 if name
in binary_mapping
:
38 name
= binary_mapping
[name
]
39 return os
.path
.join(bindir(), name
)
41 binary_mapping_string
= os
.getenv("BINARY_MAPPING", None)
42 if binary_mapping_string
is not None:
43 for binmapping_entry
in binary_mapping_string
.split(','):
45 (from_path
, to_path
) = binmapping_entry
.split(':', 1)
48 binary_mapping
[from_path
] = to_path
50 # Split perl variable to allow $PERL to be set to e.g. "perl -W"
51 perl
= os
.getenv("PERL", "perl").split()
53 if subprocess
.call(perl
+ ["-e", "eval require Test::More;"]) == 0:
54 has_perl_test_more
= True
56 has_perl_test_more
= False
59 from subunit
.run
import TestProgram
61 has_system_subunit_run
= False
63 has_system_subunit_run
= True
65 python
= os
.getenv("PYTHON", "python")
67 #Set a default value, overridden if we find a working one on the system
68 tap2subunit
= "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools %s %s/lib/subunit/filters/tap2subunit" % (srcdir(), srcdir(), python
, srcdir())
70 sub
= subprocess
.Popen("tap2subunit 2> /dev/null", stdout
=subprocess
.PIPE
, stdin
=subprocess
.PIPE
, shell
=True)
73 if sub
.returncode
== 0:
74 cmd
= "echo -ne \"1..1\nok 1 # skip doesn't seem to work yet\n\" | tap2subunit 2> /dev/null | grep skip"
75 sub
= subprocess
.Popen(cmd
, stdout
=subprocess
.PIPE
, stdin
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
76 if sub
.returncode
== 0:
77 tap2subunit
= "tap2subunit"
79 def valgrindify(cmdline
):
80 """Run a command under valgrind, if $VALGRIND was set."""
81 valgrind
= os
.getenv("VALGRIND")
84 return valgrind
+ " " + cmdline
87 def plantestsuite(name
, env
, cmdline
, allow_empty_output
=False):
90 :param name: Testsuite name
91 :param env: Environment to run the testsuite in
92 :param cmdline: Command line to run
97 if isinstance(cmdline
, list):
98 cmdline
= " ".join(cmdline
)
99 filter_subunit_args
= []
100 if not allow_empty_output
:
101 filter_subunit_args
.append("--fail-on-empty")
102 if "$LISTOPT" in cmdline
:
103 filter_subunit_args
.append("$LISTOPT")
104 print "%s 2>&1 | %s/selftest/filter-subunit %s --prefix=\"%s.\" --suffix=\"(%s)\"" % (cmdline
,
106 " ".join(filter_subunit_args
),
108 if allow_empty_output
:
109 print >>sys
.stderr
, "WARNING: allowing empty subunit output from %s" % name
112 def add_prefix(prefix
, env
, support_list
=False):
114 listopt
= "$LISTOPT "
117 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" % (srcdir(), listopt
, prefix
, env
)
120 def plantestsuite_loadlist(name
, env
, cmdline
):
121 print "-- TEST-LOADLIST --"
125 fullname
= "%s(%s)" % (name
, env
)
128 if isinstance(cmdline
, list):
129 cmdline
= " ".join(cmdline
)
130 support_list
= ("$LISTOPT" in cmdline
)
131 print "%s $LOADLIST 2>&1 | %s" % (cmdline
, add_prefix(name
, env
, support_list
))
134 def plantestsuite_idlist(name
, env
, cmdline
):
135 print "-- TEST-IDLIST --"
139 fullname
= "%s(%s)" % (name
, env
)
142 if isinstance(cmdline
, list):
143 cmdline
= " ".join(cmdline
)
147 def skiptestsuite(name
, reason
):
148 """Indicate that a testsuite was skipped.
150 :param name: Test suite name
151 :param reason: Reason the test suite was skipped
153 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
154 print >>sys
.stderr
, "skipping %s (%s)" % (name
, reason
)
157 def planperltestsuite(name
, path
):
158 """Run a perl test suite.
160 :param name: Name of the test suite
161 :param path: Path to the test runner
163 if has_perl_test_more
:
164 plantestsuite(name
, "none", "%s %s | %s" % (" ".join(perl
), path
, tap2subunit
))
166 skiptestsuite(name
, "Test::More not available")
169 def planpythontestsuite(env
, module
, name
=None, extra_path
=[]):
172 pypath
= list(extra_path
)
173 if not has_system_subunit_run
:
174 pypath
.extend(["%s/lib/subunit/python" % srcdir(),
175 "%s/lib/testtools" % srcdir()])
176 args
= [python
, "-m", "subunit.run", "$LISTOPT", module
]
178 args
.insert(0, "PYTHONPATH=%s" % ":".join(["$PYTHONPATH"] + pypath
))
179 plantestsuite_idlist(name
, env
, args
)