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
25 return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
28 return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../source4"))
31 return os.path.normpath(os.path.join(os.getenv("BUILDDIR", "."), "bin"))
34 return os.path.join(bindir(), "%s%s" % (name, os.getenv("EXEEXT", "")))
36 perl = os.getenv("PERL", "perl")
38 if subprocess.call([perl, "-e", "eval require Test::More;"]) == 0:
39 has_perl_test_more = True
41 has_perl_test_more = False
44 from subunit.run import TestProgram
46 has_system_subunit_run = False
48 has_system_subunit_run = True
50 python = os.getenv("PYTHON", "python")
52 #Set a default value, overridden if we find a working one on the system
53 tap2subunit = "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools %s %s/lib/subunit/filters/tap2subunit" % (srcdir(), srcdir(), python, srcdir())
55 sub = subprocess.Popen("tap2subunit 2> /dev/null", stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
58 if sub.returncode == 0:
59 cmd = "echo -ne \"1..1\nok 1 # skip doesn't seem to work yet\n\" | tap2subunit 2> /dev/null | grep skip"
60 sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
61 if sub.returncode == 0:
62 tap2subunit = "tap2subunit"
64 def valgrindify(cmdline):
65 """Run a command under valgrind, if $VALGRIND was set."""
66 valgrind = os.getenv("VALGRIND")
69 return valgrind + " " + cmdline
72 def plantestsuite(name, env, cmdline, allow_empty_output=False):
75 :param name: Testsuite name
76 :param env: Environment to run the testsuite in
77 :param cmdline: Command line to run
82 if isinstance(cmdline, list):
83 cmdline = " ".join(cmdline)
84 filter_subunit_args = []
85 if not allow_empty_output:
86 filter_subunit_args.append("--fail-on-empty")
87 if "$LISTOPT" in cmdline:
88 filter_subunit_args.append("$LISTOPT")
89 print "%s 2>&1 | %s/selftest/filter-subunit %s --prefix=\"%s.\"" % (cmdline,
91 " ".join(filter_subunit_args),
93 if allow_empty_output:
94 print "WARNING: allowing empty subunit output from %s" % name
97 def add_prefix(prefix, support_list=False):
102 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\"" % (srcdir(), listopt, prefix)
105 def plantestsuite_loadlist(name, env, cmdline):
106 print "-- TEST-LOADLIST --"
110 fullname = "%s(%s)" % (name, env)
113 if isinstance(cmdline, list):
114 cmdline = " ".join(cmdline)
115 support_list = ("$LISTOPT" in cmdline)
116 print "%s $LOADLIST 2>&1 | %s" % (cmdline, add_prefix(name, support_list))
119 def plantestsuite_idlist(name, env, cmdline):
120 print "-- TEST-IDLIST --"
123 if isinstance(cmdline, list):
124 cmdline = " ".join(cmdline)
128 def skiptestsuite(name, reason):
129 """Indicate that a testsuite was skipped.
131 :param name: Test suite name
132 :param reason: Reason the test suite was skipped
134 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
135 print "skipping %s (%s)" % (name, reason)
138 def planperltestsuite(name, path):
139 """Run a perl test suite.
141 :param name: Name of the test suite
142 :param path: Path to the test runner
144 if has_perl_test_more:
145 plantestsuite(name, "none", "%s %s | %s" % (perl, path, tap2subunit))
147 skiptestsuite(name, "Test::More not available")
150 def planpythontestsuite(env, module):
151 if has_system_subunit_run:
152 plantestsuite_idlist(module, env, [python, "-m", "subunit.run", "$LISTOPT", module])
154 plantestsuite_idlist(module, env, "PYTHONPATH=$PYTHONPATH:%s/lib/subunit/python:%s/lib/testtools %s -m subunit.run $LISTOPT %s" % (srcdir(), srcdir(), python, module))