~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/kewpie/lib/util/crashme_methods.py

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (1.2.12) (2.1.19 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029154340-2gp39el6cv8bwf2o
Tags: 1:7.2.3-2ubuntu1
* Merge from debian, remaining changes:
  - Link against boost_system because of boost_thread.
  - Add required libs to message/include.am
  - Add upstart job and adjust init script to be upstart compatible.
  - Disable -floop-parallelize-all due to gcc-4.8/4.9 compiler ICE
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57732

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
# -*- mode: python; indent-tabs-mode: nil; -*-
3
 
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
 
#
5
 
# Copyright (C) 2011 Patrick Crews
6
 
#
7
 
#
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.
12
 
#
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.
17
 
#
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
21
 
 
22
 
import os
23
 
import subprocess
24
 
 
25
 
""" crashme_methods
26
 
 
27
 
    utility / standard functions used when executing crashme
28
 
    these methods are used by native mode / unittest cases
29
 
 
30
 
"""
31
 
 
32
 
def prepare_config(bot):
33
 
    """ Create the config file crash-me needs to execute """
34
 
 
35
 
    output_filename= "%s/crashme.cfg" % (bot.system_manager.workdir)
36
 
 
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)
41
 
  
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")
49
 
    output_file.flush()
50
 
    output_file.close()
51
 
 
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 
55
 
 
56
 
    """
57
 
 
58
 
    # prepare our config file
59
 
    bot = test_executor
60
 
    prepare_config(bot)
61
 
        
62
 
 
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...")
70
 
        
71
 
    crashme_subproc = subprocess.Popen( crashme_cmd
72
 
                                      , shell=True
73
 
                                      , cwd=os.path.join(bot.system_manager.testdir, 'sql-bench')
74
 
                                      , env=bot.working_environment
75
 
                                      , stdout = crashme_output
76
 
                                      , stderr = subprocess.STDOUT
77
 
                                      )
78
 
    crashme_subproc.wait()
79
 
    retcode = crashme_subproc.returncode     
80
 
 
81
 
    crashme_output.close()
82
 
    crashme_file = open(crashme_outfile,'r')
83
 
    output = ''.join(crashme_file.readlines())
84
 
    bot.logging.debug(output)
85
 
    crashme_file.close()
86
 
 
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
92
 
 
93
 
def process_crashme_output(bot):
94
 
    if bot.current_test_retcode == 0:
95
 
 
96
 
        output_data = bot.current_test_output.split('\n')
97
 
        if output_data[0].startswith('Using an array as a reference is deprecated'):
98
 
            file_name_idx = 6
99
 
        else:
100
 
            file_name_idx = 3
101
 
        infile_name = output_data[file_name_idx].split(':')[1].strip()
102
 
        output_data = None
103
 
        inf= open(infile_name, "r")
104
 
        inlines= inf.readlines()
105
 
        error_flag= False
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
109
 
        if not bot.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:
115
 
                error_flag= True
116
 
                in_error_section= True
117
 
            if in_error_section:
118
 
                bot.current_test_output += inline
119
 
        inf.close()                
120
 
        if not error_flag:
121
 
            if not bot.verbose:
122
 
                bot.current_test_output = None
123
 
            return 'pass'
124
 
        return 'fail'
125
 
 
126
 
 
127