~ubuntu-branches/ubuntu/vivid/drizzle/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/kewpie/lib/opts/test_run_options.py

  • Committer: Package Import Robot
  • Author(s): Tobias Frost
  • Date: 2013-08-22 20:18:31 UTC
  • mto: (20.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20130822201831-gn3ozsh7o7wmc5tk
Tags: upstream-7.2.3
ImportĀ upstreamĀ versionĀ 7.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
# -*- mode: python; indent-tabs-mode: nil; -*-
3
 
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
 
#
5
 
# Copyright (C) 2010, 2011 Patrick Crews
6
 
#
7
 
# This program is free software; you can redistribute it and/or modify
8
 
# it under the terms of the GNU General Public License as published by
9
 
# the Free Software Foundation; either version 2 of the License, or
10
 
# (at your option) any later version.
11
 
#
12
 
# This program is distributed in the hope that it will be useful,
13
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
# GNU General Public License for more details.
16
 
#
17
 
# You should have received a copy of the GNU General Public License
18
 
# along with this program; if not, write to the Free Software
19
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
 
 
21
 
 
22
 
 
23
 
"""Processes command line options for Drizzle test-runner"""
24
 
 
25
 
import os
26
 
import sys
27
 
import copy
28
 
import exceptions
29
 
import optparse
30
 
 
31
 
# functions
32
 
def comma_list_split(option, opt, value, parser):
33
 
    """Callback for splitting input expected in list form"""
34
 
    cur_list = getattr(parser.values, option.dest,[])
35
 
    input_list = value.split(',')
36
 
    # this is a hack to work with make target - we
37
 
    # don't deal with a dangling ',' in our list
38
 
    if '' in input_list:
39
 
        input_list.remove('')
40
 
    if cur_list:
41
 
        value_list = cur_list + input_list 
42
 
    else:
43
 
        value_list = input_list 
44
 
    setattr(parser.values, option.dest, value_list)
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
 
 
54
 
def organize_options(args, test_cases):
55
 
    """Put our arguments in a nice dictionary
56
 
       We use option.dest as dictionary key
57
 
       item = supplied input
58
 
 ['
59
 
    """
60
 
    variables = {}
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))
65
 
    variables['test_cases']= test_cases
66
 
    # This code should become a function once
67
 
    # enough thought has been given to it
68
 
    if variables['manualgdb']:
69
 
        variables['gdb']=True
70
 
    if variables['repeat'] <= 0:
71
 
        print "Setting --repeat=1.  You chose a silly value that I will ignore :P"
72
 
        variables['repeat'] = 1
73
 
    # we disable the secure-file-priv option if not using dtr / mtr
74
 
    # this might need to be changed in the future...
75
 
    if variables['mode'] not in ['dtr','mtr']:
76
 
        print "Setting --no-secure-file-priv=True for randgen usage..."
77
 
        variables['nosecurefilepriv']=True
78
 
    if variables['mode'] == 'cleanup':
79
 
        print "Setting --start-dirty=True for cleanup mode..."
80
 
        variables['startdirty']=True
81
 
    if variables['libeatmydata'] and os.path.exists(variables['libeatmydatapath']):
82
 
        # We are using libeatmydata vs. shared mem for server speedup
83
 
        print "Using libeatmydata at %s.  Setting --no-shm / not using shared memory for testing..." %(variables['libeatmydatapath'])
84
 
        variables['noshm']=True
85
 
    return variables
86
 
 
87
 
def populate_defaults(variables, basedir_default):
88
 
    """ We fill in any default values that need
89
 
        to be put in post-parsing
90
 
 
91
 
    """
92
 
    if not variables['basedir']:
93
 
        # We populate this value with the default now
94
 
        # it allows us to have a default and have user
95
 
        # supplied opts to override them
96
 
        variables['basedir'].append(basedir_default)
97
 
    return variables
98
 
 
99
 
def handle_user_opts(variables, defaults):
100
 
    """ Some variables are dependent upon default values
101
 
        We do the probably hacky thing of going through
102
 
        and updating them accordingly
103
 
 
104
 
        We make the assumption / decision that only
105
 
        the first basedir value supplied should
106
 
        be applicable when searching for tests
107
 
 
108
 
    """
109
 
    master_basedir = os.path.abspath(variables['basedir'][0].split(':type:')[0])
110
 
    if master_basedir != defaults['basedir']:
111
 
        new_path = os.path.join(master_basedir, 'plugin')
