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

« back to all changes in this revision

Viewing changes to tests/lib/dbqp_modes/randgen/randgen_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) 2010 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
""" dtr_test_execution:
 
23
    code related to the execution of dtr test cases 
 
24
    
 
25
    We are provided access to a testManager with 
 
26
    randgen-specific testCases.  We contact the executionManager
 
27
    to produce the system and server configurations we need
 
28
    to execute a test.
 
29
 
 
30
"""
 
31
 
 
32
# imports
 
33
import os
 
34
import sys
 
35
import subprocess
 
36
import commands
 
37
 
 
38
import lib.test_mgmt.test_execution as test_execution
 
39
 
 
40
class testExecutor(test_execution.testExecutor):
 
41
    """ randgen-specific testExecutor 
 
42
 
 
43
    """
 
44
  
 
45
    def execute_testCase (self):
 
46
        """ Execute a randgen testCase
 
47
 
 
48
        """
 
49
        test_execution.testExecutor.execute_testCase(self)
 
50
        self.status = 0
 
51
 
 
52
        # execute the randgen
 
53
        self.execute_randgen()
 
54
 
 
55
        # analyze results
 
56
        self.current_test_status = self.process_randgen_output()
 
57
        self.set_server_status(self.current_test_status)
 
58
        self.server_manager.reset_servers(self.name)
 
59
 
 
60
 
 
61
    
 
62
 
 
63
    def execute_randgen(self):
 
64
        """ Execute the commandline and return the result.
 
65
            We use subprocess as we can pass os.environ dicts and whatnot 
 
66
 
 
67
        """
 
68
      
 
69
        testcase_name = self.current_testcase.fullname
 
70
        self.time_manager.start(testcase_name,'test')
 
71
        randgen_outfile = os.path.join(self.logdir,'randgen.out')
 
72
        randgen_output = open(randgen_outfile,'w')
 
73
        dsn = "--dsn=dbi:drizzle:host=localhost:port=%d:user=root:password="":database=test" %(self.master_server.master_port)
 
74
        randgen_cmd = " ".join([self.current_testcase.test_command, dsn])
 
75
        randgen_subproc = subprocess.Popen( randgen_cmd
 
76
                                         , shell=True
 
77
                                         , cwd=self.system_manager.randgen_path
 
78
                                         , env=self.working_environment
 
79
                                         , stdout = randgen_output
 
80
                                         , stderr = subprocess.STDOUT
 
81
                                         )
 
82
        randgen_subproc.wait()
 
83
        retcode = randgen_subproc.returncode     
 
84
        execution_time = int(self.time_manager.stop(testcase_name)*1000) # millisec
 
85
 
 
86
        randgen_output.close()
 
87
        randgen_file = open(randgen_outfile,'r')
 
88
        output = ''.join(randgen_file.readlines())
 
89
        self.logging.debug(output)
 
90
        randgen_file.close()
 
91
 
 
92
        self.logging.debug("randgen_retcode: %d" %(retcode))
 
93
        self.current_test_retcode = retcode
 
94
        self.current_test_output = output
 
95
        self.current_test_exec_time = execution_time
 
96
 
 
97
    def process_randgen_output(self):
 
98
        """ randgen has run, we now check out what we have """
 
99
        retcode = self.current_test_retcode
 
100
        if retcode == 0:
 
101
            return 'pass'
 
102
        else:
 
103
            return 'fail'
 
104