~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: patrick crews
  • Date: 2011-06-28 21:07:43 UTC
  • mto: (2429.2.1 dbqp_revamp)
  • mto: This revision was merged to the branch mainline in revision 2435.
  • Revision ID: gleebix@gmail.com-20110628210743-vkwxw84rs6lcmtb3
Code cleanup / reorganization

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
 
40
40
 
41
 
class sqlbenchTestExecutor(test_execution.testExecutor):
 
41
class testExecutor(test_execution.testExecutor):
42
42
    """ sqlbench-specific testExecutor 
43
43
        
44
44
    """
113
113
        else:
114
114
            return 'fail'
115
115
 
116
 
 
117
 
    
118
 
class crashmeTestExecutor(sqlbenchTestExecutor):
119
 
    """ crashme-specific variant of sqlbench executor """
120
 
 
121
 
    def execute_testCase (self):
122
 
        """ Execute a crashme testCase
123
 
 
124
 
        """
125
 
        test_execution.testExecutor.execute_testCase(self)
126
 
        self.status = 0
127
 
 
128
 
        self.prepare_config()
129
 
 
130
 
        # execute sqlbench
131
 
        self.execute_crashme()
132
 
 
133
 
        # analyze results
134
 
        self.current_test_status = self.process_crashme_output()
135
 
        self.set_server_status(self.current_test_status)
136
 
        self.server_manager.reset_servers(self.name)
137
 
 
138
 
    def prepare_config(self):
139
 
        """ Create the config file crash-me needs to execute """
140
 
 
141
 
        output_filename= "%s/drizzle.cfg" % (self.system_manager.workdir)
142
 
 
143
 
        # remove the existing configuration file to start fresh
144
 
        if os.path.exists(output_filename):
145
 
            logging.info("Removing %s" % output_filename)
146
 
            os.remove(output_filename)
147
 
  
148
 
        output_file= open(output_filename,"w")
149
 
        # don't support '+' for concatenation
150
 
        output_file.writelines("func_extra_concat_as_+=no\n")
151
 
        # new boost libraries are causing us to put these limits in, needs investigation
152
 
        output_file.writelines("max_text_size=1048576\n")
153
 
        output_file.writelines("where_string_size=1048576\n")
154
 
        output_file.writelines("select_string_size=1048576\n")
155
 
        output_file.flush()
156
 
        output_file.close()
157
 
 
158
 
    def execute_crashme(self):
159
 
        """ Execute the commandline and return the result.
160
 
            We use subprocess as we can pass os.environ dicts and whatnot 
161
 
 
162
 
        """
163
 
 
164
 
        output_filename= "%s/drizzle.cfg" % (self.system_manager.workdir)      
165
 
        testcase_name = self.current_testcase.fullname
166
 
        self.time_manager.start(testcase_name,'test')
167
 
        crashme_outfile = os.path.join(self.logdir,'crashme.out')
168
 
        crashme_output = open(crashme_outfile,'w')
169
 
        crashme_cmd = self.current_testcase.test_command + " --config-file=%s" %(output_filename)
170
 
        self.logging.info("Executing crash-me:  %s" %(crashme_cmd))
171
 
        
172
 
        crashme_subproc = subprocess.Popen( crashme_cmd
173
 
                                         , shell=True
174
 
                                         , cwd=os.path.join(self.system_manager.testdir, 'sql-bench')
175
 
                                         , env=self.working_environment
176
 
                                         , stdout = crashme_output
177
 
                                         , stderr = subprocess.STDOUT
178
 
                                         )
179
 
        crashme_subproc.wait()
180
 
        retcode = crashme_subproc.returncode     
181
 
        execution_time = int(self.time_manager.stop(testcase_name)*1000) # millisec
182
 
 
183
 
        crashme_output.close()
184
 
        crashme_file = open(crashme_outfile,'r')
185
 
        output = ''.join(crashme_file.readlines())
186
 
        self.logging.debug(output)
187
 
        crashme_file.close()
188
 
 
189
 
        self.logging.debug("crashme_retcode: %d" %(retcode))
190
 
        self.current_test_retcode = retcode
191
 
        self.current_test_output = output
192
 
        self.current_test_exec_time = execution_time
193
 
 
194
 
    def process_crashme_output(self):
195
 
        if self.current_test_retcode == 0:
196
 
            infile_name = self.current_test_output.split('\n')[3].split(':')[1].strip()
197
 
            inf= open(infile_name, "r")
198
 
            inlines= inf.readlines()
199
 
            error_flag= False
200
 
            in_error_section = False
201
 
            # crash-me is quite chatty and we don't normally want to sift
202
 
            # through ALL of that stuff.  We do allow seeing it via --verbose
203
 
            if not self.verbose:
204
 
                self.current_test_output = ''
205
 
            for inline in inlines:
206
 
                if in_error_section and not inline.strip().startswith('#'):
207
 
                    in_error_section = False
208
 
                if '=error' in inline:
209
 
                    error_flag= True
210
 
                    in_error_section= True
211
 
                if in_error_section:
212
 
                    self.current_test_output += inline
213
 
            inf.close()                
214
 
            if not error_flag:
215
 
                return 'pass'
216
 
        
217
 
        return 'fail'
218
 
 
219