source: vendor/current/selftest/selftesthelpers.py

Last change on this file was 989, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.7

File size: 6.2 KB
Line 
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.
4
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".
8
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.
15
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.
20
21import os
22import subprocess
23import sys
24
25def srcdir():
26 return os.path.normpath(os.getenv("SRCDIR", os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")))
27
28def source4dir():
29 return os.path.normpath(os.path.join(srcdir(), "source4"))
30
31def source3dir():
32 return os.path.normpath(os.path.join(srcdir(), "source3"))
33
34def bindir():
35 return os.path.normpath(os.getenv("BINDIR", "./bin"))
36
37def binpath(name):
38 return os.path.join(bindir(), name)
39
40# Split perl variable to allow $PERL to be set to e.g. "perl -W"
41perl = os.getenv("PERL", "perl").split()
42
43if subprocess.call(perl + ["-e", "eval require Test::More;"]) == 0:
44 has_perl_test_more = True
45else:
46 has_perl_test_more = False
47
48python = os.getenv("PYTHON", "python")
49
50tap2subunit = python + " " + os.path.join(srcdir(), "selftest", "tap2subunit")
51
52
53def 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
59
60
61def plantestsuite(name, env, cmdline):
62 """Plan a test suite.
63
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)
76
77
78def 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)
84
85
86def 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)
103
104
105def skiptestsuite(name, reason):
106 """Indicate that a testsuite was skipped.
107
108 :param name: Test suite name
109 :param reason: Reason the test suite was skipped
110 """
111 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
112 print >>sys.stderr, "skipping %s (%s)" % (name, reason)
113
114
115def planperltestsuite(name, path):
116 """Run a perl test suite.
117
118 :param name: Name of the test suite
119 :param path: Path to the test runner
120 """
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")
125
126
127def 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)
135
136
137def 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
144
145
146samba4srcdir = source4dir()
147samba3srcdir = source3dir()
148bbdir = os.path.join(srcdir(), "testprogs/blackbox")
149configuration = "--configfile=$SMB_CONF_PATH"
150
151smbtorture4 = binpath("smbtorture")
152smbtorture4_testsuite_list = subprocess.Popen([smbtorture4, "--list-suites"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate("")[0].splitlines()
153
154smbtorture4_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()
161
162
163def 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)
171
172
173def smbtorture4_testsuites(prefix):
174 return filter(lambda x: x.startswith(prefix), smbtorture4_testsuite_list)
175
176
177smbclient3 = binpath('smbclient')
178smbtorture3 = binpath('smbtorture3')
179ntlm_auth3 = binpath('ntlm_auth')
180net = binpath('net')
181scriptdir = os.path.join(srcdir(), "script/tests")
182
183wbinfo = binpath('wbinfo')
184dbwrap_tool = binpath('dbwrap_tool')
185vfstest = binpath('vfstest')
186smbcquotas = binpath('smbcquotas')
187smbget = binpath('smbget')
188smbcacls = binpath('smbcacls')
Note: See TracBrowser for help on using the repository browser.