112
 
        search_path = os.path.join(defaults['basedir'],'plugin')
113
 
        tmp = variables['suitepaths']
114
 
        tmp[tmp.index(search_path)] = new_path
115
 
        variables['suitepaths'] = tmp
116
 
    """
117
 
    if variables['testdir'] != defaults['testdir']:
118
 
        new_path = os.path.join(variables['testdir'],'suite')
119
 
        search_path = os.path.join(defaults['testdir'],'suite')
120
 
        tmp = variables['suitepaths']
121
 
        tmp[tmp.index(search_path)] = new_path
122
 
        variables['suitepaths'] = tmp
123
 
    """
124
 
    return variables
125
 
 
126
 
def parse_qp_options(defaults):
127
 
    """ We parse our options and do our magic based on some default values """
128
 
    # Create the CLI option parser
129
 
    parser= optparse.OptionParser(version='%prog (database quality platform aka project steve austin) version 0.1.1')
130
 
    config_control_group = optparse.OptionGroup(parser, 
131
 
                         "Configuration controls - allows you to specify a file with a number of options already specified")
132
 
    config_control_group.add_option(
133
 
       "--sys-config"
134
 
        , dest="sysconfigfilepath"
135
 
        , action='store'
136
 
        , default=None # We want to have a file that will be our default defaults file...
137
 
        , help="The file that specifies system configuration specs for kewpie to execute tests"
138
 
        )
139
 
    parser.add_option_group(config_control_group)
140
 
 
141
 
 
142
 
    system_control_group = optparse.OptionGroup(parser, 
143
 
                             "Options for the test-runner itself - defining the system under test and how to execute tests")
144
 
 
145
 
    system_control_group.add_option(
146
 
          "--force"
147
 
        , dest="force"
148
 
        , action="store_true"
149
 
        , default=False
150
 
        , help="Set this to continue test execution beyond the first failed test"
151
 
        )
152
 
 
153
 
    system_control_group.add_option(
154
 
           "--start-and-exit"
155
 
         , dest="startandexit"
156
 
         , action="store_true"
157
 
         , default=False
158
 
         , help="Spin up the server(s) for the first specified test then exit (will leave servers running)"
159
 
         )
160
 
 
161
 
    system_control_group.add_option(
162
 
           "--verbose"
163
 
         , dest="verbose"
164
 
         , action="store_true"
165
 
         , default = False
166
 
         , help="Produces extensive output about test-runner state.  Distinct from --debug"
167
 
         )
168
 
   
169
 
    system_control_group.add_option(
170
 
           "--debug"
171
 
         , dest="debug"
172
 
         , action="store_true"
173
 
         , default = False
174
 
         , help="Provide internal-level debugging output.  Distinct from --verbose"
175
 
         )
176
 
 
177
 
    system_control_group.add_option(
178
 
           "--mode"
179
 
         , dest="mode"
180
 
         , default="native"
181
 
         , help="Testing mode.  We currently support dtr, randgen, sysbench, sqlbench, crashme and cleanup modes.  See docs for further details about individual modes [%default]"
182
 
         )
183
 
 
184
 
    system_control_group.add_option(
185
 
           "--record"
186
 
         , dest="record"
187
 
         , action="store_true"
188
 
         , default=False
189
 
         , help="Record a testcase result (if the testing mode supports it) [%default]"
190
 
         )
191
 
 
192
 
    system_control_group.add_option(
193
 
           "--fast"
194
 
         , dest="fast"
195
 
         , action="store_true"
196
 
         , default=False
197
 
         , help="Don't try to cleanup from earlier runs (currently just a placeholder) [%default]"
198
 
         )
199
 
   
200
 
    parser.add_option_group(system_control_group)
201
 
 
202
 
    test_exec_control_group = optparse.OptionGroup(parser,
203
 
                                       "Options for controlling how tests are executed")
204
 
 
205
 
    test_exec_control_group.add_option(
206
 
        "--test-debug"
207
 
      , dest="testdebug"
208
 
      , action="store_true"
209
 
      , default=False
210
 
      , help="Toggle to control any debugging / helper output with unittest test cases [%default]"
211
 
      )
212
 
 
213
 
    test_exec_control_group.add_option(
214
 
        "--randgen-seed"
215
 
      , dest="randgenseed"
216
 
      , type='string'
217
 
      , action="store"
218
 
      , default='1'
219
 
      , help="Alter the seed value provided to the random query generator to vary test runs. (string) [%default]"
220
 
      )
