3 import Scripting, os, Options, Utils, Environment, optparse, sys
4 from samba_utils import RUN_COMMAND
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('--tests',
13 help=("wildcard pattern of tests to run"),
14 action="store", dest='TESTS', default='')
15 gr.add_option('--quick',
16 help=("enable only quick tests"),
17 action="store_true", dest='QUICKTEST', default=False)
18 gr.add_option('--slow',
19 help=("enable the really slow tests"),
20 action="store_true", dest='SLOWTEST', default=False)
21 gr.add_option('--testenv',
22 help=("start a terminal with the test environment setup"),
23 action="store_true", dest='TESTENV', default=False)
24 gr.add_option('--valgrind',
25 help=("use valgrind on client programs in the tests"),
26 action="store_true", dest='VALGRIND', default=False)
27 gr.add_option('--valgrind-log',
28 help=("where to put the valgrind log"),
29 action="store", dest='VALGRINDLOG', default=None)
30 gr.add_option('--valgrind-server',
31 help=("use valgrind on the server in the tests (opens an xterm)"),
32 action="store_true", dest='VALGRIND_SERVER', default=False)
35 def cmd_testonly(opt):
36 '''run tests without doing a build first'''
37 env = Environment.Environment()
39 env.TESTS = Options.options.TESTS
43 env.TEST_FORMAT = 'plain'
44 env.SUBUNIT_FORMATTER = '${PERL} ../selftest/format-subunit.pl --prefix=./st --format=${TEST_FORMAT} --immediate'
45 env.FILTER_XFAIL = '${PERL} ../selftest/filter-subunit.pl --expected-failures=./selftest/knownfail'
46 env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
49 if not Options.options.SLOWTEST:
50 env.OPTIONS += ' --exclude=./selftest/slow'
51 if Options.options.QUICKTEST:
52 env.OPTIONS += ' --quick --include=./selftest/quick'
54 if Options.options.TESTENV:
55 env.OPTIONS += ' --testenv'
57 if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
58 env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
60 env.FILTER_OPTIONS = '${FILTER_XFAIL} | ${FORMAT_TEST_OUTPUT}'
62 if Options.options.VALGRIND:
63 os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
64 if Options.options.VALGRINDLOG is not None:
65 os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
67 if Options.options.VALGRIND_SERVER:
68 os.environ['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/valgrind_run A=B '
70 st_done = 'st/st_done'
71 if os.path.exists(st_done):
74 cmd = '(PYTHON=/usr/bin/python perl -W ../selftest/selftest.pl --prefix=./st --builddir=. --srcdir=. --exclude=./selftest/skip --testlist="./selftest/tests.sh|" ${OPTIONS} --socket-wrapper ${TESTS} && touch st/st_done) | tee st/test.out | ${FILTER_OPTIONS}'
76 print "test: running %s" % cmd
77 ret = RUN_COMMAND(cmd, env=env)
79 print("ERROR: test failed with exit code %d" % ret)
82 if not os.path.exists(st_done):
83 print("ERROR: test command failed to complete")
87 ########################################################################
88 # main test entry point
90 '''Run the test suite (see test options below)'''
91 Scripting.commands.append('build')
92 Scripting.commands.append('testonly')