3 import Scripting, os, Options, Utils, Environment, optparse, sys
4 from samba_utils import RUN_COMMAND, ADD_LD_LIBRARY_PATH
7 opt.ADD_COMMAND('test', cmd_test)
8 opt.ADD_COMMAND('testonly', cmd_testonly)
10 gr = opt.add_option_group('test options')
12 gr.add_option('--with-selftest-prefix',
13 help=("specify location of selftest directory"),
14 action="store", dest='SELFTEST_PREFIX', default='./st')
15 gr.add_option('--tests',
16 help=("wildcard pattern of tests to run"),
17 action="store", dest='TESTS', default='')
18 gr.add_option('--quick',
19 help=("enable only quick tests"),
20 action="store_true", dest='QUICKTEST', default=False)
21 gr.add_option('--slow',
22 help=("enable the really slow tests"),
23 action="store_true", dest='SLOWTEST', default=False)
24 gr.add_option('--testenv',
25 help=("start a terminal with the test environment setup"),
26 action="store_true", dest='TESTENV', default=False)
27 gr.add_option('--valgrind',
28 help=("use valgrind on client programs in the tests"),
29 action="store_true", dest='VALGRIND', default=False)
30 gr.add_option('--valgrind-log',
31 help=("where to put the valgrind log"),
32 action="store", dest='VALGRINDLOG', default=None)
33 gr.add_option('--valgrind-server',
34 help=("use valgrind on the server in the tests (opens an xterm)"),
35 action="store_true", dest='VALGRIND_SERVER', default=False)
38 def cmd_testonly(opt):
39 '''run tests without doing a build first'''
40 env = Environment.Environment()
42 env.TESTS = Options.options.TESTS
46 env.TEST_FORMAT = 'plain'
47 env.SUBUNIT_FORMATTER = '${PERL} ../selftest/format-subunit.pl --prefix=${SELFTEST_PREFIX} --format=${TEST_FORMAT} --immediate'
48 env.FILTER_XFAIL = '${PERL} ../selftest/filter-subunit.pl --expected-failures=./selftest/knownfail'
49 env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
52 if not Options.options.SLOWTEST:
53 env.OPTIONS += ' --exclude=./selftest/slow'
54 if Options.options.QUICKTEST:
55 env.OPTIONS += ' --quick --include=./selftest/quick'
57 if Options.options.TESTENV:
58 env.OPTIONS += ' --testenv'
60 if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
61 env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
63 env.FILTER_OPTIONS = '${FILTER_XFAIL} | ${FORMAT_TEST_OUTPUT}'
65 if Options.options.VALGRIND:
66 os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
67 if Options.options.VALGRINDLOG is not None:
68 os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
70 if Options.options.VALGRIND_SERVER:
71 os.environ['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/valgrind_run A=B '
73 env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
75 # this is needed for systems without rpath, or with rpath disabled
76 ADD_LD_LIBRARY_PATH('bin/shared')
78 # tell build system where to find config.h
79 os.environ['CONFIG_H'] = 'bin/default/source4/include/config.h'
81 st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
82 if os.path.exists(st_done):
85 cmd = '(perl -W ../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}'
87 print "test: running %s" % cmd
88 ret = RUN_COMMAND(cmd, env=env)
90 print("ERROR: test failed with exit code %d" % ret)
93 if not os.path.exists(st_done):
94 print("ERROR: test command failed to complete")
98 ########################################################################
99 # main test entry point
101 '''Run the test suite (see test options below)'''
102 Scripting.commands.append('build')
103 Scripting.commands.append('testonly')