~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/lib/sqlbench/sqlbench_test_management.py

  • Committer: Andrew Hutchings
  • Date: 2011-06-13 17:29:43 UTC
  • mfrom: (2331 drizzle)
  • mto: This revision was merged to the branch mainline in revision 2332.
  • Revision ID: andrew@linuxjedi.co.uk-20110613172943-y3gig2cyg4p2a0tq
Merge with trunk

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) 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
""" sqlbench_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 sqlbench mode
 
26
 
 
27
"""
 
28
 
 
29
# imports
 
30
import os
 
31
import re
 
32
import sys
 
33
from ConfigParser import RawConfigParser
 
34
 
 
35
import lib.test_mgmt.test_management as test_management
 
36
 
 
37
 
 
38
    
 
39
class testCase:
 
40
    """Holds info on a single sqlbench test
 
41
 
 
42
    """
 
43
    def __init__( self, system_manager, name=None
 
44
                , fullname = None, server_requirements=[[]]
 
45
                , comment=None, test_command=None, cnf_path=None
 
46
                , suitename = 'sqlbench_tests'
 
47
                , debug=False ):
 
48
        self.system_manager = system_manager
 
49
        self.logging = self.system_manager.logging
 
50
        self.skip_keys = ['system_manager','logging']
 
51
        self.name = name
 
52
        self.fullname = fullname
 
53
        self.suitename = suitename
 
54
        self.master_sh = None
 
55
        self.comment = comment
 
56
        self.server_requirements = server_requirements
 
57
        self.test_command = test_command
 
58
        self.cnf_path = cnf_path
 
59
        
 
60
        if debug:
 
61
            self.system_manager.logging.debug_class(self)
 
62
 
 
63
    def should_run(self):
 
64
        if self.skip_flag or self.disable:
 
65
            return 0
 
66
        else:
 
67
            return 1
 
68
 
 
69
 
 
70
        
 
71
        
 
72
          
 
73
class testManager(test_management.testManager):
 
74
    """Deals with scanning test directories, gathering test cases, and 
 
75
       collecting per-test information (opt files, etc) for use by the
 
76
       test-runner
 
77
 
 
78
    """
 
79
 
 
80
    def __init__(self, verbose, debug, default_engine, dotest, skiptest
 
81
                , reorder, suitelist, suitepaths, system_manager
 
82
                , test_cases, mode):
 
83
        super(testManager, self).__init__( verbose, debug, default_engine
 
84
                                         , dotest, skiptest, reorder
 
85
                                         , suitelist, suitepaths
 
86
                                         , system_manager, test_cases, mode)
 
87
        self.suitepaths = [os.path.join(self.testdir,'sqlbench_tests')]
 
88
        if suitelist is None:
 
89
            self.suitelist = ['main']
 
90
        else:
 
91
            self.suitelist = suitelist
 
92
 
 
93
    def process_suite(self,suite_dir):
 
94
        """Process a test suite.
 
95
           Look for sqlbench tests, which are nice clean conf files
 
96
        
 
97
        """
 
98
 
 
99
        # We know this based on how we organize sqlbench test conf files
 
100
        suite_name = os.path.basename(suite_dir) 
 
101
        if self.verbose:
 
102
                self.system_manager.logging.verbose("Processing suite: %s" %(suite_name))
 
103
        testlist = [os.path.join(suite_dir,test_file) for test_file in sorted(os.listdir(suite_dir)) if test_file.endswith('.cnf')]
 
104
 
 
105
        # Search for specific test names
 
106
        if self.desired_tests: # We have specific, named tests we want from the suite(s)
 
107
           tests_to_use = []
 
108
           for test in self.desired_tests:
 
109
               if test.endswith('.cnf'): 
 
110
                   pass
 
111
               else:
 
112
                   test = test+'.cnf'
 
113
               test = os.path.join(suite_dir,test)
 
114
               if test in testlist:
 
115
                   tests_to_use.append(test)
 
116
           testlist = tests_to_use
 
117
        for test_case in testlist:
 
118
            self.add_test(self.process_test_file(suite_name, test_case))
 
119
 
 
120
 
 
121
    def process_test_file(self, suite_name, testfile):
 
122
        """ We convert the info in a testfile into a testCase object """
 
123
 
 
124
        config_reader = RawConfigParser()
 
125
        config_reader.read(testfile)
 
126
        # test_name = filename - .cnf...simpler
 
127
        test_name = os.path.basename(testfile).replace('.cnf','')
 
128
        test_comment = config_reader.get('test_info','comment')
 
129
        server_requirements = self.process_server_reqs(config_reader.get('test_servers','servers'))
 
130
        test_command = config_reader.get('test_command','command')
 
131
        return testCase( self.system_manager
 
132
                       , name = test_name
 
133
                       , fullname = "%s.%s" %(suite_name, test_name)
 
134
                       , server_requirements = server_requirements
 
135
                       , test_command = test_command
 
136
                       , cnf_path = testfile
 
137
                       , debug = self.debug )
 
138
 
 
139
        #sys.exit(0)
 
140
 
 
141
    def process_server_reqs(self,data_string):
 
142
        """ We read in the list of lists as a string, so we need to 
 
143
            handle this / break it down into proper chunks
 
144
 
 
145
        """
 
146
        server_reqs = []
 
147
        # We expect to see a list of lists and throw away the 
 
148
        # enclosing brackets
 
149
        option_sets = data_string[1:-1].strip().split(',')
 
150
        for option_set in option_sets:
 
151
            server_reqs.append([option_set[1:-1].strip()])
 
152
        return server_reqs
 
153
 
 
154
    def record_test_result(self, test_case, test_status, output, exec_time):
 
155
        """ Accept the results of an executed testCase for further
 
156
            processing.
 
157
 
 
158
        """
 
159
        if test_status not in self.executed_tests:
 
160
            self.executed_tests[test_status] = [test_case]
 
161
        else:
 
162
            self.executed_tests[test_status].append(test_case)
 
163
        # report
 
164
        self.logging.test_report( test_case.fullname, test_status
 
165
                                , str(exec_time), output
 
166
                                , report_output= True)
 
167
 
 
168
class crashmeTestManager(testManager):
 
169
    """Deals with scanning test directories, gathering test cases, and 
 
170
       collecting per-test information (opt files, etc) for use by the
 
171
       test-runner
 
172
 
 
173
    """
 
174
 
 
175
    def __init__(self, verbose, debug, default_engine, dotest, skiptest
 
176
                , reorder, suitelist, suitepaths, system_manager
 
177
                , test_cases, mode):
 
178
        super(testManager, self).__init__( verbose, debug, default_engine
 
179
                                         , dotest, skiptest, reorder
 
180
                                         , suitelist, suitepaths
 
181
                                         , system_manager, test_cases, mode)
 
182
        self.suitepaths = [os.path.join(self.testdir,'crashme_tests')]
 
183
        if suitelist is None:
 
184
            self.suitelist = ['main']
 
185
        else:
 
186
            self.suitelist = suitelist
 
187
 
 
188
    def record_test_result(self, test_case, test_status, output, exec_time):
 
189
        """ Accept the results of an executed testCase for further
 
190
            processing.
 
191
 
 
192
        """
 
193
        if test_status not in self.executed_tests:
 
194
            self.executed_tests[test_status] = [test_case]
 
195
        else:
 
196
            self.executed_tests[test_status].append(test_case)
 
197
        # report
 
198
        self.logging.test_report( test_case.fullname, test_status
 
199
                                , str(exec_time), output
 
200
                                , report_output= True)