~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/lib/dbqp_opts/test_run_options.py

  • Committer: patrick crews
  • Date: 2011-10-05 20:40:33 UTC
  • mfrom: (2337.1.24 dbqp_revamp2)
  • mto: This revision was merged to the branch mainline in revision 2435.
  • Revision ID: gleebix@gmail.com-20111005204033-5m6kvcii1q87yur6
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
# -*- mode: python; indent-tabs-mode: nil; -*-
3
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
4
#
5
 
# Copyright (C) 2010 Patrick Crews
 
5
# Copyright (C) 2010, 2011 Patrick Crews
6
6
#
7
7
# This program is free software; you can redistribute it and/or modify
8
8
# it under the terms of the GNU General Public License as published by
22
22
 
23
23
"""Processes command line options for Drizzle test-runner"""
24
24
 
 
25
import os
25
26
import sys
26
 
import os
 
27
import copy
27
28
import exceptions
28
29
import optparse
29
30
 
42
43
        value_list = input_list 
43
44
    setattr(parser.values, option.dest, value_list)
44
45
 
 
46
def get_abspath(option, opt, value, parser):
 
47
    """ Utility function to make sure we have absolute paths
 
48
        if the user supplies values
 
49
 
 
50
    """
 
51
    the_path = os.path.abspath(value)
 
52
    setattr(parser.values, option.dest, the_path)
 
53
 
45
54
def organize_options(args, test_cases):
46
55
    """Put our arguments in a nice dictionary
47
56
       We use option.dest as dictionary key
48
57
       item = supplied input
49
 
 
 
58
 ['
50
59
    """
51
60
    variables = {}
52
 
    variables = vars(args)
 
61
    # we make a copy as the python manual on vars
 
62
    # says we shouldn't alter the dictionary returned
 
63
    # by vars() - could affect symbol table?
 
64
    variables = copy.copy(vars(args))
53
65
    variables['test_cases']= test_cases
54
66
    # This code should become a function once
55
67
    # enough thought has been given to it
58
70
    if variables['repeat'] <= 0:
59
71
        print "Setting --repeat=1.  You chose a silly value that I will ignore :P"
60
72
        variables['repeat'] = 1
61
 
    if variables['mode'] == 'randgen':
62
 
        print "Setting --no-secure-file-priv=True for randgen mode..."
 
73
    if variables['mode'] == 'randgen' or variables['gendatafile']:
 
74
        print "Setting --no-secure-file-priv=True for randgen usage..."
63
75
        variables['nosecurefilepriv']=True
64
76
    if variables['mode'] == 'cleanup':
65
77
        print "Setting --start-dirty=True for cleanup mode..."
66
78
        variables['startdirty']=True
67
 
    return variables
 
79
    if variables['libeatmydata'] and os.path.exists(variables['libeatmydatapath']):
 
80
        # We are using libeatmydata vs. shared mem for server speedup
 
81
        print "Using libeatmydata at %s.  Setting --no-shm / not using shared memory for testing..." %(variables['libeatmydatapath'])
 
82
        variables['noshm']=True
 
83
    return variables
 
84
 
 
85
def populate_defaults(variables, basedir_default):
 
86
    """ We fill in any default values that need
 
87
        to be put in post-parsing
 
88
 
 
89
    """
 
90
    if not variables['basedir']:
 
91
        # We populate this value with the default now
 
92
        # it allows us to have a default and have user
 
93
        # supplied opts to override them
 
94
        variables['basedir'].append(basedir_default)
 
95
    return variables
 
96
 
 
97
def handle_user_opts(variables, basedir_default, testdir_default, suitepaths_default):
 
98
    """ Some variables are dependent upon default values
 
99
        We do the probably hacky thing of going through
 
100
        and updating them accordingly
 
101
 
 
102
        We make the assumption / decision that only
 
103
        the first basedir value supplied should
 
104
        be applicable when searching for tests
 
105
 
 
106
    """
 
107
    master_basedir = os.path.abspath(variables['basedir'][0])
 
108
    if master_basedir != basedir_default:
 
109
        new_path = os.path.join(master_basedir, 'plugin')
 
110
        search_path = os.path.join(basedir_default,'plugin')
 
111
        tmp = variables['suitepaths']
 
112
        tmp[tmp.index(search_path)] = new_path
 
113
        variables['suitepaths'] = tmp
 
114
    if variables['testdir'] != testdir_default:
 
115
        new_path = os.path.join(variables['testdir'],'suite')
 
116
        search_path = os.path.join(testdir_default,'suite')
 
117
        tmp = variables['suitepaths']
 
118
        tmp[tmp.index(search_path)] = new_path
 
119
        variables['suitepaths'] = tmp
 
120
    return variables
 
121
 
68
122
 
