s4:rpc_server: only pass dcesrv_auth to auth_state.session_key_fn()
[samba.git] / selftest / wscript
index 5fa0dac457e83af3da95b9acf1a1fa791ddcf635..b7eec2c2605e8d74020da6c770d2ae9a73903b41 100644 (file)
@@ -3,14 +3,19 @@
 
 # selftest main code.
 
-import Scripting, os, Options, Utils, Environment, optparse, sys
+import sys
+import os
+import optparse
+from waflib import Scripting, Options, Utils
+from waflib.ConfigSet import ConfigSet as Environment
+
 from samba_utils import *
 from samba_autoconf import *
 import types
 
 DEFAULT_SELFTEST_PREFIX="./st"
 
-def set_options(opt):
+def options(opt):
 
     opt.add_option('--enable-selftest',
                    help=("enable options necessary for selftest (default=no)"),
@@ -81,6 +86,10 @@ def set_options(opt):
                   action="store_true", help="Run testsuites in random order")
     gr.add_option('--perf-test', dest='PERF_TEST', default=False,
                   action="store_true", help="run performance tests only")
+    gr.add_option('--test-list', dest='TEST_LIST', default='',
+                  help=("use tests listed here, not defaults "
+                        "(--test-list='FOO|' will execute FOO; "
+                        "--test-list='FOO' will read it)"))
 
 def configure(conf):
     conf.env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
@@ -112,9 +121,31 @@ def cmd_testonly(opt):
     env.TESTS  = Options.options.TESTS
 
     env.SUBUNIT_FORMATTER = os.getenv('SUBUNIT_FORMATTER')
+
+    # Lots of test scripts need to run with the correct version
+    # of python. With the correct shebang the script should run with the
+    # correct version, the problem is that not all scripts are part
+    # of the installation, some scripts are part of the source code,
+    # and the shebang is not dynamically generated as yet.
+    # It is safer if we are somewhat version neutral at the moment and
+    # ignore the shebang and always run scripts from the test environment
+    # with the python version (determined by PYTHON env variable) If this
+    # env variable isn't set then set it according to the python version
+    # that is running the tests
+    if not os.getenv('PYTHON', None):
+        from sys import executable as exe
+        os.environ['PYTHON'] = os.path.basename(exe)
+
     if not env.SUBUNIT_FORMATTER:
-        env.SUBUNIT_FORMATTER = '${PYTHON} -u ${srcdir}/selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
-    env.FILTER_XFAIL = '${PYTHON} -u ${srcdir}/selftest/filter-subunit --expected-failures=${srcdir}/selftest/knownfail --flapping=${srcdir}/selftest/flapping'
+        if Options.options.PERF_TEST:
+            env.SUBUNIT_FORMATTER = '${PYTHON} -u ${srcdir}/selftest/format-subunit-json --prefix=${SELFTEST_PREFIX}'
+        else:
+            env.SUBUNIT_FORMATTER = '${PYTHON} -u ${srcdir}/selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
+    env.FILTER_XFAIL = ('${PYTHON} -u ${srcdir}/selftest/filter-subunit '
+                        '--expected-failures=${srcdir}/selftest/knownfail '
+                        '--expected-failures=${srcdir}/selftest/knownfail.d '
+                        '--flapping=${srcdir}/selftest/flapping '
+                        '--flapping=${srcdir}/selftest/flapping.d')
 
     if Options.options.FAIL_IMMEDIATELY:
         env.FILTER_XFAIL += ' --fail-immediately'
@@ -186,11 +217,19 @@ def cmd_testonly(opt):
     # if we are using a system version of ldb then we need to tell it to
     # load modules from our modules path
     if env.USING_SYSTEM_LDB:
-        os.environ['LDB_MODULES_PATH'] = os.path.abspath(os.path.join(env.cwd, 'bin/modules/ldb'))
+        os.environ['LDB_MODULES_PATH'] = os.path.abspath(
+                os.path.join(*(env.cwd + ['bin/modules/ldb'])))
 
     # tell build system where to find config.h
     os.environ['CONFIG_H'] = 'bin/default/include/config.h'
 
+    # tell the test system where perl is
+    if isinstance(env.PERL, list):
+        perl = ' '.join(env.PERL)
+    else:
+        perl = env.PERL
+    os.environ['PERL'] = perl
+
     st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
     if os.path.exists(st_done):
         os.unlink(st_done)
