s3: smbd: VFS: fake_acl module called get_full_smb_filename() with a stream path...
[Samba.git] / selftest / selftesthelpers.py
blob0ec213704a8b7498944993f697423fa556cdbdef
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.
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
19 # comments.
21 import errno
22 import os
23 import subprocess
24 import sys
26 def srcdir():
27 return os.path.normpath(os.getenv("SRCDIR", os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")))
29 def source4dir():
30 return os.path.normpath(os.path.join(srcdir(), "source4"))
32 def source3dir():
33 return os.path.normpath(os.path.join(srcdir(), "source3"))
35 def bindir():
36 return os.path.normpath(os.getenv("BINDIR", "./bin"))
38 binary_mapping = {}
40 def binpath(name):
41 if name in binary_mapping:
42 name = binary_mapping[name]
43 return os.path.join(bindir(), name)
45 binary_mapping_string = os.getenv("BINARY_MAPPING", None)
46 if binary_mapping_string is not None:
47 for binmapping_entry in binary_mapping_string.split(','):
48 try:
49 (from_path, to_path) = binmapping_entry.split(':', 1)
50 except ValueError:
51 continue
52 binary_mapping[from_path] = to_path
54 # Split perl variable to allow $PERL to be set to e.g. "perl -W"
55 perl = os.getenv("PERL", "perl").split()
57 if subprocess.call(perl + ["-e", "eval require Test::More;"]) == 0:
58 has_perl_test_more = True
59 else:
60 has_perl_test_more = False
62 try:
63 from subunit.run import TestProgram
64 except ImportError:
65 has_system_subunit_run = False
66 else:
67 has_system_subunit_run = True
69 python = os.getenv("PYTHON", "python")
71 # Set a default value, overridden if we find a working one on the system
72 tap2subunit = "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools:%s/lib/extras:%s/lib/mimeparse %s %s/lib/subunit/filters/tap2subunit" % (srcdir(), srcdir(), srcdir(), srcdir(), python, srcdir())
73 subunit2to1 = "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools:%s/lib/extras:%s/lib/mimeparse %s %s/lib/subunit/filters/subunit-2to1" % (srcdir(), srcdir(), srcdir(), srcdir(), python, srcdir())
75 sub = subprocess.Popen("tap2subunit", stdin=subprocess.PIPE,
76 stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
77 sub.communicate("")
79 if sub.returncode == 0:
80 cmd = "echo -ne \"1..1\nok 1 # skip doesn't seem to work yet\n\" | tap2subunit | grep skip"
81 sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
82 stderr=subprocess.PIPE, shell=True)
83 if sub.returncode == 0:
84 tap2subunit = "tap2subunit"
86 def to_subunit1(subunit_version):
87 if subunit_version == 1:
88 return ""
89 return " | " + subunit2to1
92 def valgrindify(cmdline):
93 """Run a command under valgrind, if $VALGRIND was set."""
94 valgrind = os.getenv("VALGRIND")
95 if valgrind is None:
96 return cmdline
97 return valgrind + " " + cmdline
100 def plantestsuite(name, env, cmdline, subunit_version=1):
101 """Plan a test suite.
103 :param name: Testsuite name
104 :param env: Environment to run the testsuite in
105 :param cmdline: Command line to run
107 print "-- TEST --"
108 print name
109 print env
110 if isinstance(cmdline, list):
111 cmdline = " ".join(cmdline)
112 if "$LISTOPT" in cmdline:
113 raise AssertionError("test %s supports --list, but not --load-list" % name)
114 print cmdline + " 2>&1 " + to_subunit1(subunit_version) + " | " + add_prefix(name, env)
117 def add_prefix(prefix, env, support_list=False):
118 if support_list:
119 listopt = "$LISTOPT "
120 else:
121 listopt = ""
122 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" % (srcdir(), listopt, prefix, env)
125 def plantestsuite_loadlist(name, env, cmdline, subunit_version=1):
126 print "-- TEST-LOADLIST --"
127 if env == "none":
128 fullname = name
129 else:
130 fullname = "%s(%s)" % (name, env)
131 print fullname
132 print env
133 if isinstance(cmdline, list):
134 cmdline = " ".join(cmdline)
135 support_list = ("$LISTOPT" in cmdline)
136 if not "$LISTOPT" in cmdline:
137 raise AssertionError("loadlist test %s does not support not --list" % name)
138 if not "$LOADLIST" in cmdline:
139 raise AssertionError("loadlist test %s does not support --load-list" % name)
140 print ("%s | %s" % (cmdline.replace("$LOADLIST", ""), add_prefix(name, env, support_list))).replace("$LISTOPT", "--list")
141 print cmdline.replace("$LISTOPT", "") + " 2>&1 " + to_subunit1(subunit_version) + " | " + add_prefix(name, env, False)
144 def skiptestsuite(name, reason):
145 """Indicate that a testsuite was skipped.
147 :param name: Test suite name
148 :param reason: Reason the test suite was skipped
150 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
151 print >>sys.stderr, "skipping %s (%s)" % (name, reason)
154 def planperltestsuite(name, path):
155 """Run a perl test suite.
157 :param name: Name of the test suite
158 :param path: Path to the test runner
160 if has_perl_test_more:
161 plantestsuite(name, "none", "%s %s | %s" % (" ".join(perl), path, tap2subunit))
162 else:
163 skiptestsuite(name, "Test::More not available")
166 def planpythontestsuite(env, module, name=None, extra_path=[]):
167 if name is None:
168 name = module
169 pypath = list(extra_path)
170 if not has_system_subunit_run:
171 pypath.extend([
172 "%s/lib/subunit/python" % srcdir(),
173 "%s/lib/testtools" % srcdir(),
174 "%s/lib/extras" % srcdir(),
175 "%s/lib/mimeparse" % srcdir()])
176 args = [python, "-m", "subunit.run", "$LISTOPT", "$LOADLIST", module]
177 if pypath:
178 args.insert(0, "PYTHONPATH=%s" % ":".join(["$PYTHONPATH"] + pypath))
179 plantestsuite_loadlist(name, env, args)
182 def get_env_torture_options():
183 ret = []
184 if not os.getenv("SELFTEST_VERBOSE"):
185 ret.append("--option=torture:progress=no")
186 if os.getenv("SELFTEST_QUICK"):
187 ret.append("--option=torture:quick=yes")
188 return ret
191 samba4srcdir = source4dir()
192 samba3srcdir = source3dir()
193 bbdir = os.path.join(srcdir(), "testprogs/blackbox")
194 configuration = "--configfile=$SMB_CONF_PATH"
196 smbtorture4 = binpath("smbtorture4")
197 smbtorture4_testsuite_list = subprocess.Popen([smbtorture4, "--list-suites"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate("")[0].splitlines()
199 smbtorture4_options = [
200 configuration,
201 "--maximum-runtime=$SELFTEST_MAXTIME",
202 "--basedir=$SELFTEST_TMPDIR",
203 "--format=subunit"
204 ] + get_env_torture_options()
207 def plansmbtorture4testsuite(name, env, options, target, modname=None):
208 if modname is None:
209 modname = "samba4.%s" % name
210 if isinstance(options, list):
211 options = " ".join(options)
212 options = " ".join(smbtorture4_options + ["--target=%s" % target]) + " " + options
213 cmdline = "%s $LISTOPT $LOADLIST %s %s" % (valgrindify(smbtorture4), options, name)
214 plantestsuite_loadlist(modname, env, cmdline)
217 def smbtorture4_testsuites(prefix):
218 return filter(lambda x: x.startswith(prefix), smbtorture4_testsuite_list)
221 smbclient3 = binpath('smbclient3')
222 smbtorture3 = binpath('smbtorture3')
223 ntlm_auth3 = binpath('ntlm_auth3')
224 net = binpath('net')
225 scriptdir = os.path.join(srcdir(), "script/tests")
227 wbinfo = binpath('wbinfo')
228 dbwrap_tool = binpath('dbwrap_tool')
229 vfstest = binpath('vfstest')