s3:smb2_notify: make use of file_fsp_smb2()
[Samba/vl.git] / selftest / wscript
blobea37a62cc84be4ca09fe5f7157411392c6332d8c
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:nmblookup,' +
114 'nmblookup4:nmblookup4,' +
115 'smbclient3:smbclient,' +
116 'smbclient4:smbclient4,' +
117 'smbtorture4:smbtorture,' +
118 'ntlm_auth3:ntlm_auth3')
120 env.OPTIONS = '--binary-mapping=%s' % binary_mapping
121 if not Options.options.SLOWTEST:
122 env.OPTIONS += ' --exclude=${srcdir}/selftest/slow'
123 if Options.options.QUICKTEST:
124 env.OPTIONS += ' --quick --include=${srcdir}/selftest/quick'
125 if Options.options.LOAD_LIST:
126 env.OPTIONS += ' --load-list=%s' % Options.options.LOAD_LIST
127 if Options.options.TESTENV:
128 env.OPTIONS += ' --testenv'
129 if Options.options.SOCKET_WRAPPER_PCAP:
130 env.OPTIONS += ' --socket-wrapper-pcap'
131 if Options.options.SOCKET_WRAPPER_KEEP_PCAP:
132 env.OPTIONS += ' --socket-wrapper-keep-pcap'
133 if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
134 env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
135 else:
136 env.FILTER_OPTIONS = '${FILTER_XFAIL}'
138 if Options.options.VALGRIND:
139 os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
140 if Options.options.VALGRINDLOG is not None:
141 os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
143 server_wrapper=''
145 if Options.options.VALGRIND_SERVER:
146 server_wrapper = '${srcdir}/selftest/valgrind_run _DUMMY=X'
147 elif Options.options.GDBTEST:
148 server_wrapper = '${srcdir}/selftest/gdb_run _DUMMY=X'
150 if Options.options.SCREEN:
151 server_wrapper = '${srcdir}/selftest/in_screen %s' % server_wrapper
152 os.environ['TERMINAL'] = EXPAND_VARIABLES(opt, '${srcdir}/selftest/in_screen')
153 elif server_wrapper != '':
154 server_wrapper = 'xterm -n server -l -e %s' % server_wrapper
156 if server_wrapper != '':
157 os.environ['SAMBA_VALGRIND'] = EXPAND_VARIABLES(opt, server_wrapper)
159 # this is needed for systems without rpath, or with rpath disabled
160 ADD_LD_LIBRARY_PATH('bin/shared')
161 ADD_LD_LIBRARY_PATH('bin/shared/private')
163 # if we are using a system version of ldb then we need to tell it to
164 # load modules from our modules path
165 if env.USING_SYSTEM_LDB:
166 os.environ['LDB_MODULES_PATH'] = 'bin/modules/ldb'
168 if env.BUILD_TDB2:
169 os.environ['BUILD_TDB2'] = '1'
171 # tell build system where to find config.h
172 os.environ['VFSLIBDIR'] = os.path.abspath('bin/modules/vfs')
173 os.environ['CONFIG_H'] = 'bin/default/include/config.h'
175 st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
176 if os.path.exists(st_done):
177 os.unlink(st_done)
179 if not os.path.isdir(env.SELFTEST_PREFIX):
180 os.makedirs(env.SELFTEST_PREFIX, int('755', 8))
182 env.TESTLISTS = ('--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
183 '--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
185 if CONFIG_SET(opt, 'AD_DC_BUILD_IS_ENABLED'):
186 env.SELFTEST_TARGET="samba"
187 else:
188 env.SELFTEST_TARGET="samba3"
190 # We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
191 env.CORE_COMMAND = '${PERL} ${srcdir}/selftest/selftest.pl --target=${SELFTEST_TARGET} --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${srcdir}/selftest/skip ${TESTLISTS} ${OPTIONS} ${TESTS}'
192 if Options.options.LIST:
193 cmd = '${CORE_COMMAND} --list'
194 else:
195 env.OPTIONS += ' --socket-wrapper'
196 cmd = '(${CORE_COMMAND} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
197 if (os.environ.get('RUN_FROM_BUILD_FARM') is None and
198 not Options.options.FILTERED_SUBUNIT):
199 cmd += ' | tee ${SELFTEST_PREFIX}/subunit | ${FORMAT_TEST_OUTPUT}'
200 else:
201 cmd += ' | ${FILTER_OPTIONS}'
202 runcmd = EXPAND_VARIABLES(opt, cmd)
204 print("test: running %s" % runcmd)
205 ret = RUN_COMMAND(cmd, env=env)
207 if os.path.exists(".testrepository") and not Options.options.LIST:
208 testrcmd = 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
209 runcmd = EXPAND_VARIABLES(opt, testrcmd)
210 RUN_COMMAND(runcmd, env=env)
212 if ret != 0:
213 print("ERROR: test failed with exit code %d" % ret)
214 sys.exit(ret)
216 if not Options.options.LIST and not os.path.exists(st_done):
217 print("ERROR: test command failed to complete")
218 sys.exit(1)
221 ########################################################################
222 # main test entry point
223 def cmd_test(opt):
224 '''Run the test suite (see test options below)'''
226 # if running all tests, then force a symbol check
227 env = LOAD_ENVIRONMENT()
228 CHECK_MAKEFLAGS(env)
229 if not Options.options.TESTS and not Options.options.TESTENV:
230 Options.options.DUP_SYMBOLCHECK = True
232 Scripting.commands.append('build')
233 Scripting.commands.append('testonly')