tests/krb5: Fix PA-PAC-OPTIONS checking
[Samba.git] / selftest / selftesthelpers.py
blob1dd30b01ea7fc805427a4049d8545d5e6185038c
1 #!/usr/bin/env python3
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
20 # comments.
21 from __future__ import print_function
23 import os
24 import subprocess
25 import sys
28 def srcdir():
29 alternate_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
30 return os.path.normpath(os.getenv("SRCDIR", alternate_path))
33 def source4dir():
34 return os.path.normpath(os.path.join(srcdir(), "source4"))
37 def source3dir():
38 return os.path.normpath(os.path.join(srcdir(), "source3"))
41 def bindir():
42 return os.path.normpath(os.getenv("BINDIR", "./bin"))
45 def binpath(name):
46 return os.path.join(bindir(), name)
49 # Split perl variable to allow $PERL to be set to e.g. "perl -W"
50 perl = os.getenv("PERL", "perl").split()
52 if subprocess.call(perl + ["-e", "eval require Test::More;"]) == 0:
53 has_perl_test_more = True
54 else:
55 has_perl_test_more = False
57 python = os.getenv("PYTHON", "python")
59 tap2subunit = python + " " + os.path.join(srcdir(), "selftest", "tap2subunit")
62 def valgrindify(cmdline):
63 """Run a command under valgrind, if $VALGRIND was set."""
64 valgrind = os.getenv("VALGRIND")
65 if valgrind is None:
66 return cmdline
67 return valgrind + " " + cmdline
70 def plantestsuite(name, env, cmd, environ={}):
71 """Plan a test suite.
73 :param name: Testsuite name
74 :param env: Environment to run the testsuite in
75 :param cmdline: Command line to run
76 """
77 print("-- TEST --")
78 if env == "none":
79 fullname = name
80 else:
81 fullname = "%s(%s)" % (name, env)
82 print(fullname)
83 print(env)
85 cmdline = ""
86 if environ:
87 environ = dict(environ)
88 cmdline_env = ["%s=%s" % item for item in environ.items()]
89 cmdline = " ".join(cmdline_env) + " "
91 if isinstance(cmd, list):
92 cmdline += " ".join(cmd)
93 else:
94 cmdline += cmd
96 if "$LISTOPT" in cmdline:
97 raise AssertionError("test %s supports --list, but not --load-list" % name)
98 print(cmdline + " 2>&1 " + " | " + add_prefix(name, env))
101 def add_prefix(prefix, env, support_list=False):
102 if support_list:
103 listopt = "$LISTOPT "
104 else:
105 listopt = ""
106 return ("%s %s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" %
107 (python, srcdir(), listopt, prefix, env))
110 def plantestsuite_loadlist(name, env, cmdline):
111 print("-- TEST-LOADLIST --")
112 if env == "none":
113 fullname = name
114 else:
115 fullname = "%s(%s)" % (name, env)
116 print(fullname)
117 print(env)
118 if isinstance(cmdline, list):
119 cmdline = " ".join(cmdline)
120 support_list = ("$LISTOPT" in cmdline)
121 if "$LISTOPT" not in cmdline:
122 raise AssertionError("loadlist test %s does not support not --list" % name)
123 if "$LOADLIST" not in cmdline:
124 raise AssertionError("loadlist test %s does not support --load-list" % name)
125 print(("%s | %s" %
126 (cmdline.replace("$LOADLIST", ""),
127 add_prefix(name, env, support_list))).replace("$LISTOPT", "--list "))
128 print(cmdline.replace("$LISTOPT", "") + " 2>&1 " + " | " + add_prefix(name, env, False))
131 def skiptestsuite(name, reason):
132 """Indicate that a testsuite was skipped.
134 :param name: Test suite name
135 :param reason: Reason the test suite was skipped
137 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
138 print("skipping %s (%s)" % (name, reason), file=sys.stderr)
141 def planperltestsuite(name, path):
142 """Run a perl test suite.
144 :param name: Name of the test suite
145 :param path: Path to the test runner
147 if has_perl_test_more:
148 plantestsuite(name, "none", "%s %s | %s" % (" ".join(perl), path, tap2subunit))
149 else:
150 skiptestsuite(name, "Test::More not available")
153 def planpythontestsuite(env, module, name=None, extra_path=[], environ={}, extra_args=[]):
154 environ = dict(environ)
155 py_path = list(extra_path)
156 if py_path is not None:
157 environ["PYTHONPATH"] = ":".join(["$PYTHONPATH"] + py_path)
158 args = ["%s=%s" % item for item in environ.items()]
159 args += [python, "-m", "samba.subunit.run", "$LISTOPT", "$LOADLIST", module]
160 args += extra_args
161 if name is None:
162 name = module
164 plantestsuite_loadlist(name, env, args)
167 def get_env_torture_options():
168 ret = []
169 if not os.getenv("SELFTEST_VERBOSE"):
170 ret.append("--option=torture:progress=no")
171 if os.getenv("SELFTEST_QUICK"):
172 ret.append("--option=torture:quick=yes")
173 return ret
176 samba4srcdir = source4dir()
177 samba3srcdir = source3dir()
178 bbdir = os.path.join(srcdir(), "testprogs/blackbox")
179 configuration = "--configfile=$SMB_CONF_PATH"
181 smbtorture4 = binpath("smbtorture")
182 smbtorture4_testsuite_list = subprocess.Popen(
183 [smbtorture4, "--list-suites"],
184 stdout=subprocess.PIPE,
185 stderr=subprocess.PIPE).communicate("")[0].decode('utf8').splitlines()
187 smbtorture4_options = [
188 configuration,
189 "--option=\'fss:sequence timeout=1\'",
190 "--maximum-runtime=$SELFTEST_MAXTIME",
191 "--basedir=$SELFTEST_TMPDIR",
192 "--format=subunit"
193 ] + get_env_torture_options()
196 def plansmbtorture4testsuite(name, env, options, target, modname=None, environ={}):
197 if modname is None:
198 modname = "samba4.%s" % name
199 if isinstance(options, list):
200 options = " ".join(options)
201 options = " ".join(smbtorture4_options + ["--target=%s" % target]) + " " + options
202 cmdline = ""
203 if environ:
204 environ = dict(environ)
205 cmdline = ["%s=%s" % item for item in environ.items()]
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')
217 net = binpath('net')
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')