s4-param: use "state directory" and "cache directory" options
[Samba/gebeck_regimport.git] / selftest / selftesthelpers.py
blob085c62c46602b38ef15c76bf565b700977dfe174
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
24 def srcdir():
25 return os.path.normpath(os.getenv("SRCDIR", os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")))
27 def source4dir():
28 return os.path.normpath(os.path.join(srcdir(), "source4"))
30 def bindir():
31 return os.path.normpath(os.getenv("BINDIR", "./bin"))
33 binary_mapping = {}
35 def binpath(name):
36 if name in binary_mapping:
37 name = binary_mapping[name]
38 return os.path.join(bindir(), "%s%s" % (name, os.getenv("EXEEXT", "")))
40 binary_mapping_string = os.getenv("BINARY_MAPPING", None)
41 if binary_mapping_string is not None:
42 for binmapping_entry in binary_mapping_string.split(','):
43 binmapping = binmapping_entry.split(':')
44 binary_mapping[binmapping[0]] = binmapping[1]
46 perl = os.getenv("PERL", "perl")
47 perl = perl.split()
49 if subprocess.call(perl + ["-e", "eval require Test::More;"]) == 0:
50 has_perl_test_more = True
51 else:
52 has_perl_test_more = False
54 try:
55 from subunit.run import TestProgram
56 except ImportError:
57 has_system_subunit_run = False
58 else:
59 has_system_subunit_run = True
61 python = os.getenv("PYTHON", "python")
63 #Set a default value, overridden if we find a working one on the system
64 tap2subunit = "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools %s %s/lib/subunit/filters/tap2subunit" % (srcdir(), srcdir(), python, srcdir())
66 sub = subprocess.Popen("tap2subunit 2> /dev/null", stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
67 sub.communicate("")
69 if sub.returncode == 0:
70 cmd = "echo -ne \"1..1\nok 1 # skip doesn't seem to work yet\n\" | tap2subunit 2> /dev/null | grep skip"
71 sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
72 if sub.returncode == 0:
73 tap2subunit = "tap2subunit"
75 def valgrindify(cmdline):
76 """Run a command under valgrind, if $VALGRIND was set."""
77 valgrind = os.getenv("VALGRIND")
78 if valgrind is None:
79 return cmdline
80 return valgrind + " " + cmdline
83 def plantestsuite(name, env, cmdline, allow_empty_output=False):
84 """Plan a test suite.
86 :param name: Testsuite name
87 :param env: Environment to run the testsuite in
88 :param cmdline: Command line to run
89 """
90 print "-- TEST --"
91 print name
92 print env
93 if isinstance(cmdline, list):
94 cmdline = " ".join(cmdline)
95 filter_subunit_args = []
96 if not allow_empty_output:
97 filter_subunit_args.append("--fail-on-empty")
98 if "$LISTOPT" in cmdline:
99 filter_subunit_args.append("$LISTOPT")
100 print "%s 2>&1 | %s/selftest/filter-subunit %s --prefix=\"%s.\"" % (cmdline,
101 srcdir(),
102 " ".join(filter_subunit_args),
103 name)
104 if allow_empty_output:
105 print "WARNING: allowing empty subunit output from %s" % name
108 def add_prefix(prefix, support_list=False):
109 if support_list:
110 listopt = "$LISTOPT "
111 else:
112 listopt = ""
113 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\"" % (srcdir(), listopt, prefix)
116 def plantestsuite_loadlist(name, env, cmdline):
117 print "-- TEST-LOADLIST --"
118 if env == "none":
119 fullname = name
120 else:
121 fullname = "%s(%s)" % (name, env)
122 print fullname
123 print env
124 if isinstance(cmdline, list):
125 cmdline = " ".join(cmdline)
126 support_list = ("$LISTOPT" in cmdline)
127 print "%s $LOADLIST 2>&1 | %s" % (cmdline, add_prefix(name, support_list))
130 def plantestsuite_idlist(name, env, cmdline):
131 print "-- TEST-IDLIST --"
132 print name
133 print env
134 if isinstance(cmdline, list):
135 cmdline = " ".join(cmdline)
136 print cmdline
139 def skiptestsuite(name, reason):
140 """Indicate that a testsuite was skipped.
142 :param name: Test suite name
143 :param reason: Reason the test suite was skipped
145 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
146 print "skipping %s (%s)" % (name, reason)
149 def planperltestsuite(name, path):
150 """Run a perl test suite.
152 :param name: Name of the test suite
153 :param path: Path to the test runner
155 if has_perl_test_more:
156 plantestsuite(name, "none", "%s %s | %s" % (" ".join(perl), path, tap2subunit))
157 else:
158 skiptestsuite(name, "Test::More not available")
161 def planpythontestsuite(env, module):
162 if has_system_subunit_run:
163 plantestsuite_idlist(module, env, [python, "-m", "subunit.run", "$LISTOPT", module])
164 else:
165 plantestsuite_idlist(module, env, "PYTHONPATH=$PYTHONPATH:%s/lib/subunit/python:%s/lib/testtools %s -m subunit.run $LISTOPT %s" % (srcdir(), srcdir(), python, module))