s3:smbd: allow GetInfo responses with STATUS_BUFFER_OVERFLOW to return partial, but...
[Samba.git] / selftest / selftesthelpers.py
blob781c8ccb9a82a3302d9606ce929b263034357e0d
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.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
27 def source4dir():
28 return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../source4"))
30 def bindir():
31 return os.path.normpath(os.path.join(os.getenv("BUILDDIR", "."), "bin"))
33 def binpath(name):
34 return os.path.join(bindir(), "%s%s" % (name, os.getenv("EXEEXT", "")))
36 perl = os.getenv("PERL", "perl")
37 perl = perl.split()
39 if subprocess.call(perl + ["-e", "eval require Test::More;"]) == 0:
40 has_perl_test_more = True
41 else:
42 has_perl_test_more = False
44 try:
45 from subunit.run import TestProgram
46 except ImportError:
47 has_system_subunit_run = False
48 else:
49 has_system_subunit_run = True
51 python = os.getenv("PYTHON", "python")
53 #Set a default value, overridden if we find a working one on the system
54 tap2subunit = "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools %s %s/lib/subunit/filters/tap2subunit" % (srcdir(), srcdir(), python, srcdir())
56 sub = subprocess.Popen("tap2subunit 2> /dev/null", stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
57 sub.communicate("")
59 if sub.returncode == 0:
60 cmd = "echo -ne \"1..1\nok 1 # skip doesn't seem to work yet\n\" | tap2subunit 2> /dev/null | grep skip"
61 sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
62 if sub.returncode == 0:
63 tap2subunit = "tap2subunit"
65 def valgrindify(cmdline):
66 """Run a command under valgrind, if $VALGRIND was set."""
67 valgrind = os.getenv("VALGRIND")
68 if valgrind is None:
69 return cmdline
70 return valgrind + " " + cmdline
73 def plantestsuite(name, env, cmdline, allow_empty_output=False):
74 """Plan a test suite.
76 :param name: Testsuite name
77 :param env: Environment to run the testsuite in
78 :param cmdline: Command line to run
79 """
80 print "-- TEST --"
81 print name
82 print env
83 if isinstance(cmdline, list):
84 cmdline = " ".join(cmdline)
85 filter_subunit_args = []
86 if not allow_empty_output:
87 filter_subunit_args.append("--fail-on-empty")
88 if "$LISTOPT" in cmdline:
89 filter_subunit_args.append("$LISTOPT")
90 print "%s 2>&1 | %s/selftest/filter-subunit %s --prefix=\"%s.\"" % (cmdline,
91 srcdir(),
92 " ".join(filter_subunit_args),
93 name)
94 if allow_empty_output:
95 print "WARNING: allowing empty subunit output from %s" % name
98 def add_prefix(prefix, support_list=False):
99 if support_list:
100 listopt = "$LISTOPT "
101 else:
102 listopt = ""
103 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\"" % (srcdir(), listopt, prefix)
106 def plantestsuite_loadlist(name, env, cmdline):
107 print "-- TEST-LOADLIST --"
108 if env == "none":
109 fullname = name
110 else:
111 fullname = "%s(%s)" % (name, env)
112 print fullname
113 print env
114 if isinstance(cmdline, list):
115 cmdline = " ".join(cmdline)
116 support_list = ("$LISTOPT" in cmdline)
117 print "%s $LOADLIST 2>&1 | %s" % (cmdline, add_prefix(name, support_list))
120 def plantestsuite_idlist(name, env, cmdline):
121 print "-- TEST-IDLIST --"
122 print name
123 print env
124 if isinstance(cmdline, list):
125 cmdline = " ".join(cmdline)
126 print cmdline
129 def skiptestsuite(name, reason):
130 """Indicate that a testsuite was skipped.
132 :param name: Test suite name
133 :param reason: Reason the test suite was skipped
135 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
136 print "skipping %s (%s)" % (name, reason)
139 def planperltestsuite(name, path):
140 """Run a perl test suite.
142 :param name: Name of the test suite
143 :param path: Path to the test runner
145 if has_perl_test_more:
146 plantestsuite(name, "none", "%s %s | %s" % (" ".join(perl), path, tap2subunit))
147 else:
148 skiptestsuite(name, "Test::More not available")
151 def planpythontestsuite(env, module):
152 if has_system_subunit_run:
153 plantestsuite_idlist(module, env, [python, "-m", "subunit.run", "$LISTOPT", module])
154 else:
155 plantestsuite_idlist(module, env, "PYTHONPATH=$PYTHONPATH:%s/lib/subunit/python:%s/lib/testtools %s -m subunit.run $LISTOPT %s" % (srcdir(), srcdir(), python, module))