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
.path
.join(srcdir(), "source3"))
35 return os
.path
.normpath(os
.getenv("BINDIR", "./bin"))
40 if name
in binary_mapping
:
41 name
= binary_mapping
[name
]
42 return os
.path
.join(bindir(), name
)
44 binary_mapping_string
= os
.getenv("BINARY_MAPPING", None)
45 if binary_mapping_string
is not None:
46 for binmapping_entry
in binary_mapping_string
.split(','):
48 (from_path
, to_path
) = binmapping_entry
.split(':', 1)
51 binary_mapping
[from_path
] = to_path
53 # Split perl variable to allow $PERL to be set to e.g. "perl -W"
54 perl
= os
.getenv("PERL", "perl").split()
56 if subprocess
.call(perl
+ ["-e", "eval require Test::More;"]) == 0:
57 has_perl_test_more
= True
59 has_perl_test_more
= False
62 from subunit
.run
import TestProgram
64 has_system_subunit_run
= False
66 has_system_subunit_run
= True
68 python
= os
.getenv("PYTHON", "python")
70 # Set a default value, overridden if we find a working one on the system
71 tap2subunit
= "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools %s %s/lib/subunit/filters/tap2subunit" % (srcdir(), srcdir(), python
, srcdir())
73 sub
= subprocess
.Popen("tap2subunit", stdin
=subprocess
.PIPE
,
74 stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, shell
=True)
77 if sub
.returncode
== 0:
78 cmd
= "echo -ne \"1..1\nok 1 # skip doesn't seem to work yet\n\" | tap2subunit | grep skip"
79 sub
= subprocess
.Popen(cmd
, stdout
=subprocess
.PIPE
, stdin
=subprocess
.PIPE
,
80 stderr
=subprocess
.PIPE
, shell
=True)
81 if sub
.returncode
== 0:
82 tap2subunit
= "tap2subunit"
84 def valgrindify(cmdline
):
85 """Run a command under valgrind, if $VALGRIND was set."""
86 valgrind
= os
.getenv("VALGRIND")
89 return valgrind
+ " " + cmdline
92 def plantestsuite(name
, env
, cmdline
):
95 :param name: Testsuite name
96 :param env: Environment to run the testsuite in
97 :param cmdline: Command line to run
102 if isinstance(cmdline
, list):
103 cmdline
= " ".join(cmdline
)
104 filter_subunit_args
= ["--fail-on-empty"]
105 if "$LISTOPT" in cmdline
:
106 filter_subunit_args
.append("$LISTOPT")
107 print "%s 2>&1 | %s/selftest/filter-subunit %s --prefix=\"%s.\" --suffix=\"(%s)\"" % (cmdline
,
109 " ".join(filter_subunit_args
),
113 def add_prefix(prefix
, env
, support_list
=False):
115 listopt
= "$LISTOPT "
118 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" % (srcdir(), listopt
, prefix
, env
)
121 def plantestsuite_loadlist(name
, env
, cmdline
):
122 print "-- TEST-LOADLIST --"
126 fullname
= "%s(%s)" % (name
, env
)
129 if isinstance(cmdline
, list):
130 cmdline
= " ".join(cmdline
)
131 support_list
= ("$LISTOPT" in cmdline
)
132 print "%s $LOADLIST 2>&1 | %s" % (cmdline
, add_prefix(name
, env
, support_list
))
135 def plantestsuite_idlist(name
, env
, cmdline
):
136 print "-- TEST-IDLIST --"
140 fullname
= "%s(%s)" % (name
, env
)
143 if isinstance(cmdline
, list):
144 cmdline
= " ".join(cmdline
)
148 def skiptestsuite(name
, reason
):
149 """Indicate that a testsuite was skipped.
151 :param name: Test suite name
152 :param reason: Reason the test suite was skipped
154 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
155 print >>sys
.stderr
, "skipping %s (%s)" % (name
, reason
)
158 def planperltestsuite(name
, path
):
159 """Run a perl test suite.
161 :param name: Name of the test suite
162 :param path: Path to the test runner
164 if has_perl_test_more
:
165 plantestsuite(name
, "none", "%s %s | %s" % (" ".join(perl
), path
, tap2subunit
))
167 skiptestsuite(name
, "Test::More not available")
170 def planpythontestsuite(env
, module
, name
=None, extra_path
=[]):
173 pypath
= list(extra_path
)
174 if not has_system_subunit_run
:
175 pypath
.extend(["%s/lib/subunit/python" % srcdir(),
176 "%s/lib/testtools" % srcdir()])
177 args
= [python
, "-m", "subunit.run", "$LISTOPT", module
]
179 args
.insert(0, "PYTHONPATH=%s" % ":".join(["$PYTHONPATH"] + pypath
))
180 plantestsuite_idlist(name
, env
, args
)
183 def get_env_torture_options():
185 if not os
.getenv("SELFTEST_VERBOSE"):
186 ret
.append("--option=torture:progress=no")
187 if os
.getenv("SELFTEST_QUICK"):
188 ret
.append("--option=torture:quick=yes")
192 samba4srcdir
= source4dir()
193 samba3srcdir
= source3dir()
194 bbdir
= os
.path
.join(srcdir(), "testprogs/blackbox")
195 configuration
= "--configfile=$SMB_CONF_PATH"
197 smbtorture4
= binpath("smbtorture4")
198 smbtorture4_testsuite_list
= subprocess
.Popen([smbtorture4
, "--list-suites"], stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
).communicate("")[0].splitlines()
200 smbtorture4_options
= [
202 "--maximum-runtime=$SELFTEST_MAXTIME",
203 "--basedir=$SELFTEST_TMPDIR",
205 ] + get_env_torture_options()
208 def plansmbtorture4testsuite(name
, env
, options
, target
, modname
=None):
210 modname
= "samba4.%s" % name
211 if isinstance(options
, list):
212 options
= " ".join(options
)
213 options
= " ".join(smbtorture4_options
+ ["--target=%s" % target
]) + " " + options
214 cmdline
= "%s $LISTOPT %s %s" % (valgrindify(smbtorture4
), options
, name
)
215 plantestsuite_loadlist(modname
, env
, cmdline
)
218 def smbtorture4_testsuites(prefix
):
219 return filter(lambda x
: x
.startswith(prefix
), smbtorture4_testsuite_list
)
222 smbclient3
= binpath('smbclient3')
223 smbtorture3
= binpath('smbtorture3')
224 ntlm_auth3
= binpath('ntlm_auth3')
226 scriptdir
= os
.path
.join(srcdir(), "script/tests")
228 wbinfo
= binpath('wbinfo')
229 dbwrap_tool
= binpath('dbwrap_tool')
230 vfstest
= binpath('vfstest')