s4-test: fixed samba4.policy.python test for top level build
[rusty/samba.git] / source4 / selftest / tests.py
1 #!/usr/bin/python
2 # This script generates a list of testsuites that should be run as part of
3 # the Samba 4 test suite.
4
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".
8
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.
15
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
19 # comments.
20
21 import os
22 import subprocess
23
24 def binpath(name):
25     return os.path.join(samba4bindir, "%s%s" % (name, os.getenv("EXEEXT", "")))
26
27 perl = os.getenv("PERL", "perl")
28
29 if subprocess.call([perl, "-e", "eval require Test::More;"]) == 0:
30     has_perl_test_more = True
31 else:
32     has_perl_test_more = False
33
34 try:
35     from subunit.run import TestProgram
36 except ImportError:
37     has_system_subunit_run = False
38 else:
39     has_system_subunit_run = True
40
41 python = os.getenv("PYTHON", "python")
42
43 def valgrindify(cmdline):
44     """Run a command under valgrind, if $VALGRIND was set."""
45     valgrind = os.getenv("VALGRIND")
46     if valgrind is None:
47         return cmdline
48     return valgrind + " " + cmdline
49
50
51 def plantestsuite(name, env, cmdline, allow_empty_output=False):
52     """Plan a test suite.
53
54     :param name: Testsuite name
55     :param env: Environment to run the testsuite in
56     :param cmdline: Command line to run
57     """
58     print "-- TEST --"
59     print name
60     print env
61     if isinstance(cmdline, list):
62         cmdline = " ".join(cmdline)
63     filter_subunit_args = []
64     if not allow_empty_output:
65         filter_subunit_args.append("--fail-on-empty")
66     if "$LISTOPT" in cmdline:
67         filter_subunit_args.append("$LISTOPT")
68     print "%s 2>&1 | %s/selftest/filter-subunit %s --prefix=\"%s.\"" % (cmdline,
69                                                                         srcdir,
70                                                                         " ".join(filter_subunit_args),
71                                                                         name)
72     if allow_empty_output:
73         print "WARNING: allowing empty subunit output from %s" % name
74
75
76 def add_prefix(prefix, support_list=False):
77     if support_list:
78         listopt = "$LISTOPT "
79     else:
80         listopt = ""
81     return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\"" % (srcdir, listopt, prefix)
82
83
84 def plantestsuite_loadlist(name, env, cmdline):
85     print "-- TEST-LOADLIST --"
86     if env == "none":
87         fullname = name
88     else:
89         fullname = "%s(%s)" % (name, env)
90     print fullname
91     print env
92     if isinstance(cmdline, list):
93         cmdline = " ".join(cmdline)
94     support_list = ("$LISTOPT" in cmdline)
95     print "%s $LOADLIST 2>&1 | %s" % (cmdline, add_prefix(name, support_list))
96
97
98 def plantestsuite_idlist(name, env, cmdline):
99     print "-- TEST-IDLIST --"
100     print name
101     print env
102     if isinstance(cmdline, list):
103         cmdline = " ".join(cmdline)
104     print cmdline
105
106
107 def skiptestsuite(name, reason):
108     """Indicate that a testsuite was skipped.
109
110     :param name: Test suite name
111     :param reason: Reason the test suite was skipped
112     """
113     # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
114     print "skipping %s (%s)" % (name, reason)
115
116
117 def planperltestsuite(name, path):
118     """Run a perl test suite.
119
120     :param name: Name of the test suite
121     :param path: Path to the test runner
122     """
123     if has_perl_test_more:
124         plantestsuite(name, "none", "%s %s | %s" % (perl, path, tap2subunit))
125     else:
126         skiptestsuite(name, "Test::More not available")
127
128
129 def planpythontestsuite(env, module):
130     if has_system_subunit_run:
131         plantestsuite_idlist(module, env, [python, "-m", "subunit.run", "$LISTOPT", module])
132     else:
133         plantestsuite_idlist(module, env, "PYTHONPATH=$PYTHONPATH:%s/../lib/subunit/python:%s/../lib/testtools %s -m subunit.run $LISTOPT %s" % (samba4srcdir, samba4srcdir, python, module))
134
135
136 def plansmbtorturetestsuite(name, env, options):
137     modname = "samba4.%s" % name
138     cmdline = "%s $LISTOPT %s %s" % (valgrindify(smb4torture), options, name)
139     plantestsuite_loadlist(modname, env, cmdline)
140
141
142 srcdir = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../.."))
143 samba4srcdir = os.path.join(srcdir, 'source4')
144 builddir = os.getenv("BUILDDIR", samba4srcdir)
145 samba4bindir = os.path.normpath(os.path.join(builddir, "bin"))
146 smb4torture = binpath("smbtorture")
147 smb4torture_testsuite_list = subprocess.Popen([smb4torture, "--list-suites"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate("")[0].splitlines()
148 validate = os.getenv("VALIDATE", "")
149 if validate:
150     validate_list = [validate]
151 else:
152     validate_list = []
153 def smb4torture_testsuites(prefix):
154     return filter(lambda x: x.startswith(prefix), smb4torture_testsuite_list)
155
156 sub = subprocess.Popen("tap2subunit 2> /dev/null", stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
157 sub.communicate("")
158 if sub.returncode != 0:
159     tap2subunit = "PYTHONPATH=%s/../lib/subunit/python:%s/../lib/testtools %s %s/../lib/subunit/filters/tap2subunit" % (samba4srcdir, samba4srcdir, python, samba4srcdir)
160 else:
161     cmd = "echo -ne \"1..1\nok 1 # skip doesn't seem to work yet\n\" | tap2subunit 2> /dev/null | grep skip"
162     sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
163     if sub.returncode == 0:
164         tap2subunit = "tap2subunit"
165     else:
166         tap2subunit = "PYTHONPATH=%s/../lib/subunit/python:%s/../lib/testtools %s %s/../lib/subunit/filters/tap2subunit" % (samba4srcdir, samba4srcdir, python, samba4srcdir)
167
168 subprocess.call([smb4torture, "-V"])
169
170 bbdir = os.path.join(srcdir, "testprogs/blackbox")
171
172 configuration = "--configfile=$SMB_CONF_PATH"
173
174 torture_options = [configuration, "--maximum-runtime=$SELFTEST_MAXTIME", "--target=$SELFTEST_TARGET", "--basedir=$SELFTEST_TMPDIR"]
175 if not os.getenv("SELFTEST_VERBOSE"):
176     torture_options.append("--option=torture:progress=no")
177 torture_options.append("--format=subunit")
178 if os.getenv("SELFTEST_QUICK"):
179     torture_options.append("--option=torture:quick=yes")
180 smb4torture += " " + " ".join(torture_options)
181
182 print "OPTIONS %s" % " ".join(torture_options)
183
184 # Simple tests for LDAP and CLDAP
185 for options in ['-U"$USERNAME%$PASSWORD" --option=socket:testnonblock=true', '-U"$USERNAME%$PASSWORD"', '-U"$USERNAME%$PASSWORD" -k yes', '-U"$USERNAME%$PASSWORD" -k no', '-U"$USERNAME%$PASSWORD" -k no --sign', '-U"$USERNAME%$PASSWORD" -k no --encrypt', '-U"$USERNAME%$PASSWORD" -k yes --encrypt', '-U"$USERNAME%$PASSWORD" -k yes --sign']:
186     plantestsuite("samba4.ldb.ldap with options %s(dc)" % options, "dc", "%s/test_ldb.sh ldap $SERVER %s" % (bbdir, options))
187
188 # see if we support ldaps
189 try:
190     config_h = os.environ["CONFIG_H"]
191 except KeyError:
192     config_h = os.path.join(samba4bindir, "default/source4/include/config.h")
193 f = open(config_h, 'r')
194 try:
195     have_tls_support = ("ENABLE_GNUTLS 1" in f.read())
196 finally:
197     f.close()
198
199 if have_tls_support:
200     for options in ['-U"$USERNAME%$PASSWORD"']:
201         plantestsuite("samba4.ldb.ldaps with options %s(dc)" % options, "dc",
202                 "%s/test_ldb.sh ldaps $SERVER_IP %s" % (bbdir, options))
203
204 for options in ['-U"$USERNAME%$PASSWORD"']:
205     plantestsuite("samba4.ldb.ldapi with options %s(dc:local)" % options, "dc:local",
206             "%s/test_ldb.sh ldapi $PREFIX_ABS/dc/private/ldapi %s" % (bbdir, options))
207
208 for t in smb4torture_testsuites("ldap."):
209     plansmbtorturetestsuite(t, "dc", '-U"$USERNAME%$PASSWORD" //$SERVER_IP/_none_')
210
211 ldbdir = os.path.join(samba4srcdir, "lib/ldb")
212 # Don't run LDB tests when using system ldb, as we won't have ldbtest installed
213 if os.path.exists(os.path.join(samba4bindir, "ldbtest")):
214     plantestsuite("ldb.base", "none", "%s/tests/test-tdb.sh" % ldbdir,
215                   allow_empty_output=True)
216 else:
217     skiptestsuite("ldb.base", "Using system LDB, ldbtest not available")
218
219 # Tests for RPC
220
221 # add tests to this list as they start passing, so we test
222 # that they stay passing
223 ncacn_np_tests = ["rpc.schannel", "rpc.join", "rpc.lsa", "rpc.dssetup", "rpc.altercontext", "rpc.multibind", "rpc.netlogon", "rpc.handles", "rpc.samsync", "rpc.samba3-sessionkey", "rpc.samba3-getusername", "rpc.samba3-lsa", "rpc.samba3-bind", "rpc.samba3-netlogon", "rpc.asyncbind", "rpc.lsalookup", "rpc.lsa-getuser", "rpc.schannel2", "rpc.authcontext"]
224 ncalrpc_tests = ["rpc.schannel", "rpc.join", "rpc.lsa", "rpc.dssetup", "rpc.altercontext", "rpc.multibind", "rpc.netlogon", "rpc.drsuapi", "rpc.asyncbind", "rpc.lsalookup", "rpc.lsa-getuser", "rpc.schannel2", "rpc.authcontext"]
225 drs_rpc_tests = smb4torture_testsuites("drs.rpc")
226 ncacn_ip_tcp_tests = ["rpc.schannel", "rpc.join", "rpc.lsa", "rpc.dssetup", "rpc.altercontext", "rpc.multibind", "rpc.netlogon", "rpc.handles", "rpc.asyncbind", "rpc.lsalookup", "rpc.lsa-getuser", "rpc.schannel2", "rpc.authcontext", "rpc.objectuuid"] + drs_rpc_tests
227 slow_ncacn_np_tests = ["rpc.samlogon", "rpc.samr.users", "rpc.samr.large-dc", "rpc.samr.users.privileges", "rpc.samr.passwords", "rpc.samr.passwords.pwdlastset"]
228 slow_ncacn_ip_tcp_tests = ["rpc.samr", "rpc.cracknames"]
229
230 all_rpc_tests = ncalrpc_tests + ncacn_np_tests + ncacn_ip_tcp_tests + slow_ncacn_np_tests + slow_ncacn_ip_tcp_tests + ["rpc.lsa.secrets", "rpc.pac", "rpc.samba3-sharesec", "rpc.countcalls"]
231
232 # Make sure all tests get run
233 rpc_tests = smb4torture_testsuites("rpc.")
234 auto_rpc_tests = filter(lambda t: t not in all_rpc_tests, rpc_tests)
235
236 for bindoptions in ["seal,padcheck"] + validate_list + ["bigendian"]:
237     for transport in ["ncalrpc", "ncacn_np", "ncacn_ip_tcp"]:
238         env = "dc"
239         if transport == "ncalrpc":
240             tests = ncalrpc_tests
241             env = "dc:local"
242         elif transport == "ncacn_np":
243             tests = ncacn_np_tests
244         elif transport == "ncacn_ip_tcp":
245             tests = ncacn_ip_tcp_tests
246         for t in tests:
247             plantestsuite_loadlist("samba4.%s on %s with %s" % (t, transport, bindoptions), env, [valgrindify(smb4torture), "$LISTOPT", "%s:$SERVER[%s]" % (transport, bindoptions), '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', t])
248         plantestsuite_loadlist("samba4.rpc.samba3.sharesec on %s with %s" % (transport, bindoptions), env, [valgrindify(smb4torture), "$LISTOPT", "%s:$SERVER[%s]" % (transport, bindoptions), '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', '--option=torture:share=tmp', 'rpc.samba3-sharesec'])
249
250 for bindoptions in [""] + validate_list + ["bigendian"]:
251     for t in auto_rpc_tests:
252         plantestsuite_loadlist("samba4.%s with %s" % (t, bindoptions), "dc", [valgrindify(smb4torture), "$LISTOPT", "$SERVER[%s]" % bindoptions, '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', t])
253
254 t = "rpc.countcalls"
255 plantestsuite_loadlist("samba4.%s" % t, "dc:local", [valgrindify(smb4torture), "$LISTOPT", "$SERVER[%s]" % bindoptions, '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', t])
256
257 for transport in ["ncacn_np", "ncacn_ip_tcp"]:
258     env = "dc"
259     if transport == "ncacn_np":
260         tests = slow_ncacn_np_tests
261     elif transport == "ncacn_ip_tcp":
262         tests = slow_ncacn_ip_tcp_tests
263     for t in tests:
264         plantestsuite_loadlist("samba4.%s on %s" % (t, transport), env, [valgrindify(smb4torture), "$LISTOPT", "%s:$SERVER" % transport, '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', t])
265
266 # Tests for the DFS referral calls implementation
267 for t in smb4torture_testsuites("dfs."):
268     plansmbtorturetestsuite(t, "dc", '//$SERVER/ipc\$ -U$USERNAME%$PASSWORD')
269
270 # Tests for the NET API (net.api.become.dc tested below against all the roles)
271 net_tests = filter(lambda x: "net.api.become.dc" not in x, smb4torture_testsuites("net."))
272 for t in net_tests:
273     plansmbtorturetestsuite(t, "dc", '$SERVER[%s] -U$USERNAME%%$PASSWORD -W $DOMAIN' % validate)
274
275 # Tests for session keys and encryption of RPC pipes
276 # FIXME: Integrate these into a single smbtorture test
277
278 transport = "ncacn_np"
279 for ntlmoptions in [
280     "-k no --option=usespnego=yes",
281     "-k no --option=usespnego=yes --option=ntlmssp_client:128bit=no",
282     "-k no --option=usespnego=yes --option=ntlmssp_client:56bit=yes",
283     "-k no --option=usespnego=yes --option=ntlmssp_client:56bit=no",
284     "-k no --option=usespnego=yes --option=ntlmssp_client:128bit=no --option=ntlmssp_client:56bit=yes",
285     "-k no --option=usespnego=yes --option=ntlmssp_client:128bit=no --option=ntlmssp_client:56bit=no",
286     "-k no --option=usespnego=yes --option=clientntlmv2auth=yes",
287     "-k no --option=usespnego=yes --option=clientntlmv2auth=yes --option=ntlmssp_client:128bit=no",
288     "-k no --option=usespnego=yes --option=clientntlmv2auth=yes --option=ntlmssp_client:128bit=no --option=ntlmssp_client:56bit=yes",
289     "-k no --option=usespnego=no --option=clientntlmv2auth=yes",
290     "-k no --option=gensec:spnego=no --option=clientntlmv2auth=yes",
291     "-k no --option=usespnego=no"]:
292     name = "rpc.lsa.secrets on %s with with %s" % (transport, ntlmoptions)
293     plantestsuite_loadlist("samba4.%s" % name, "dc", [smb4torture, "$LISTOPT", "%s:$SERVER[]" % (transport), ntlmoptions, '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', '--option=gensec:target_hostname=$NETBIOSNAME', 'rpc.lsa.secrets'])
294
295 transports = ["ncacn_np", "ncacn_ip_tcp"]
296
297 #Kerberos varies between functional levels, so it is important to check this on all of them
298 for env in ["dc", "fl2000dc", "fl2003dc", "fl2008r2dc"]:
299     transport = "ncacn_np"
300     plantestsuite_loadlist("samba4.rpc.pac on %s" % (transport,), env, [smb4torture, "$LISTOPT", "%s:$SERVER[]" % (transport, ), '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', 'rpc.pac'])
301     for transport in transports:
302         plantestsuite_loadlist("samba4.rpc.lsa.secrets on %s with Kerberos" % (transport,), env, [smb4torture, "$LISTOPT", "%s:$SERVER[]" % (transport, ), '-k', 'yes', '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', '--option=gensec:target_hostname=$NETBIOSNAME', 'rpc.lsa.secrets'])
303         plantestsuite_loadlist("samba4.rpc.lsa.secrets on %s with Kerberos - use target principal" % (transport,), env, [smb4torture, "$LISTOPT", "%s:$SERVER[]" % (transport, ), '-k', 'yes', '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', "--option=clientusespnegoprincipal=yes", '--option=gensec:target_hostname=$NETBIOSNAME', 'rpc.lsa.secrets'])
304         plantestsuite_loadlist("samba4.rpc.lsa.secrets on %s with Kerberos - use Samba3 style login" % transport, env, [smb4torture, "$LISTOPT", "%s:$SERVER" % transport, '-k', 'yes', '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', "--option=gensec:fake_gssapi_krb5=yes", '--option=gensec:gssapi_krb5=no', '--option=gensec:target_hostname=$NETBIOSNAME', "rpc.lsa.secrets.none*"])
305         plantestsuite_loadlist("samba4.rpc.lsa.secrets on %s with Kerberos - use Samba3 style login, use target principal" % transport, env, [smb4torture, "$LISTOPT", "%s:$SERVER" % transport, '-k', 'yes', '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', "--option=clientusespnegoprincipal=yes", '--option=gensec:fake_gssapi_krb5=yes', '--option=gensec:gssapi_krb5=no', '--option=gensec:target_hostname=$NETBIOSNAME', "rpc.lsa.secrets.none*"])
306         plantestsuite_loadlist("samba4.rpc.echo on %s" % (transport, ), env, [smb4torture, "$LISTOPT", "%s:$SERVER[]" % (transport,), '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', 'rpc.echo'])
307
308         # Echo tests test bulk Kerberos encryption of DCE/RPC
309         for bindoptions in ["connect", "spnego", "spnego,sign", "spnego,seal"] + validate_list + ["padcheck", "bigendian", "bigendian,seal"]:
310             echooptions = "--option=socket:testnonblock=True --option=torture:quick=yes -k yes"
311             plantestsuite_loadlist("samba4.rpc.echo on %s with %s and %s" % (transport, bindoptions, echooptions), env, [smb4torture, "$LISTOPT", "%s:$SERVER[%s]" % (transport, bindoptions), echooptions, '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', 'rpc.echo'])
312     plansmbtorturetestsuite("net.api.become.dc", env, '$SERVER[%s] -U$USERNAME%%$PASSWORD -W $DOMAIN' % validate)
313
314 for transport in transports:
315     for bindoptions in ["sign", "seal"]:
316         for ntlmoptions in [
317         "--option=ntlmssp_client:ntlm2=yes --option=torture:quick=yes",
318         "--option=ntlmssp_client:ntlm2=no --option=torture:quick=yes",
319         "--option=ntlmssp_client:ntlm2=yes --option=ntlmssp_client:128bit=no --option=torture:quick=yes",
320         "--option=ntlmssp_client:ntlm2=no --option=ntlmssp_client:128bit=no --option=torture:quick=yes",
321         "--option=ntlmssp_client:ntlm2=yes --option=ntlmssp_client:keyexchange=no --option=torture:quick=yes",
322         "--option=ntlmssp_client:ntlm2=no --option=ntlmssp_client:keyexchange=no --option=torture:quick=yes",
323         "--option=clientntlmv2auth=yes --option=ntlmssp_client:keyexchange=no --option=torture:quick=yes",
324         "--option=clientntlmv2auth=yes --option=ntlmssp_client:128bit=no --option=ntlmssp_client:keyexchange=yes --option=torture:quick=yes",
325         "--option=clientntlmv2auth=yes --option=ntlmssp_client:128bit=no --option=ntlmssp_client:keyexchange=no --option=torture:quick=yes"]:
326             if transport == "ncalrpc":
327                 env = "dc:local"
328             else:
329                 env = "dc"
330             plantestsuite_loadlist("samba4.rpc.echo on %s with %s and %s" % (transport, bindoptions, ntlmoptions), env, [smb4torture, "$LISTOPT", "%s:$SERVER[%s]" % (transport, bindoptions), ntlmoptions, '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', 'rpc.echo'])
331
332 plantestsuite_loadlist("samba4.rpc.echo on ncacn_np over smb2", "dc", [smb4torture, "$LISTOPT", 'ncacn_np:$SERVER[smb2]', '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', 'rpc.echo'])
333
334 plantestsuite_loadlist("samba4.ntp.signd", "dc:local", [smb4torture, "$LISTOPT", 'ncacn_np:$SERVER', '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', 'ntp.signd'])
335
336 # Tests against the NTVFS POSIX backend
337 ntvfsargs = ["--option=torture:sharedelay=10000", "--option=torture:oplocktimeout=3", "--option=torture:writetimeupdatedelay=50000"]
338
339 smb2 = smb4torture_testsuites("smb2.")
340 #The QFILEINFO-IPC test needs to be on ipc$
341 raw = filter(lambda x: "raw.qfileinfo.ipc" not in x, smb4torture_testsuites("raw."))
342 base = smb4torture_testsuites("base.")
343
344 for t in base + raw + smb2:
345     plansmbtorturetestsuite(t, "dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD' + " " + " ".join(ntvfsargs))
346
347 plansmbtorturetestsuite("raw.qfileinfo.ipc", "dc", '//$SERVER/ipc\$ -U$USERNAME%$PASSWORD')
348
349 for t in smb4torture_testsuites("rap."):
350     plansmbtorturetestsuite(t, "dc", '//$SERVER/IPC\$ -U$USERNAME%$PASSWORD')
351
352 # Tests against the NTVFS CIFS backend
353 for t in base + raw:
354     plantestsuite_loadlist("samba4.ntvfs.cifs.%s" % t, "dc", [valgrindify(smb4torture), "$LISTOPT", '//$NETBIOSNAME/cifs', '-U$USERNAME%$PASSWORD'] + ntvfsargs + [t])
355
356 plansmbtorturetestsuite('echo.udp', 'dc:local', '//$SERVER/whatever')
357
358 # Local tests
359 for t in smb4torture_testsuites("local."):
360     plansmbtorturetestsuite(t, "none", "ncalrpc:")
361
362 tdbtorture4 = binpath("tdbtorture")
363 if os.path.exists(tdbtorture4):
364     plantestsuite("tdb.stress", "none", valgrindify(tdbtorture4))
365 else:
366     skiptestsuite("tdb.stress", "Using system TDB, tdbtorture not available")
367
368 plansmbtorturetestsuite("drs.unit", "none", "ncalrpc:")
369
370 # Pidl tests
371 for f in sorted(os.listdir(os.path.join(samba4srcdir, "../pidl/tests"))):
372     if f.endswith(".pl"):
373         planperltestsuite("pidl.%s" % f[:-3], os.path.normpath(os.path.join(samba4srcdir, "../pidl/tests", f)))
374 planperltestsuite("selftest.samba4", os.path.normpath(os.path.join(samba4srcdir, "../selftest/test_samba4.pl")))
375
376 # Blackbox Tests:
377 # tests that interact directly with the command-line tools rather than using
378 # the API. These mainly test that the various command-line options of commands
379 # work correctly.
380
381 planpythontestsuite("none", "samba.tests.blackbox.ndrdump")
382 plantestsuite("samba4.blackbox.samba_tool(dc:local)", "dc:local", [os.path.join(samba4srcdir, "utils/tests/test_samba_tool.sh"),  '$SERVER', "$USERNAME", "$PASSWORD", "$DOMAIN"])
383 plantestsuite("samba4.blackbox.pkinit(dc:local)", "dc:local", [os.path.join(bbdir, "test_pkinit.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$REALM', '$DOMAIN', '$PREFIX', "aes256-cts-hmac-sha1-96", configuration])
384 plantestsuite("samba4.blackbox.kinit(dc:local)", "dc:local", [os.path.join(bbdir, "test_kinit.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$REALM', '$DOMAIN', '$PREFIX', "aes256-cts-hmac-sha1-96", configuration])
385 plantestsuite("samba4.blackbox.kinit(fl2000dc:local)", "fl2000dc:local", [os.path.join(bbdir, "test_kinit.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$REALM', '$DOMAIN', '$PREFIX', "arcfour-hmac-md5", configuration])
386 plantestsuite("samba4.blackbox.kinit(fl2008r2dc:local)", "fl2008r2dc:local", [os.path.join(bbdir, "test_kinit.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$REALM', '$DOMAIN', '$PREFIX', "aes256-cts-hmac-sha1-96", configuration])
387 plantestsuite("samba4.blackbox.ktpass(dc)", "dc", [os.path.join(bbdir, "test_ktpass.sh"), '$PREFIX'])
388 plantestsuite("samba4.blackbox.passwords(dc:local)", "dc:local", [os.path.join(bbdir, "test_passwords.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$REALM', '$DOMAIN', "$PREFIX"])
389 plantestsuite("samba4.blackbox.export.keytab(dc:local)", "dc:local", [os.path.join(bbdir, "test_export_keytab.sh"), '$SERVER', '$USERNAME', '$REALM', '$DOMAIN', "$PREFIX"])
390 plantestsuite("samba4.blackbox.cifsdd(dc)", "dc", [os.path.join(samba4srcdir, "client/tests/test_cifsdd.sh"), '$SERVER', '$USERNAME', '$PASSWORD', "$DOMAIN"])
391 plantestsuite("samba4.blackbox.nmblookup(dc)", "dc", [os.path.join(samba4srcdir, "utils/tests/test_nmblookup.sh"), '$NETBIOSNAME', '$NETBIOSALIAS', '$SERVER', '$SERVER_IP'])
392 plantestsuite("samba4.blackbox.nmblookup(member)", "member", [os.path.join(samba4srcdir, "utils/tests/test_nmblookup.sh"), '$NETBIOSNAME', '$NETBIOSALIAS', '$SERVER', '$SERVER_IP'])
393 plantestsuite("samba4.blackbox.locktest(dc)", "dc", [os.path.join(samba4srcdir, "torture/tests/test_locktest.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$DOMAIN', '$PREFIX'])
394 plantestsuite("samba4.blackbox.masktest", "dc", [os.path.join(samba4srcdir, "torture/tests/test_masktest.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$DOMAIN', '$PREFIX'])
395 plantestsuite("samba4.blackbox.gentest(dc)", "dc", [os.path.join(samba4srcdir, "torture/tests/test_gentest.sh"), '$SERVER', '$USERNAME', '$PASSWORD', '$DOMAIN', "$PREFIX"])
396 plantestsuite("samba4.blackbox.wbinfo(dc:local)", "dc:local", [os.path.join(samba4srcdir, "../nsswitch/tests/test_wbinfo.sh"), '$DOMAIN', '$USERNAME', '$PASSWORD', "dc"])
397 plantestsuite("samba4.blackbox.wbinfo(member:local)", "member:local", [os.path.join(samba4srcdir, "../nsswitch/tests/test_wbinfo.sh"), '$DOMAIN', '$DC_USERNAME', '$DC_PASSWORD', "member"])
398 plantestsuite("samba4.blackbox.chgdcpass(dc)", "dc", [os.path.join(bbdir, "test_chgdcpass.sh"), '$SERVER', "LOCALDC\$", '$REALM', '$DOMAIN', '$PREFIX', "aes256-cts-hmac-sha1-96", '$SELFTEST_PREFIX/dc'])
399
400 # Tests using the "Simple" NTVFS backend
401 for t in ["base.rw1"]:
402     plantestsuite_loadlist("samba4.ntvfs.simple.%s" % t, "dc", [valgrindify(smb4torture), "$LISTOPT", "//$SERVER/simple", '-U$USERNAME%$PASSWORD', t])
403
404 # Domain Member Tests
405 plantestsuite_loadlist("samba4.rpc.echo against member server with local creds", "member", [valgrindify(smb4torture), "$LISTOPT", 'ncacn_np:$NETBIOSNAME', '-U$NETBIOSNAME/$USERNAME%$PASSWORD', 'rpc.echo'])
406 plantestsuite_loadlist("samba4.rpc.echo against member server with domain creds", "member", [valgrindify(smb4torture), "$LISTOPT", 'ncacn_np:$NETBIOSNAME', '-U$DOMAIN/$DC_USERNAME%$DC_PASSWORD', 'rpc.echo'])
407 plantestsuite_loadlist("samba4.rpc.samr against member server with local creds", "member", [valgrindify(smb4torture), "$LISTOPT", 'ncacn_np:$NETBIOSNAME', '-U$NETBIOSNAME/$USERNAME%$PASSWORD', "rpc.samr"])
408 plantestsuite_loadlist("samba4.rpc.samr.users against member server with local creds", "member", [valgrindify(smb4torture), "$LISTOPT", 'ncacn_np:$NETBIOSNAME', '-U$NETBIOSNAME/$USERNAME%$PASSWORD', "rpc.samr.users"])
409 plantestsuite_loadlist("samba4.rpc.samr.passwords against member server with local creds", "member", [valgrindify(smb4torture), "$LISTOPT", 'ncacn_np:$NETBIOSNAME', '-U$NETBIOSNAME/$USERNAME%$PASSWORD', "rpc.samr.passwords"])
410 plantestsuite("samba4.blackbox.smbclient against member server with local creds", "member", [os.path.join(samba4srcdir, "client/tests/test_smbclient.sh"), '$NETBIOSNAME', '$USERNAME', '$PASSWORD', '$NETBIOSNAME', '$PREFIX'])
411
412 # RPC Proxy
413 plantestsuite_loadlist("samba4.rpc.echo against rpc proxy with domain creds", "rpc_proxy", [valgrindify(smb4torture), "$LISTOPT", 'ncacn_ip_tcp:$NETBIOSNAME', '-U$DOMAIN/$DC_USERNAME%$DC_PASSWORD', "rpc.echo"])
414
415 # Tests SMB signing
416 for mech in [
417     "-k no",
418     "-k no --option=usespnego=no",
419     "-k no --option=gensec:spengo=no",
420     "-k yes",
421     "-k yes --option=gensec:fake_gssapi_krb5=yes --option=gensec:gssapi_krb5=no"]:
422     for signing in ["--signing=on", "--signing=required"]:
423         signoptions = "%s %s" % (mech, signing)
424         name = "smb.signing on with %s" % signoptions
425         plantestsuite_loadlist("samba4.%s" % name, "dc", [valgrindify(smb4torture), "$LISTOPT", '//$NETBIOSNAME/tmp', signoptions, '-U$USERNAME%$PASSWORD', 'base.xcopy'])
426
427 for mech in [
428     "-k no",
429     "-k no --option=usespnego=no",
430     "-k no --option=gensec:spengo=no",
431     "-k yes",
432     "-k yes --option=gensec:fake_gssapi_krb5=yes --option=gensec:gssapi_krb5=no"]:
433     signoptions = "%s --signing=off" % mech
434     name = "smb.signing on with %s" % signoptions
435     plantestsuite_loadlist("samba4.%s domain-creds" % name, "member", [valgrindify(smb4torture), "$LISTOPT", '//$NETBIOSNAME/tmp', signoptions, '-U$DC_USERNAME%$DC_PASSWORD', 'base.xcopy'])
436
437 for mech in [
438     "-k no",
439     "-k no --option=usespnego=no",
440     "-k no --option=gensec:spengo=no"]:
441     signoptions = "%s --signing=off" % mech
442     name = "smb.signing on with %s" % signoptions
443     plantestsuite_loadlist("samba4.%s local-creds" % name, "member", [valgrindify(smb4torture), "$LISTOPT", '//$NETBIOSNAME/tmp', signoptions, '-U$NETBIOSNAME/$USERNAME%$PASSWORD', 'base.xcopy'])
444 plantestsuite_loadlist("samba4.smb.signing --signing=yes anon", "dc", [valgrindify(smb4torture), "$LISTOPT", '//$NETBIOSNAME/tmp', '-k', 'no', '--signing=yes', '-U%', 'base.xcopy'])
445 plantestsuite_loadlist("samba4.smb.signing --signing=required anon", "dc", [valgrindify(smb4torture), "$LISTOPT", '//$NETBIOSNAME/tmp', '-k', 'no', '--signing=required', '-U%', 'base.xcopy'])
446 plantestsuite_loadlist("samba4.smb.signing --signing=no anon", "member",  [valgrindify(smb4torture), "$LISTOPT", '//$NETBIOSNAME/tmp', '-k', 'no', '--signing=no', '-U%', 'base.xcopy'])
447
448 nbt_tests = smb4torture_testsuites("nbt.")
449 for t in nbt_tests:
450     plansmbtorturetestsuite(t, "dc", "//$SERVER/_none_ -U\"$USERNAME%$PASSWORD\"")
451
452 wb_opts = ["--option=\"torture:strict mode=no\"", "--option=\"torture:timelimit=1\"", "--option=\"torture:winbindd_separator=/\"", "--option=\"torture:winbindd_netbios_name=$SERVER\"", "--option=\"torture:winbindd_netbios_domain=$DOMAIN\""]
453
454 winbind_struct_tests = smb4torture_testsuites("winbind.struct")
455 winbind_ndr_tests = smb4torture_testsuites("winbind.ndr")
456 for env in ["dc", "member"]:
457     for t in winbind_struct_tests:
458         plansmbtorturetestsuite(t, env, "%s //_none_/_none_" % " ".join(wb_opts))
459
460     for t in winbind_ndr_tests:
461         plansmbtorturetestsuite(t, env, "%s //_none_/_none_" % " ".join(wb_opts))
462
463 nsstest4 = binpath("nsstest")
464 if os.path.exists(nsstest4):
465     plantestsuite("samba4.nss.test using winbind(member)", "member", [valgrindify(nsstest4), os.path.join(samba4bindir, "shared/libnss_winbind.so")])
466 else:
467     skiptestsuite("samba4.nss.test using winbind(member)", "nsstest not available")
468
469 subunitrun = valgrindify(python) + " " + os.path.join(samba4srcdir, "scripting/bin/subunitrun")
470 def plansambapythontestsuite(name, env, path, module, environ={}, extra_args=[]):
471     environ = dict(environ)
472     environ["PYTHONPATH"] = "$PYTHONPATH:" + path
473     args = ["%s=%s" % item for item in environ.iteritems()]
474     args += [subunitrun, "$LISTOPT", module]
475     args += extra_args
476     plantestsuite(name, env, args)
477
478
479 plansambapythontestsuite("ldb.python", "none", "%s/lib/ldb/tests/python/" % samba4srcdir, 'api')
480 planpythontestsuite("none", "samba.tests.credentials")
481 plantestsuite_idlist("samba.tests.gensec", "dc:local", [subunitrun, "$LISTOPT", '-U"$USERNAME%$PASSWORD"', "samba.tests.gensec"])
482 planpythontestsuite("none", "samba.tests.registry")
483 plansambapythontestsuite("tdb.python", "none", "%s/lib/tdb/python/tests" % srcdir, 'simple')
484 planpythontestsuite("none", "samba.tests.auth")
485 planpythontestsuite("none", "samba.tests.security")
486 planpythontestsuite("none", "samba.tests.dcerpc.misc")
487 planpythontestsuite("none", "samba.tests.param")
488 planpythontestsuite("none", "samba.tests.upgrade")
489 planpythontestsuite("none", "samba.tests.core")
490 planpythontestsuite("none", "samba.tests.provision")
491 planpythontestsuite("none", "samba.tests.samba3")
492 planpythontestsuite("dc:local", "samba.tests.dcerpc.sam")
493 planpythontestsuite("dc:local", "samba.tests.dsdb")
494 planpythontestsuite("none", "samba.tests.netcmd")
495 planpythontestsuite("dc:local", "samba.tests.dcerpc.bare")
496 planpythontestsuite("dc:local", "samba.tests.dcerpc.unix")
497 planpythontestsuite("none", "samba.tests.dcerpc.rpc_talloc")
498 planpythontestsuite("none", "samba.tests.samdb")
499 planpythontestsuite("none", "samba.tests.hostconfig")
500 planpythontestsuite("none", "samba.tests.messaging")
501 planpythontestsuite("none", "samba.tests.samba3sam")
502 planpythontestsuite("none", "subunit")
503 planpythontestsuite("dc:local", "samba.tests.dcerpc.rpcecho")
504 plantestsuite_idlist("samba.tests.dcerpc.registry", "dc:local", [subunitrun, "$LISTOPT", '-U"$USERNAME%$PASSWORD"', "samba.tests.dcerpc.registry"])
505 plantestsuite("samba4.ldap.python(dc)", "dc", [python, os.path.join(samba4srcdir, "dsdb/tests/python/ldap.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '-W', '$DOMAIN'])
506 plantestsuite("samba4.tokengroups.python(dc)", "dc:local", [python, os.path.join(samba4srcdir, "dsdb/tests/python/token_group.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '-W', '$DOMAIN'])
507 plantestsuite("samba4.sam.python(dc)", "dc", [python, os.path.join(samba4srcdir, "dsdb/tests/python/sam.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '-W', '$DOMAIN'])
508 plansambapythontestsuite("samba4.schemaInfo.python(dc)", "dc", os.path.join(samba4srcdir, 'dsdb/tests/python'), 'dsdb_schema_info', extra_args=['-U"$DOMAIN/$DC_USERNAME%$DC_PASSWORD"'])
509 plantestsuite("samba4.urgent_replication.python(dc)", "dc", [python, os.path.join(samba4srcdir, "dsdb/tests/python/urgent_replication.py"), '$PREFIX_ABS/dc/private/sam.ldb'], allow_empty_output=True)
510 for env in ["dc", "fl2000dc", "fl2003dc", "fl2008r2dc"]:
511     plantestsuite("samba4.ldap_schema.python(%s)" % env, env, [python, os.path.join(samba4srcdir, "dsdb/tests/python/ldap_schema.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '-W', '$DOMAIN'])
512     plantestsuite("samba4.ldap.possibleInferiors.python(%s)" % env, env, [python, os.path.join(samba4srcdir, "dsdb/samdb/ldb_modules/tests/possibleinferiors.py"), "ldap://$SERVER", '-U"$USERNAME%$PASSWORD"', "-W", "$DOMAIN"])
513     plantestsuite("samba4.ldap.secdesc.python(%s)" % env, env, [python, os.path.join(samba4srcdir, "dsdb/tests/python/sec_descriptor.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '-W', '$DOMAIN'])
514     plantestsuite("samba4.ldap.acl.python(%s)" % env, env, [python, os.path.join(samba4srcdir, "dsdb/tests/python/acl.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"', '-W', '$DOMAIN'])
515     if env != "fl2000dc":
516         # This test makes excessively use of the "userPassword" attribute which
517         # isn't available on DCs with Windows 2000 domain function level -
518         # therefore skip it in that configuration
519         plantestsuite("samba4.ldap.passwords.python(%s)" % env, env, [python, os.path.join(samba4srcdir, "dsdb/tests/python/passwords.py"), "$SERVER", '-U"$USERNAME%$PASSWORD"', "-W", "$DOMAIN"])
520 planpythontestsuite("dc:local", "samba.tests.upgradeprovisionneeddc")
521 planpythontestsuite("none", "samba.tests.upgradeprovision")
522 planpythontestsuite("none", "samba.tests.xattr")
523 planpythontestsuite("none", "samba.tests.ntacls")
524 plantestsuite("samba4.deletetest.python(dc)", "dc", ['PYTHONPATH="$PYTHONPATH:%s/lib/subunit/python:%s/lib/testtools"' % (srcdir, srcdir),
525                                                      python, os.path.join(samba4srcdir, "dsdb/tests/python/deletetest.py"),
526                                                      '$SERVER', '-U"$USERNAME%$PASSWORD"', '-W', '$DOMAIN'])
527 plansambapythontestsuite("samba4.policy.python", "none", "%s/lib/policy/tests/python" % samba4srcdir, 'bindings')
528 plantestsuite("samba4.blackbox.samba3dump", "none", [python, os.path.join(samba4srcdir, "scripting/bin/samba3dump"), os.path.join(samba4srcdir, "../testdata/samba3")], allow_empty_output=True)
529 plantestsuite("samba4.blackbox.upgrade", "none", ["rm -rf $PREFIX/upgrade;", python, os.path.join(samba4srcdir, "setup/upgrade_from_s3"), "--targetdir=$PREFIX/upgrade", os.path.normpath(os.path.join(samba4srcdir, "../testdata/samba3")), os.path.normpath(os.path.join(samba4srcdir, "../testdata/samba3/smb.conf"))], allow_empty_output=True)
530 plantestsuite("samba4.blackbox.provision.py", "none", ["PYTHON=%s" % python, os.path.join(samba4srcdir, "setup/tests/blackbox_provision.sh"), '$PREFIX/provision'])
531 plantestsuite("samba4.blackbox.upgradeprovision.py", "none", ["PYTHON=%s" % python, os.path.join(samba4srcdir, "setup/tests/blackbox_upgradeprovision.sh"), '$PREFIX/provision'])
532 plantestsuite("samba4.blackbox.setpassword.py", "none", ["PYTHON=%s" % python, os.path.join(samba4srcdir, "setup/tests/blackbox_setpassword.sh"), '$PREFIX/provision'])
533 plantestsuite("samba4.blackbox.newuser.py", "none", ["PYTHON=%s" % python, os.path.join(samba4srcdir, "setup/tests/blackbox_newuser.sh"), '$PREFIX/provision'])
534 plantestsuite("samba4.blackbox.group.py", "none", ["PYTHON=%s" % python, os.path.join(samba4srcdir, "setup/tests/blackbox_group.sh"), '$PREFIX/provision'])
535 plantestsuite("samba4.blackbox.spn.py(dc:local)", "dc:local", ["PYTHON=%s" % python, os.path.join(samba4srcdir, "setup/tests/blackbox_spn.sh"), '$PREFIX/dc'])
536 plantestsuite("samba4.ldap.bind(dc)", "dc", [python, os.path.join(samba4srcdir, "auth/credentials/tests/bind.py"), '$SERVER', '-U"$USERNAME%$PASSWORD"'])
537
538 # DRS python tests
539 plansambapythontestsuite("samba4.drs.delete_object.python(vampire_dc)", "vampire_dc", os.path.join(samba4srcdir, 'torture/drs/python'), "delete_object", environ={'DC1': '$DC_SERVER', 'DC2': '$VAMPIRE_DC_SERVER'}, extra_args=['-U$DOMAIN/$DC_USERNAME%$DC_PASSWORD'])
540 plansambapythontestsuite("samba4.drs.fsmo.python(vampire_dc)", "vampire_dc", os.path.join(samba4srcdir, 'torture/drs/python'), "fsmo", environ={'DC1': "$DC_SERVER", 'DC2': "$VAMPIRE_DC_SERVER"}, extra_args=['-U$DOMAIN/$DC_USERNAME%$DC_PASSWORD'])
541 plansambapythontestsuite("samba4.drs.repl_schema.python(vampire_dc)", "vampire_dc", os.path.join(samba4srcdir, 'torture/drs/python'), "repl_schema", environ={'DC1': "$DC_SERVER", 'DC2': '$VAMPIRE_DC_SERVER'}, extra_args=['-U$DOMAIN/$DC_USERNAME%$DC_PASSWORD'])
542
543 # This makes sure we test the rid allocation code
544 t = "rpc.samr.large-dc"
545 plantestsuite_loadlist("samba4.%s.one" % t, "vampire_dc", [valgrindify(smb4torture), "$LISTOPT", '$SERVER', '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', t])
546 plantestsuite_loadlist("samba4.%s.two" % t, "vampire_dc", [valgrindify(smb4torture), "$LISTOPT", '$SERVER', '-U$USERNAME%$PASSWORD', '-W', '$DOMAIN', t])
547
548 # some RODC testing
549 plantestsuite_loadlist("samba4.rpc.echo", "rodc", [smb4torture, "$LISTOPT", 'ncacn_np:$SERVER', "-k", "yes", '-U$USERNAME%$PASSWORD', '-W' '$DOMAIN', 'rpc.echo'])
550 plantestsuite("samba4.blackbox.provision-backend.py", "none", ["PYTHON=%s" % python, os.path.join(samba4srcdir, "setup/tests/blackbox_provision-backend.sh"), '$PREFIX/provision'])