69
123
# Create the CLI option parser
70
 
parser= optparse.OptionParser()
 
124
parser= optparse.OptionParser(version='%prog (database quality platform aka project steve austin) version 0.1.1')
71
125
 
72
 
# find some default values
73
 
# assume we are in-tree testing in general and operating from root/test(?)
 
126
# set some default values
74
127
testdir_default = os.path.abspath(os.getcwd())
75
 
 
76
 
server_default = os.path.abspath(os.path.join(testdir_default,
77
 
                                       '../drizzled/drizzled'))
78
 
 
79
128
workdir_default = os.path.join(testdir_default,'workdir')
80
 
 
81
 
clientbindir_default = os.path.abspath(os.path.join(testdir_default,
82
 
                                       '../client'))
83
 
 
 
129
clientbindir_default = os.path.abspath(os.path.join(testdir_default,'../client'))
84
130
basedir_default = os.path.split(testdir_default)[0]
85
 
 
86
 
 
87
 
# system_control_group - things like verbose, debug, etc
88
 
# test-runner affecting options
 
131
server_type_default = 'drizzle'
 
132
valgrind_suppression_default = os.path.join(testdir_default,'valgrind.supp')
 
133
suitepaths_default = [ os.path.join(basedir_default,'plugin')
 
134
                     , os.path.join(testdir_default,'suite')
 
135
                     ]
 
136
randgen_path_default = os.path.join(testdir_default,'randgen')
 
137
 
 
138
 
 
139
config_control_group = optparse.OptionGroup(parser, 
 
140
                     "Configuration controls - allows you to specify a file with a number of options already specified")
 
141
config_control_group.add_option(
 
142
   "--sys_config_file"
 
143
    , dest="sysconfigfilepath"
 
144
    , action='store'
 
145
    , default=None # We want to have a file that will be our default defaults file...
 
146
    , help="The file that specifies system configuration specs for dbqp to execute tests (not yet implemented)"
 
147
    )
 
148
parser.add_option_group(config_control_group)
 
149
 
 
150
 
89
151
system_control_group = optparse.OptionGroup(parser, 
90
 
                         "Options for the test-runner itself")
91
 
 
92
 
system_control_group.add_option(
93
 
   "--force"
94
 
 , dest="force"
95
 
 , action="store_true"
96
 
 , default=False
97
 
 , help="Set this to continue test execution beyond the first failed test"
98
 
 )
99
 
 
100
 
system_control_group.add_option(
101
 
    "--start-and-exit"
102
 
  , dest="startandexit"
103
 
  , action="store_true"
104
 
  , default=False
105
 
  , help="Spin up the server(s) for the first specified test then exit (will leave servers running)"
106
 
  )
107
 
 
108
 
system_control_group.add_option(
109
 
    "--verbose"
110
 
   , dest="verbose"
111
 
   , action="store_true"
112
 
   , default = False
113
 
   , help="Produces extensive output about test-runner state.  Distinct from --debug"
114
 
   )
115
 
 
116
 
system_control_group.add_option(
117
 
    "--debug"
118
 
   , dest="debug"
119
 
   , action="store_true"
120
 
   , default = False
121
 
   , help="Provide internal-level debugging output.  Distinct from --verbose"
122
 
   )
123
 
 
124
 
system_control_group.add_option(
125
 
    "--mode"
126
 
  , dest="mode"
127
 
  , default="dtr"
128
 
  , help="Testing mode.  We currently support dtr, randgen, and cleanup modes.  See docs for further details about individual modes [%default]"
129
 
  )
130
 
 
131
 
system_control_group.add_option(
132
 
    "--record"
133
 
  , dest="record"
134
 
  , action="store_true"
135
 
  , default=False
136
 
  , help="Record a testcase result (if the testing mode supports it) [%default]"
137
 
  )
138
 
 
139
 
system_control_group.add_option(
140
 
    "--fast"
141
 
  , dest="fast"
142
 
  , action="store_true"
143
 
  , default=False
144
 
  , help="Don't try to cleanup from earlier runs (currently just a placeholder) [%default]"
145
 
  )
146
 
 
147
 
system_control_group.add_option(
148
 
    "--randgen-path"
149
 
  , dest="randgenpath"
150
 
  , action='store'
151
 
  , default=None
152
 
  , help = "The path to a randgen installation that can be used to execute randgen-based tests"
153
 
  )
154
 
 
 
152
                         "Options for the test-runner itself - defining the system under test and how to execute tests")
 
153
 
 
154
system_control_group.add_option(
 
155
      "--force"
 
156
    , dest="force"
 
157
    , action="store_true"
 
158
    , default=False
 
159
    , help="Set this to continue test execution beyond the first failed test"
 
160
    )
 
