s3:smb2_server: allow logoff, close, unlock, cancel and echo on expired sessions
[Samba.git] / selftest / selftesthelpers.py
blob8b885b59419cb27f1a76633c0e31edaf5f27f2ea
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 os
22 import subprocess
23 import sys
25 def srcdir():
26 return os.path.normpath(os.getenv("SRCDIR", os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")))
28 def source4dir():
29 return os.path.normpath(os.path.join(srcdir(), "source4"))
31 def source3dir():
32 return os.path.normpath(os.path.join(srcdir(), "source3"))
34 def bindir():
35 return os.path.normpath(os.getenv("BINDIR", "./bin"))
37 def binpath(name):
38 return os.path.join(bindir(), name)
40 # Split perl variable to allow $PERL to be set to e.g. "perl -W"
41 perl = os.getenv("PERL", "perl").split()
43 if subprocess.call(perl + ["-e", "eval require Test::More;"]) == 0:
44 has_perl_test_more = True
45 else:
46 has_perl_test_more = False
48 python = os.getenv("PYTHON", "python")
49 extra_python = os.getenv("EXTRA_PYTHON", None)
51 tap2subunit = python + " " + os.path.join(srcdir(), "selftest", "tap2subunit")
54 def valgrindify(cmdline):
55 """Run a command under valgrind, if $VALGRIND was set."""
56 valgrind = os.getenv("VALGRIND")
57 if valgrind is None:
58 return cmdline
59 return valgrind + " " + cmdline
62 def plantestsuite(name, env, cmdline):
63 """Plan a test suite.
65 :param name: Testsuite name
66 :param env: Environment to run the testsuite in
67 :param cmdline: Command line to run
68 """
69 print "-- TEST --"
70 if env == "none":
71 fullname = name
72 else:
73 fullname = "%s(%s)" % (name, env)
74 print fullname
75 print env
76 if isinstance(cmdline, list):
77 cmdline = " ".join(cmdline)
78 if "$LISTOPT" in cmdline:
79 raise AssertionError("test %s supports --list, but not --load-list" % name)
80 print cmdline + " 2>&1 " + " | " + add_prefix(name, env)
83 def add_prefix(prefix, env, support_list=False):
84 if support_list:
85 listopt = "$LISTOPT "
86 else:
87 listopt = ""
88 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" % (srcdir(), listopt, prefix, env)
91 def plantestsuite_loadlist(name, env, cmdline):
92 print "-- TEST-LOADLIST --"
93 if env == "none":
94 fullname = name
95 else:
96 fullname = "%s(%s)" % (name, env)
97 print fullname
98 print env
99 if isinstance(cmdline, list):
100 cmdline = " ".join(cmdline)
101 support_list = ("$LISTOPT" in cmdline)
102 if not "$LISTOPT" in cmdline:
103 raise AssertionError("loadlist test %s does not support not --list" % name)
104 if not "$LOADLIST" in cmdline:
105 raise AssertionError("loadlist test %s does not support --load-list" % name)
106 print ("%s | %s" % (cmdline.replace("$LOADLIST", ""), add_prefix(name, env, support_list))).replace("$LISTOPT", "--list")
107 print cmdline.replace("$LISTOPT", "") + " 2>&1 " + " | " + add_prefix(name, env, False)
110 def skiptestsuite(name, reason):
111 """Indicate that a testsuite was skipped.
113 :param name: Test suite name
114 :param reason: Reason the test suite was skipped
116 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
117 print >>sys.stderr, "skipping %s (%s)" % (name, reason)
120 def planperltestsuite(name, path):
121 """Run a perl test suite.
123 :param name: Name of the test suite
124 :param path: Path to the test runner
126 if has_perl_test_more:
127 plantestsuite(name, "none", "%s %s | %s" % (" ".join(perl), path, tap2subunit))
128 else:
129 skiptestsuite(name, "Test::More not available")
132 def planpythontestsuite(env, module, name=None, extra_path=[], py3_compatible=False):
133 if name is None:
134 name = module
135 pypath = list(extra_path)
136 args = [python, "-m", "samba.subunit.run", "$LISTOPT", "$LOADLIST", module]
137 if pypath:
138 args.insert(0, "PYTHONPATH=%s" % ":".join(["$PYTHONPATH"] + pypath))
139 plantestsuite_loadlist(name, env, args)
140 if py3_compatible and extra_python is not None:
141 # Plan one more test for Python 3 compatible module
142 args[0] = extra_python
143 plantestsuite_loadlist(name + ".python3", env, args)
146 def get_env_torture_options():
147 ret = []
148 if not os.getenv("SELFTEST_VERBOSE"):
149 ret.append("--option=torture:progress=no")
150 if os.getenv("SELFTEST_QUICK"):
151 ret.append("--option=torture:quick=yes")
152 return ret
155 samba4srcdir = source4dir()
156 samba3srcdir = source3dir()
157 bbdir = os.path.join(srcdir(), "testprogs/blackbox")
158 configuration = "--configfile=$SMB_CONF_PATH"
160 smbtorture4 = binpath("smbtorture")
161 smbtorture4_testsuite_list = subprocess.Popen([smbtorture4, "--list-suites"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate("")[0].splitlines()
163 smbtorture4_options = [
164 configuration,
165 "--option=\'fss:sequence timeout=1\'",
166 "--maximum-runtime=$SELFTEST_MAXTIME",
167 "--basedir=$SELFTEST_TMPDIR",
168 "--format=subunit"
169 ] + get_env_torture_options()
172 def plansmbtorture4testsuite(name, env, options, target, modname=None):
173 if modname is None:
174 modname = "samba4.%s" % name
175 if isinstance(options, list):
176 options = " ".join(options)
177 options = " ".join(smbtorture4_options + ["--target=%s" % target]) + " " + options
178 cmdline = "%s $LISTOPT $LOADLIST %s %s" % (valgrindify(smbtorture4), options, name)
179 plantestsuite_loadlist(modname, env, cmdline)
182 def smbtorture4_testsuites(prefix):
183 return filter(lambda x: x.startswith(prefix), smbtorture4_testsuite_list)
186 smbclient3 = binpath('smbclient')
187 smbtorture3 = binpath('smbtorture3')
188 ntlm_auth3 = binpath('ntlm_auth')
189 net = binpath('net')
190 scriptdir = os.path.join(srcdir(), "script/tests")
192 wbinfo = binpath('wbinfo')
193 dbwrap_tool = binpath('dbwrap_tool')
194 vfstest = binpath('vfstest')
195 smbcquotas = binpath('smbcquotas')
196 smbget = binpath('smbget')
197 rpcclient = binpath('rpcclient')
198 smbcacls = binpath('smbcacls')