s3:locking: fix uninitialiazed variable in brl_get_locks_readonly_parser()
[obnox/samba/samba-obnox.git] / selftest / selftesthelpers.py
index 8d36356293ebdd3a4a9ffe31c221c5f06994d62b..6e387ec9dd3e6917b6d4b2b0fdbe5bcdf0866c6b 100644 (file)
@@ -18,7 +18,6 @@
 # three separated by newlines. All other lines in the output are considered
 # comments.
 
-import errno
 import os
 import subprocess
 import sys
@@ -29,6 +28,9 @@ def srcdir():
 def source4dir():
     return os.path.normpath(os.path.join(srcdir(), "source4"))
 
+def source3dir():
+    return os.path.normpath(os.path.join(srcdir(), "source3"))
+
 def bindir():
     return os.path.normpath(os.getenv("BINDIR", "./bin"))
 
@@ -66,7 +68,8 @@ else:
 python = os.getenv("PYTHON", "python")
 
 # Set a default value, overridden if we find a working one on the system
-tap2subunit = "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools %s %s/lib/subunit/filters/tap2subunit" % (srcdir(), srcdir(), python, srcdir())
+tap2subunit = "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools:%s/lib/extras:%s/lib/mimeparse %s %s/lib/subunit/filters/tap2subunit" % (srcdir(), srcdir(), srcdir(), srcdir(), python, srcdir())
+subunit2to1 = "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools:%s/lib/extras:%s/lib/mimeparse %s %s/lib/subunit/filters/subunit-2to1" % (srcdir(), srcdir(), srcdir(), srcdir(), python, srcdir())
 
 sub = subprocess.Popen("tap2subunit", stdin=subprocess.PIPE,
     stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
@@ -79,6 +82,12 @@ if sub.returncode == 0:
     if sub.returncode == 0:
         tap2subunit = "tap2subunit"
 
+def to_subunit1(subunit_version):
+    if subunit_version == 1:
+        return ""
+    return " | " + subunit2to1
+
+
 def valgrindify(cmdline):
     """Run a command under valgrind, if $VALGRIND was set."""
     valgrind = os.getenv("VALGRIND")
@@ -87,7 +96,7 @@ def valgrindify(cmdline):
     return valgrind + " " + cmdline
 
 
-def plantestsuite(name, env, cmdline, allow_empty_output=False):
+def plantestsuite(name, env, cmdline, subunit_version=1):
     """Plan a test suite.
 
     :param name: Testsuite name
@@ -99,17 +108,9 @@ def plantestsuite(name, env, cmdline, allow_empty_output=False):
     print env
     if isinstance(cmdline, list):
         cmdline = " ".join(cmdline)
-    filter_subunit_args = []
-    if not allow_empty_output:
-        filter_subunit_args.append("--fail-on-empty")
     if "$LISTOPT" in cmdline:
-        filter_subunit_args.append("$LISTOPT")
-    print "%s 2>&1 | %s/selftest/filter-subunit %s --prefix=\"%s.\" --suffix=\"(%s)\"" % (cmdline,
-                                                                        srcdir(),
-                                                                        " ".join(filter_subunit_args),
-                                                                        name, env)
-    if allow_empty_output:
-        print >>sys.stderr, "WARNING: allowing empty subunit output from %s" % name
+        raise AssertionError("test %s supports --list, but not --load-list" % name)
+    print cmdline + " 2>&1 " + to_subunit1(subunit_version) + " | " + add_prefix(name, env)
 
 
 def add_prefix(prefix, env, support_list=False):
@@ -120,7 +121,7 @@ def add_prefix(prefix, env, support_list=False):
     return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" % (srcdir(), listopt, prefix, env)
 
 
-def plantestsuite_loadlist(name, env, cmdline):
+def plantestsuite_loadlist(name, env, cmdline, subunit_version=1):
     print "-- TEST-LOADLIST --"
     if env == "none":
         fullname = name
@@ -131,20 +132,12 @@ def plantestsuite_loadlist(name, env, cmdline):
     if isinstance(cmdline, list):
         cmdline = " ".join(cmdline)
     support_list = ("$LISTOPT" in cmdline)
-    print "%s $LOADLIST 2>&1 | %s" % (cmdline, add_prefix(name, env, support_list))
-
-
-def plantestsuite_idlist(name, env, cmdline):
-    print "-- TEST-IDLIST --"
-    if env == "none":
-        fullname = name
-    else:
-        fullname = "%s(%s)" % (name, env)
-    print fullname
-    print env
-    if isinstance(cmdline, list):
-        cmdline = " ".join(cmdline)
-    print cmdline
+    if not "$LISTOPT" in cmdline:
+        raise AssertionError("loadlist test %s does not support not --list" % name)
+    if not "$LOADLIST" in cmdline:
+        raise AssertionError("loadlist test %s does not support --load-list" % name)
+    print ("%s | %s" % (cmdline.replace("$LOADLIST", ""), add_prefix(name, env, support_list))).replace("$LISTOPT", "--list")
+    print cmdline.replace("$LISTOPT", "") + " 2>&1 " + to_subunit1(subunit_version) + " | " + add_prefix(name, env, False)
 
 
 def skiptestsuite(name, reason):
@@ -174,12 +167,15 @@ def planpythontestsuite(env, module, name=None, extra_path=[]):
         name = module
     pypath = list(extra_path)
     if not has_system_subunit_run:
-        pypath.extend(["%s/lib/subunit/python" % srcdir(),
-            "%s/lib/testtools" % srcdir()])
-    args = [python, "-m", "subunit.run", "$LISTOPT", module]
+        pypath.extend([
+            "%s/lib/subunit/python" % srcdir(),
+            "%s/lib/testtools" % srcdir(),
+            "%s/lib/extras" % srcdir(),
+            "%s/lib/mimeparse" % srcdir()])
+    args = [python, "-m", "subunit.run", "$LISTOPT", "$LOADLIST", module]
     if pypath:
         args.insert(0, "PYTHONPATH=%s" % ":".join(["$PYTHONPATH"] + pypath))
-    plantestsuite_idlist(name, env, args)
+    plantestsuite_loadlist(name, env, args)
 
 
 def get_env_torture_options():
@@ -192,6 +188,7 @@ def get_env_torture_options():
 
 
 samba4srcdir = source4dir()
+samba3srcdir = source3dir()
 bbdir = os.path.join(srcdir(), "testprogs/blackbox")
 configuration = "--configfile=$SMB_CONF_PATH"
 
@@ -206,30 +203,26 @@ smbtorture4_options = [
     ] + get_env_torture_options()
 
 
-def print_smbtorture4_version():
-    """Print the version of Samba smbtorture4 comes from.
-
-    :return: Whether smbtorture4 was successfully run
-    """
-    try:
-        sub = subprocess.Popen([smbtorture4, "-V"], stdout=sys.stderr)
-    except OSError, e:
-        if e.errno == errno.ENOENT:
-            return False
-        raise
-    sub.communicate("")
-    return (sub.returncode == 0)
-
-
 def plansmbtorture4testsuite(name, env, options, target, modname=None):
     if modname is None:
         modname = "samba4.%s" % name
     if isinstance(options, list):
         options = " ".join(options)
     options = " ".join(smbtorture4_options + ["--target=%s" % target]) + " " + options
-    cmdline = "%s $LISTOPT %s %s" % (valgrindify(smbtorture4), options, name)
+    cmdline = "%s $LISTOPT $LOADLIST %s %s" % (valgrindify(smbtorture4), options, name)
     plantestsuite_loadlist(modname, env, cmdline)
 
 
 def smbtorture4_testsuites(prefix):
     return filter(lambda x: x.startswith(prefix), smbtorture4_testsuite_list)
+
+
+smbclient3 = binpath('smbclient3')
+smbtorture3 = binpath('smbtorture3')
+ntlm_auth3 = binpath('ntlm_auth3')
+net = binpath('net')
+scriptdir = os.path.join(srcdir(), "script/tests")
+
+wbinfo = binpath('wbinfo')
+dbwrap_tool = binpath('dbwrap_tool')
+vfstest = binpath('vfstest')