docs: fix a typo in history file
[bbaumbach/samba-autobuild/.git] / selftest / wscript
index 2c45e1bf8f78dcdbac2d004301f7784b8b2b6618..308aa85cad5240f9100374f0411f0fc2e41db1c2 100644 (file)
@@ -20,10 +20,6 @@ def options(opt):
     opt.add_option('--enable-selftest',
                    help=("enable options necessary for selftest (default=no)"),
                    action="store_true", dest='enable_selftest', default=False)
-    opt.add_option('--enable-coverage',
-                   help=("enable options necessary for code coverage "
-                         "reporting on selftest (default=no)"),
-                   action="store_true", dest='enable_coverage', default=False)
     opt.add_option('--with-selftest-prefix',
                    help=("specify location of selftest directory "
                          "(default=%s)" % DEFAULT_SELFTEST_PREFIX),
@@ -90,14 +86,13 @@ def options(opt):
                   help=("use tests listed here, not defaults "
                         "(--test-list='FOO|' will execute FOO; "
                         "--test-list='FOO' will read it)"))
+    gr.add_option('--no-subunit-filter',
+                  help=("no (xfail) subunit filtering"),
+                  action="store_true", dest='NO_SUBUNIT_FILTER', default=False)
+
 
 def configure(conf):
     conf.env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
-    conf.env.enable_coverage = Options.options.enable_coverage
-    if conf.env.enable_coverage:
-        conf.ADD_LDFLAGS('-lgcov', testflags=True)
-        conf.ADD_CFLAGS('--coverage')
-
     if Options.options.enable_selftest or Options.options.developer:
         conf.DEFINE('ENABLE_SELFTEST', 1)
 
@@ -121,6 +116,21 @@ 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:
         if Options.options.PERF_TEST:
             env.SUBUNIT_FORMATTER = '${PYTHON} -u ${srcdir}/selftest/format-subunit-json --prefix=${SELFTEST_PREFIX}'
@@ -166,8 +176,6 @@ def cmd_testonly(opt):
     if Options.options.PERF_TEST:
         env.FILTER_OPTIONS = ('${PYTHON} -u ${srcdir}/selftest/filter-subunit '
                               '--perf-test-output')
-    elif os.environ.get('RUN_FROM_BUILD_FARM') is not None:
-        env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
     else:
         env.FILTER_OPTIONS = '${FILTER_XFAIL}'
 
@@ -194,6 +202,7 @@ def cmd_testonly(opt):
         os.environ['NMBD_VALGRIND'] = EXPAND_VARIABLES(opt, server_wrapper)
         os.environ['WINBINDD_VALGRIND'] = EXPAND_VARIABLES(opt, server_wrapper)
         os.environ['SMBD_VALGRIND'] = EXPAND_VARIABLES(opt, server_wrapper)
+        os.environ['SAMBA_DCERPCD_VALGRIND'] = EXPAND_VARIABLES(opt, server_wrapper)
 
     # this is needed for systems without rpath, or with rpath disabled
     ADD_LD_LIBRARY_PATH('bin/shared')
@@ -202,7 +211,8 @@ 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'
@@ -225,10 +235,6 @@ def cmd_testonly(opt):
         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|" ' +
@@ -241,56 +247,119 @@ def cmd_testonly(opt):
 
     env.OPTIONS += " --nss_wrapper_so_path=" + CONFIG_GET(opt, 'LIBNSS_WRAPPER_SO_PATH')
     env.OPTIONS += " --resolv_wrapper_so_path=" + CONFIG_GET(opt, 'LIBRESOLV_WRAPPER_SO_PATH')
-    env.OPTIONS += " --socket_wrapper_so_path=" + CONFIG_GET(opt, 'LIBSOCKET_WRAPPER_SO_PATH')
     env.OPTIONS += " --uid_wrapper_so_path=" + CONFIG_GET(opt, 'LIBUID_WRAPPER_SO_PATH')
 
-    #if unversioned_sys_platform in ('freebsd', 'netbsd', 'openbsd', 'sunos'):
-    #    env.OPTIONS += " --use-dns-faking"
+    # selftest can optionally use kernel namespaces instead of socket-wrapper
+    if os.environ.get('USE_NAMESPACES') is None:
+        env.OPTIONS += " --socket_wrapper_so_path=" + CONFIG_GET(opt, 'LIBSOCKET_WRAPPER_SO_PATH')
 
-    # FIXME REMOVE ME!
-    env.OPTIONS += " --use-dns-faking"
+    if not CONFIG_SET(opt, 'HAVE_RESOLV_CONF_SUPPORT'):
+        env.OPTIONS += " --use-dns-faking"
+
+    if CONFIG_GET(opt, 'USING_SYSTEM_KRB5'):
+        env.OPTIONS += " --mitkrb5"
 
     if CONFIG_GET(opt, 'USING_SYSTEM_KRB5') and CONFIG_GET(opt, 'MIT_KDC_PATH'):
