s3:libsmb: make use of cli_tree_connect_creds() in SMBC_server_internal()
[Samba.git] / selftest / selftesthelpers.py
blob1a1e080b12b25bd5aee63a639d2a95c605fdc9b3
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", "python3")
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 print name
71 print env
72 if isinstance(cmdline, list):
73 cmdline = " ".join(cmdline)
74 if "$LISTOPT" in cmdline:
75 raise AssertionError("test %s supports --list, but not --load-list" % name)
76 print cmdline + " 2>&1 " + " | " + add_prefix(name, env)
79 def add_prefix(prefix, env, support_list=False):
80 if support_list:
81 listopt = "$LISTOPT "
82 else:
83 listopt = ""
84 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" % (srcdir(), listopt, prefix, env)
87 def plantestsuite_loadlist(name, env, cmdline):
88 print "-- TEST-LOADLIST --"
89 if env == "none":
90 fullname = name
91 else:
92 fullname = "%s(%s)" % (name, env)
93 print fullname
94 print env
95 if isinstance(cmdline, list):
96 cmdline = " ".join(cmdline)
97 support_list = ("$LISTOPT" in cmdline)
98 if not "$LISTOPT" in cmdline:
99 raise AssertionError("loadlist test %s does not support not --list" % name)
100 if not "$LOADLIST" in cmdline:
101 raise AssertionError("loadlist test %s does not support --load-list" % name)
102 print ("%s | %s" % (cmdline.replace("$LOADLIST", ""), add_prefix(name, env, support_list))).replace("$LISTOPT", "--list")
103 print cmdline.replace("$LISTOPT", "") + " 2>&1 " + " | " + add_prefix(name, env, False)
106 def skiptestsuite(name, reason):
107 """Indicate that a testsuite was skipped.
109 :param name: Test suite name
110 :param reason: Reason the test suite was skipped
112 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
113 print >>sys.stderr, "skipping %s (%s)" % (name, reason)
116 def planperltestsuite(name, path):
117 """Run a perl test suite.
119 :param name: Name of the test suite
120 :param path: Path to the test runner
122 if has_perl_test_more:
123 plantestsuite(name, "none", "%s %s | %s" % (" ".join(perl), path, tap2subunit))
124 else:
125 skiptestsuite(name, "Test::More not available")
128 def planpythontestsuite(env, module, name=None, extra_path=[], py3_compatible=False):
129 if name is None:
130 name = module
131 pypath = list(extra_path)
132 args = [python, "-m", "samba.subunit.run", "$LISTOPT", "$LOADLIST", module]
133 if pypath:
134 args.insert(0, "PYTHONPATH=%s" % ":".join(["$PYTHONPATH"] + pypath))
135 plantestsuite_loadlist(name, env, args)
136 if py3_compatible:
137 # Plan one more test for Python 3 compatible module
138 args[0] = extra_python
139 plantestsuite_loadlist(name, env, args)
142 def get_env_torture_options():
143 ret = []
144 if not os.getenv("SELFTEST_VERBOSE"):
145 ret.append("--option=torture:progress=no")
146 if os.getenv("SELFTEST_QUICK"):
147 ret.append("--option=torture:quick=yes")
148 return ret
151 samba4srcdir = source4dir()
152 samba3srcdir = source3dir()
153 bbdir = os.path.join(srcdir(), "testprogs/blackbox")
154 configuration = "--configfile=$SMB_CONF_PATH"
156 smbtorture4 = binpath("smbtorture")
157 smbtorture4_testsuite_list = subprocess.Popen([smbtorture4, "--list-suites"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate("")[0].splitlines()
159 smbtorture4_options = [
160 configuration,
161 "--option=\'fss:sequence timeout=1\'",
162 "--maximum-runtime=$SELFTEST_MAXTIME",
163 "--basedir=$SELFTEST_TMPDIR",
164 "--format=subunit"
165 ] + get_env_torture_options()
168 def plansmbtorture4testsuite(name, env, options, target, modname=None):
169 if modname is None:
170 modname = "samba4.%s" % name
171 if isinstance(options, list):
172 options = " ".join(options)
173 options = " ".join(smbtorture4_options + ["--target=%s" % target]) + " " + options
174 cmdline = "%s $LISTOPT $LOADLIST %s %s" % (valgrindify(smbtorture4), options, name)
175 plantestsuite_loadlist(modname, env, cmdline)
178 def smbtorture4_testsuites(prefix):
179 return filter(lambda x: x.startswith(prefix), smbtorture4_testsuite_list)
182 smbclient3 = binpath('smbclient')
183 smbtorture3 = binpath('smbtorture3')
184 ntlm_auth3 = binpath('ntlm_auth')
185 net = binpath('net')
186 scriptdir = os.path.join(srcdir(), "script/tests")
188 wbinfo = binpath('wbinfo')
189 dbwrap_tool = binpath('dbwrap_tool')
190 vfstest = binpath('vfstest')
191 smbcquotas = binpath('smbcquotas')
192 smbget = binpath('smbget')
193 rpcclient = binpath('rpcclient')
194 smbcacls = binpath('smbcacls')