python/samba/netcmd/schema.py: add schema show_oc for attribute
[kai/samba-autobuild/.git] / selftest / wscript
index b251370c332e54c69a0b4fcf560acb6a00063482..6a6dcb5c644c42c1627136ebb14dbdd808b76cdb 100644 (file)
@@ -8,27 +8,31 @@ from samba_utils import *
 from samba_autoconf import *
 import types
 
 from samba_autoconf import *
 import types
 
+DEFAULT_SELFTEST_PREFIX="./st"
+
 def set_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',
 def set_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)"),
+                   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',
                    action="store_true", dest='enable_coverage', default=False)
     opt.add_option('--with-selftest-prefix',
-                   help=("specify location of selftest directory (default=./st)"),
-                   action="store", dest='SELFTEST_PREFIX', default='./st')
+                   help=("specify location of selftest directory "
+                         "(default=%s)" % DEFAULT_SELFTEST_PREFIX),
+                   action="store", dest='SELFTEST_PREFIX', default=DEFAULT_SELFTEST_PREFIX)
 
     opt.ADD_COMMAND('test', cmd_test)
     opt.ADD_COMMAND('testonly', cmd_testonly)
 
     gr = opt.add_option_group('test options')
 
 
     opt.ADD_COMMAND('test', cmd_test)
     opt.ADD_COMMAND('testonly', cmd_testonly)
 
     gr = opt.add_option_group('test options')
 
-    gr.add_option('--load-list', 
+    gr.add_option('--load-list',
                   help=("Load a test id list from a text file"),
                   action="store", dest='LOAD_LIST', default=None)
                   help=("Load a test id list from a text file"),
                   action="store", dest='LOAD_LIST', default=None)
-    gr.add_option('--list', 
+    gr.add_option('--list',
                   help=("List available tests"),
                   action="store_true", dest='LIST', default=False)
     gr.add_option('--tests',
                   help=("List available tests"),
                   action="store_true", dest='LIST', default=False)
     gr.add_option('--tests',
@@ -43,6 +47,9 @@ def set_options(opt):
     gr.add_option('--slow',
                   help=("enable the really slow tests"),
                   action="store_true", dest='SLOWTEST', default=False)
     gr.add_option('--slow',
                   help=("enable the really slow tests"),
                   action="store_true", dest='SLOWTEST', default=False)
+    gr.add_option('--nb-slowest',
+                  help=("Show the n slowest tests (default=10)"),
+                  type=int, default=10, dest='NB_SLOWEST')
     gr.add_option('--testenv',
                   help=("start a terminal with the test environment setup"),
                   action="store_true", dest='TESTENV', default=False)
     gr.add_option('--testenv',
                   help=("start a terminal with the test environment setup"),
                   action="store_true", dest='TESTENV', default=False)
@@ -72,6 +79,12 @@ def set_options(opt):
                   action="store_true", dest='SOCKET_WRAPPER_KEEP_PCAP', default=False)
     gr.add_option('--random-order', dest='RANDOM_ORDER', default=False,
                   action="store_true", help="Run testsuites in random order")
                   action="store_true", dest='SOCKET_WRAPPER_KEEP_PCAP', default=False)
     gr.add_option('--random-order', dest='RANDOM_ORDER', default=False,
                   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
 
 def configure(conf):
     conf.env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
@@ -89,6 +102,9 @@ def cmd_testonly(opt):
     env = LOAD_ENVIRONMENT()
     opt.env = env
 
     env = LOAD_ENVIRONMENT()
     opt.env = env
 
+    if Options.options.SELFTEST_PREFIX != DEFAULT_SELFTEST_PREFIX:
+        env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
+
     if (not CONFIG_SET(opt, 'NSS_WRAPPER') or
         not CONFIG_SET(opt, 'UID_WRAPPER') or
         not CONFIG_SET(opt, 'SOCKET_WRAPPER')):
     if (not CONFIG_SET(opt, 'NSS_WRAPPER') or
         not CONFIG_SET(opt, 'UID_WRAPPER') or
         not CONFIG_SET(opt, 'SOCKET_WRAPPER')):
@@ -101,8 +117,15 @@ def cmd_testonly(opt):
 
     env.SUBUNIT_FORMATTER = os.getenv('SUBUNIT_FORMATTER')
     if not env.SUBUNIT_FORMATTER:
 
     env.SUBUNIT_FORMATTER = os.getenv('SUBUNIT_FORMATTER')
     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'
 
     if Options.options.FAIL_IMMEDIATELY:
         env.FILTER_XFAIL += ' --fail-immediately'
@@ -120,15 +143,7 @@ def cmd_testonly(opt):
                     and not issubclass(type(val), types.MethodType):
                 os.environ['TESTENV_%s' % o.upper()] = str(getattr(Options.options, o, ''))
 
                     and not issubclass(type(val), types.MethodType):
                 os.environ['TESTENV_%s' % o.upper()] = str(getattr(Options.options, o, ''))
 
-
-    binary_mapping = ('nmblookup3:nmblookup,' +
-                      'nmblookup4:nmblookup4,' +
-                      'smbclient3:smbclient,' +
-                      'smbclient4:smbclient4,' +
-                      'smbtorture4:smbtorture,' + 
-                      'ntlm_auth3:ntlm_auth')
-
-    env.OPTIONS = '--binary-mapping=%s' % binary_mapping 
+    env.OPTIONS = ''
     if not Options.options.SLOWTEST:
         env.OPTIONS += ' --exclude=${srcdir}/selftest/slow'
     if Options.options.QUICKTEST:
     if not Options.options.SLOWTEST:
         env.OPTIONS += ' --exclude=${srcdir}/selftest/slow'
     if Options.options.QUICKTEST:
@@ -143,7 +158,10 @@ def cmd_testonly(opt):
         env.OPTIONS += ' --socket-wrapper-keep-pcap'
     if Options.options.RANDOM_ORDER:
         env.OPTIONS += ' --random-order'
         env.OPTIONS += ' --socket-wrapper-keep-pcap'
     if Options.options.RANDOM_ORDER:
         env.OPTIONS += ' --random-order'
-    if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
+    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}'
         env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
     else:
         env.FILTER_OPTIONS = '${FILTER_XFAIL}'
