winbindd: as DC we should try to get the target_domain from @SOMETHING part of the...
[metze/samba/wip.git] / selftest / selftesthelpers.py
index 502ba1079bcbc0685389c65f4c6a264427815d56..8b885b59419cb27f1a76633c0e31edaf5f27f2ea 100644 (file)
@@ -34,22 +34,9 @@ def source3dir():
 def bindir():
     return os.path.normpath(os.getenv("BINDIR", "./bin"))
 
-binary_mapping = {}
-
 def binpath(name):
-    if name in binary_mapping:
-        name = binary_mapping[name]
     return os.path.join(bindir(), name)
 
-binary_mapping_string = os.getenv("BINARY_MAPPING", None)
-if binary_mapping_string is not None:
-    for binmapping_entry in binary_mapping_string.split(','):
-        try:
-            (from_path, to_path) = binmapping_entry.split(':', 1)
-        except ValueError:
-            continue
-        binary_mapping[from_path] = to_path
-
 # Split perl variable to allow $PERL to be set to e.g. "perl -W"
 perl = os.getenv("PERL", "perl").split()
 
@@ -58,29 +45,11 @@ if subprocess.call(perl + ["-e", "eval require Test::More;"]) == 0:
 else:
     has_perl_test_more = False
 
-try:
-    from subunit.run import TestProgram
-except ImportError:
-    has_system_subunit_run = False
-else:
-    has_system_subunit_run = True
-
 python = os.getenv("PYTHON", "python")
+extra_python = os.getenv("EXTRA_PYTHON", None)
 
-# Set a default value, overridden if we find a working one on the system
-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)
-sub.communicate("")
+tap2subunit = python + " " + os.path.join(srcdir(), "selftest", "tap2subunit")
 
-if sub.returncode == 0:
-    cmd = "echo -ne \"1..1\nok 1 # skip doesn't seem to work yet\n\" | tap2subunit | grep skip"
-    sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
-        stderr=subprocess.PIPE, shell=True)
-    if sub.returncode == 0:
-        tap2subunit = "tap2subunit"
 
 def valgrindify(cmdline):
     """Run a command under valgrind, if $VALGRIND was set."""
@@ -98,17 +67,17 @@ def plantestsuite(name, env, cmdline):
     :param cmdline: Command line to run
     """
     print "-- TEST --"
-    print name
+    if env == "none":
+        fullname = name
+    else:
+        fullname = "%s(%s)" % (name, env)
+    print fullname
     print env
     if isinstance(cmdline, list):
         cmdline = " ".join(cmdline)
-    filter_subunit_args = ["--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)
+        raise AssertionError("test %s supports --list, but not --load-list" % name)
+    print cmdline + " 2>&1 " + " | " + add_prefix(name, env)
 
 
 def add_prefix(prefix, env, support_list=False):
@@ -130,20 +99,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 " + " | " + add_prefix(name, env, False)
 
 
 def skiptestsuite(name, reason):
@@ -168,20 +129,18 @@ def planperltestsuite(name, path):
         skiptestsuite(name, "Test::More not available")
 
 
-def planpythontestsuite(env, module, name=None, extra_path=[]):
+def planpythontestsuite(env, module, name=None, extra_path=[], py3_compatible=False):
     if name is None:
         name = module
     pypath = list(extra_path)
-    if not has_system_subunit_run:
-        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", module]
+    args = [python, "-m", "samba.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)
+    if py3_compatible and extra_python is not None:
+        # Plan one more test for Python 3 compatible module
+        args[0] = extra_python
+        plantestsuite_loadlist(name + ".python3", env, args)
 
 
 def get_env_torture_options():
@@ -198,11 +157,12 @@ samba3srcdir = source3dir()
 bbdir = os.path.join(srcdir(), "testprogs/blackbox")
 configuration = "--configfile=$SMB_CONF_PATH"
 
-smbtorture4 = binpath("smbtorture4")
+smbtorture4 = binpath("smbtorture")
 smbtorture4_testsuite_list = subprocess.Popen([smbtorture4, "--list-suites"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate("")[0].splitlines()
 
 smbtorture4_options = [
     configuration,
+    "--option=\'fss:sequence timeout=1\'",
     "--maximum-runtime=$SELFTEST_MAXTIME",
     "--basedir=$SELFTEST_TMPDIR",
     "--format=subunit"
@@ -215,7 +175,7 @@ def plansmbtorture4testsuite(name, env, options, target, modname=None):
     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)
 
 
@@ -223,12 +183,16 @@ def smbtorture4_testsuites(prefix):
     return filter(lambda x: x.startswith(prefix), smbtorture4_testsuite_list)
 
 
-smbclient3 = binpath('smbclient3')
+smbclient3 = binpath('smbclient')
 smbtorture3 = binpath('smbtorture3')
-ntlm_auth3 = binpath('ntlm_auth3')
+ntlm_auth3 = binpath('ntlm_auth')
 net = binpath('net')
 scriptdir = os.path.join(srcdir(), "script/tests")
 
 wbinfo = binpath('wbinfo')
 dbwrap_tool = binpath('dbwrap_tool')
 vfstest = binpath('vfstest')
+smbcquotas = binpath('smbcquotas')
+smbget = binpath('smbget')
+rpcclient = binpath('rpcclient')
+smbcacls = binpath('smbcacls')