161
 
 
162
system_control_group.add_option(
 
163
       "--start-and-exit"
 
164
     , dest="startandexit"
 
165
     , action="store_true"
 
166
     , default=False
 
167
     , help="Spin up the server(s) for the first specified test then exit (will leave servers running)"
 
168
     )
 
169
 
 
170
system_control_group.add_option(
 
171
       "--verbose"
 
172
     , dest="verbose"
 
173
     , action="store_true"
 
174
     , default = False
 
175
     , help="Produces extensive output about test-runner state.  Distinct from --debug"
 
176
     )
 
177
   
 
178
system_control_group.add_option(
 
179
       "--debug"
 
180
     , dest="debug"
 
181
     , action="store_true"
 
182
     , default = False
 
183
     , help="Provide internal-level debugging output.  Distinct from --verbose"
 
184
     )
 
185
 
 
186
system_control_group.add_option(
 
187
       "--mode"
 
188
     , dest="mode"
 
189
     , default="dtr"
 
190
     , help="Testing mode.  We currently support dtr, randgen, sysbench, sqlbench, crashme and cleanup modes.  See docs for further details about individual modes [%default]"
 
191
     )
 
192
 
 
193
system_control_group.add_option(
 
194
       "--record"
 
195
     , dest="record"
 
196
     , action="store_true"
 
197
     , default=False
 
198
     , help="Record a testcase result (if the testing mode supports it) [%default]"
 
199
     )
 
200
 
 
201
system_control_group.add_option(
 
202
       "--fast"
 
203
     , dest="fast"
 
204
     , action="store_true"
 
205
     , default=False
 
206
     , help="Don't try to cleanup from earlier runs (currently just a placeholder) [%default]"
 
207
     )
 
208
   
155
209
parser.add_option_group(system_control_group)
156
210
 
157
 
# end system_control_group
158
 
 
159
 
# test_control_group - things like suite, do-test, skip-test
160
 
# Affect which tests are run
161
211
test_control_group = optparse.OptionGroup(parser, 
162
212
                         "Options for controlling which tests are executed")
163
213
 
164
 
 
165
214
test_control_group.add_option(
166
215
    "--suite"
167
216
  , dest="suitelist"
168
217
  , type='string'
169
218
  , action="callback"
170
219
  , callback=comma_list_split
171
 
  , 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]"
 
220
  , 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]"
172
221
  )
173
222
 
174
223
test_control_group.add_option(
176
225
  , dest="suitepaths"
177
226
  , type='string'
178
227
  , action="append"
179
 
  , default = []
180
 
  , help="The path containing the suite(s) you wish to execute.  Use on --suitepath for each suite you want to use."
 
228
  , default = suitepaths_default
 
229
  , help="The path containing the suite(s) you wish to execute.  Use one --suitepath for each suite you want to use. [%default]"
181
230
  )
 
231
 
182
232
test_control_group.add_option(
183
233
    "--do-test"
184
234
  , dest="dotest"
213
263
  )
214
264
 
215
265
parser.add_option_group(test_control_group)
216
 
# end test_control_group
217
266
 
218
267
# test subject control group
219
268
# terrible name for options tht define the server / code
220
269
# that is under test
 
270
 
 
271
# find some default values
 
272
# assume we are in-tree testing in general and operating from root/test(?)
 
273
testdir_default = os.path.abspath(os.getcwd())
 
274
 
 
275
basedir_default = os.path.split(testdir_default)[0]
 
276
 
221
277
test_subject_control_group = optparse.OptionGroup(parser,
222
278
                                 "Options for defining the code that will be under test")
223
279
 
225
281
    "--basedir"
226
282
  , dest="basedir"
227
283
  , type='string'
228
 
  , default = basedir_default
229
 
  , 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]"
 
284
  , default = []
 
285
  , action="append"
 
286
  , 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) [%basedir_default]"
 
287
  )
 
288
 
 
289
test_subject_control_group.add_option(
 
290
    "--default_server_type"
 
291
  , dest="defaultservertype"
 
292
  , type='string'
 
293
  , default = server_type_default
 
294
  , action='store'
 
295
  , help = "Defines what we consider to be the default server type.  We assume a server is default type unless specified otherwise. [%default]"
230
296
  )
231
297
 
232
298
test_subject_control_group.add_option(
233
299
    "--serverdir"
234
300
  , dest="serverpath"
235
301
  , type='string'
236
 
  , default = "auto-search"
 
302
  , action="callback"
 
303
  , callback=get_abspath
237
304
  , help = "Path to the server executable.  [%default]"
238
305
  )
239
306
 
241
308
    "--client-bindir"
242
309
  , dest="clientbindir"
243
310
  , type = 'string'
244
 
  , default = "auto-search"
 
