2010-03-28 01:48:49 +03:00
#!/usr/bin/env python
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-17 07:22:36 +03:00
def set_options(opt):
opt.ADD_COMMAND('test', cmd_test)
opt.ADD_COMMAND('testonly', cmd_testonly)
gr = opt.add_option_group('test options')
2010-03-23 01:51:09 +03:00
gr.add_option('--with-selftest-prefix',
help=("specify location of selftest directory"),
action="store", dest='SELFTEST_PREFIX', default='./st')
2010-03-17 07:22:36 +03:00
gr.add_option('--tests',
help=("wildcard pattern of tests to run"),
action="store", dest='TESTS', default='')
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-03-17 12:12:16 +03:00
2010-03-17 12:38:03 +03:00
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-17 07:22:36 +03:00
env.TESTS = Options.options.TESTS
2010-03-29 14:11:33 +04:00
env.SUBUNIT_FORMATTER = '${PERL} ../selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
2010-03-17 07:22:36 +03:00
env.FILTER_XFAIL = '${PERL} ../selftest/filter-subunit.pl --expected-failures=./selftest/knownfail'
env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
2010-03-15 09:46:09 +03:00
env.OPTIONS = ''
2010-03-17 07:22:36 +03:00
if not Options.options.SLOWTEST:
env.OPTIONS += ' --exclude=./selftest/slow'
2010-03-15 09:46:09 +03:00
if Options.options.QUICKTEST:
2010-03-17 07:22:36 +03:00
env.OPTIONS += ' --quick --include=./selftest/quick'
if Options.options.TESTENV:
env.OPTIONS += ' --testenv'
if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
else:
env.FILTER_OPTIONS = '${FILTER_XFAIL} | ${FORMAT_TEST_OUTPUT}'
if Options.options.VALGRIND:
os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
if Options.options.VALGRINDLOG is not None:
os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
if Options.options.VALGRIND_SERVER:
os.environ['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/valgrind_run A=B '
2010-03-15 09:46:09 +03:00
2010-03-23 01:51:09 +03:00
env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
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-03-20 15:41:15 +03:00
2010-03-27 04:44:36 +03:00
# tell build system where to find config.h
os.environ['CONFIG_H'] = 'bin/default/source4/include/config.h'
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-03-29 16:46:38 +04:00
cmd = '(${PERL} ../selftest/selftest.pl --prefix=${SELFTEST_PREFIX} --builddir=. --srcdir=. --exclude=./selftest/skip --testlist="./selftest/tests.sh|" ${OPTIONS} --socket-wrapper ${TESTS} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
2010-03-30 04:54:23 +04:00
cmd = EXPAND_VARIABLES(opt, cmd)
2010-03-15 09:46:09 +03:00
print "test: running %s" % cmd
2010-03-19 06:25:50 +03:00
ret = RUN_COMMAND(cmd, env=env)
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')