~drizzle-trunk/drizzle/development

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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#! /usr/bin/python
# -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
#
# Copyright (C) 2010 Patrick Crews
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA



"""Processes command line options for Drizzle test-runner"""

import sys
import os
import exceptions
import optparse

# functions
def comma_list_split(option, opt, value, parser):
    """Callback for splitting input expected in list form"""
    cur_list = getattr(parser.values, option.dest,[])
    input_list = value.split(',')
    # this is a hack to work with make target - we
    # don't deal with a dangling ',' in our list
    if '' in input_list:
        input_list.remove('')
    if cur_list:
        value_list = cur_list + input_list 
    else:
        value_list = input_list 
    setattr(parser.values, option.dest, value_list)

def organize_options(args, test_cases):
    """Put our arguments in a nice dictionary
       We use option.dest as dictionary key
       item = supplied input
 
    """
    variables = {}
    variables = vars(args)
    variables['test_cases']= test_cases
    return variables

# Create the CLI option parser
parser= optparse.OptionParser()

# find some default values
# assume we are in-tree testing in general and operating from root/test(?)
testdir_default = os.path.abspath(os.getcwd())

server_default = os.path.abspath(os.path.join(testdir_default,
                                       '../drizzled/drizzled'))

workdir_default = os.path.join(testdir_default,'dbqp_work')

clientbindir_default = os.path.abspath(os.path.join(testdir_default,
                                       '../client'))

basedir_default = os.path.split(testdir_default)[0]


# system_control_group - things like verbose, debug, etc
# test-runner affecting options
system_control_group = optparse.OptionGroup(parser, 
                         "Options for the test-runner itself")

system_control_group.add_option(
   "--force"
 , dest="force"
 , action="store_true"
 , default=False
 , help="Set this to continue test execution beyond the first failed test"
 )

system_control_group.add_option(
    "--verbose"
   , dest="verbose"
   , action="store_true"
   , default = False
   , help="Produces extensive output about test-runner state.  Distinct from --debug"
   )

system_control_group.add_option(
    "--debug"
   , dest="debug"
   , action="store_true"
   , default = False
   , help="Provide internal-level debugging output.  Distinct from --verbose"
   )

system_control_group.add_option(
    "--mode"
  , dest="mode"
  , default="dtr"
  , help="Testing mode.  We only support dtr...for now >;) [%default]"
  )

system_control_group.add_option(
    "--record"
  , dest="record"
  , action="store_true"
  , default=False
  , help="Record a testcase result (if the testing mode supports it) [%default]"
  )

system_control_group.add_option(
    "--fast"
  , dest="fast"
  , action="store_true"
  , default=False
  , help="Don't try to cleanup from earlier runs (currently just a placeholder) [%default]"
  )

parser.add_option_group(system_control_group)

# end system_control_group

# test_control_group - things like suite, do-test, skip-test
# Affect which tests are run
test_control_group = optparse.OptionGroup(parser, 
                         "Options for controlling which tests are executed")


test_control_group.add_option(
    "--suite"
  , dest="suitelist"
  , type='string'
  , action="callback"
  , callback=comma_list_split
  , help="The name of the suite containing tests we want. Can accept comma-separated list (with no spaces).  Additional --suite args are appended to existing list [autosearch]"
  )

test_control_group.add_option(
    "--suitepath"
  , dest="suitepaths"
  , type='string'
  , action="append"
  , default = []
  , help="The path containing the suite(s) you wish to execute.  Use on --suitepath for each suite you want to use."
  )
test_control_group.add_option(
    "--do-test"
  , dest="dotest"
  , type='string'
  , default = None
  , help="input can either be a prefix or a regex. Will only execute tests that match the provided pattern"
  )

test_control_group.add_option(
    "--skip-test"
  , dest="skiptest"
  , type='string'
  , default = None
  , help = "input can either be a prefix or a regex.  Will exclude tests that match the provided pattern"
  )

test_control_group.add_option(
    "--reorder"
  , dest="reorder"
  , action="store_true"
  , default=False
  , help = "sort the testcases so that they are executed optimally for the given mode [%default]"
  )