311
  , action="callback"
 
312
  , callback=get_abspath
245
313
  , help = "Path to the directory containing client program binaries for use in testing [%default]"
246
314
  )
247
315
 
257
325
parser.add_option_group(test_subject_control_group)
258
326
# end test subject control group
259
327
 
260
 
 
261
328
# environment options
262
 
# define where to find our testsets, working dirs, etc
 
329
 
263
330
environment_control_group = optparse.OptionGroup(parser, 
264
331
                            "Options for defining the testing environment")
265
332
 
268
335
  , dest="testdir"
269
336
  , type = 'string'
270
337
  , default = testdir_default
 
338
  , action="callback"
 
339
  , callback=get_abspath
271
340
  , help = "Path to the test dir, containing additional files for test execution. [%default]"
272
341
  )
273
342
 
276
345
  , dest="workdir"
277
346
  , type='string'
278
347
  , default = workdir_default
 
348
  , action="callback"
 
349
  , callback=get_abspath
279
350
  , help = "Path to the directory test-run will use to store generated files and directories. [%default]"
280
351
  )
281
352
 
304
375
  )
305
376
 
306
377
environment_control_group.add_option(
 
378
    "--libeatmydata"
 
379
  , dest="libeatmydata"
 
380
  , action='store_true'
 
381
  , default=False
 
382
  , help = "We use libeatmydata (if available) to disable fsyncs and speed up test execution.  Implies --no-shm"
 
383
  )
 
384
 
 
385
environment_control_group.add_option(
 
386
    "--libeatmydata-path"
 
387
  , dest="libeatmydatapath"
 
388
  , action='store'
 
389
  , default='/usr/local/lib/libeatmydata.so'
 
390
  , help = "Path to the libeatmydata install you want to use [%default]"
 
391
  )
 
392
 
 
393
environment_control_group.add_option(
307
394
    "--start-dirty"
308
395
  , dest="startdirty"
309
396
  , action='store_true'
319
406
  , help = "Turn off the use of --secure-file-priv=vardir for started servers"
320
407
  )
321
408
 
 
409
environment_control_group.add_option(
 
410
       "--randgen-path"
 
411
     , dest="randgenpath"
 
412
     , action='store'
 
413
     , default=randgen_path_default
 
414
     , help = "The path to a randgen installation that can be used to execute randgen-based tests"
 
415
     )
 
416
 
322
417
parser.add_option_group(environment_control_group)
323
418
# end environment control group
324
419
 
325
420
option_passing_group = optparse.OptionGroup(parser,
326
 
                          "Options to pass options on to the server")
 
421
                      "Options to pass options on to the server")
327
422
 
328
423
option_passing_group.add_option(
329
 
    "--drizzled"
 
424
"--drizzled"
330
425
  , dest="drizzledoptions"
331
426
  , type='string'
332
427
  , action='append' 
336
431
 
337
432
parser.add_option_group(option_passing_group)
338
433
# end option passing group
339
 
 
340
434
 
341
435
analysis_control_group = optparse.OptionGroup(parser, 
342
436
                            "Options for defining the tools we use for code analysis (valgrind, gprof, gcov, etc)")
348
442
  , default = False
349
443
  , help = "Run drizzletest and drizzled executables using valgrind with default options [%default]"
350
444
  )
 
445
 
351
446
analysis_control_group.add_option(
352
447
    "--valgrind-option"
353
448
  , dest="valgrindarglist"
356
451
  , help = "Pass an option to valgrind (overrides/removes default valgrind options)"
357
452
  )
358
453
 
 
454
analysis_control_group.add_option(
 
455
    "--valgrind-suppressions"
 
456
  , dest="valgrindsuppressions"
 
457
  , type='string'
 
458
  , action='store'
 
459
  , default = valgrind_suppression_default
 
460
  , help = "Point at a valgrind suppression file [%default]"
 
461
  )
 
462
 
359
463
parser.add_option_group(analysis_control_group)
360
464
 
361
465
debugger_control_group = optparse.OptionGroup(parser,
379
483
 
380
484
parser.add_option_group(debugger_control_group)
381
485
 
382
 
 
383
486
utility_group = optparse.OptionGroup(parser,
384
487
                  "Options to call additional utilities such as datagen")
385
488
 
393
496
 
394
497
parser.add_option_group(utility_group)
395
498
 
396
 
 
397
499
# supplied will be those arguments matching an option, 
398
500
# and test_cases will be everything else
399
501
(args, test_cases)= parser.parse_args()
400
502
 
401
503
variables = {}
402
504
variables = organize_options(args, test_cases)
 
505
variables = populate_defaults(variables, basedir_default)
 
506
variables = handle_user_opts(variables, basedir_default, testdir_default, suitepaths_default)
403
507