Package qm :: Package test :: Package classes :: Module compilation_test_database
[hide private]
[frames] | no frames]

Source Code for Module qm.test.classes.compilation_test_database

  1  ######################################################################## 
  2  # 
  3  # File:   compilation_test_database.py 
  4  # Author: Stefan Seefeld 
  5  # Date:   2006-07-28 
  6  # 
  7  # Contents: 
  8  #   CompilationTestDatabase. 
  9  # 
 10  # Copyright (c) 2006 by CodeSourcery, Inc.  All rights reserved.  
 11  # 
 12  # For license terms see the file COPYING. 
 13  # 
 14  ######################################################################## 
 15   
 16  ######################################################################## 
 17  # imports 
 18  ######################################################################## 
 19   
 20  import os, dircache 
 21  from   qm.common import parse_string_list 
 22  from   qm.extension import get_class_arguments 
 23  from   qm.fields import * 
 24  import qm.label 
 25  import qm.structured_text 
 26  import qm.test.base 
 27  from   qm.test.database import * 
 28  from   qm.test.suite import * 
 29  from   qm.test import context 
 30  from   qm.test.classes.explicit_suite import ExplicitSuite 
 31  from   qm.test.classes import compilation_test 
 32  from   qm.test.classes.compiler import Compiler 
 33  from   qm.test.classes.compiler_test import CompilationStep 
 34  from   qm.test.classes.compiler_table import CompilerTable 
 35   
 36  ######################################################################## 
 37  # classes 
 38  ######################################################################## 
 39   
40 -class CompilationTest(compilation_test.CompilationTest):
41 """A CompilationTest fetches compilation parameters from environment 42 variables CPPFLAGS, <lang>_options, and <lang>_ldflags in addition 43 to the CompilerTable-related parameters.""" 44 45 options = SetField(TextField(), computed="true") 46 ldflags = SetField(TextField(), computed="true") 47 source_files = SetField(TextField(), computed="true") 48 executable = TextField(computed="true") 49 language = TextField() 50 51
52 - def _GetCompilationSteps(self, c):
53 54 lang = self.language 55 compiler = c['CompilerTable.compilers'][lang] 56 label_components = self.GetDatabase().GetLabelComponents(self.GetId()) 57 label_components[-1] = os.path.splitext(label_components[-1])[0] 58 selector = '.'.join(label_components) 59 path = c.GetDerivedValue(selector, lang + '_path') 60 if path: 61 compiler = Compiler(path, compiler.GetOptions(), compiler.GetLDFlags()) 62 options = (parse_string_list(c.GetDerivedValue( 63 selector, 'CPPFLAGS', '')) + 64 parse_string_list(c.GetDerivedValue( 65 selector, lang + '_options', ''))) 66 ldflags = (parse_string_list(c.GetDerivedValue( 67 selector, lang + '_ldflags', ''))) 68 69 return [CompilationStep(compiler, 70 Compiler.MODE_LINK, self.source_files, 71 self.options + options, 72 self.ldflags + ldflags, 73 self.executable, [])]
74 75
76 -class CompilationTestDatabase(Database):
77 """A 'CompilationTestDatabase' test database maps source code files to 78 compilation tests.""" 79 80 srcdir = TextField(title = "Source Directory", 81 description = "The root of the test suite's source tree.") 82 excluded_subdirs = SetField(TextField(), 83 default_value = ['QMTest', 'CVS', '.svn', 'build']) 84 test_extensions = DictionaryField(TextField(), 85 EnumerationField(enumerals = ['c', 'cplusplus']), 86 default_value = {'.c':'c', 87 '.cpp':'cplusplus', 88 '.cxx':'cplusplus', 89 '.cc':'cplusplus', 90 '.C':'cplusplus', 91 '.f':'fortran'}) 92 _is_generic_database = True 93 94
95 - def __init__(self, path, arguments):
96 97 self.label_class = "file_label.FileLabel" 98 self.modifiable = "false" 99 # Initialize the base class. 100 super(CompilationTestDatabase, self).__init__(path, **arguments)
101 102
103 - def GetSubdirectories(self, directory):
104 105 dirname = os.path.join(self.srcdir, directory) 106 return [subdir for subdir in dircache.listdir(dirname) 107 if (os.path.isdir(os.path.join(dirname, subdir)) and 108 subdir not in self.excluded_subdirs)]
109 110
111 - def GetIds(self, kind, directory = '', scan_subdirs = 1):
112 113 dirname = os.path.join(self.srcdir, directory) 114 if not os.path.isdir(dirname): 115 raise NoSuchSuiteError, directory 116 117 if kind == Database.TEST: 118 ids = [self.JoinLabels(directory, f) 119 for f in dircache.listdir(dirname) 120 if (os.path.isfile(os.path.join(dirname, f)) and 121 os.path.splitext(f)[1] in self.test_extensions)] 122 123 elif kind == Database.RESOURCE: 124 ids = [] 125 126 else: # SUITE 127 ids = [self.JoinLabels(directory, d) 128 for d in self.GetSubdirectories(directory) 129 if d not in self.excluded_subdirs] 130 131 if scan_subdirs: 132 for subdir in dircache.listdir(dirname): 133 if (subdir not in self.excluded_subdirs 134 and os.path.isdir(os.path.join(dirname, subdir))): 135 dir = self.JoinLabels(directory, subdir) 136 ids.extend(self.GetIds(kind, dir, True)) 137 138 return ids
139 140
141 - def GetExtension(self, id):
142 143 if not id: 144 return DirectorySuite(self, id) 145 146 elif id == 'compiler_table': 147 return CompilerTable({}, 148 qmtest_id = id, 149 qmtest_database = self) 150 151 id_components = self.GetLabelComponents(id) 152 file_ext = os.path.splitext(id_components[-1])[1] 153 if (file_ext in self.test_extensions and 154 os.path.isfile(os.path.join(self.srcdir, id))): 155 return self._MakeTest(id, self.test_extensions[file_ext]) 156 157 elif os.path.isdir(os.path.join(self.srcdir, id)): 158 basename = os.path.basename(id) 159 if not basename in self.excluded_subdirs: 160 return DirectorySuite(self, id) 161 162 else: 163 return None
164 165
166 - def _MakeTest(self, test_id, language):
167 168 169 src = os.path.abspath(os.path.join(self.srcdir, test_id)) 170 # Construct a unique name for the executable as it may be 171 # kept for failure analysis. 172 executable = os.path.splitext(os.path.basename(test_id))[0] 173 if sys.platform == 'win32': 174 executable += '.exe' 175 176 resources = ['compiler_table'] 177 arguments = {} 178 arguments['language'] = language 179 arguments['source_files'] = [src] 180 arguments['executable'] = executable 181 arguments['resources'] = resources 182 183 return CompilationTest(arguments, 184 qmtest_id = test_id, 185 qmtest_database = self)
186