selftesthelpers.py 6.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/python
# This script generates a list of testsuites that should be run as part of
# the Samba 4 test suite.

# The output of this script is parsed by selftest.pl, which then decides
# which of the tests to actually run. It will, for example, skip all tests
# listed in selftest/skip or only run a subset during "make quicktest".

# The idea is that this script outputs all of the tests of Samba 4, not
# just those that are known to pass, and list those that should be skipped
# or are known to fail in selftest/skip or selftest/knownfail. This makes it
# very easy to see what functionality is still missing in Samba 4 and makes
# it possible to run the testsuite against other servers, such as Samba 3 or
# Windows that have a different set of features.

# The syntax for a testsuite is "-- TEST --" on a single line, followed
# by the name of the test, the environment it needs and the command to run, all
# three separated by newlines. All other lines in the output are considered
# comments.
20
from __future__ import print_function
21 22 23

import os
import subprocess
24
import sys
25 26

def srcdir():
27
    return os.path.normpath(os.getenv("SRCDIR", os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")))
28 29

def source4dir():
30
    return os.path.normpath(os.path.join(srcdir(), "source4"))
31

32 33 34
def source3dir():
    return os.path.normpath(os.path.join(srcdir(), "source3"))

35
def bindir():
36
    return os.path.normpath(os.getenv("BINDIR", "./bin"))
37 38

def binpath(name):
39
    return os.path.join(bindir(), name)
40

41 42
# Split perl variable to allow $PERL to be set to e.g. "perl -W"
perl = os.getenv("PERL", "perl").split()
43

44
if subprocess.call(perl + ["-e", "eval require Test::More;"]) == 0:
45 46 47 48 49
    has_perl_test_more = True
else:
    has_perl_test_more = False

python = os.getenv("PYTHON", "python")
50
extra_python = os.getenv("EXTRA_PYTHON", None)
51

52
tap2subunit = python + " " + os.path.join(srcdir(), "selftest", "tap2subunit")
53 54


55 56 57 58 59 60 61 62
def valgrindify(cmdline):
    """Run a command under valgrind, if $VALGRIND was set."""
    valgrind = os.getenv("VALGRIND")
    if valgrind is None:
        return cmdline
    return valgrind + " " + cmdline


63
def plantestsuite(name, env, cmdline):
64 65 66 67 68 69
    """Plan a test suite.

    :param name: Testsuite name
    :param env: Environment to run the testsuite in
    :param cmdline: Command line to run
    """
70
    print("-- TEST --")
71 72 73 74
    if env == "none":
        fullname = name
    else:
        fullname = "%s(%s)" % (name, env)
75 76
    print(fullname)
    print(env)
77 78
    if isinstance(cmdline, list):
        cmdline = " ".join(cmdline)
79 80
    if "$LISTOPT" in cmdline:
        raise AssertionError("test %s supports --list, but not --load-list" % name)
81
    print(cmdline + " 2>&1 " + " | " + add_prefix(name, env))
82 83


84
def add_prefix(prefix, env, support_list=False):
85 86 87 88
    if support_list:
        listopt = "$LISTOPT "
    else:
        listopt = ""
89
    return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" % (srcdir(), listopt, prefix, env)
90 91


92
def plantestsuite_loadlist(name, env, cmdline):
93
    print("-- TEST-LOADLIST --")
94 95 96 97
    if env == "none":
        fullname = name
    else:
        fullname = "%s(%s)" % (name, env)
98 99
    print(fullname)
    print(env)
100 101 102
    if isinstance(cmdline, list):
        cmdline = " ".join(cmdline)
    support_list = ("$LISTOPT" in cmdline)
103
    if not "$LISTOPT" in cmdline:
104 105 106
        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)
107 108
    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))
109 110 111 112 113 114 115 116 117


def skiptestsuite(name, reason):
    """Indicate that a testsuite was skipped.

    :param name: Test suite name
    :param reason: Reason the test suite was skipped
    """
    # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
118
    print("skipping %s (%s)" % (name, reason), file=sys.stderr)
119 120 121 122 123 124 125 126 127


def planperltestsuite(name, path):
    """Run a perl test suite.

    :param name: Name of the test suite
    :param path: Path to the test runner
    """
    if has_perl_test_more:
128
        plantestsuite(name, "none", "%s %s | %s" % (" ".join(perl), path, tap2subunit))
129 130 131 132
    else:
        skiptestsuite(name, "Test::More not available")


133
def planpythontestsuite(env, module, name=None, extra_path=[], py3_compatible=False):
134 135
    if name is None:
        name = module
136
    pypath = list(extra_path)
137
    args = [python, "-m", "samba.subunit.run", "$LISTOPT", "$LOADLIST", module]
138
    if pypath:
139
        args.insert(0, "PYTHONPATH=%s" % ":".join(["$PYTHONPATH"] + pypath))
140
    plantestsuite_loadlist(name, env, args)
141
    if py3_compatible and extra_python is not None:
142 143
        # Plan one more test for Python 3 compatible module
        args[0] = extra_python
144
        plantestsuite_loadlist(name + ".python3", env, args)
145 146


147 148 149 150 151 152 153 154 155
def get_env_torture_options():
    ret = []
    if not os.getenv("SELFTEST_VERBOSE"):
        ret.append("--option=torture:progress=no")
    if os.getenv("SELFTEST_QUICK"):
        ret.append("--option=torture:quick=yes")
    return ret


156
samba4srcdir = source4dir()
157
samba3srcdir = source3dir()
158 159 160
bbdir = os.path.join(srcdir(), "testprogs/blackbox")
configuration = "--configfile=$SMB_CONF_PATH"

161
smbtorture4 = binpath("smbtorture")
162 163
smbtorture4_testsuite_list = subprocess.Popen([smbtorture4, "--list-suites"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate("")[0].splitlines()

164 165
smbtorture4_options = [
    configuration,
166
    "--option=\'fss:sequence timeout=1\'",
167 168 169 170
    "--maximum-runtime=$SELFTEST_MAXTIME",
    "--basedir=$SELFTEST_TMPDIR",
    "--format=subunit"
    ] + get_env_torture_options()
171

172 173

def plansmbtorture4testsuite(name, env, options, target, modname=None):
174 175 176 177
    if modname is None:
        modname = "samba4.%s" % name
    if isinstance(options, list):
        options = " ".join(options)
178
    options = " ".join(smbtorture4_options + ["--target=%s" % target]) + " " + options
179
    cmdline = "%s $LISTOPT $LOADLIST %s %s" % (valgrindify(smbtorture4), options, name)
180 181
    plantestsuite_loadlist(modname, env, cmdline)

182

183 184
def smbtorture4_testsuites(prefix):
    return filter(lambda x: x.startswith(prefix), smbtorture4_testsuite_list)
185 186


187
smbclient3 = binpath('smbclient')
188
smbtorture3 = binpath('smbtorture3')
189
ntlm_auth3 = binpath('ntlm_auth')
190
net = binpath('net')
191 192 193 194 195
scriptdir = os.path.join(srcdir(), "script/tests")

wbinfo = binpath('wbinfo')
dbwrap_tool = binpath('dbwrap_tool')
vfstest = binpath('vfstest')
196
smbcquotas = binpath('smbcquotas')
197
smbget = binpath('smbget')
198
rpcclient = binpath('rpcclient')
199
smbcacls = binpath('smbcacls')
200
smbcontrol = binpath('smbcontrol')