lib: Remove unused parmlist code
[Samba.git] / selftest / selftesthelpers.py
blob0dfcf5428c47905f6dbfc7433a2cd795dabc9f03
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")
50 tap2subunit = python + " " + os.path.join(srcdir(), "selftest", "tap2subunit")
53 def valgrindify(cmdline):
54 """Run a command under valgrind, if $VALGRIND was set."""
55 valgrind = os.getenv("VALGRIND")
56 if valgrind is None:
57 return cmdline
58 return valgrind + " " + cmdline
61 def plantestsuite(name, env, cmdline):
62 """Plan a test suite.
64 :param name: Testsuite name
65 :param env: Environment to run the testsuite in
66 :param cmdline: Command line to run
67 """
68 print "-- TEST --"
69 print name
70 print env
71 if isinstance(cmdline, list):
72 cmdline = " ".join(cmdline)
73 if "$LISTOPT" in cmdline:
74 raise AssertionError("test %s supports --list, but not --load-list" % name)
75 print cmdline + " 2>&1 " + " | " + add_prefix(name, env)
78 def add_prefix(prefix, env, support_list=False):
79 if support_list:
80 listopt = "$LISTOPT "
81 else:
82 listopt = ""
83 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" % (srcdir(), listopt, prefix, env)
86 def plantestsuite_loadlist(name, env, cmdline):
87 print "-- TEST-LOADLIST --"
88 if env == "none":
89 fullname = name
90 else:
91 fullname = "%s(%s)" % (name, env)
92 print fullname
93 print env
94 if isinstance(cmdline, list):
95 cmdline = " ".join(cmdline)
96 support_list = ("$LISTOPT" in cmdline)
97 if not "$LISTOPT" in cmdline:
98 raise AssertionError("loadlist test %s does not support not --list" % name)
99 if not "$LOADLIST" in cmdline:
100 raise AssertionError("loadlist test %s does not support --load-list" % name)
101 print ("%s | %s" % (cmdline.replace("$LOADLIST", ""), add_prefix(name, env, support_list))).replace("$LISTOPT", "--list")
102 print cmdline.replace("$LISTOPT", "") + " 2>&1 " + " | " + add_prefix(name, env, False)
105 def skiptestsuite(name, reason):
106 """Indicate that a testsuite was skipped.
108 :param name: Test suite name
109 :param reason: Reason the test suite was skipped
111 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
112 print >>sys.stderr, "skipping %s (%s)" % (name, reason)
115 def planperltestsuite(name, path):
116 """Run a perl test suite.
118 :param name: Name of the test suite
119 :param path: Path to the test runner
121 if has_perl_test_more:
122 plantestsuite(name, "none", "%s %s | %s" % (" ".join(perl), path, tap2subunit))
123 else:
124 skiptestsuite(name, "Test::More not available")
127 def planpythontestsuite(env, module, name=None, extra_path=[]):
128 if name is None:
129 name = module
130 pypath = list(extra_path)
131 args = [python, "-m", "samba.subunit.run", "$LISTOPT", "$LOADLIST", module]
132 if pypath:
133 args.insert(0, "PYTHONPATH=%s" % ":".join(["$PYTHONPATH"] + pypath))
134 plantestsuite_loadlist(name, env, args)
137 def get_env_torture_options():
138 ret = []
139 if not os.getenv("SELFTEST_VERBOSE"):
140 ret.append("--option=torture:progress=no")
141 if os.getenv("SELFTEST_QUICK"):
142 ret.append("--option=torture:quick=yes")
143 return ret
146 samba4srcdir = source4dir()
147 samba3srcdir = source3dir()
148 bbdir = os.path.join(srcdir(), "testprogs/blackbox")
149 configuration = "--configfile=$SMB_CONF_PATH"
151 smbtorture4 = binpath("smbtorture")
152 smbtorture4_testsuite_list = subprocess.Popen([smbtorture4, "--list-suites"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate("")[0].splitlines()
154 smbtorture4_options = [
155 configuration,
156 "--option=\'fss:sequence timeout=1\'",
157 "--maximum-runtime=$SELFTEST_MAXTIME",
158 "--basedir=$SELFTEST_TMPDIR",
159 "--format=subunit"
160 ] + get_env_torture_options()
163 def plansmbtorture4testsuite(name, env, options, target, modname=None):
164 if modname is None:
165 modname = "samba4.%s" % name
166 if isinstance(options, list):
167 options = " ".join(options)
168 options = " ".join(smbtorture4_options + ["--target=%s" % target]) + " " + options
169 cmdline = "%s $LISTOPT $LOADLIST %s %s" % (valgrindify(smbtorture4), options, name)
170 plantestsuite_loadlist(modname, env, cmdline)
173 def smbtorture4_testsuites(prefix):
174 return filter(lambda x: x.startswith(prefix), smbtorture4_testsuite_list)
177 smbclient3 = binpath('smbclient')
178 smbtorture3 = binpath('smbtorture3')
179 ntlm_auth3 = binpath('ntlm_auth')
180 net = binpath('net')
181 scriptdir = os.path.join(srcdir(), "script/tests")
183 wbinfo = binpath('wbinfo')
184 dbwrap_tool = binpath('dbwrap_tool')
185 vfstest = binpath('vfstest')