~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: patrick crews
  • Date: 2011-06-08 03:02:27 UTC
  • mto: This revision was merged to the branch mainline in revision 2329.
  • Revision ID: gleebix@gmail.com-20110608030227-updkyv2652zvfajc
Initial voodoo worked to give us a crashme mode.  Need docs still

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
import lib.test_mgmt.test_execution as test_execution
38
38
 
 
39
 
 
40
 
39
41
class sqlbenchTestExecutor(test_execution.testExecutor):
40
42
    """ sqlbench-specific testExecutor 
41
43
        
95
97
 
96
98
    def process_sqlbench_output(self):
97
99
        
98
 
                    
99
 
        if self.current_test_retcode == 0:
 
100
        # Check for 'Failed' in sql-bench output
 
101
        # The tests don't die on a failed test and
 
102
        # require some checking of the output file
 
103
        infile_name = self.current_test_output.split('\n')[1].strip()
 
104
        inf= open(infile_name, "r")
 
105
        inlines= inf.readlines()
 
106
        error_flag= False
 
107
        for inline in inlines:
 
108
            if 'Failed' in inline:
 
109
                error_flag= True
 
110
                logging.info(inline.strip())
 
111
        inf.close()                    
 
112
        self.current_test_output += ''.join(inlines)
 
113
        if self.current_test_retcode == 0 and not error_flag:
100
114
            return 'pass'
101
115
        else:
102
116
            return 'fail'
163
177
        self.system_manager.create_symlinks(needed_symlinks)
164
178
 
165
179
    
166
 
   
 
180
class crashmeTestExecutor(sqlbenchTestExecutor):
 
181
    """ crashme-specific variant of sqlbench executor """
 
182
 
 
183
    def execute_testCase (self):
 
184
        """ Execute a crashme testCase
 
185
 
 
186
        """
 
187
        test_execution.testExecutor.execute_testCase(self)
 
188
        self.status = 0
 
189
 
 
190
        self.prepare_config()
 
191
 
 
192
        # execute sqlbench
 
193
        self.execute_crashme()
 
194
 
 
195
        # analyze results
 
196
        self.current_test_status = self.process_crashme_output()
 
197
        self.set_server_status(self.current_test_status)
 
198
        self.server_manager.reset_servers(self.name)
 
199
 
 
200
    def prepare_config(self):
 
201
        """ Create the config file crash-me needs to execute """
 
202
 
 
203
        output_filename= "%s/drizzle.cfg" % (self.system_manager.workdir)
 
204
 
 
205
        # remove the existing configuration file to start fresh
 
206
        if os.path.exists(output_filename):
 
207
            logging.info("Removing %s" % output_filename)
 
208
            os.remove(output_filename)
 
209
  
 
210
        output_file= open(output_filename,"w")
 
211
        # don't support '+' for concatenation
 
212
        output_file.writelines("func_extra_concat_as_+=no\n")
 
213
        # new boost libraries are causing us to put these limits in, needs investigation
 
214
        output_file.writelines("max_text_size=1048576\n")
 
215
        output_file.writelines("where_string_size=1048576\n")
 
216
        output_file.writelines("select_string_size=1048576\n")
 
217
        output_file.flush()
 
218
        output_file.close()
 
219
 
 
220
    def execute_crashme(self):
 
221
        """ Execute the commandline and return the result.
 
222
            We use subprocess as we can pass os.environ dicts and whatnot 
 
223
 
 
224
        """
 
225
 
 
226
        output_filename= "%s/drizzle.cfg" % (self.system_manager.workdir)      
 
227
        testcase_name = self.current_testcase.fullname
 
228
        self.time_manager.start(testcase_name,'test')
 
229
        crashme_outfile = os.path.join(self.logdir,'crashme.out')
 
230
        crashme_output = open(crashme_outfile,'w')
 
231
        crashme_cmd = self.current_testcase.test_command + " --config-file=%s" %(output_filename)
 
232
        self.logging.info("Executing crash-me:  %s" %(crashme_cmd))
 
233
        
 
234
        crashme_subproc = subprocess.Popen( crashme_cmd
 
235
                                         , shell=True
 
236
                                         , cwd=os.path.join(self.system_manager.testdir, 'sql-bench')
 
237
                                         , env=self.working_environment
 
238
                                         , stdout = crashme_output
 
239
                                         , stderr = subprocess.STDOUT
 
240
                                         )
 
241
        crashme_subproc.wait()
 
242
        retcode = crashme_subproc.returncode     
 
243
        execution_time = int(self.time_manager.stop(testcase_name)*1000) # millisec
 
244
 
 
245
        crashme_output.close()
 
246
        crashme_file = open(crashme_outfile,'r')
 
247
        output = ''.join(crashme_file.readlines())
 
248
        if self.debug:
 
249
            self.logging.debug(output)
 
250
        crashme_file.close()
 
251
 
 
252
        if self.debug:
 
253
            self.logging.debug("crashme_retcode: %d" %(retcode))
 
254
        self.current_test_retcode = retcode
 
255
        self.current_test_output = output
 
256
        self.current_test_exec_time = execution_time
 
257
 
 
258
    def process_crashme_output(self):
 
259
        infile_name = self.current_test_output.split('\n')[3].split(':')[1].strip()
 
260
        inf= open(infile_name, "r")
 
261
        inlines= inf.readlines()
 
262
        error_flag= False
 
263
        in_error_section = False
 
264
        # crash-me is quite chatty and we don't normally want to sift
 
265
        # through ALL of that stuff.  We do allow seeing it via --verbose
 
266
        if not self.verbose:
 
267
            self.current_test_output = ''
 
268
        for inline in inlines:
 
269
            if in_error_section and not inline.strip().startswith('#'):
 
270
                in_error_section = False
 
271
            if '=error' in inline:
 
272
                error_flag= True
 
273
                in_error_section= True
 
274
            if in_error_section:
 
275
                self.current_test_output += inline
 
276
        inf.close()                
 
277
        if self.current_test_retcode == 0 and not error_flag:
 
278
            return 'pass'
 
279
        else:
 
280
            return 'fail'
167
281
 
168
282