2 # vim: expandtab ft=python
6 import Scripting
, os
, Options
, Utils
, Environment
, optparse
, sys
7 from samba_utils
import *
8 from samba_autoconf
import *
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('--with-selftest-prefix',
16 help=("specify location of selftest directory (default=./st)"),
17 action
="store", dest
='SELFTEST_PREFIX', default
='./st')
19 opt
.ADD_COMMAND('test', cmd_test
)
20 opt
.ADD_COMMAND('testonly', cmd_testonly
)
22 gr
= opt
.add_option_group('test options')
24 gr
.add_option('--load-list',
25 help=("Load a test id list from a text file"),
26 action
="store", dest
='LOAD_LIST', default
=None)
27 gr
.add_option('--tests',
28 help=("wildcard pattern of tests to run"),
29 action
="store", dest
='TESTS', default
='')
30 gr
.add_option('--filtered-subunit',
31 help=("output (xfail) filtered subunit"),
32 action
="store_true", dest
='FILTERED_SUBUNIT', default
=False)
33 gr
.add_option('--quick',
34 help=("enable only quick tests"),
35 action
="store_true", dest
='QUICKTEST', default
=False)
36 gr
.add_option('--slow',
37 help=("enable the really slow tests"),
38 action
="store_true", dest
='SLOWTEST', default
=False)
39 gr
.add_option('--testenv',
40 help=("start a terminal with the test environment setup"),
41 action
="store_true", dest
='TESTENV', default
=False)
42 gr
.add_option('--valgrind',
43 help=("use valgrind on client programs in the tests"),
44 action
="store_true", dest
='VALGRIND', default
=False)
45 gr
.add_option('--valgrind-log',
46 help=("where to put the valgrind log"),
47 action
="store", dest
='VALGRINDLOG', default
=None)
48 gr
.add_option('--valgrind-server',
49 help=("use valgrind on the server in the tests (opens an xterm)"),
50 action
="store_true", dest
='VALGRIND_SERVER', default
=False)
51 gr
.add_option('--screen',
52 help=("run the samba servers in screen sessions"),
53 action
="store_true", dest
='SCREEN', default
=False)
54 gr
.add_option('--gdbtest',
55 help=("run the servers within a gdb window"),
56 action
="store_true", dest
='GDBTEST', default
=False)
57 gr
.add_option('--fail-immediately',
58 help=("stop tests on first failure"),
59 action
="store_true", dest
='FAIL_IMMEDIATELY', default
=False)
60 gr
.add_option('--socket-wrapper-pcap',
61 help=("create a pcap file for each failing test"),
62 action
="store_true", dest
='SOCKET_WRAPPER_PCAP', default
=False)
63 gr
.add_option('--socket-wrapper-keep-pcap',
64 help=("create a pcap file for all individual test"),
65 action
="store_true", dest
='SOCKET_WRAPPER_KEEP_PCAP', default
=False)
68 conf
.env
.SELFTEST_PREFIX
= Options
.options
.SELFTEST_PREFIX
70 def cmd_testonly(opt
):
71 '''run tests without doing a build first'''
72 env
= LOAD_ENVIRONMENT()
75 if (not CONFIG_SET(opt
, 'NSS_WRAPPER') or
76 not CONFIG_SET(opt
, 'UID_WRAPPER') or
77 not CONFIG_SET(opt
, 'SOCKET_WRAPPER')):
78 print("ERROR: You must use --enable-selftest to enable selftest")
81 os
.environ
['SAMBA_SELFTEST'] = '1'
83 env
.TESTS
= Options
.options
.TESTS
85 env
.SUBUNIT_FORMATTER
= '${PYTHON} -u ../selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
86 env
.FILTER_XFAIL
= '${PYTHON} -u ../selftest/filter-subunit --expected-failures=./selftest/knownfail'
88 if Options
.options
.FAIL_IMMEDIATELY
:
89 env
.FILTER_XFAIL
+= ' --fail-immediately'
91 env
.FORMAT_TEST_OUTPUT
= '${SUBUNIT_FORMATTER}'
93 # clean any previous temporary files
94 os
.system("rm -rf %s/tmp" % env
.SELFTEST_PREFIX
);
96 # put all command line options in the environment as TESTENV_*=*
97 for o
in dir(Options
.options
):
99 os
.environ
['TESTENV_%s' % o
.upper()] = str(getattr(Options
.options
, o
, ''))
102 if not Options
.options
.SLOWTEST
:
103 env
.OPTIONS
+= ' --exclude=./selftest/slow'
104 if Options
.options
.QUICKTEST
:
105 env
.OPTIONS
+= ' --quick --include=./selftest/quick'
106 if Options
.options
.LOAD_LIST
:
107 env
.OPTIONS
+= ' --load-list=%s' % Options
.options
.LOAD_LIST
108 if Options
.options
.TESTENV
:
109 env
.OPTIONS
+= ' --testenv'
110 if Options
.options
.SOCKET_WRAPPER_PCAP
:
111 env
.OPTIONS
+= ' --socket-wrapper-pcap'
112 if Options
.options
.SOCKET_WRAPPER_KEEP_PCAP
:
113 env
.OPTIONS
+= ' --socket-wrapper-keep-pcap'
115 if os
.environ
.get('RUN_FROM_BUILD_FARM') is not None:
116 env
.FILTER_OPTIONS
= '${FILTER_XFAIL} --strip-passed-output'
118 env
.FILTER_OPTIONS
= '${FILTER_XFAIL}'
120 if Options
.options
.VALGRIND
:
121 os
.environ
['VALGRIND'] = 'valgrind -q --num-callers=30'
122 if Options
.options
.VALGRINDLOG
is not None:
123 os
.environ
['VALGRIND'] += ' --log-file=%s' % Options
.options
.VALGRINDLOG
127 if Options
.options
.VALGRIND_SERVER
:
128 server_wrapper
= '../selftest/valgrind_run _DUMMY=X'
129 elif Options
.options
.GDBTEST
:
130 server_wrapper
= '../selftest/gdb_run _DUMMY=X'
132 if Options
.options
.SCREEN
:
133 server_wrapper
= '%s/../selftest/in_screen %s' % (os
.getcwd(), server_wrapper
)
134 os
.environ
['TERMINAL'] = '%s/../selftest/in_screen' % os
.getcwd()
135 elif server_wrapper
!= '':
136 server_wrapper
= 'xterm -n server -l -e %s' % server_wrapper
138 if server_wrapper
!= '':
139 os
.environ
['SAMBA_VALGRIND'] = server_wrapper
141 # this is needed for systems without rpath, or with rpath disabled
142 ADD_LD_LIBRARY_PATH('bin/shared')
143 ADD_LD_LIBRARY_PATH('bin/shared/private')
145 # if we are using a system version of ldb then we need to tell it to
146 # load modules from our modules path
147 if env
.USING_SYSTEM_LDB
:
148 os
.environ
['LDB_MODULES_PATH'] = 'bin/modules/ldb'
150 # tell build system where to find config.h
151 os
.environ
['CONFIG_H'] = 'bin/default/source4/include/config.h'
153 st_done
= os
.path
.join(env
.SELFTEST_PREFIX
, 'st_done')
154 if os
.path
.exists(st_done
):
157 if not os
.path
.isdir(env
.SELFTEST_PREFIX
):
158 os
.makedirs(env
.SELFTEST_PREFIX
, int('755', 8))
160 # We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
161 cmd
= '(${PERL} %s/../selftest/selftest.pl --prefix=${SELFTEST_PREFIX} --builddir=. --srcdir=. --exclude=./selftest/skip --testlist="${PYTHON} ./selftest/tests.py|" ${OPTIONS} --socket-wrapper ${TESTS} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS} | tee ${SELFTEST_PREFIX}/subunit' % (os
.getcwd())
162 if os
.environ
.get('RUN_FROM_BUILD_FARM') is None and not Options
.options
.FILTERED_SUBUNIT
:
163 cmd
+= ' | ${FORMAT_TEST_OUTPUT}'
165 cmd
+= ' | ${PYTHON} -u ../selftest/filter-subunit'
166 cmd
= EXPAND_VARIABLES(opt
, cmd
)
168 print("test: running %s" % cmd
)
169 ret
= RUN_COMMAND(cmd
, env
=env
)
170 if os
.path
.exists(".testrepository"):
171 # "testr load -q" isn't
172 cmd
= 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
173 cmd
= EXPAND_VARIABLES(opt
, cmd
)
174 RUN_COMMAND(cmd
, env
=env
)
177 print("ERROR: test failed with exit code %d" % ret
)
180 if not os
.path
.exists(st_done
):
181 print("ERROR: test command failed to complete")
185 ########################################################################
186 # main test entry point
188 '''Run the test suite (see test options below)'''
189 Scripting
.commands
.append('build')
190 Scripting
.commands
.append('testonly')