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
20 from __future__
import print_function
27 return os
.path
.normpath(os
.getenv("SRCDIR", os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), "..")))
30 return os
.path
.normpath(os
.path
.join(srcdir(), "source4"))
33 return os
.path
.normpath(os
.path
.join(srcdir(), "source3"))
36 return os
.path
.normpath(os
.getenv("BINDIR", "./bin"))
39 return os
.path
.join(bindir(), name
)
41 # Split perl variable to allow $PERL to be set to e.g. "perl -W"
42 perl
= os
.getenv("PERL", "perl").split()
44 if subprocess
.call(perl
+ ["-e", "eval require Test::More;"]) == 0:
45 has_perl_test_more
= True
47 has_perl_test_more
= False
49 python
= os
.getenv("PYTHON", "python")
50 extra_python
= os
.getenv("EXTRA_PYTHON", None)
52 tap2subunit
= python
+ " " + os
.path
.join(srcdir(), "selftest", "tap2subunit")
55 def valgrindify(cmdline
):
56 """Run a command under valgrind, if $VALGRIND was set."""
57 valgrind
= os
.getenv("VALGRIND")
60 return valgrind
+ " " + cmdline
63 def plantestsuite(name
, env
, cmdline
):
66 :param name: Testsuite name
67 :param env: Environment to run the testsuite in
68 :param cmdline: Command line to run
74 fullname
= "%s(%s)" % (name
, env
)
77 if isinstance(cmdline
, list):
78 cmdline
= " ".join(cmdline
)
79 if "$LISTOPT" in cmdline
:
80 raise AssertionError("test %s supports --list, but not --load-list" % name
)
81 print(cmdline
+ " 2>&1 " + " | " + add_prefix(name
, env
))
84 def add_prefix(prefix
, env
, support_list
=False):
89 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" % (srcdir(), listopt
, prefix
, env
)
92 def plantestsuite_loadlist(name
, env
, cmdline
):
93 print("-- TEST-LOADLIST --")
97 fullname
= "%s(%s)" % (name
, env
)
100 if isinstance(cmdline
, list):
101 cmdline
= " ".join(cmdline
)
102 support_list
= ("$LISTOPT" in cmdline
)
103 if not "$LISTOPT" in cmdline
:
104 raise AssertionError("loadlist test %s does not support not --list" % name
)
105 if not "$LOADLIST" in cmdline
:
106 raise AssertionError("loadlist test %s does not support --load-list" % name
)
107 print(("%s | %s" % (cmdline
.replace("$LOADLIST", ""), add_prefix(name
, env
, support_list
))).replace("$LISTOPT", "--list"))
108 print(cmdline
.replace("$LISTOPT", "") + " 2>&1 " + " | " + add_prefix(name
, env
, False))
111 def skiptestsuite(name
, reason
):
112 """Indicate that a testsuite was skipped.
114 :param name: Test suite name
115 :param reason: Reason the test suite was skipped
117 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
118 print("skipping %s (%s)" % (name
, reason
), file=sys
.stderr
)
121 def planperltestsuite(name
, path
):
122 """Run a perl test suite.
124 :param name: Name of the test suite
125 :param path: Path to the test runner
127 if has_perl_test_more
:
128 plantestsuite(name
, "none", "%s %s | %s" % (" ".join(perl
), path
, tap2subunit
))
130 skiptestsuite(name
, "Test::More not available")
133 def planpythontestsuite(env
, module
, name
=None, extra_path
=[], py3_compatible
=False):
136 pypath
= list(extra_path
)
137 args
= [python
, "-m", "samba.subunit.run", "$LISTOPT", "$LOADLIST", module
]
139 args
.insert(0, "PYTHONPATH=%s" % ":".join(["$PYTHONPATH"] + pypath
))
140 plantestsuite_loadlist(name
, env
, args
)
141 if py3_compatible
and extra_python
is not None:
142 # Plan one more test for Python 3 compatible module
143 args
[0] = extra_python
144 plantestsuite_loadlist(name
+ ".python3", env
, args
)
147 def get_env_torture_options():
149 if not os
.getenv("SELFTEST_VERBOSE"):
150 ret
.append("--option=torture:progress=no")
151 if os
.getenv("SELFTEST_QUICK"):
152 ret
.append("--option=torture:quick=yes")
156 samba4srcdir
= source4dir()
157 samba3srcdir
= source3dir()
158 bbdir
= os
.path
.join(srcdir(), "testprogs/blackbox")
159 configuration
= "--configfile=$SMB_CONF_PATH"
161 smbtorture4
= binpath("smbtorture")
162 smbtorture4_testsuite_list
= subprocess
.Popen([smbtorture4
, "--list-suites"], stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
).communicate("")[0].splitlines()
164 smbtorture4_options
= [
166 "--option=\'fss:sequence timeout=1\'",
167 "--maximum-runtime=$SELFTEST_MAXTIME",
168 "--basedir=$SELFTEST_TMPDIR",
170 ] + get_env_torture_options()
173 def plansmbtorture4testsuite(name
, env
, options
, target
, modname
=None):
175 modname
= "samba4.%s" % name
176 if isinstance(options
, list):
177 options
= " ".join(options
)
178 options
= " ".join(smbtorture4_options
+ ["--target=%s" % target
]) + " " + options
179 cmdline
= "%s $LISTOPT $LOADLIST %s %s" % (valgrindify(smbtorture4
), options
, name
)
180 plantestsuite_loadlist(modname
, env
, cmdline
)
183 def smbtorture4_testsuites(prefix
):
184 return filter(lambda x
: x
.startswith(prefix
), smbtorture4_testsuite_list
)
187 smbclient3
= binpath('smbclient')
188 smbtorture3
= binpath('smbtorture3')
189 ntlm_auth3
= binpath('ntlm_auth')
191 scriptdir
= os
.path
.join(srcdir(), "script/tests")
193 wbinfo
= binpath('wbinfo')
194 dbwrap_tool
= binpath('dbwrap_tool')
195 vfstest
= binpath('vfstest')
196 smbcquotas
= binpath('smbcquotas')
197 smbget
= binpath('smbget')
198 rpcclient
= binpath('rpcclient')
199 smbcacls
= binpath('smbcacls')