s4/scripting: in MIT build do not install samba-tool, it is not usable yet
[Samba/vl.git] / selftest / wscript
blob182f8f9a1674c3e75643a0d515202c5f105b4e01
1 #!/usr/bin/env python
2 # vim: expandtab ft=python
4 # selftest main code.
6 import Scripting, os, Options, Utils, Environment, optparse, sys
7 from samba_utils import *
8 from samba_autoconf import *
10 def set_options(opt):
12 opt.add_option('--enable-selftest',
13 help=("enable options necessary for selftest (default=no)"),
14 action="store_true", dest='enable_selftest', default=False)
15 opt.add_option('--enable-coverage',
16 help=("enable options necessary for code coverage reporting on selftest (default=no)"),
17 action="store_true", dest='enable_coverage', default=False)
18 opt.add_option('--with-selftest-prefix',
19 help=("specify location of selftest directory (default=./st)"),
20 action="store", dest='SELFTEST_PREFIX', default='./st')
22 opt.ADD_COMMAND('test', cmd_test)
23 opt.ADD_COMMAND('testonly', cmd_testonly)
25 gr = opt.add_option_group('test options')
27 gr.add_option('--load-list',
28 help=("Load a test id list from a text file"),
29 action="store", dest='LOAD_LIST', default=None)
30 gr.add_option('--list',
31 help=("List available tests"),
32 action="store_true", dest='LIST', default=False)
33 gr.add_option('--tests',
34 help=("wildcard pattern of tests to run"),
35 action="store", dest='TESTS', default='')
36 gr.add_option('--filtered-subunit',
37 help=("output (xfail) filtered subunit"),
38 action="store_true", dest='FILTERED_SUBUNIT', default=False)
39 gr.add_option('--quick',
40 help=("enable only quick tests"),
41 action="store_true", dest='QUICKTEST', default=False)
42 gr.add_option('--slow',
43 help=("enable the really slow tests"),
44 action="store_true", dest='SLOWTEST', default=False)
45 gr.add_option('--testenv',
46 help=("start a terminal with the test environment setup"),
47 action="store_true", dest='TESTENV', default=False)
48 gr.add_option('--valgrind',
49 help=("use valgrind on client programs in the tests"),
50 action="store_true", dest='VALGRIND', default=False)
51 gr.add_option('--valgrind-log',
52 help=("where to put the valgrind log"),
53 action="store", dest='VALGRINDLOG', default=None)
54 gr.add_option('--valgrind-server',
55 help=("use valgrind on the server in the tests (opens an xterm)"),
56 action="store_true", dest='VALGRIND_SERVER', default=False)
57 gr.add_option('--screen',
58 help=("run the samba servers in screen sessions"),
59 action="store_true", dest='SCREEN', default=False)
60 gr.add_option('--gdbtest',
61 help=("run the servers within a gdb window"),
62 action="store_true", dest='GDBTEST', default=False)
63 gr.add_option('--fail-immediately',
64 help=("stop tests on first failure"),
65 action="store_true", dest='FAIL_IMMEDIATELY', default=False)
66 gr.add_option('--socket-wrapper-pcap',
67 help=("create a pcap file for each failing test"),
68 action="store_true", dest='SOCKET_WRAPPER_PCAP', default=False)
69 gr.add_option('--socket-wrapper-keep-pcap',
70 help=("create a pcap file for all individual test"),
71 action="store_true", dest='SOCKET_WRAPPER_KEEP_PCAP', default=False)
73 def configure(conf):
74 conf.env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
75 conf.env.enable_coverage = Options.options.enable_coverage
76 if conf.env.enable_coverage:
77 conf.ADD_LDFLAGS('-lgcov', testflags=True)
78 conf.ADD_CFLAGS('--coverage')
80 def cmd_testonly(opt):
81 '''run tests without doing a build first'''
82 env = LOAD_ENVIRONMENT()
83 opt.env = env
85 if (not CONFIG_SET(opt, 'NSS_WRAPPER') or
86 not CONFIG_SET(opt, 'UID_WRAPPER') or
87 not CONFIG_SET(opt, 'SOCKET_WRAPPER')):
88 print("ERROR: You must use --enable-selftest to enable selftest")
89 sys.exit(1)
91 os.environ['SAMBA_SELFTEST'] = '1'
93 env.TESTS = Options.options.TESTS
95 env.SUBUNIT_FORMATTER = os.getenv('SUBUNIT_FORMATTER')
96 if not env.SUBUNIT_FORMATTER:
97 env.SUBUNIT_FORMATTER = '${PYTHON} -u ${srcdir}/selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
98 env.FILTER_XFAIL = '${PYTHON} -u ${srcdir}/selftest/filter-subunit --expected-failures=${srcdir}/selftest/knownfail --flapping=${srcdir}/selftest/flapping'
100 if Options.options.FAIL_IMMEDIATELY:
101 env.FILTER_XFAIL += ' --fail-immediately'
103 env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
105 # clean any previous temporary files
106 os.system("rm -rf %s/tmp" % env.SELFTEST_PREFIX);
108 # put all command line options in the environment as TESTENV_*=*
109 for o in dir(Options.options):
110 if o[0:1] != '_':
111 os.environ['TESTENV_%s' % o.upper()] = str(getattr(Options.options, o, ''))
113 binary_mapping = ('nmblookup3:nmblookup3,' +
114 'smbclient3:smbclient3,' +
115 'smbtorture4:smbtorture,' +
116 'ntlm_auth3:ntlm_auth3')
118 env.OPTIONS = '--binary-mapping=%s' % binary_mapping
119 if not Options.options.SLOWTEST:
120 env.OPTIONS += ' --exclude=${srcdir}/selftest/slow'
121 if Options.options.QUICKTEST:
122 env.OPTIONS += ' --quick --include=${srcdir}/selftest/quick'
123 if Options.options.LOAD_LIST:
124 env.OPTIONS += ' --load-list=%s' % Options.options.LOAD_LIST
125 if Options.options.TESTENV:
126 env.OPTIONS += ' --testenv'
127 if Options.options.SOCKET_WRAPPER_PCAP:
128 env.OPTIONS += ' --socket-wrapper-pcap'
129 if Options.options.SOCKET_WRAPPER_KEEP_PCAP:
130 env.OPTIONS += ' --socket-wrapper-keep-pcap'
131 if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
132 env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
133 else:
134 env.FILTER_OPTIONS = '${FILTER_XFAIL}'
136 if Options.options.VALGRIND:
137 os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
138 if Options.options.VALGRINDLOG is not None:
139 os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
141 server_wrapper=''
143 if Options.options.VALGRIND_SERVER:
144 server_wrapper = '${srcdir}/selftest/valgrind_run _DUMMY=X'
145 elif Options.options.GDBTEST:
146 server_wrapper = '${srcdir}/selftest/gdb_run _DUMMY=X'
148 if Options.options.SCREEN:
149 server_wrapper = '${srcdir}/selftest/in_screen %s' % server_wrapper
150 os.environ['TERMINAL'] = EXPAND_VARIABLES(opt, '${srcdir}/selftest/in_screen')
151 elif server_wrapper != '':
152 server_wrapper = 'xterm -n server -l -e %s' % server_wrapper
154 if server_wrapper != '':
155 os.environ['SAMBA_VALGRIND'] = EXPAND_VARIABLES(opt, server_wrapper)
157 # this is needed for systems without rpath, or with rpath disabled
158 ADD_LD_LIBRARY_PATH('bin/shared')
159 ADD_LD_LIBRARY_PATH('bin/shared/private')
161 # if we are using a system version of ldb then we need to tell it to
162 # load modules from our modules path
163 if env.USING_SYSTEM_LDB:
164 os.environ['LDB_MODULES_PATH'] = 'bin/modules/ldb'
166 if env.BUILD_TDB2:
167 os.environ['BUILD_TDB2'] = '1'
169 # tell build system where to find config.h
170 os.environ['VFSLIBDIR'] = os.path.abspath('bin/modules/vfs')
171 os.environ['CONFIG_H'] = 'bin/default/include/config.h'
173 st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
174 if os.path.exists(st_done):
175 os.unlink(st_done)
177 if not os.path.isdir(env.SELFTEST_PREFIX):
178 os.makedirs(env.SELFTEST_PREFIX, int('755', 8))
180 env.TESTLISTS = ('--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
181 '--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
183 if CONFIG_SET(opt, 'AD_DC_BUILD_IS_ENABLED'):
184 env.SELFTEST_TARGET="samba"
185 else:
186 env.SELFTEST_TARGET="samba3"
188 # We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
189 env.CORE_COMMAND = '${PERL} ${srcdir}/selftest/selftest.pl --target=${SELFTEST_TARGET} --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${srcdir}/selftest/skip ${TESTLISTS} ${OPTIONS} ${TESTS}'
190 if Options.options.LIST:
191 cmd = '${CORE_COMMAND} --list'
192 else:
193 env.OPTIONS += ' --socket-wrapper'
194 cmd = '(${CORE_COMMAND} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
195 if (os.environ.get('RUN_FROM_BUILD_FARM') is None and
196 not Options.options.FILTERED_SUBUNIT):
197 cmd += ' | tee ${SELFTEST_PREFIX}/subunit | ${FORMAT_TEST_OUTPUT}'
198 else:
199 cmd += ' | ${FILTER_OPTIONS}'
200 runcmd = EXPAND_VARIABLES(opt, cmd)
202 print("test: running %s" % runcmd)
203 ret = RUN_COMMAND(cmd, env=env)
205 if os.path.exists(".testrepository") and not Options.options.LIST:
206 testrcmd = 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
207 runcmd = EXPAND_VARIABLES(opt, testrcmd)
208 RUN_COMMAND(runcmd, env=env)
210 if ret != 0:
211 print("ERROR: test failed with exit code %d" % ret)
212 sys.exit(ret)
214 if not Options.options.LIST and not os.path.exists(st_done):
215 print("ERROR: test command failed to complete")
216 sys.exit(1)
219 ########################################################################
220 # main test entry point
221 def cmd_test(opt):
222 '''Run the test suite (see test options below)'''
224 # if running all tests, then force a symbol check
225 env = LOAD_ENVIRONMENT()
226 CHECK_MAKEFLAGS(env)
227 if not Options.options.TESTS and not Options.options.TESTENV:
228 Options.options.DUP_SYMBOLCHECK = True
230 Scripting.commands.append('build')
231 Scripting.commands.append('testonly')