b588648af93ea3703350d39bcfa5540a453b4976
[nivanova/samba-autobuild/.git] / source4 / selftest / wscript
1 #!/usr/bin/env python
2
3 # selftest main code.
4
5 import Scripting, os, Options, Utils, Environment, optparse, sys
6 from samba_utils import RUN_COMMAND, ADD_LD_LIBRARY_PATH
7
8 def set_options(opt):
9     opt.ADD_COMMAND('test', cmd_test)
10     opt.ADD_COMMAND('testonly', cmd_testonly)
11
12     gr = opt.add_option_group('test options')
13
14     gr.add_option('--with-selftest-prefix',
15                   help=("specify location of selftest directory"),
16                   action="store", dest='SELFTEST_PREFIX', default='./st')
17     gr.add_option('--tests',
18                   help=("wildcard pattern of tests to run"),
19                   action="store", dest='TESTS', default='')
20     gr.add_option('--quick',
21                   help=("enable only quick tests"),
22                   action="store_true", dest='QUICKTEST', default=False)
23     gr.add_option('--slow',
24                   help=("enable the really slow tests"),
25                   action="store_true", dest='SLOWTEST', default=False)
26     gr.add_option('--testenv',
27                   help=("start a terminal with the test environment setup"),
28                   action="store_true", dest='TESTENV', default=False)
29     gr.add_option('--valgrind',
30                   help=("use valgrind on client programs in the tests"),
31                   action="store_true", dest='VALGRIND', default=False)
32     gr.add_option('--valgrind-log',
33                   help=("where to put the valgrind log"),
34                   action="store", dest='VALGRINDLOG', default=None)
35     gr.add_option('--valgrind-server',
36                   help=("use valgrind on the server in the tests (opens an xterm)"),
37                   action="store_true", dest='VALGRIND_SERVER', default=False)
38
39
40 def cmd_testonly(opt):
41     '''run tests without doing a build first'''
42     env = Environment.Environment()
43
44     env.TESTS  = Options.options.TESTS
45     env.PERL   = 'perl -W'
46     env.PYTHON = 'python'
47
48     env.TEST_FORMAT = 'plain'
49     env.SUBUNIT_FORMATTER = '${PERL} ../selftest/format-subunit.pl --prefix=${SELFTEST_PREFIX} --format=${TEST_FORMAT} --immediate'
50     env.FILTER_XFAIL = '${PERL} ../selftest/filter-subunit.pl --expected-failures=./selftest/knownfail'
51     env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
52
53     env.OPTIONS = ''
54     if not Options.options.SLOWTEST:
55         env.OPTIONS += ' --exclude=./selftest/slow'
56     if Options.options.QUICKTEST:
57         env.OPTIONS += ' --quick --include=./selftest/quick'
58
59     if Options.options.TESTENV:
60         env.OPTIONS += ' --testenv'
61
62     if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
63         env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
64     else:
65         env.FILTER_OPTIONS = '${FILTER_XFAIL} | ${FORMAT_TEST_OUTPUT}'
66
67     if Options.options.VALGRIND:
68         os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
69         if Options.options.VALGRINDLOG is not None:
70             os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
71
72     if Options.options.VALGRIND_SERVER:
73         os.environ['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/valgrind_run A=B '
74
75     env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
76
77     # this is needed for systems without rpath, or with rpath disabled
78     ADD_LD_LIBRARY_PATH('bin/shared')
79
80     # tell build system where to find config.h
81     os.environ['CONFIG_H'] = 'bin/default/source4/include/config.h'
82
83     st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
84     if os.path.exists(st_done):
85         os.unlink(st_done)
86
87     cmd = '(perl -W ../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}'
88
89     print "test: running %s" % cmd
90     ret = RUN_COMMAND(cmd, env=env)
91     if ret != 0:
92         print("ERROR: test failed with exit code %d" % ret)
93         sys.exit(ret)
94
95     if not os.path.exists(st_done):
96         print("ERROR: test command failed to complete")
97         sys.exit(1)
98
99
100 ########################################################################
101 # main test entry point
102 def cmd_test(opt):
103     '''Run the test suite (see test options below)'''
104     Scripting.commands.append('build')
105     Scripting.commands.append('testonly')