summaryrefslogtreecommitdiff
path: root/source3/selftest/wscript
blob: b3139d531c6daba1d06f5c35a5fff3ec571527a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python
# vim: expandtab ft=python

# selftest main code.

import Scripting, os, Options, Utils, Environment, optparse, sys
from samba_utils import *
from samba_autoconf import *

def set_options(opt):

    opt.add_option('--enable-selftest',
                   help=("enable options necessary for selftest (default=no)"),
                   action="store_true", dest='enable_selftest', default=False)
    opt.add_option('--with-selftest-prefix',
                   help=("specify location of selftest directory (default=./st)"),
                   action="store", dest='SELFTEST_PREFIX', default='./st')

    opt.ADD_COMMAND('test', cmd_test)
    opt.ADD_COMMAND('testonly', cmd_testonly)

    gr = opt.add_option_group('test options')

    gr.add_option('--load-list', 
                  help=("Load a test id list from a text file"),
                  action="store", dest='LOAD_LIST', default=None)
    gr.add_option('--tests',
                  help=("wildcard pattern of tests to run"),
                  action="store", dest='TESTS', default='')
    gr.add_option('--filtered-subunit',
                  help=("output (xfail) filtered subunit"),
                  action="store_true", dest='FILTERED_SUBUNIT', default=False)
    gr.add_option('--quick',
                  help=("enable only quick tests"),
                  action="store_true", dest='QUICKTEST', default=False)
    gr.add_option('--slow',
                  help=("enable the really slow tests"),
                  action="store_true", dest='SLOWTEST', default=False)
    gr.add_option('--testenv',
                  help=("start a terminal with the test environment setup"),
                  action="store_true", dest='TESTENV', default=False)
    gr.add_option('--valgrind',
                  help=("use valgrind on client programs in the tests"),
                  action="store_true", dest='VALGRIND', default=False)
    gr.add_option('--valgrind-log',
                  help=("where to put the valgrind log"),
                  action="store", dest='VALGRINDLOG', default=None)
    gr.add_option('--valgrind-server',
                  help=("use valgrind on the server in the tests (opens an xterm)"),
                  action="store_true", dest='VALGRIND_SERVER', default=False)
    gr.add_option('--gdbtest',
                  help=("run the testsuite within a gdb xterm window"),
                  action="store_true", dest='GDBTEST', default=False)
    gr.add_option('--fail-immediately',
                  help=("stop tests on first failure"),
                  action="store_true", dest='FAIL_IMMEDIATELY', default=False)
    gr.add_option('--socket-wrapper-pcap',
                  help=("create a pcap file for each failing test"),
                  action="store_true", dest='SOCKET_WRAPPER_PCAP', default=False)
    gr.add_option('--socket-wrapper-keep-pcap',
                  help=("create a pcap file for all individual test"),
                  action="store_true", dest='SOCKET_WRAPPER_KEEP_PCAP', default=False)

def configure(conf):
    conf.env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX

def cmd_testonly(opt):
    '''run tests without doing a build first'''
    env = LOAD_ENVIRONMENT()
    opt.env = env

    if (not CONFIG_SET(opt, 'NSS_WRAPPER') or
#        not CONFIG_SET(opt, 'UID_WRAPPER') or
        not CONFIG_SET(opt, 'SOCKET_WRAPPER')):
        print("ERROR: You must use --enable-selftest to enable selftest")
        sys.exit(1)

    env.TESTS  = Options.options.TESTS

    env.SUBUNIT_FORMATTER = '${PYTHON} -u ../selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
    env.FILTER_XFAIL = '${PYTHON} -u ../selftest/filter-subunit --expected-failures=./selftest/knownfail'

    if Options.options.FAIL_IMMEDIATELY:
        env.FILTER_XFAIL += ' --fail-immediately'

    env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'

    env.OPTIONS = ''
    if not Options.options.SLOWTEST:
        env.OPTIONS += ' --exclude=./selftest/slow'
    if Options.options.QUICKTEST:
        env.OPTIONS += ' --quick --include=./selftest/quick'
    if Options.options.LOAD_LIST:
        env.OPTIONS += ' --load-list=%s' % Options.options.LOAD_LIST
    if Options.options.TESTENV:
        env.OPTIONS += ' --testenv'
    if Options.options.SOCKET_WRAPPER_PCAP:
        env.OPTIONS += ' --socket-wrapper-pcap'
    if Options.options.SOCKET_WRAPPER_KEEP_PCAP:
        env.OPTIONS += ' --socket-wrapper-keep-pcap'

    if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
        env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
    else:
        env.FILTER_OPTIONS = '${FILTER_XFAIL}'

    if Options.options.VALGRIND:
        os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
        if Options.options.VALGRINDLOG is not None:
            os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG

    if Options.options.VALGRIND_SERVER:
        os.environ['SAMBA_VALGRIND'] = 'xterm -n server -l -e ../selftest/valgrind_run DUMMY=X'

    if Options.options.GDBTEST:
        os.environ['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/gdb_run DUMMY=X'

    # this is needed for systems without rpath, or with rpath disabled
    ADD_LD_LIBRARY_PATH('bin/shared')

    # tell build system where to find config.h
    os.environ['CONFIG_H'] = 'bin/default/source3/include/config.h'

    st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
    if os.path.exists(st_done):
        os.unlink(st_done)

    cmd = '(${PERL} ../selftest/selftest.pl --target=samba3 --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'
    if os.environ.get('RUN_FROM_BUILD_FARM') is None and not Options.options.FILTERED_SUBUNIT:
        cmd += ' | ${FORMAT_TEST_OUTPUT}'
    cmd = EXPAND_VARIABLES(opt, cmd)

    print("test: running %s" % cmd)
    ret = RUN_COMMAND(cmd, env=env)
    if os.path.exists(".testrepository"):
        # "testr load -q" isn't
        cmd = 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
        cmd = EXPAND_VARIABLES(opt, cmd)
        RUN_COMMAND(cmd, env=env)

    if ret != 0:
        print("ERROR: test failed with exit code %d" % ret)
        sys.exit(ret)

    if not os.path.exists(st_done):
        print("ERROR: test command failed to complete")
        sys.exit(1)


########################################################################
# main test entry point
def cmd_test(opt):
    '''Run the test suite (see test options below)'''
    Scripting.commands.append('build')
    Scripting.commands.append('testonly')