-        env.OPTIONS += " --mitkrb5 --exclude=${srcdir}/selftest/skip_mit_kdc"
+        env.OPTIONS += " --exclude=${srcdir}/selftest/skip_mit_kdc"
+        if CONFIG_GET(opt, 'HAVE_MIT_KRB5_PRE_1_20'):
+            env.OPTIONS += " --exclude=${srcdir}/selftest/skip_mit_kdc_pre_1_20"
+
+        env.FILTER_XFAIL += " --expected-failures=${srcdir}/selftest/"\
+                            "knownfail_mit_kdc"
+
+        if CONFIG_GET(opt, 'HAVE_MIT_KRB5_PRE_1_20'):
+            env.FILTER_XFAIL += ' --expected-failures=${srcdir}/selftest/knownfail_mit_kdc_pre_1_20'
+
+        if CONFIG_GET(opt, 'HAVE_MIT_KRB5_1_20'):
+            env.FILTER_XFAIL += ' --expected-failures=${srcdir}/selftest/knownfail_mit_kdc_1_20'
+    else:
+        env.FILTER_XFAIL += " --expected-failures=${srcdir}/selftest/"\
+                            "knownfail_heimdal_kdc"
+
+    if CONFIG_GET(opt, 'SIZEOF_VOID_P') == 4:
+        env.FILTER_XFAIL += " --expected-failures=${srcdir}/selftest/knownfail-32bit"
+        env.OPTIONS += " --default-ldb-backend=tdb --exclude=${srcdir}/selftest/skip-32bit"
 
     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 os.environ.get('DISABLE_OPATH'):
+        env.OPTIONS += " --exclude=${srcdir}/selftest/skip.opath-required"
+
+    libasan = None
     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()
+        libasan = Utils.cmd_output(
+            r'ldd bin/texpect | grep libasan| cut -f 3 -d \ ',
+            silent=True).strip()
+        libasan = libasan.decode('utf8')
 
         # Have the selftest.pl LD_PRELOAD libasan in the right spot
         env.OPTIONS += " --asan_so_path=" + libasan
 
+        if CONFIG_SET(opt, 'HAVE_CRYPT_R'):
+            # We try to find the correct libcrypt automatically
+            libcrypt = Utils.cmd_output(
+                'ldd bin/modules/ldb/password_hash.so | awk \'/libcrypt.so/ { print $3 }\'',
+                silent=True).strip()
+            libcrypt = libcrypt.decode('utf8')
+            env.OPTIONS += " --crypt_so_path=" + libcrypt
+
     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
+    # If using namespaces (rather than socket-wrapper), run the selftest script
+    # in its own network namespace (by doing an 'unshare'). (To create a new
+    # namespace as a non-root user, we have to also unshare the current user
+    # namespace, and remap ourself as root in the namespace created)
+    if os.environ.get('USE_NAMESPACES') is not None:
+        env.CORE_COMMAND = 'unshare --net --user --map-root-user ' + env.CORE_COMMAND
+
+    if env.ADDRESS_SANITIZER and libasan:
+        # For now we cannot run with leak and odr detection
+        asan_options = "ASAN_OPTIONS=detect_leaks=0"
+        asan_options += ":detect_odr_violation=0"
+        # uncomment if you need asan logs
+        # asan_options += ":verbosity=111"
+        asan_options += ":suppressions=${srcdir}/selftest/sanitizer/asan.supp"
+        asan_options += " "
+
+        # And we need to disable RTLD_DEEPBIND in ldb and socket wrapper
+        no_leak_check = "LDB_MODULES_DISABLE_DEEPBIND=1 "
+        no_leak_check += "SOCKET_WRAPPER_DISABLE_DEEP_BIND=1"
+        no_leak_check += " "
+        env.CORE_COMMAND = asan_options + 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 + ' '
+        asan_envs = (asan_options + no_leak_check + "LD_PRELOAD=" + libasan
+                     + ' ')
         env.FILTER_OPTIONS = asan_envs + env.FILTER_OPTIONS
         env.SUBUNIT_FORMATTER = asan_envs + env.SUBUNIT_FORMATTER
 
+    if env.UNDEFINED_SANITIZER:
+        # print a stack trace with the error.
+        print_stack_trace = "UBSAN_OPTIONS=print_stacktrace=1"
+        print_stack_trace += ",suppressions=${srcdir}/selftest/ubsan.supp"
+        env.CORE_COMMAND = print_stack_trace + " " + env.CORE_COMMAND
+
     if Options.options.LIST:
         cmd = '${CORE_COMMAND} --list'
     else:
         env.OPTIONS += ' --socket-wrapper'
         cmd = '(${CORE_COMMAND} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
-        if (os.environ.get('RUN_FROM_BUILD_FARM') is None and
-            not Options.options.FILTERED_SUBUNIT):
+
+        if Options.options.NO_SUBUNIT_FILTER:
+            # Skip subunit filtering (i.e. because python is disabled).
+            # Use --one to bail out upon any failure
+            cmd = '(${CORE_COMMAND} --one && touch ${SELFTEST_PREFIX}/st_done)'
+        elif not Options.options.FILTERED_SUBUNIT:
             subunit_cache = os.path.join(env.SELFTEST_PREFIX, "subunit")
             cmd += ' | tee %s | ${FORMAT_TEST_OUTPUT}' % subunit_cache
         else: