~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/lib/randgen/randgen_test_management.py

  • Committer: Lee Bieber
  • Date: 2011-02-23 21:21:20 UTC
  • mfrom: (2195.1.4 build)
  • Revision ID: kalebral@gmail.com-20110223212120-jr9bo1nckyk4n5h4
Merge Olaf - remove register keyword
Merge Stewart - 646898: Query causes RAM usage spike    
Merge Stewart - 710818: SHOW TABLE doesn't use generator    
Merge Patrick - 723828: dbqp should integrate with the randgen

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
4
#
 
5
# Copyright (C) 2010 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
""" randgen_test_management:
 
22
    code related to the gathering / analysis / management of 
 
23
    the test cases
 
24
    ie - collecting the list of tests in each suite, then
 
25
    gathering additional, relevant information for randgen
 
26
    mode. (stocastic model-based testing)
 
27
 
 
28
"""
 
29
 
 
30
# imports
 
31
import os
 
32
import re
 
33
import sys
 
34
from ConfigParser import RawConfigParser
 
35
 
 
36
import lib.test_mgmt.test_management as test_management
 
37
 
 
38
 
 
39
    
 
40
class testCase:
 
41
    """Holds info on a single randgen test
 
42
 
 
43
    """
 
44
    def __init__( self, system_manager, name=None
 
45
                , fullname = None, server_requirements=[[]]
 
46
                , comment=None, test_command=None, debug=False ):
 
47
        self.system_manager = system_manager
 
48
        self.logging = self.system_manager.logging
 
49
        self.skip_keys = ['system_manager','logging']
 
50
        self.name = name
 
51
        self.fullname = fullname
 
52
        self.suitename = 'randgen_tests'
 
53
        self.master_sh = None
 
54
        self.comment = comment
 
55
        self.server_requirements = server_requirements
 
56
        self.test_command = test_command
 
57
        
 
58
        if debug:
 
59
            self.system_manager.logging.debug_class(self)
 
60
 
 
61
    def should_run(self):
 
62
        if self.skip_flag or self.disable:
 
63
            return 0
 
64
        else:
 
65
            return 1
 
66
 
 
67
 
 
68
        
 
69
        
 
70
          
 
71
class testManager(test_management.testManager):
 
72
    """Deals with scanning test directories, gathering test cases, and 
 
73
       collecting per-test information (opt files, etc) for use by the
 
74
       test-runner
 
75
 
 
76
    """
 
77
 
 
78
    def __init__(self, verbose, debug, default_engine, dotest, skiptest
 
79
                , reorder, suitelist, suitepaths, system_manager
 
80
                , test_cases, mode):
 
81
        super(testManager, self).__init__( verbose, debug, default_engine
 
82
                                         , dotest, skiptest, reorder
 
83
                                         , suitelist, suitepaths
 
84
                                         , system_manager, test_cases, mode)
 
85
        self.suitepaths = [os.path.join(self.testdir,'randgen_tests')]
 
86
        if suitelist is None:
 
87
            self.suitelist = ['main']
 
88
        else:
 
89
            self.suitelist = suitelist
 
90
 
 
91
    def process_suite(self,suite_dir):
 
92
        """Process a test suite.
 
93
           Look for randgen tests, which are nice clean conf files
 
94
        
 
95
        """
 
96
 
 
97
        # We know this based on how we organize randgen test conf files
 
98
        suite_name = os.path.basename(suite_dir) 
 
99
        if self.verbose:
 
100
                self.system_manager.logging.verbose("Processing suite: %s" %(suite_name))
 
101
        testlist = [os.path.join(suite_dir,test_file) for test_file in sorted(os.listdir(suite_dir)) if test_file.endswith('.cnf')]
 
102
 
 
103
        # Search for specific test names
 
104
        if self.desired_tests: # We have specific, named tests we want from the suite(s)
 
105
           tests_to_use = []
 
106
           for test in self.desired_tests:
 
107
               if test.endswith('.cnf'): 
 
108
                   pass
 
109
               else:
 
110
                   test = test+'.cnf'
 
111
               test = os.path.join(suite_dir,test)
 
112
               if test in testlist:
 
113
                   tests_to_use.append(test)
 
114
           testlist = tests_to_use
 
115
        for test_case in testlist:
 
116
            self.add_test(self.process_test_file(suite_name, test_case))
 
117
 
 
118
 
 
119
    def process_test_file(self, suite_name, testfile):
 
120
        """ We convert the info in a testfile into a testCase object """
 
121
 
 
122
        config_reader = RawConfigParser()
 
123
        config_reader.read(testfile)
 
124
        # test_name = filename - .cnf...simpler
 
125
        test_name = os.path.basename(testfile).replace('.cnf','')
 
126
        test_comment = config_reader.get('test_info','comment')
 
127
        server_requirements = self.process_server_reqs(config_reader.get('test_servers','servers'))
 
128
        test_command = config_reader.get('test_command','command')
 
129
        return testCase( self.system_manager
 
130
                       , name = test_name
 
131
                       , fullname = "%s.%s" %(suite_name, test_name)
 
132
                       , server_requirements = server_requirements
 
133
                       , test_command = test_command
 
134
                       , debug = self.debug )
 
135
 
 
136
        #sys.exit(0)
 
137
 
 
138
    def process_server_reqs(self,data_string):
 
139
        """ We read in the list of lists as a string, so we need to 
 
140
            handle this / break it down into proper chunks
 
141
 
 
142
        """
 
143
        server_reqs = []
 
144
        # We expect to see a list of lists and throw away the 
 
145
        # enclosing brackets
 
146
        option_sets = data_string[1:-1].strip().split(',')
 
147
        for option_set in option_sets:
 
148
            server_reqs.append([option_set[1:-1].strip()])
 
149
        return server_reqs