221
 
 
222
 
    parser.add_option_group(test_exec_control_group)
223
 
 
224
 
    test_control_group = optparse.OptionGroup(parser, 
225
 
                             "Options for controlling which tests are executed")
226
 
 
227
 
    test_control_group.add_option(
228
 
        "--suite"
229
 
      , dest="suitelist"
230
 
      , type='string'
231
 
      , action="callback"
232
 
      , callback=comma_list_split
233
 
      , default = defaults['suitelist']
234
 
      , 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]"
235
 
      )
236
 
 
237
 
    test_control_group.add_option(
238
 
        "--suitepath"
239
 
      , dest="suitepaths"
240
 
      , type='string'
241
 
      , action="append"
242
 
      , default = defaults['suitepaths']
243
 
      , help="The path containing the suite(s) you wish to execute.  Use one --suitepath for each suite you want to use. [%default]"
244
 
      )
245
 
 
246
 
    test_control_group.add_option(
247
 
        "--do-test"
248
 
      , dest="dotest"
249
 
      , type='string'
250
 
      , default = None
251
 
      , help="input can either be a prefix or a regex. Will only execute tests that match the provided pattern"
252
 
      )
253
 
 
254
 
    test_control_group.add_option(
255
 
        "--skip-test"
256
 
      , dest="skiptest"
257
 
      , type='string'
258
 
      , default = None
259
 
      , help = "input can either be a prefix or a regex.  Will exclude tests that match the provided pattern"
260
 
      )
261
 
 
262
 
    test_control_group.add_option(
263
 
        "--reorder"
264
 
      , dest="reorder"
265
 
      , action="store_true"
266
 
      , default=False
267
 
      , help = "sort the testcases so that they are executed optimally for the given mode [%default]"
268
 
      )
269
 
 
270
 
    test_control_group.add_option(
271
 
        "--repeat"
272
 
      , dest="repeat"
273
 
      , type='int'
274
 
      , action="store"
275
 
      , default=1
276
 
      , help = "Run each test case the specified number of times.  For a given sequence, the first test will be run n times, then the second, etc [%default]"
277
 
      )
278
 
 
279
 
    parser.add_option_group(test_control_group)
280
 
 
281
 
    # test subject control group
282
 
    # terrible name for options tht define the server / code
283
 
    # that is under test
284
 
    test_subject_control_group = optparse.OptionGroup(parser,
285
 
                                     "Options for defining the code that will be under test")
286
 
 
287
 
    test_subject_control_group.add_option(
288
 
        "--basedir"
289
 
      , dest="basedir"
290
 
      , type='string'
291
 
      , default = []
292
 
      , action="append"
293
 
      , 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) [%defaults['basedir']]"
294
 
      )
295
 
 
296
 
    test_subject_control_group.add_option(
297
 
        "--default-server-type"
298
 
      , dest="defaultservertype"
299
 
      , type='string'
300
 
      , default = defaults['server_type']
301
 
      , action='store'
302
 
      , help = "Defines what we consider to be the default server type.  We assume a server is default type unless specified otherwise. [%default]"
303
 
      )
304
 
 
305
 
    test_subject_control_group.add_option(
306
 
        "--serverdir"
307
 
      , dest="serverpath"
308
 
      , type='string'
309
 
      , action="callback"
310
 
      , callback=get_abspath
311
 
      , help = "Path to the server executable.  [%default]"
312
 
      )
313
 
 
314
 
    test_subject_control_group.add_option(
315
 
        "--client-bindir"
316
 
      , dest="clientbindir"
317
 
      , type = 'string'
318
 
      , action="callback"
319
 
      , callback=get_abspath
320
 
      , help = "Path to the directory containing client program binaries for use in testing [%default]"
321
 
      )
322
 
 
323
 
 
324
 
    test_subject_control_group.add_option(
325
 
        "--default-storage-engine"
326
 
       , dest="defaultengine"
327
 
       , default = 'innodb'
328
 
       , help="Start drizzled using the specified engine [%default]"
329
 
       )
330
 
 
331
 
 
332
 
    parser.add_option_group(test_subject_control_group)
333
 
    # end test subject control group
334
 
 
335
 
    # environment options
336
 
 
337
 
    environment_control_group = optparse.OptionGroup(parser, 
338
 
                                "Options for defining the testing environment")
