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

« back to all changes in this revision

Viewing changes to tests/lib/dbqp_modes/crashme/crashme_test_execution.py

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

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
""" crashme_test_execution:
 
23
    code related to the execution of crashme test cases 
 
24
    
 
25
    We are provided access to a testManager with 
 
26
    crashme-specific testCases.  
 
27
 
 
28
"""
 
29
 
 
30
# imports
 
31
import os
 
32
import re
 
33
import sys
 
34
import subprocess
 
35
import commands
 
36
 
 
37
import lib.test_mgmt.test_execution as test_execution
 
38
    
 
39
class testExecutor(test_execution.testExecutor):
 
40
    """ crashme-specific  executor """
 
41
 
 
42
    def execute_testCase (self):
 
43
        """ Execute a crashme testCase
 
44
 
 
45
        """
 
46
        test_execution.testExecutor.execute_testCase(self)
 
47
        self.status = 0
 
48
 
 
49
        self.prepare_config()
 
50
 
 
51
        # execute crashme
 
52
        self.execute_crashme()
 
53
 
 
54
        # analyze results
 
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)
 
58
 
 
59
    def prepare_config(self):
 
60
        """ Create the config file crash-me needs to execute """
 
61
 
 
62
        output_filename= "%s/drizzle.cfg" % (self.system_manager.workdir)
 
63
 
 
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)
 
68
  
 
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")
 
76
        output_file.flush()
 
77
        output_file.close()
 
78
 
 
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 
 
82
 
 
83
        """
 
84
 
 
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))
 
92
        
 
93
        crashme_subproc = subprocess.Popen( crashme_cmd
 
94
                                         , shell=True
 
95
                                         , cwd=os.path.join(self.system_manager.testdir, 'sql-bench')
 
96
                                         , env=self.working_environment
 
97
                                         , stdout = crashme_output
 
98
                                         , stderr = subprocess.STDOUT
 
99
                                         )
 
100
        crashme_subproc.wait()
 
101
        retcode = crashme_subproc.returncode     
 
102
        execution_time = int(self.time_manager.stop(testcase_name)*1000) # millisec
 
103
 
 
104
        crashme_output.close()
 
105
        crashme_file = open(crashme_outfile,'r')
 
106
        output = ''.join(crashme_file.readlines())
 
107
        self.logging.debug(output)
 
108
        crashme_file.close()
 
109
 
 
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
 
114
 
 
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()
 
120
            error_flag= False
 
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
 
124
            if not self.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:
 
130
                    error_flag= True
 
131
                    in_error_section= True
 
132
                if in_error_section:
 
133
                    self.current_test_output += inline
 
134
            inf.close()                
 
135
            if not error_flag:
 
136
                return 'pass'
 
137
        
 
138
        return 'fail'
 
139
 
 
140