s3:smbd: change blocking.c to use fsp_fnum_dbg() for fsp->fnum logging.
[Samba/gebeck_regimport.git] / selftest / selftesthelpers.py
blob7fc085477d8484f4c0ec7f1dcdfdeca93d24ed17
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 bindir():
32 return os.path.normpath(os.getenv("BINDIR", "./bin"))
34 binary_mapping = {}
36 def binpath(name):
37 if name in binary_mapping:
38 name = binary_mapping[name]
39 return os.path.join(bindir(), name)
41 binary_mapping_string = os.getenv("BINARY_MAPPING", None)
42 if binary_mapping_string is not None:
43 for binmapping_entry in binary_mapping_string.split(','):
44 try:
45 (from_path, to_path) = binmapping_entry.split(':', 1)
46 except ValueError:
47 continue
48 binary_mapping[from_path] = to_path
50 # Split perl variable to allow $PERL to be set to e.g. "perl -W"
51 perl = os.getenv("PERL", "perl").split()
53 if subprocess.call(perl + ["-e", "eval require Test::More;"]) == 0:
54 has_perl_test_more = True
55 else:
56 has_perl_test_more = False
58 try:
59 from subunit.run import TestProgram
60 except ImportError:
61 has_system_subunit_run = False
62 else:
63 has_system_subunit_run = True
65 python = os.getenv("PYTHON", "python")
67 #Set a default value, overridden if we find a working one on the system
68 tap2subunit = "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools %s %s/lib/subunit/filters/tap2subunit" % (srcdir(), srcdir(), python, srcdir())
70 sub = subprocess.Popen("tap2subunit 2> /dev/null", stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
71 sub.communicate("")
73 if sub.returncode == 0:
74 cmd = "echo -ne \"1..1\nok 1 # skip doesn't seem to work yet\n\" | tap2subunit 2> /dev/null | grep skip"
75 sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
76 if sub.returncode == 0:
77 tap2subunit = "tap2subunit"
79 def valgrindify(cmdline):
80 """Run a command under valgrind, if $VALGRIND was set."""
81 valgrind = os.getenv("VALGRIND")
82 if valgrind is None:
83 return cmdline
84 return valgrind + " " + cmdline
87 def plantestsuite(name, env, cmdline, allow_empty_output=False):
88 """Plan a test suite.
90 :param name: Testsuite name
91 :param env: Environment to run the testsuite in
92 :param cmdline: Command line to run
93 """
94 print "-- TEST --"
95 print name
96 print env
97 if isinstance(cmdline, list):
98 cmdline = " ".join(cmdline)
99 filter_subunit_args = []
100 if not allow_empty_output:
101 filter_subunit_args.append("--fail-on-empty")
102 if "$LISTOPT" in cmdline:
103 filter_subunit_args.append("$LISTOPT")
104 print "%s 2>&1 | %s/selftest/filter-subunit %s --prefix=\"%s.\" --suffix=\"(%s)\"" % (cmdline,
105 srcdir(),
106 " ".join(filter_subunit_args),
107 name, env)
108 if allow_empty_output:
109 print >>sys.stderr, "WARNING: allowing empty subunit output from %s" % name
112 def add_prefix(prefix, env, support_list=False):
113 if support_list:
114 listopt = "$LISTOPT "
115 else:
116 listopt = ""
117 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" % (srcdir(), listopt, prefix, env)
120 def plantestsuite_loadlist(name, env, cmdline):
121 print "-- TEST-LOADLIST --"
122 if env == "none":
123 fullname = name
124 else:
125 fullname = "%s(%s)" % (name, env)
126 print fullname
127 print env
128 if isinstance(cmdline, list):
129 cmdline = " ".join(cmdline)
130 support_list = ("$LISTOPT" in cmdline)
131 print "%s $LOADLIST 2>&1 | %s" % (cmdline, add_prefix(name, env, support_list))
134 def plantestsuite_idlist(name, env, cmdline):
135 print "-- TEST-IDLIST --"
136 if env == "none":
137 fullname = name
138 else:
139 fullname = "%s(%s)" % (name, env)
140 print fullname
141 print env
142 if isinstance(cmdline, list):
143 cmdline = " ".join(cmdline)
144 print cmdline
147 def skiptestsuite(name, reason):
148 """Indicate that a testsuite was skipped.
150 :param name: Test suite name
151 :param reason: Reason the test suite was skipped
153 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
154 print >>sys.stderr, "skipping %s (%s)" % (name, reason)
157 def planperltestsuite(name, path):
158 """Run a perl test suite.
160 :param name: Name of the test suite
161 :param path: Path to the test runner
163 if has_perl_test_more:
164 plantestsuite(name, "none", "%s %s | %s" % (" ".join(perl), path, tap2subunit))
165 else:
166 skiptestsuite(name, "Test::More not available")
169 def planpythontestsuite(env, module, name=None, extra_path=[]):
170 if name is None:
171 name = module
172 pypath = list(extra_path)
173 if not has_system_subunit_run:
174 pypath.extend(["%s/lib/subunit/python" % srcdir(),
175 "%s/lib/testtools" % srcdir()])
176 args = [python, "-m", "subunit.run", "$LISTOPT", module]
177 if pypath:
178 args.insert(0, "PYTHONPATH=%s" % ":".join(["$PYTHONPATH"] + pypath))
179 plantestsuite_idlist(name, env, args)