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
27
utility / standard functions used when executing crashme
28
these methods are used by native mode / unittest cases
32
def prepare_config(bot):
33
""" Create the config file crash-me needs to execute """
35
output_filename= "%s/crashme.cfg" % (bot.system_manager.workdir)
37
# remove the existing configuration file to start fresh
38
if os.path.exists(output_filename):
39
logging.info("Removing %s" % output_filename)
40
os.remove(output_filename)
42
output_file= open(output_filename,"w")
43
# don't support '+' for concatenation
44
output_file.writelines("func_extra_concat_as_+=no\n")
45
# new boost libraries are causing us to put these limits in, needs investigation
46
output_file.writelines("max_text_size=1048576\n")
47
output_file.writelines("where_string_size=1048576\n")
48
output_file.writelines("select_string_size=1048576\n")
52
def execute_crashme(test_cmd, test_executor, servers):
53
""" Execute the commandline and return the result.
54
We use subprocess as we can pass os.environ dicts and whatnot
58
# prepare our config file
63
output_filename= "%s/crashme.cfg" % (bot.system_manager.workdir)
64
testcase_name = bot.current_testcase.fullname
65
crashme_outfile = os.path.join(bot.logdir,'crashme.out')
66
crashme_output = open(crashme_outfile,'w')
67
crashme_cmd = test_cmd + " --config-file=%s" %(output_filename)
68
bot.logging.info("Executing crash-me: %s" %(crashme_cmd))
69
bot.logging.info("This may take some time. Please be patient...")
71
crashme_subproc = subprocess.Popen( crashme_cmd
73
, cwd=os.path.join(bot.system_manager.testdir, 'sql-bench')
74
, env=bot.working_environment
75
, stdout = crashme_output
76
, stderr = subprocess.STDOUT
78
crashme_subproc.wait()
79
retcode = crashme_subproc.returncode
81
crashme_output.close()
82
crashme_file = open(crashme_outfile,'r')
83
output = ''.join(crashme_file.readlines())
84
bot.logging.debug(output)
87
bot.logging.debug("crashme_retcode: %d" %(retcode))
88
bot.current_test_retcode = retcode
89
bot.current_test_output = output
90
test_status = process_crashme_output(bot)
91
return test_status, retcode, bot.current_test_output
93
def process_crashme_output(bot):
94
if bot.current_test_retcode == 0:
96
output_data = bot.current_test_output.split('\n')
97
if output_data[0].startswith('Using an array as a reference is deprecated'):
101
infile_name = output_data[file_name_idx].split(':')[1].strip()
103
inf= open(infile_name, "r")
104
inlines= inf.readlines()
106
in_error_section = False
107
# crash-me is quite chatty and we don't normally want to sift
108
# through ALL of that stuff. We do allow seeing it via --verbose
110
bot.current_test_output = ''
111
for inline in inlines:
112
if in_error_section and not inline.strip().startswith('#'):
113
in_error_section = False
114
if '=error' in inline:
116
in_error_section= True
118
bot.current_test_output += inline
122
bot.current_test_output = None