~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-10-05 20:40:33 UTC
  • mfrom: (2337.1.24 dbqp_revamp2)
  • mto: This revision was merged to the branch mainline in revision 2435.
  • Revision ID: gleebix@gmail.com-20111005204033-5m6kvcii1q87yur6
Merge with trunk

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
    """
85
85
        sqlbench_output.close()
86
86
        sqlbench_file = open(sqlbench_outfile,'r')
87
87
        output = ''.join(sqlbench_file.readlines())
88
 
        if self.debug:
89
 
            self.logging.debug(output)
 
88
        self.logging.debug(output)
90
89
        sqlbench_file.close()
91
90
 
92
 
        if self.debug:
93
 
            self.logging.debug("sqlbench_retcode: %d" %(retcode))
 
91
        self.logging.debug("sqlbench_retcode: %d" %(retcode))
94
92
        self.current_test_retcode = retcode
95
93
        self.current_test_output = output
96
94
        self.current_test_exec_time = execution_time
115
113
        else:
116
114
            return 'fail'
117
115
 
118
 
    def handle_system_reqs(self):
119
 
        """ We check our test case and see what we need to do
120
 
            system-wise to get ready.  This is likely to be 
121
 
            mode-dependent and this is just a placeholder
122
 
            method
123
 
 
124
 
        """
125
 
 
126
 
        self.process_environment_reqs()
127
 
        self.process_symlink_reqs()
128
 
        self.process_master_sh()  
129
 
        return
130
 
 
131
 
    def process_master_sh(self):
132
 
        """ We do what we need to if we have a master.sh file """
133
 
        if self.current_testcase.master_sh:
134
 
            retcode, output = self.system_manager.execute_cmd("/bin/sh %s" %(self.current_testcase.master_sh))
135
 
            if self.debug:
136
 
                self.logging.info("retcode: %retcode")
137
 
                self.logging.info("%output")
138
 
 
139
 
    def process_environment_reqs(self):
140
 
        """ We generate the ENV vars we need set
141
 
            and then ask systemManager to do so
142
 
 
143
 
        """
144
 
        env_reqs = {  'DRIZZLETEST_VARDIR': self.master_server.vardir
145
 
                   ,  'DRIZZLE_TMP_DIR': self.master_server.tmpdir
146
 
                   ,  'MASTER_MYSOCK': self.master_server.socket_file
147
 
                   ,  'MASTER_MYPORT': str(self.master_server.master_port)
148
 
                   ,  'MC_PORT': str(self.master_server.mc_port)
149
 
                   ,  'PBMS_PORT': str(self.master_server.pbms_port)
150
 
                   ,  'RABBITMQ_NODE_PORT': str(self.master_server.rabbitmq_node_port)
151
 
                   ,  'DRIZZLE_TCP_PORT': str(self.master_server.drizzle_tcp_port)
152
 
                   ,  'EXE_DRIZZLE': self.master_server.drizzle_client
153
 
                   ,  'MASTER_SERVER_SLAVE_CONFIG' : self.master_server.slave_config_file
154
 
                   ,  'DRIZZLE_DUMP': "%s --no-defaults -uroot -p%d" %( self.master_server.drizzledump
155
 
                                                        , self.master_server.master_port)
156
 
                   ,  'DRIZZLE_SLAP': "%s -uroot -p%d" %( self.master_server.drizzleslap
157
 
                                                        , self.master_server.master_port)
158
 
                   ,  'DRIZZLE_IMPORT': "%s -uroot -p%d" %( self.master_server.drizzleimport
159
 
                                                          , self.master_server.master_port)
160
 
                   ,  'DRIZZLE': "%s -uroot -p%d" %( self.master_server.drizzle_client
161
 
                                                   , self.master_server.master_port)
162
 
                   ,  'DRIZZLE_BASEDIR' : self.system_manager.code_tree.basedir
163
 
                   ,  'DRIZZLE_TRX_READER' : self.system_manager.code_tree.drizzle_trx_reader
164
 
                   ,  'DRIZZLE_TEST_WORKDIR' : self.system_manager.workdir
165
 
                   }     
166
 
 
167
 
 
168
 
        self.working_environment = self.system_manager.create_working_environment(env_reqs)
169
 
 
170
 
 
171
 
    def process_symlink_reqs(self):
172
 
        """ Create any symlinks we may need """
173
 
        needed_symlinks = []
174
 
 
175
 
        self.system_manager.create_symlinks(needed_symlinks)
176
 
 
177
 
    
178
 
class crashmeTestExecutor(sqlbenchTestExecutor):
179
 
    """ crashme-specific variant of sqlbench executor """
180
 
 
181
 
    def execute_testCase (self):
182
 
        """ Execute a crashme testCase
