5 import Scripting, os, Options, Utils, Environment, optparse, sys
6 from samba_utils import *
7 from samba_autoconf import *
10 opt.ADD_COMMAND('test', cmd_test)
11 opt.ADD_COMMAND('testonly', cmd_testonly)
13 gr = opt.add_option_group('test options')
15 gr.add_option('--enable-selftest',
16 help=("enable options necessary for selftest"),
17 action="store_true", dest='enable_selftest', default=False)
18 gr.add_option('--load-list',
19 help=("Load a test id list from a text file"),
20 action="store", dest='LOAD_LIST', default=None)
21 gr.add_option('--with-selftest-prefix',
22 help=("specify location of selftest directory"),
23 action="store", dest='SELFTEST_PREFIX', default='./st')
24 gr.add_option('--tests',
25 help=("wildcard pattern of tests to run"),
26 action="store", dest='TESTS', default='')
27 gr.add_option('--filtered-subunit',
28 help=("output (xfail) filtered subunit"),
29 action="store_true", dest='FILTERED_SUBUNIT', default=False)
30 gr.add_option('--quick',
31 help=("enable only quick tests"),
32 action="store_true", dest='QUICKTEST', default=False)
33 gr.add_option('--slow',
34 help=("enable the really slow tests"),
35 action="store_true", dest='SLOWTEST', default=False)
36 gr.add_option('--testenv',
37 help=("start a terminal with the test environment setup"),
38 action="store_true", dest='TESTENV', default=False)
39 gr.add_option('--valgrind',
40 help=("use valgrind on client programs in the tests"),
41 action="store_true", dest='VALGRIND', default=False)
42 gr.add_option('--valgrind-log',
43 help=("where to put the valgrind log"),
44 action="store", dest='VALGRINDLOG', default=None)
45 gr.add_option('--valgrind-server',
46 help=("use valgrind on the server in the tests (opens an xterm)"),
47 action="store_true", dest='VALGRIND_SERVER', default=False)
48 gr.add_option('--gdbtest',
49 help=("run the testsuite within a gdb xterm window"),
50 action="store_true", dest='GDBTEST', default=False)
53 def cmd_testonly(opt):
54 '''run tests without doing a build first'''
55 env = LOAD_ENVIRONMENT()
58 if (not CONFIG_SET(opt, 'NSS_WRAPPER') or
59 not CONFIG_SET(opt, 'UID_WRAPPER') or
60 not CONFIG_SET(opt, 'SOCKET_WRAPPER')):
61 print("ERROR: You must use --enable-selftest to enable selftest")
64 env.TESTS = Options.options.TESTS
66 env.SUBUNIT_FORMATTER = '${PYTHON} -u ../selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
67 env.FILTER_XFAIL = '${PYTHON} -u ../selftest/filter-subunit --expected-failures=./selftest/knownfail'
68 env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
71 if not Options.options.SLOWTEST:
72 env.OPTIONS += ' --exclude=./selftest/slow'
73 if Options.options.QUICKTEST:
74 env.OPTIONS += ' --quick --include=./selftest/quick'
75 if Options.options.LOAD_LIST:
76 env.OPTIONS += ' --load-list=%s' % Options.options.LOAD_LIST
77 if Options.options.TESTENV:
78 env.OPTIONS += ' --testenv'
80 if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
81 env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
83 env.FILTER_OPTIONS = '${FILTER_XFAIL}'
84 if not Options.options.FILTERED_SUBUNIT:
85 env.FILTER_OPTIONS += ' | ${FORMAT_TEST_OUTPUT}'
87 if Options.options.VALGRIND:
88 os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
89 if Options.options.VALGRINDLOG is not None:
90 os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
92 if Options.options.VALGRIND_SERVER:
93 os.environ['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/valgrind_run DUMMY=X'
95 if Options.options.GDBTEST:
96 os.environ['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/gdb_run DUMMY=X'
98 env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
100 # this is needed for systems without rpath, or with rpath disabled
101 ADD_LD_LIBRARY_PATH('bin/shared')
103 # tell build system where to find config.h
104 os.environ['CONFIG_H'] = 'bin/default/source4/include/config.h'
106 st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
107 if os.path.exists(st_done):
110 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}'
111 cmd = EXPAND_VARIABLES(opt, cmd)
113 print("test: running %s" % cmd)
114 ret = RUN_COMMAND(cmd, env=env)
116 print("ERROR: test failed with exit code %d" % ret)
119 if not os.path.exists(st_done):
120 print("ERROR: test command failed to complete")
124 ########################################################################
125 # main test entry point
127 '''Run the test suite (see test options below)'''
128 Scripting.commands.append('build')
129 Scripting.commands.append('testonly')