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

Source Code for Module qm.test.classes.compiler_table

  1  ######################################################################## 
  2  # 
  3  # File:   compiler_table.py 
  4  # Author: Mark Mitchell 
  5  # Date:   04/16/2003 
  6  # 
  7  # Contents: 
  8  #   CompilerTable 
  9  # 
 10  # Copyright (c) 2003 by CodeSourcery, LLC.  All rights reserved.  
 11  # 
 12  ######################################################################## 
 13   
 14  """Support for compiler test databases. 
 15   
 16  This module contains the 'CompilerTable' resource class which can be 
 17  used by compiler test databases to determine which compiler to test 
 18  based on context variables provided by the user.""" 
 19   
 20  ######################################################################## 
 21  # Imports 
 22  ######################################################################## 
 23   
 24  import compiler 
 25  import qm 
 26  from   qm.test.database import get_database 
 27  from   qm.test.resource import Resource 
 28  from   local_host import LocalHost 
 29   
 30  ######################################################################## 
 31  # Classes 
 32  ######################################################################## 
 33   
34 -class CompilerTable(Resource):
35 """A map from programming languages to 'Compiler's. 36 37 The 'CompilerTable' resource uses the context to determine which 38 compilers the user wants to test. Test databases containing 39 compiler tests should arrange for the tests they compain to depend 40 on a 'CompilerTable' resource. 41 42 The first context variable which is examined is 43 'CompilerTable.languages'. The value should be a 44 whitespace-separated list of programming language names. (See 45 below for standardized names for some languages.) 46 47 Then, for each language 'l' in the list of languages, the 48 following context variables are examined: 49 50 - 'CompilerTable.l_kind' 51 52 The kind of compiler (e.g., "GCC" or "EDG") used to compile 53 programs of language 'l'. The 'kind' must name a class derived 54 from 'Compiler'. 55 56 - 'CompilerTable.l_path' 57 58 The path to the compiler for language 'l'. This path may be 59 either absolute or relative. 60 61 - 'CompilerTable.l_options' 62 63 A whitespace-separated list of command-line options to provide 64 to the compiler for language 'l'. These options are passed to 65 the constructor for the 'Compiler' object; generally, all tests 66 are run with these options, followed by any test-specific 67 options. For example, if the user wants to test the compiler 68 when run with '-O2', the user would put '-O2' in the 'l_options' 69 context variable. 70 71 The 'CompilerTable' resource provides the following context 72 variables to all tests that depend upon the resource: 73 74 - 'CompilerTable.compilers' 75 76 The 'compilers' variable is a map from language names to 77 instances of 'Compiler'. Test classes should obtain the 78 'Compiler' to use when compiling source files by using this 79 map. 80 81 - 'CompilerTable.target' 82 83 An instance of 'Host' that can be used to run compiler 84 programs.""" 85 86 LANG_C = "c" 87 """The name of the C programming language.""" 88 89 LANG_CPLUSPLUS = "cplusplus" 90 """The name of the C++ programming language.""" 91
92 - def SetUp(self, context, result):
93 94 # There are no compilers yet. 95 compilers = {} 96 97 # See what programming languages are supported. 98 languages = context["CompilerTable.languages"].split() 99 100 # For each language, create a Compiler. 101 for l in languages: 102 # Retrieve information from the context. 103 kind = context["CompilerTable." + l + "_kind"].strip() 104 path = context["CompilerTable." + l + "_path"].strip() 105 # Look for (optional) command-line options. 106 opts = context.get("CompilerTable." + l + "_options", 107 "").split() 108 ldflags = context.get("CompilerTable." + l + "_ldflags", 109 "").split() 110 # Find the Python class corresponding to this compiler. 111 compiler_class = compiler.__dict__[kind] 112 # Instantiate the compiler. 113 c = compiler_class(path, opts) 114 c.SetLDFlags(ldflags) 115 # Store it in the compilers map. 116 compilers[l] = c 117 118 # Make the table available to tests. 119 context["CompilerTable.compilers"] = compilers 120 121 # For backwards compatibility, we recognize this old 122 # context variable here. 123 interpreter = context.get("CompilerTest.interpreter") 124 if interpreter: 125 interpreter = interpreter.split() 126 arguments = { simulator : interpreter[0], 127 simulator_args : interpreter[1:] } 128 target = qm.test.classes.Simulator(arguments) 129 else: 130 target_desc = context.get("CompilerTable.target") 131 if target_desc is None: 132 target = LocalHost({}) 133 else: 134 f = lambda n: qm.test.base.get_extension_class(n, "host", 135 get_database()) 136 host_class, arguments \ 137 = qm.extension.parse_descriptor(target_desc.strip(), f) 138 target = host_class(arguments) 139 context["CompilerTable.target"] = target
140