339
 
 
340
 
    environment_control_group.add_option(
341
 
        "--testdir"
342
 
      , dest="testdir"
343
 
      , type = 'string'
344
 
      , default = defaults['testdir']
345
 
      , action="callback"
346
 
      , callback=get_abspath
347
 
      , help = "Path to the test dir, containing additional files for test execution. [%default]"
348
 
      )
349
 
 
350
 
    environment_control_group.add_option(
351
 
        "--workdir"
352
 
      , dest="workdir"
353
 
      , type='string'
354
 
      , default = defaults['workdir']
355
 
      , action="callback"
356
 
      , callback=get_abspath
357
 
      , help = "Path to the directory test-run will use to store generated files and directories. [%default]"
358
 
      )
359
 
 
360
 
    environment_control_group.add_option(
361
 
        "--top-srcdir"
362
 
      , dest="topsrcdir"
363
 
      , type='string'
364
 
      , default = defaults['basedir']
365
 
      , help = "build option [%default]"
366
 
      )
367
 
 
368
 
    environment_control_group.add_option(
369
 
        "--top-builddir"
370
 
      , dest="topbuilddir"
371
 
      , type='string'
372
 
      , default = defaults['basedir']
373
 
      , help = "build option [%default]"
374
 
      )
375
 
 
376
 
    environment_control_group.add_option(
377
 
        "--no-shm"
378
 
      , dest="noshm"
379
 
      , action='store_true'
380
 
      , default=defaults['noshm']
381
 
      , help = "By default, we symlink workdir to a location in shm.  Use this flag to not symlink [%default]"
382
 
      )
383
 
 
384
 
    environment_control_group.add_option(
385
 
        "--libeatmydata"
386
 
      , dest="libeatmydata"
387
 
      , action='store_true'
388
 
      , default=False
389
 
      , help = "We use libeatmydata (if available) to disable fsyncs and speed up test execution.  Implies --no-shm"
390
 
      )
391
 
 
392
 
    environment_control_group.add_option(
393
 
        "--libeatmydata-path"
394
 
      , dest="libeatmydatapath"
395
 
      , action='store'
396
 
      , default='/usr/local/lib/libeatmydata.so'
397
 
      , help = "Path to the libeatmydata install you want to use [%default]"
398
 
      )
399
 
 
400
 
    environment_control_group.add_option(
401
 
        "--start-dirty"
402
 
      , dest="startdirty"
403
 
      , action='store_true'
404
 
      , default=False
405
 
      , help = "Don't try to clean up working directories before test execution [%default]"
406
 
      )
407
 
 
408
 
    environment_control_group.add_option(
409
 
        "--no-secure-file-priv"
410
 
      , dest = "nosecurefilepriv"
411
 
      , action='store_true'
412
 
      , default=False
413
 
      , help = "Turn off the use of --secure-file-priv=vardir for started servers"
414
 
      )
415
 
 
416
 
    environment_control_group.add_option(
417
 
           "--randgen-path"
418
 
         , dest="randgenpath"
419
 
         , action='store'
420
 
         , default=defaults['randgen_path']
421
 
         , help = "The path to a randgen installation that can be used to execute randgen-based tests"
422
 
         )
423
 
 
424
 
    environment_control_group.add_option(
425
 
           "--innobackupex-path"
426
 
         , dest="innobackupexpath"
427
 
         , action='store'
428
 
         , default=defaults['innobackupexpath']
429
 
         , help = "The path to the innobackupex script that facilitates the use of Xtrabackup"
430
 
         )
431
 
 
432
 
    environment_control_group.add_option(
433
 
          "--xtrabackup-path"
434
 
        , dest="xtrabackuppath"
435
 
        , action='store'
436
 
        , default=defaults['xtrabackuppath']
437
 
        , help = "The path the xtrabackup binary to be tested"
438
 
        )
439
 
 
440
 
    environment_control_group.add_option(
441
 
        "--tar4ibd-path"
442
 
      , dest="tar4ibdpath"
443
 
      , action='store'
444
 
      , default=defaults['tar4ibdpath']
445
 
      , help="The path to the tar4ibd binary that will be used for any applicable tests"
446
 
      )
447
 
 
448
 
    environment_control_group.add_option(
449
 
          "--wsrep-provider-path"
450
 
       , dest="wsrepprovider"
451
 
       , action='store'
452
 
       , default=defaults['wsrep_provider_path']
453
 
       , help = "The path to a wsrep provider library for use with mysql"
454
 
       )