parser.add_option_group(test_control_group)
# end test_control_group

# test subject control group
# terrible name for options tht define the server / code
# that is under test
test_subject_control_group = optparse.OptionGroup(parser,
                                 "Options for defining the code that will be under test")

test_subject_control_group.add_option(
    "--basedir"
  , dest="basedir"
  , type='string'
  , default = basedir_default
  , help = "Pass this argument to signal to the test-runner that this is an in-tree test.  We automatically set a number of variables relative to the argument (client-bindir, serverdir, testdir) [%default]"
  )

test_subject_control_group.add_option(
    "--serverdir"
  , dest="serverpath"
  , type='string'
  , default = "auto-search"
  , help = "Path to the server executable.  [%default]"
  )

test_subject_control_group.add_option(
    "--client-bindir"
  , dest="clientbindir"
  , type = 'string'
  , default = "auto-search"
  , help = "Path to the directory containing client program binaries for use in testing [%default]"
  )


test_subject_control_group.add_option(
    "--engine"
   , dest="engine"
   , default = 'innodb'
   , help="Start drizzled using the specified engine [%default]"
   )    


parser.add_option_group(test_subject_control_group)
# end test subject control group


# environment options
# define where to find our testsets, working dirs, etc
environment_control_group = optparse.OptionGroup(parser, 
                            "Options for defining the testing environment")

environment_control_group.add_option(
    "--testdir"
  , dest="testdir"
  , type = 'string'
  , default = testdir_default
  , help = "Path to the test dir, containing additional files for test execution. [%default]"
  )

environment_control_group.add_option(
    "--workdir"
  , dest="workdir"
  , type='string'
  , default = workdir_default
  , help = "Path to the directory test-run will use to store generated files and directories. [%default]"
  )

environment_control_group.add_option(
    "--top-srcdir"
  , dest="topsrcdir"
  , type='string'
  , default = basedir_default
  , help = "build option [%default]"
  )

environment_control_group.add_option(
    "--top-builddir"
  , dest="topbuilddir"
  , type='string'
  , default = basedir_default
  , help = "build option [%default]"
  )

environment_control_group.add_option(
    "--no-shm"
  , dest="noshm"
  , action='store_true'
  , default=False
  , help = "By default, we symlink workdir to a location in shm.  Use this flag to not symlink [%default]"
  )

environment_control_group.add_option(
    "--start-dirty"
  , dest="startdirty"
  , action='store_true'
  , default=False
  , help = "Don't try to clean up working directories before test execution [%default]"
  )

environment_control_group.add_option(
    "--no-secure-file-priv"
  , dest = "nosecurefilepriv"
  , action='store_true'
  , default=False
  , help = "Turn off the use of --secure-file-priv=vardir for started servers"
  )

 
parser.add_option_group(environment_control_group)
# end environment control group

analysis_control_group = optparse.OptionGroup(parser, 
                            "Options for defining the tools we use for code analysis (valgrind, gprof, gcov, etc)")

analysis_control_group.add_option(
    "--valgrind"
  , dest="valgrind"
  , action='store_true'
  , default = False
  , help = "Run drizzletest and drizzled executables using valgrind with default options [%default]"
  )
analysis_control_group.add_option(
    "--valgrind-option"
  , dest="valgrindarglist"
  , type='string'
  , action="append"
  , help = "Pass an option to valgrind (overrides/removes default valgrind options)"
  )

parser.add_option_group(analysis_control_group)

debugger_control_group = optparse.OptionGroup(parser,
                           "Options for controlling the use of debuggers with test execution")

debugger_control_group.add_option(
    "--gdb"
  , dest="gdb"
  , action='store_true'
  , default=False
  , help="Start the drizzled server(s) in gdb"
  )

parser.add_option_group(debugger_control_group)





# supplied will be those arguments matching an option, 
# and test_cases will be everything else
(args, test_cases)= parser.parse_args()

variables = {}
variables = organize_options(args, test_cases)