183
 
 
184
 
        """
185
 
        test_execution.testExecutor.execute_testCase(self)
186
 
        self.status = 0
187
 
 
188
 
        self.prepare_config()
189
 
 
190
 
        # execute sqlbench
191
 
        self.execute_crashme()
192
 
 
193
 
        # analyze results
194
 
        self.current_test_status = self.process_crashme_output()
195
 
        self.set_server_status(self.current_test_status)
196
 
        self.server_manager.reset_servers(self.name)
197
 
 
198
 
    def prepare_config(self):
199
 
        """ Create the config file crash-me needs to execute """
200
 
 
201
 
        output_filename= "%s/drizzle.cfg" % (self.system_manager.workdir)
202
 
 
203
 
        # remove the existing configuration file to start fresh
204
 
        if os.path.exists(output_filename):
205
 
            logging.info("Removing %s" % output_filename)
206
 
            os.remove(output_filename)
207
 
  
208
 
        output_file= open(output_filename,"w")
209
 
        # don't support '+' for concatenation
210
 
        output_file.writelines("func_extra_concat_as_+=no\n")
211
 
        # new boost libraries are causing us to put these limits in, needs investigation
212
 
        output_file.writelines("max_text_size=1048576\n")
213
 
        output_file.writelines("where_string_size=1048576\n")
214
 
        output_file.writelines("select_string_size=1048576\n")
215
 
        output_file.flush()
216
 
        output_file.close()
217
 
 
218
 
    def execute_crashme(self):
219
 
        """ Execute the commandline and return the result.
220
 
            We use subprocess as we can pass os.environ dicts and whatnot 
221
 
 
222
 
        """
223
 
 
224
 
        output_filename= "%s/drizzle.cfg" % (self.system_manager.workdir)      
225
 
        testcase_name = self.current_testcase.fullname
226
 
        self.time_manager.start(testcase_name,'test')
227
 
        crashme_outfile = os.path.join(self.logdir,'crashme.out')
228
 
        crashme_output = open(crashme_outfile,'w')
229
 
        crashme_cmd = self.current_testcase.test_command + " --config-file=%s" %(output_filename)
230
 
        self.logging.info("Executing crash-me:  %s" %(crashme_cmd))
231
 
        
232
 
        crashme_subproc = subprocess.Popen( crashme_cmd
233
 
                                         , shell=True
234
 
                                         , cwd=os.path.join(self.system_manager.testdir, 'sql-bench')
235
 
                                         , env=self.working_environment
236
 
                                         , stdout = crashme_output
237
 
                                         , stderr = subprocess.STDOUT
238
 
                                         )
239
 
        crashme_subproc.wait()
240
 
        retcode = crashme_subproc.returncode     
241
 
        execution_time = int(self.time_manager.stop(testcase_name)*1000) # millisec
242
 
 
243
 
        crashme_output.close()
244
 
        crashme_file = open(crashme_outfile,'r')
245
 
        output = ''.join(crashme_file.readlines())
246
 
        if self.debug:
247
 
            self.logging.debug(output)
248
 
        crashme_file.close()
249
 
 
250
 
        if self.debug:
251
 
            self.logging.debug("crashme_retcode: %d" %(retcode))
252
 
        self.current_test_retcode = retcode
253
 
        self.current_test_output = output
254
 
        self.current_test_exec_time = execution_time
255
 
 
256
 
    def process_crashme_output(self):
257
 
        if self.current_test_retcode == 0:
258
 
            infile_name = self.current_test_output.split('\n')[3].split(':')[1].strip()
259
 
            inf= open(infile_name, "r")
260
 
            inlines= inf.readlines()
261
 
            error_flag= False
262
 
            in_error_section = False
263
 
            # crash-me is quite chatty and we don't normally want to sift
264
 
            # through ALL of that stuff.  We do allow seeing it via --verbose
265
 
            if not self.verbose:
266
 
                self.current_test_output = ''
267
 
            for inline in inlines:
268
 
                if in_error_section and not inline.strip().startswith('#'):
269
 
                    in_error_section = False
270
 
                if '=error' in inline:
271
 
                    error_flag= True
272
 
                    in_error_section= True
273
 
                if in_error_section:
274
 
                    self.current_test_output += inline
275
 
            inf.close()                
276
 
            if not error_flag:
277
 
                return 'pass'
278
 
        
279
 
        return 'fail'
280
 
 
281