455
 
 
456
 
    environment_control_group.add_option(
457
 
          "--cluster-cnf"
458
 
        , dest="clustercnf"
459
 
        , action='store'
460
 
        , default=None
461
 
        , help = "The path to a config file defining a running cluster (node info)"
462
 
        )
463
 
 
464
 
    environment_control_group.add_option(
465
 
          "--subunit-outfile"
466
 
        , dest="subunitoutfile"
467
 
        , action='store'
468
 
        , default=defaults['subunit_file']
469
 
        , help = "File path where subunit output will be logged [%default]"
470
 
        )
471
 
 
472
 
    parser.add_option_group(environment_control_group)
473
 
    # end environment control group
474
 
 
475
 
    option_passing_group = optparse.OptionGroup(parser,
476
 
                          "Options to pass options on to the server")
477
 
 
478
 
    option_passing_group.add_option(
479
 
    "--drizzled"
480
 
      , dest="drizzledoptions"
481
 
      , type='string'
482
 
      , action='append' 
483
 
      , default = []
484
 
      , help = "Pass additional options to the server.  Will be passed to all servers for all tests (mostly for --start-and-exit)"
485
 
      )
486
 
 
487
 
    parser.add_option_group(option_passing_group)
488
 
    # end option passing group
489
 
 
490
 
    analysis_control_group = optparse.OptionGroup(parser, 
491
 
                                "Options for defining the tools we use for code analysis (valgrind, gprof, gcov, etc)")
492
 
 
493
 
    analysis_control_group.add_option(
494
 
        "--valgrind"
495
 
      , dest="valgrind"
496
 
      , action='store_true'
497
 
      , default = False
498
 
      , help = "Run drizzletest and drizzled executables using valgrind with default options [%default]"
499
 
      )
500
 
 
501
 
    analysis_control_group.add_option(
502
 
        "--valgrind-option"
503
 
      , dest="valgrindarglist"
504
 
      , type='string'
505
 
      , action="append"
506
 
      , help = "Pass an option to valgrind (overrides/removes default valgrind options)"
507
 
      )
508
 
 
509
 
    analysis_control_group.add_option(
510
 
        "--valgrind-suppressions"
511
 
      , dest="valgrindsuppressions"
512
 
      , type='string'
513
 
      , action='store'
514
 
      , default = defaults['valgrind_suppression']
515
 
      , help = "Point at a valgrind suppression file [%default]"
516
 
      )
517
 
 
518
 
    analysis_control_group.add_option(
519
 
        "--helgrind"
520
 
      , dest="helgrind"
521
 
      , action='store_true'
522
 
      , default=False
523
 
      , help="Use the helgrind tool for valgrind.  Implies / will auto-use --valgrind"
524
 
      )
525
 
 
526
 
    parser.add_option_group(analysis_control_group)
527
 
 
528
 
    debugger_control_group = optparse.OptionGroup(parser,
529
 
                               "Options for controlling the use of debuggers with test execution")
530
 
 
531
 
    debugger_control_group.add_option(
532
 
        "--gdb"
533
 
      , dest="gdb"
534
 
      , action='store_true'
535
 
      , default=False
536
 
      , help="Start the drizzled server(s) in gdb"
537
 
      )
538
 
 
539
 
    debugger_control_group.add_option(
540
 
        "--manual-gdb"
541
 
      , dest="manualgdb"
542
 
      , action='store_true'
543
 
      , default=False
544
 
      , help="Allows you to start the drizzled server(s) in gdb manually (in another window, etc)"
545
 
      )
546
 
 
547
 
    parser.add_option_group(debugger_control_group)
548
 
 
549
 
    utility_group = optparse.OptionGroup(parser,
550
 
                      "Options to call additional utilities such as datagen")
551
 
 
552
 
    utility_group.add_option(
553
 
        "--gendata"
554
 
      , dest="gendatafile"
555
 
      , action='store'
556
 
      , type='string'
557
 
      , default=None
558
 
      , help="Call the randgen's gendata utility to use the specified configuration file.  This will populate the server prior to any test execution")
559
 
 
560
 
    parser.add_option_group(utility_group)
561
 
 
562
 
    # supplied will be those arguments matching an option, 
563
 
    # and test_cases will be everything else
564
 
    (args, test_cases)= parser.parse_args()
565
 
 
566
 
    variables = {}
567
 
    variables = organize_options(args, test_cases)
568
 
    variables = populate_defaults(variables, defaults['basedir'])
569
 
    variables = handle_user_opts(variables, defaults)
570
 
    return variables