@@ -184,6 +202,9 @@ def cmd_testonly(opt):
     # tell build system where to find config.h
     os.environ['CONFIG_H'] = 'bin/default/include/config.h'
 
     # tell build system where to find config.h
     os.environ['CONFIG_H'] = 'bin/default/include/config.h'
 
+    # tell the test system where perl is
+    os.environ['PERL'] = env.PERL
+
     st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
     if os.path.exists(st_done):
         os.unlink(st_done)
     st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
     if os.path.exists(st_done):
         os.unlink(st_done)
@@ -191,19 +212,69 @@ def cmd_testonly(opt):
     if not os.path.isdir(env.SELFTEST_PREFIX):
         os.makedirs(env.SELFTEST_PREFIX, int('755', 8))
 
     if not os.path.isdir(env.SELFTEST_PREFIX):
         os.makedirs(env.SELFTEST_PREFIX, int('755', 8))
 
-    env.TESTLISTS = ('--testlist="${PYTHON} ${srcdir}/selftest/tests.py|" ' +
-                     '--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
-                     '--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
+    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|" ' +
+                         '--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
 
     if CONFIG_SET(opt, 'AD_DC_BUILD_IS_ENABLED'):
 
     if CONFIG_SET(opt, 'AD_DC_BUILD_IS_ENABLED'):
-        env.SELFTEST_TARGET="samba"
+        env.SELFTEST_TARGET = "samba"
     else:
     else:
-        env.SELFTEST_TARGET="samba3"
+        env.SELFTEST_TARGET = "samba3"
 
 
+    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')
 
     env.OPTIONS += " --uid_wrapper_so_path=" + CONFIG_GET(opt, 'LIBUID_WRAPPER_SO_PATH')
 
-    # We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
+    #if unversioned_sys_platform in ('freebsd', 'netbsd', 'openbsd', 'sunos'):
+    #    env.OPTIONS += " --use-dns-faking"
+
+    # 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}'
     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:
     if Options.options.LIST:
         cmd = '${CORE_COMMAND} --list'
     else:
@@ -211,19 +282,30 @@ def cmd_testonly(opt):
         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):
         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):
-            cmd += ' | tee ${SELFTEST_PREFIX}/subunit | ${FORMAT_TEST_OUTPUT}'
+            subunit_cache = os.path.join(env.SELFTEST_PREFIX, "subunit")
+            cmd += ' | tee %s | ${FORMAT_TEST_OUTPUT}' % subunit_cache
         else:
             cmd += ' | ${FILTER_OPTIONS}'
         else:
             cmd += ' | ${FILTER_OPTIONS}'
+
     runcmd = EXPAND_VARIABLES(opt, cmd)
 
     print("test: running %s" % runcmd)
     ret = RUN_COMMAND(cmd, env=env)
 
     runcmd = EXPAND_VARIABLES(opt, cmd)
 
     print("test: running %s" % runcmd)
     ret = RUN_COMMAND(cmd, env=env)
 
-    if os.path.exists(".testrepository") and not Options.options.LIST:
-        testrcmd = 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
+    if (os.path.exists(".testrepository") and
+        not Options.options.LIST and
+        not Options.options.LOAD_LIST and
+        subunit_cache is not None):
+        testrcmd = 'testr load -q < %s > /dev/null' % subunit_cache
         runcmd = EXPAND_VARIABLES(opt, testrcmd)
         RUN_COMMAND(runcmd, env=env)
 
         runcmd = EXPAND_VARIABLES(opt, testrcmd)
         RUN_COMMAND(runcmd, env=env)
 
+    if subunit_cache is not None:
+        nb = Options.options.NB_SLOWEST
+        cmd = "./script/show_testsuite_time %s %d" % (subunit_cache, nb)
+        runcmd = EXPAND_VARIABLES(opt, cmd)
+        RUN_COMMAND(runcmd, env=env)
+
     if ret != 0:
         print("ERROR: test failed with exit code %d" % ret)
         sys.exit(ret)
     if ret != 0:
         print("ERROR: test failed with exit code %d" % ret)
         sys.exit(ret)
@@ -241,8 +323,5 @@ def cmd_test(opt):
     # if running all tests, then force a symbol check
     env = LOAD_ENVIRONMENT()
     CHECK_MAKEFLAGS(env)
     # if running all tests, then force a symbol check
     env = LOAD_ENVIRONMENT()
     CHECK_MAKEFLAGS(env)
-    if not Options.options.TESTS and not Options.options.TESTENV:
-        Options.options.DUP_SYMBOLCHECK = True
-
     Scripting.commands.append('build')
     Scripting.commands.append('testonly')
     Scripting.commands.append('build')
     Scripting.commands.append('testonly')