Home | Trees | Indices | Help |
---|
|
1 ######################################################################## 2 # 3 # File: compilation_test.py 4 # Author: Stefan Seefeld 5 # Date: 2005-10-17 6 # 7 # Contents: 8 # CompilationTest 9 # CompiledResource 10 # ExecutableTest 11 # 12 # Copyright (c) 2005 by CodeSourcery, LLC. All rights reserved. 13 # 14 # For license terms see the file COPYING. 15 # 16 ######################################################################## 17 18 from compiler_test import CompilationStep, CompilerTest 19 from qm.fields import * 20 from qm.test.database import get_database 21 from qm.test.result import * 22 from qm.test.test import * 23 from qm.test.resource import * 24 import qm.executable 25 from qm.extension import parse_descriptor 26 from qm.test.base import get_extension_class 27 from compiler import Compiler 28 from local_host import LocalHost 29 3032 """Get a host instance according to a particular context variable. 33 Return a default 'LocalHost' host if the variable is undefined. 34 35 'context' -- The context to read the host descriptor from. 36 37 'variable' -- The name to which the host descriptor is bound. 38 39 returns -- A Host instance. 40 41 """ 42 43 target_desc = context.get(variable) 44 if target_desc is None: 45 target = LocalHost({}) 46 else: 47 f = lambda n: get_extension_class(n, "host", get_database()) 48 host_class, arguments = parse_descriptor(target_desc.strip(), f) 49 target = host_class(arguments) 50 return target51 52 53 ######################################################################## 54 # Classes 55 ######################################################################## 5658 """A CompilationTest compiles and optionally runs an executable. 59 CompilationTest allows simple cross-testing. To run the executable on 60 anything other than localhost, specify a Host descriptor by means of the 61 context variable 'CompilationTest.target'.""" 62 63 options = SetField(TextField(description="""Test-specific options to pass to the compiler.""")) 64 ldflags = SetField(TextField(description="""Test-specific link flags to pass to the compiler.""")) 65 source_files = SetField(TextField(description="Source files to be compiled.")) 66 executable = TextField(description="The name of the executable to be compiled.") 67 execute = BooleanField(default_value = True, 68 description="Whether or not to run the compiled executable.") 69 70114 11572 73 self._MakeDirectory(context) 74 CompilerTest.Run(self, context, result) 75 if self.execute: 76 self._RemoveDirectory(context, result)77 7880 """The name of the compiler executable is taken from the context variable 81 'CompilationTest.compiler_path'.""" 82 83 name = context["CompilationTest.compiler_path"] 84 options = context.GetStringList("CompilationTest.compiler_options", []) 85 ldflags = context.GetStringList("CompilationTest.compiler_ldflags", []) 86 return Compiler(name, options, ldflags)87 8890 91 # Compile the executable in a single step so we can apply all 92 # options at once. 93 return [CompilationStep(self._GetCompiler(context), 94 Compiler.MODE_LINK, self.source_files, 95 self.options, self.ldflags, self.executable, [])]96 97 101 102 106 107117 """A CompiledResource compiles an executable.""" 118 119 options = SetField(TextField(description="Resource-specific options to pass to the compiler.")) 120 source_files = SetField(TextField(description="Source files to be compiled.")) 121 executable = TextField(description="The name of the executable to be compiled.") 122 123143 144125 126 self._context = context 127 self._compiler = CompilationTest({'options':self.options, 128 'source_files':self.source_files, 129 'executable':self.executable, 130 'execute':False}, 131 qmtest_id = self.GetId(), 132 qmtest_database = self.GetDatabase()) 133 134 self._compiler.Run(context, result) 135 directory = self._compiler._GetDirectory(context) 136 self._executable = os.path.join(directory, self.executable) 137 context['CompiledResource.executable'] = self._executable138 139146 """An ExecuableTest runs an executable from a CompiledResource. 147 ExecutableTest allows simple cross-testing. To run the executable on 148 anything other than localhost, specify a Host descriptor by means of the 149 context variable 'ExecutableTest.host'.""" 150 151 args = SetField(TextField(description="Arguments to pass to the executable.")) 152162154 155 executable = context['CompiledResource.executable'] 156 host = _get_host(context, 'ExecutableTest.host') 157 status, output = host.UploadAndRun(executable, self.args) 158 if not result.CheckExitStatus('ExecutableTest.', 'Program', status): 159 result.Fail('Unexpected exit_code') 160 if output: 161 result['ExecutableTest.output'] = result.Quote(output)
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Dec 23 12:30:43 2011 | http://epydoc.sourceforge.net |