2
# -*- mode: python; indent-tabs-mode: nil; -*-
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5
# Copyright (C) 2011 Patrick Crews
8
# This program is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 2 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
""" crashme_test_execution:
23
code related to the execution of crashme test cases
25
We are provided access to a testManager with
26
crashme-specific testCases.
37
import lib.test_mgmt.test_execution as test_execution
39
class testExecutor(test_execution.testExecutor):
40
""" crashme-specific executor """
42
def execute_testCase (self):
43
""" Execute a crashme testCase
46
test_execution.testExecutor.execute_testCase(self)
52
self.execute_crashme()
55
self.current_test_status = self.process_crashme_output()
56
self.set_server_status(self.current_test_status)
57
self.server_manager.reset_servers(self.name)
59
def prepare_config(self):
60
""" Create the config file crash-me needs to execute """
62
output_filename= "%s/drizzle.cfg" % (self.system_manager.workdir)
64
# remove the existing configuration file to start fresh
65
if os.path.exists(output_filename):
66
logging.info("Removing %s" % output_filename)
67
os.remove(output_filename)
69
output_file= open(output_filename,"w")
70
# don't support '+' for concatenation
71
output_file.writelines("func_extra_concat_as_+=no\n")
72
# new boost libraries are causing us to put these limits in, needs investigation
73
output_file.writelines("max_text_size=1048576\n")
74
output_file.writelines("where_string_size=1048576\n")
75
output_file.writelines("select_string_size=1048576\n")
79
def execute_crashme(self):
80
""" Execute the commandline and return the result.
81
We use subprocess as we can pass os.environ dicts and whatnot
85
output_filename= "%s/drizzle.cfg" % (self.system_manager.workdir)
86
testcase_name = self.current_testcase.fullname
87
self.time_manager.start(testcase_name,'test')
88
crashme_outfile = os.path.join(self.logdir,'crashme.out')
89
crashme_output = open(crashme_outfile,'w')
90
crashme_cmd = self.current_testcase.test_command + " --config-file=%s" %(output_filename)
91
self.logging.info("Executing crash-me: %s" %(crashme_cmd))
93
crashme_subproc = subprocess.Popen( crashme_cmd
95
, cwd=os.path.join(self.system_manager.testdir, 'sql-bench')
96
, env=self.working_environment
97
, stdout = crashme_output
98
, stderr = subprocess.STDOUT
100
crashme_subproc.wait()
101
retcode = crashme_subproc.returncode
102
execution_time = int(self.time_manager.stop(testcase_name)*1000) # millisec
104
crashme_output.close()
105
crashme_file = open(crashme_outfile,'r')
106
output = ''.join(crashme_file.readlines())
107
self.logging.debug(output)
110
self.logging.debug("crashme_retcode: %d" %(retcode))
111
self.current_test_retcode = retcode
112
self.current_test_output = output
113
self.current_test_exec_time = execution_time
115
def process_crashme_output(self):
116
if self.current_test_retcode == 0:
117
infile_name = self.current_test_output.split('\n')[3].split(':')[1].strip()
118
inf= open(infile_name, "r")
119
inlines= inf.readlines()
121
in_error_section = False
122
# crash-me is quite chatty and we don't normally want to sift
123
# through ALL of that stuff. We do allow seeing it via --verbose
125
self.current_test_output = ''
126
for inline in inlines:
127
if in_error_section and not inline.strip().startswith('#'):
128
in_error_section = False
129
if '=error' in inline:
131
in_error_section= True
133
self.current_test_output += inline