2010-03-28 01:48:49 +03:00
#!/usr/bin/env python
2010-06-25 03:21:14 +04:00
# vim: expandtab ft=python
2010-03-28 01:48:49 +03:00
2010-03-17 12:38:03 +03:00
# selftest main code.
2010-03-17 07:22:36 +03:00
import Scripting, os, Options, Utils, Environment, optparse, sys
2010-03-30 04:37:07 +04:00
from samba_utils import *
2010-03-30 06:05:15 +04:00
from samba_autoconf import *
2010-03-17 07:22:36 +03:00
def set_options(opt):
2010-04-15 10:28:20 +04:00
opt.add_option('--enable-selftest',
help=("enable options necessary for selftest (default=no)"),
action="store_true", dest='enable_selftest', default=False)
opt.add_option('--with-selftest-prefix',
help=("specify location of selftest directory (default=./st)"),
action="store", dest='SELFTEST_PREFIX', default='./st')
2010-03-17 07:22:36 +03:00
opt.ADD_COMMAND('test', cmd_test)
opt.ADD_COMMAND('testonly', cmd_testonly)
gr = opt.add_option_group('test options')
2010-04-08 17:24:33 +04:00
gr.add_option('--load-list',
help=("Load a test id list from a text file"),
action="store", dest='LOAD_LIST', default=None)
2010-12-09 16:46:09 +03:00
gr.add_option('--list',
help=("List available tests"),
action="store_true", dest='LIST', default=False)
2010-03-17 07:22:36 +03:00
gr.add_option('--tests',
help=("wildcard pattern of tests to run"),
action="store", dest='TESTS', default='')
2011-04-16 02:47:50 +04:00
gr.add_option('--target',
help=("target of samba3 or samba4"),
action="store", dest='TARGET', default=None)
2010-04-08 18:48:33 +04:00
gr.add_option('--filtered-subunit',
help=("output (xfail) filtered subunit"),
action="store_true", dest='FILTERED_SUBUNIT', default=False)
2010-03-17 07:22:36 +03:00
gr.add_option('--quick',
help=("enable only quick tests"),
action="store_true", dest='QUICKTEST', default=False)
gr.add_option('--slow',
help=("enable the really slow tests"),
action="store_true", dest='SLOWTEST', default=False)
gr.add_option('--testenv',
help=("start a terminal with the test environment setup"),
action="store_true", dest='TESTENV', default=False)
gr.add_option('--valgrind',
help=("use valgrind on client programs in the tests"),
action="store_true", dest='VALGRIND', default=False)
gr.add_option('--valgrind-log',
help=("where to put the valgrind log"),
action="store", dest='VALGRINDLOG', default=None)
gr.add_option('--valgrind-server',
help=("use valgrind on the server in the tests (opens an xterm)"),
action="store_true", dest='VALGRIND_SERVER', default=False)
2010-10-02 23:43:50 +04:00
gr.add_option('--screen',
help=("run the samba servers in screen sessions"),
action="store_true", dest='SCREEN', default=False)
2010-04-09 14:44:09 +04:00
gr.add_option('--gdbtest',
2010-10-02 23:43:50 +04:00
help=("run the servers within a gdb window"),
2010-04-09 14:44:09 +04:00
action="store_true", dest='GDBTEST', default=False)
2010-09-27 05:58:05 +04:00
gr.add_option('--fail-immediately',
help=("stop tests on first failure"),
action="store_true", dest='FAIL_IMMEDIATELY', default=False)
2010-05-08 15:55:25 +04:00
gr.add_option('--socket-wrapper-pcap',
help=("create a pcap file for each failing test"),
action="store_true", dest='SOCKET_WRAPPER_PCAP', default=False)
gr.add_option('--socket-wrapper-keep-pcap',
help=("create a pcap file for all individual test"),
action="store_true", dest='SOCKET_WRAPPER_KEEP_PCAP', default=False)
2010-03-17 12:12:16 +03:00
2010-04-15 10:28:20 +04:00
def configure(conf):
conf.env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
2010-03-17 12:38:03 +03:00
2011-04-28 07:58:07 +04:00
def combine_files(file1, file2, outfile):
f1 = open(file1)
f2 = open(file2)
of = open(outfile, mode='w')
for line in f1:
of.write(line)
for line in f2:
of.write(line)
f1.close()
f2.close()
of.close()
2010-03-15 10:03:55 +03:00
def cmd_testonly(opt):
2010-03-17 07:22:36 +03:00
'''run tests without doing a build first'''
2010-03-30 04:37:07 +04:00
env = LOAD_ENVIRONMENT()
2010-03-30 04:54:23 +04:00
opt.env = env
2010-03-15 09:46:09 +03:00
2010-03-30 06:05:15 +04:00
if (not CONFIG_SET(opt, 'NSS_WRAPPER') or
not CONFIG_SET(opt, 'UID_WRAPPER') or
not CONFIG_SET(opt, 'SOCKET_WRAPPER')):
2010-04-08 01:45:46 +04:00
print("ERROR: You must use --enable-selftest to enable selftest")
2010-03-30 06:05:15 +04:00
sys.exit(1)
2010-10-03 01:21:52 +04:00
os.environ['SAMBA_SELFTEST'] = '1'
2010-03-17 07:22:36 +03:00
env.TESTS = Options.options.TESTS
2011-03-04 16:22:35 +03:00
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'
2011-04-16 02:47:50 +04:00
env.FILTER_XFAIL = '${PYTHON} -u ${srcdir}/selftest/filter-subunit --expected-failures=${SELFTEST_DIR}/knownfail'
2010-09-27 05:58:05 +04:00
if Options.options.FAIL_IMMEDIATELY:
env.FILTER_XFAIL += ' --fail-immediately'
2010-03-17 07:22:36 +03:00
env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
2010-03-15 09:46:09 +03:00
2010-10-03 01:23:43 +04:00
# clean any previous temporary files
os.system("rm -rf %s/tmp" % env.SELFTEST_PREFIX);
2010-10-02 23:43:50 +04:00
# put all command line options in the environment as TESTENV_*=*
for o in dir(Options.options):
if o[0:1] != '_':
os.environ['TESTENV_%s' % o.upper()] = str(getattr(Options.options, o, ''))
2011-04-16 02:47:50 +04:00
binary_mapping = ('nmblookup3:nmblookup3,' +
'smbclient3:smbclient3,' +
'smbtorture4:smbtorture,' +
'ntlm_auth3:ntlm_auth3')
env.OPTIONS = '--binary-mapping=%s' % binary_mapping
2010-03-17 07:22:36 +03:00
if not Options.options.SLOWTEST:
2011-04-16 02:47:50 +04:00
env.OPTIONS += ' --exclude=${SELFTEST_DIR}/slow'
2010-03-15 09:46:09 +03:00
if Options.options.QUICKTEST:
2011-04-16 02:47:50 +04:00
env.OPTIONS += ' --quick --include=${SELFTEST_DIR}/quick'
2010-04-08 17:24:33 +04:00
if Options.options.LOAD_LIST:
env.OPTIONS += ' --load-list=%s' % Options.options.LOAD_LIST
2010-03-17 07:22:36 +03:00
if Options.options.TESTENV:
env.OPTIONS += ' --testenv'
2010-05-08 15:55:25 +04:00
if Options.options.SOCKET_WRAPPER_PCAP:
env.OPTIONS += ' --socket-wrapper-pcap'
if Options.options.SOCKET_WRAPPER_KEEP_PCAP:
env.OPTIONS += ' --socket-wrapper-keep-pcap'
2010-12-09 16:46:09 +03:00
if Options.options.LIST:
env.OPTIONS += ' --list'
2010-03-17 07:22:36 +03:00
if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
else:
2010-04-08 18:48:33 +04:00
env.FILTER_OPTIONS = '${FILTER_XFAIL}'
2010-03-17 07:22:36 +03:00
if Options.options.VALGRIND:
2010-04-08 01:45:46 +04:00
os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
2010-03-17 07:22:36 +03:00
if Options.options.VALGRINDLOG is not None:
os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
2010-10-02 23:43:50 +04:00
server_wrapper=''
2010-03-17 07:22:36 +03:00
if Options.options.VALGRIND_SERVER:
2011-02-03 07:14:31 +03:00
server_wrapper = '${srcdir}/selftest/valgrind_run _DUMMY=X'
2010-10-02 23:43:50 +04:00
elif Options.options.GDBTEST:
2011-02-03 07:14:31 +03:00
server_wrapper = '${srcdir}/selftest/gdb_run _DUMMY=X'
2010-10-02 23:43:50 +04:00
if Options.options.SCREEN:
2011-02-08 12:38:05 +03:00
server_wrapper = '${srcdir}/selftest/in_screen %s' % server_wrapper
2011-02-10 08:49:10 +03:00
os.environ['TERMINAL'] = EXPAND_VARIABLES(opt, '${srcdir}/selftest/in_screen')
2010-10-02 23:43:50 +04:00
elif server_wrapper != '':
server_wrapper = 'xterm -n server -l -e %s' % server_wrapper
2010-04-09 14:44:09 +04:00
2010-10-02 23:43:50 +04:00
if server_wrapper != '':
2011-02-08 12:38:05 +03:00
os.environ['SAMBA_VALGRIND'] = EXPAND_VARIABLES(opt, server_wrapper)
2010-03-15 09:46:09 +03:00
2010-03-20 15:41:15 +03:00
# this is needed for systems without rpath, or with rpath disabled
2010-03-25 06:20:45 +03:00
ADD_LD_LIBRARY_PATH('bin/shared')
2010-11-05 04:30:01 +03:00
ADD_LD_LIBRARY_PATH('bin/shared/private')
2010-03-20 15:41:15 +03:00
2010-11-03 06:26:04 +03:00
# 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'] = 'bin/modules/ldb'
2011-06-20 13:10:33 +04:00
if env.BUILD_TDB2:
os.environ['BUILD_TDB2'] = '1'
2010-03-27 04:44:36 +03:00
# tell build system where to find config.h
2011-04-16 02:47:50 +04:00
os.environ['VFSLIBDIR'] = os.path.abspath('bin/modules/vfs')
os.environ['CONFIG_H'] = 'bin/default/include/config.h'
2010-03-27 04:44:36 +03:00
2010-03-23 01:51:09 +03:00
st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
2010-03-17 07:22:36 +03:00
if os.path.exists(st_done):
os.unlink(st_done)
2010-11-09 02:22:48 +03:00
if not os.path.isdir(env.SELFTEST_PREFIX):
os.makedirs(env.SELFTEST_PREFIX, int('755', 8))
2011-04-16 02:47:50 +04:00
if Options.options.TARGET:
env.SELFTEST_TARGET = Options.options.TARGET
else:
2011-05-09 13:00:18 +04:00
env.SELFTEST_TARGET = "samba"
2011-04-16 02:47:50 +04:00
if env.SELFTEST_TARGET == "samba4":
env.SELFTEST_DIR = "${srcdir}/source4/selftest"
elif env.SELFTEST_TARGET == "samba3":
env.SELFTEST_DIR = "${srcdir}/source3/selftest"
2011-04-18 12:59:00 +04:00
if env.SELFTEST_TARGET == "samba":
2011-04-28 07:58:07 +04:00
for f in ["knownfail", "slow", "quick", "skip" ]:
combine_files(env.srcdir + "/source4/selftest/" + f,
env.srcdir + "/source3/selftest/" + f,
env.SELFTEST_PREFIX + "/" + f)
2011-04-29 23:12:53 +04:00
env.SELFTEST_DIR = env.SELFTEST_PREFIX
2011-04-28 07:58:07 +04:00
env.TESTLISTS = ('--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
'--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
2011-04-18 12:59:00 +04:00
else:
2011-04-28 07:58:07 +04:00
env.TESTLISTS = '--testlist="${SELFTEST_DIR}/tests.py|"'
# We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
cmd = '(${PERL} ${srcdir}/selftest/selftest.pl --target=${SELFTEST_TARGET} --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${SELFTEST_DIR}/skip ${TESTLISTS} ${OPTIONS} --socket-wrapper ${TESTS} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS} | tee ${SELFTEST_PREFIX}/subunit'
2011-04-18 12:59:00 +04:00
2010-06-25 03:21:14 +04:00
if os.environ.get('RUN_FROM_BUILD_FARM') is None and not Options.options.FILTERED_SUBUNIT:
cmd += ' | ${FORMAT_TEST_OUTPUT}'
2010-11-22 01:09:49 +03:00
else:
2011-02-03 07:14:31 +03:00
cmd += ' | ${PYTHON} -u ${srcdir}/selftest/filter-subunit'
2011-04-16 02:47:50 +04:00
runcmd = EXPAND_VARIABLES(opt, cmd)
2010-03-15 09:46:09 +03:00
2011-04-16 02:47:50 +04:00
print("test: running %s" % runcmd)
2010-03-19 06:25:50 +03:00
ret = RUN_COMMAND(cmd, env=env)
2010-06-25 03:21:14 +04:00
if os.path.exists(".testrepository"):
# "testr load -q" isn't
2011-04-16 02:47:50 +04:00
testrcmd = 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
runcmd = EXPAND_VARIABLES(opt, testrcmd)
RUN_COMMAND(runcmd, env=env)
2010-06-25 03:21:14 +04:00
2010-03-17 07:22:36 +03:00
if ret != 0:
2010-03-19 02:37:01 +03:00
print("ERROR: test failed with exit code %d" % ret)
2010-03-17 07:22:36 +03:00
sys.exit(ret)
if not os.path.exists(st_done):
2010-03-19 02:37:01 +03:00
print("ERROR: test command failed to complete")
2010-03-17 07:22:36 +03:00
sys.exit(1)
2010-03-17 12:38:03 +03:00
2010-03-15 10:03:55 +03:00
########################################################################
# main test entry point
def cmd_test(opt):
2010-03-17 07:22:36 +03:00
'''Run the test suite (see test options below)'''
2010-03-15 10:03:55 +03:00
Scripting.commands.append('build')
Scripting.commands.append('testonly')