@@ -198,8 +237,14 @@ def cmd_testonly(opt):
     if not os.path.isdir(env.SELFTEST_PREFIX):
         os.makedirs(env.SELFTEST_PREFIX, int('755', 8))
 
-    if Options.options.PERF_TEST:
+    if Options.options.TEST_LIST:
+        env.TESTLISTS = '--testlist=%r' % Options.options.TEST_LIST
+    elif Options.options.PERF_TEST:
         env.TESTLISTS = '--testlist="${PYTHON} ${srcdir}/selftest/perf_tests.py|" '
+    elif CONFIG_SET(opt, 'EXTRA_PYTHON'):
+        env.TESTLISTS = ('--testlist="EXTRA_PYTHON=${EXTRA_PYTHON} ${PYTHON} ${srcdir}/selftest/tests.py|" ' +
+                         '--testlist="EXTRA_PYTHON=${EXTRA_PYTHON} ${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
+                         '--testlist="EXTRA_PYTHON=${EXTRA_PYTHON} ${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
     else:
         env.TESTLISTS = ('--testlist="${PYTHON} ${srcdir}/selftest/tests.py|" ' +
                          '--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
@@ -221,10 +266,40 @@ def cmd_testonly(opt):
     # FIXME REMOVE ME!
     env.OPTIONS += " --use-dns-faking"
 
+    if CONFIG_GET(opt, 'USING_SYSTEM_KRB5') and CONFIG_GET(opt, 'MIT_KDC_PATH'):
+        env.OPTIONS += " --mitkrb5 --exclude=${srcdir}/selftest/skip_mit_kdc"
+
+    if not CONFIG_GET(opt, 'HAVE_GSS_KRB5_CRED_NO_CI_FLAGS_X'):
+        # older MIT krb5 libraries (< 1.14) don't have
+        # GSS_KRB5_CRED_NO_CI_FLAGS_X
+        env.OPTIONS += " --exclude=${srcdir}/selftest/skip.no-GSS_KRB5_CRED_NO_CI_FLAGS_X"
+
+    if env.ADDRESS_SANITIZER:
+        # We try to find the correct libasan automatically
+        libasan = Utils.cmd_output('ldd bin/texpect | grep libasan| cut -f 3 -d \ ',
+                                   silent=True).strip()
+
+        # Have the selftest.pl LD_PRELOAD libasan in the right spot
+        env.OPTIONS += " --asan_so_path=" + libasan
 
     subunit_cache = None
     # We use the full path rather than relative path to avoid problems on some platforms (ie. solaris 8).
     env.CORE_COMMAND = '${PERL} ${srcdir}/selftest/selftest.pl --target=${SELFTEST_TARGET} --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${srcdir}/selftest/skip ${TESTLISTS} ${OPTIONS} ${TESTS}'
+
+    if env.ADDRESS_SANITIZER:
+        # For now we cannot run with leak detection
+        no_leak_check = "ASAN_OPTIONS=detect_leaks=0"
+        env.CORE_COMMAND = no_leak_check + " " + env.CORE_COMMAND
+
+        # We need to have the subunit filter and formatter preload
+        # libasan otherwise the tests fail at startup.
+        #
+        # Also, we do not care about leaks in python
+
+        asan_envs = no_leak_check + " LD_PRELOAD=" + libasan + ' '
+        env.FILTER_OPTIONS = asan_envs + env.FILTER_OPTIONS
+        env.SUBUNIT_FORMATTER = asan_envs + env.SUBUNIT_FORMATTER
+
     if Options.options.LIST:
         cmd = '${CORE_COMMAND} --list'
     else:
@@ -236,6 +311,7 @@ def cmd_testonly(opt):
             cmd += ' | tee %s | ${FORMAT_TEST_OUTPUT}' % subunit_cache
         else:
             cmd += ' | ${FILTER_OPTIONS}'
+
     runcmd = EXPAND_VARIABLES(opt, cmd)
 
     print("test: running %s" % runcmd)
@@ -272,5 +348,5 @@ def cmd_test(opt):
     # if running all tests, then force a symbol check
     env = LOAD_ENVIRONMENT()
     CHECK_MAKEFLAGS(env)
-    Scripting.commands.append('build')
-    Scripting.commands.append('testonly')
+    Options.commands.append('build')
+    Options.commands.append('testonly')