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('--gdbtest',
52 help=("run the testsuite within a gdb xterm window"),
53 action
="store_true", dest
='GDBTEST', default
=False)
54 gr
.add_option('--socket-wrapper-pcap',
55 help=("create a pcap file for each failing test"),
56 action
="store_true", dest
='SOCKET_WRAPPER_PCAP', default
=False)
57 gr
.add_option('--socket-wrapper-keep-pcap',
58 help=("create a pcap file for all individual test"),
59 action
="store_true", dest
='SOCKET_WRAPPER_KEEP_PCAP', default
=False)
62 conf
.env
.SELFTEST_PREFIX
= Options
.options
.SELFTEST_PREFIX
64 def cmd_testonly(opt
):
65 '''run tests without doing a build first'''
66 env
= LOAD_ENVIRONMENT()
69 if (not CONFIG_SET(opt
, 'NSS_WRAPPER') or
70 not CONFIG_SET(opt
, 'UID_WRAPPER') or
71 not CONFIG_SET(opt
, 'SOCKET_WRAPPER')):
72 print("ERROR: You must use --enable-selftest to enable selftest")
75 env
.TESTS
= Options
.options
.TESTS
77 env
.SUBUNIT_FORMATTER
= '${PYTHON} -u ../selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
78 env
.FILTER_XFAIL
= '${PYTHON} -u ../selftest/filter-subunit --expected-failures=./selftest/knownfail'
79 env
.FORMAT_TEST_OUTPUT
= '${SUBUNIT_FORMATTER}'
82 if not Options
.options
.SLOWTEST
:
83 env
.OPTIONS
+= ' --exclude=./selftest/slow'
84 if Options
.options
.QUICKTEST
:
85 env
.OPTIONS
+= ' --quick --include=./selftest/quick'
86 if Options
.options
.LOAD_LIST
:
87 env
.OPTIONS
+= ' --load-list=%s' % Options
.options
.LOAD_LIST
88 if Options
.options
.TESTENV
:
89 env
.OPTIONS
+= ' --testenv'
90 if Options
.options
.SOCKET_WRAPPER_PCAP
:
91 env
.OPTIONS
+= ' --socket-wrapper-pcap'
92 if Options
.options
.SOCKET_WRAPPER_KEEP_PCAP
:
93 env
.OPTIONS
+= ' --socket-wrapper-keep-pcap'
95 if os
.environ
.get('RUN_FROM_BUILD_FARM') is not None:
96 env
.FILTER_OPTIONS
= '${FILTER_XFAIL} --strip-passed-output'
98 env
.FILTER_OPTIONS
= '${FILTER_XFAIL}'
100 if Options
.options
.VALGRIND
:
101 os
.environ
['VALGRIND'] = 'valgrind -q --num-callers=30'
102 if Options
.options
.VALGRINDLOG
is not None:
103 os
.environ
['VALGRIND'] += ' --log-file=%s' % Options
.options
.VALGRINDLOG
105 if Options
.options
.VALGRIND_SERVER
:
106 os
.environ
['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/valgrind_run DUMMY=X'
108 if Options
.options
.GDBTEST
:
109 os
.environ
['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/gdb_run DUMMY=X'
111 # this is needed for systems without rpath, or with rpath disabled
112 ADD_LD_LIBRARY_PATH('bin/shared')
114 # tell build system where to find config.h
115 os
.environ
['CONFIG_H'] = 'bin/default/source4/include/config.h'
117 st_done
= os
.path
.join(env
.SELFTEST_PREFIX
, 'st_done')
118 if os
.path
.exists(st_done
):
121 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} | tee ${SELFTEST_PREFIX}/subunit'
122 if os
.environ
.get('RUN_FROM_BUILD_FARM') is None and not Options
.options
.FILTERED_SUBUNIT
:
123 cmd
+= ' | ${FORMAT_TEST_OUTPUT}'
124 cmd
= EXPAND_VARIABLES(opt
, cmd
)
126 print("test: running %s" % cmd
)
127 ret
= RUN_COMMAND(cmd
, env
=env
)
128 if os
.path
.exists(".testrepository"):
129 # "testr load -q" isn't
130 cmd
= 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
131 cmd
= EXPAND_VARIABLES(opt
, cmd
)
132 RUN_COMMAND(cmd
, env
=env
)
135 print("ERROR: test failed with exit code %d" % ret
)
138 if not os
.path
.exists(st_done
):
139 print("ERROR: test command failed to complete")
143 ########################################################################
144 # main test entry point
146 '''Run the test suite (see test options below)'''
147 Scripting
.commands
.append('build')
148 Scripting
.commands
.append('testonly')