3 # This script generates a list of testsuites that should be run as part of
4 # the Samba 4 test suite.
6 # The output of this script is parsed by selftest.pl, which then decides
7 # which of the tests to actually run. It will, for example, skip all tests
8 # listed in selftest/skip or only run a subset during "make quicktest".
10 # The idea is that this script outputs all of the tests of Samba 4, not
11 # just those that are known to pass, and list those that should be skipped
12 # or are known to fail in selftest/skip or selftest/knownfail. This makes it
13 # very easy to see what functionality is still missing in Samba 4 and makes
14 # it possible to run the testsuite against other servers, such as Samba 3 or
15 # Windows that have a different set of features.
17 # The syntax for a testsuite is "-- TEST --" on a single line, followed
18 # by the name of the test, the environment it needs and the command to run, all
19 # three separated by newlines. All other lines in the output are considered
28 alternate_path
= os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), "..")
29 return os
.path
.normpath(os
.getenv("SRCDIR", alternate_path
))
33 return os
.path
.normpath(os
.path
.join(srcdir(), "source4"))
37 return os
.path
.normpath(os
.path
.join(srcdir(), "source3"))
41 return os
.path
.normpath(os
.getenv("BINDIR", "./bin"))
45 return os
.path
.join(bindir(), name
)
48 # Split perl variable to allow $PERL to be set to e.g. "perl -W"
49 perl
= os
.getenv("PERL", "perl").split()
51 if subprocess
.call(perl
+ ["-e", "eval require Test::More;"]) == 0:
52 has_perl_test_more
= True
54 has_perl_test_more
= False
56 python
= os
.getenv("PYTHON", "python")
58 tap2subunit
= python
+ " " + os
.path
.join(srcdir(), "selftest", "tap2subunit")
61 def valgrindify(cmdline
):
62 """Run a command under valgrind, if $VALGRIND was set."""
63 valgrind
= os
.getenv("VALGRIND")
66 return valgrind
+ " " + cmdline
69 def plantestsuite(name
, env
, cmd
, environ
={}):
72 :param name: Testsuite name
73 :param env: Environment to run the testsuite in
74 :param cmdline: Command line to run
80 fullname
= "%s(%s)" % (name
, env
)
86 environ
= dict(environ
)
87 cmdline_env
= ["%s=%s" % item
for item
in environ
.items()]
88 cmdline
= " ".join(cmdline_env
) + " "
90 if isinstance(cmd
, list):
91 cmdline
+= " ".join(cmd
)
95 if "$LISTOPT" in cmdline
:
96 raise AssertionError("test %s supports --list, but not --load-list" % name
)
97 print(cmdline
+ " 2>&1 " + " | " + add_prefix(name
, env
))
100 def add_prefix(prefix
, env
, support_list
=False):
102 listopt
= "$LISTOPT "
105 return ("%s %s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" %
106 (python
, srcdir(), listopt
, prefix
, env
))
109 def plantestsuite_loadlist(name
, env
, cmdline
):
110 print("-- TEST-LOADLIST --")
114 fullname
= "%s(%s)" % (name
, env
)
117 if isinstance(cmdline
, list):
118 cmdline
= " ".join(cmdline
)
119 support_list
= ("$LISTOPT" in cmdline
)
120 if "$LISTOPT" not in cmdline
:
121 raise AssertionError("loadlist test %s does not support not --list" % name
)
122 if "$LOADLIST" not in cmdline
:
123 raise AssertionError("loadlist test %s does not support --load-list" % name
)
125 (cmdline
.replace("$LOADLIST", ""),
126 add_prefix(name
, env
, support_list
))).replace("$LISTOPT", "--list "))
127 print(cmdline
.replace("$LISTOPT", "") + " 2>&1 " + " | " + add_prefix(name
, env
, False))
130 def skiptestsuite(name
, reason
):
131 """Indicate that a testsuite was skipped.
133 :param name: Test suite name
134 :param reason: Reason the test suite was skipped
136 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
137 print("skipping %s (%s)" % (name
, reason
), file=sys
.stderr
)
140 def planperltestsuite(name
, path
):
141 """Run a perl test suite.
143 :param name: Name of the test suite
144 :param path: Path to the test runner
146 if has_perl_test_more
:
147 plantestsuite(name
, "none", "%s %s | %s" % (" ".join(perl
), path
, tap2subunit
))
149 skiptestsuite(name
, "Test::More not available")
152 def planpythontestsuite(env
, module
, name
=None, extra_path
=[], environ
={}, extra_args
=[]):
153 environ
= dict(environ
)
154 py_path
= list(extra_path
)
155 if py_path
is not None:
156 environ
["PYTHONPATH"] = ":".join(["$PYTHONPATH"] + py_path
)
157 args
= ["%s=%s" % item
for item
in environ
.items()]
158 args
+= [python
, "-m", "samba.subunit.run", "$LISTOPT", "$LOADLIST", module
]
163 plantestsuite_loadlist(name
, env
, args
)
166 def get_env_torture_options():
168 if not os
.getenv("SELFTEST_VERBOSE"):
169 ret
.append("--option=torture:progress=no")
170 if os
.getenv("SELFTEST_QUICK"):
171 ret
.append("--option=torture:quick=yes")
175 samba4srcdir
= source4dir()
176 samba3srcdir
= source3dir()
177 bbdir
= os
.path
.join(srcdir(), "testprogs/blackbox")
178 configuration
= "--configfile=$SMB_CONF_PATH"
180 smbtorture4
= binpath("smbtorture")
181 smbtorture4_testsuite_list
= subprocess
.Popen(
182 [smbtorture4
, "--list-suites"],
183 stdout
=subprocess
.PIPE
,
184 stderr
=subprocess
.PIPE
).communicate("")[0].decode('utf8').splitlines()
186 smbtorture4_options
= [
188 "--option=\'fss:sequence timeout=1\'",
189 "--maximum-runtime=$SELFTEST_MAXTIME",
190 "--basedir=$SELFTEST_TMPDIR",
192 ] + get_env_torture_options()
195 def plansmbtorture4testsuite(name
, env
, options
, target
, modname
=None, environ
={}):
197 modname
= "samba4.%s" % name
198 if isinstance(options
, list):
199 options
= " ".join(options
)
200 options
= " ".join(smbtorture4_options
+ ["--target=%s" % target
]) + " " + options
203 environ
= dict(environ
)
204 cmdline_env
= ["%s=%s" % item
for item
in environ
.items()]
205 cmdline
+= " ".join(cmdline_env
) + " "
206 cmdline
+= " %s $LISTOPT $LOADLIST %s %s" % (valgrindify(smbtorture4
), options
, name
)
207 plantestsuite_loadlist(modname
, env
, cmdline
)
210 def smbtorture4_testsuites(prefix
):
211 return list(filter(lambda x
: x
.startswith(prefix
), smbtorture4_testsuite_list
))
214 smbclient3
= binpath('smbclient')
215 smbtorture3
= binpath('smbtorture3')
216 ntlm_auth3
= binpath('ntlm_auth')
218 scriptdir
= os
.path
.join(srcdir(), "script/tests")
220 wbinfo
= binpath('wbinfo')
221 dbwrap_tool
= binpath('dbwrap_tool')
222 vfstest
= binpath('vfstest')
223 smbcquotas
= binpath('smbcquotas')
224 smbget
= binpath('smbget')
225 rpcclient
= binpath('rpcclient')
226 smbcacls
= binpath('smbcacls')
227 smbcontrol
= binpath('smbcontrol')
228 smbstatus
= binpath('smbstatus')