Home | History | Annotate | Download | only in test
      1 # -*- Python -*-
      2 
      3 # Configuration file for the 'lit' test runner.
      4 
      5 import os
      6 import sys
      7 import re
      8 
      9 # name: The name of this test suite.
     10 config.name = 'LLVM'
     11 
     12 # testFormat: The test format to use to interpret tests.
     13 config.test_format = lit.formats.TclTest()
     14 
     15 # To ignore test output on stderr so it doesn't trigger failures uncomment this:
     16 #config.test_format = lit.formats.TclTest(ignoreStdErr=True)
     17 
     18 # suffixes: A list of file extensions to treat as test files, this is actually
     19 # set by on_clone().
     20 config.suffixes = []
     21 
     22 # test_source_root: The root path where tests are located.
     23 config.test_source_root = os.path.dirname(__file__)
     24 
     25 # Tweak PATH for Win32
     26 if sys.platform in ['win32']:
     27     # Seek sane tools in directories and set to $PATH.
     28     path = getattr(config, 'lit_tools_dir', None)
     29     path = lit.getToolsPath(path,
     30                             config.environment['PATH'],
     31                             ['cmp.exe', 'grep.exe', 'sed.exe'])
     32     if path is not None:
     33         path = os.path.pathsep.join((path,
     34                                      config.environment['PATH']))
     35         config.environment['PATH'] = path
     36 
     37 # test_exec_root: The root path where tests should be run.
     38 llvm_obj_root = getattr(config, 'llvm_obj_root', None)
     39 if llvm_obj_root is not None:
     40     config.test_exec_root = os.path.join(llvm_obj_root, 'test')
     41 
     42 # Tweak the PATH to include the scripts dir, the tools dir, and the llvm-gcc bin
     43 # dir (if available).
     44 if llvm_obj_root is not None:
     45     # Include llvm-gcc first, as the llvm-gcc binaryies will not appear
     46     # neither in the tools nor in the scripts dir. However it might be
     47     # possible, that some old llvm tools are in the llvm-gcc dir. Adding
     48     # llvm-gcc dir first ensures, that those will always be overwritten
     49     # by the new tools in llvm_tools_dir. So now outdated tools are used
     50       # for testing
     51     llvmgcc_dir = getattr(config, 'llvmgcc_dir', None)
     52     if llvmgcc_dir:
     53         path = os.path.pathsep.join((os.path.join(llvmgcc_dir, 'bin'),
     54                                      config.environment['PATH']))
     55         config.environment['PATH'] = path
     56 
     57     llvm_src_root = getattr(config, 'llvm_src_root', None)
     58     if not llvm_src_root:
     59         lit.fatal('No LLVM source root set!')
     60     path = os.path.pathsep.join((os.path.join(llvm_src_root, 'test',
     61                                               'Scripts'),
     62                                  config.environment['PATH']))
     63     config.environment['PATH'] = path
     64 
     65     llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
     66     if not llvm_tools_dir:
     67         lit.fatal('No LLVM tools dir set!')
     68     path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
     69     config.environment['PATH'] = path
     70 
     71 # Propagate 'HOME' through the environment.
     72 if 'HOME' in os.environ:
     73     config.environment['HOME'] = os.environ['HOME']
     74 
     75 # Propagate 'INCLUDE' through the environment.
     76 if 'INCLUDE' in os.environ:
     77     config.environment['INCLUDE'] = os.environ['INCLUDE']
     78 
     79 # Propagate 'LIB' through the environment.
     80 if 'LIB' in os.environ:
     81     config.environment['LIB'] = os.environ['LIB']
     82 
     83 # Propagate the temp directory. Windows requires this because it uses \Windows\
     84 # if none of these are present.
     85 if 'TMP' in os.environ:
     86     config.environment['TMP'] = os.environ['TMP']
     87 if 'TEMP' in os.environ:
     88     config.environment['TEMP'] = os.environ['TEMP']
     89 
     90 # Propagate LLVM_SRC_ROOT into the environment.
     91 config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
     92 
     93 # Propagate PYTHON_EXECUTABLE into the environment
     94 config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
     95                                                   '')
     96 
     97 ###
     98 
     99 import os
    100 
    101 # Check that the object root is known.
    102 if config.test_exec_root is None:
    103     # Otherwise, we haven't loaded the site specific configuration (the user is
    104     # probably trying to run on a test file directly, and either the site
    105     # configuration hasn't been created by the build system, or we are in an
    106     # out-of-tree build situation).
    107 
    108     # Check for 'llvm_site_config' user parameter, and use that if available.
    109     site_cfg = lit.params.get('llvm_site_config', None)
    110     if site_cfg and os.path.exists(site_cfg):
    111         lit.load_config(config, site_cfg)
    112         raise SystemExit
    113 
    114     # Try to detect the situation where we are using an out-of-tree build by
    115     # looking for 'llvm-config'.
    116     #
    117     # FIXME: I debated (i.e., wrote and threw away) adding logic to
    118     # automagically generate the lit.site.cfg if we are in some kind of fresh
    119     # build situation. This means knowing how to invoke the build system
    120     # though, and I decided it was too much magic.
    121 
    122     llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
    123     if not llvm_config:
    124         lit.fatal('No site specific configuration available!')
    125 
    126     # Get the source and object roots.
    127     llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
    128     llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
    129 
    130     # Validate that we got a tree which points to here.
    131     this_src_root = os.path.dirname(config.test_source_root)
    132     if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
    133         lit.fatal('No site specific configuration available!')
    134 
    135     # Check that the site specific configuration exists.
    136     site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
    137     if not os.path.exists(site_cfg):
    138         lit.fatal('No site specific configuration available!')
    139 
    140     # Okay, that worked. Notify the user of the automagic, and reconfigure.
    141     lit.note('using out-of-tree build at %r' % llvm_obj_root)
    142     lit.load_config(config, site_cfg)
    143     raise SystemExit
    144 
    145 ###
    146 
    147 # Load site data from DejaGNU's site.exp.
    148 import re
    149 site_exp = {}
    150 # FIXME: Implement lit.site.cfg.
    151 for line in open(os.path.join(config.llvm_obj_root, 'test', 'site.exp')):
    152     m = re.match('set ([^ ]+) "(.*)"', line)
    153     if m:
    154         site_exp[m.group(1)] = m.group(2)
    155 
    156 # Add substitutions.
    157 config.substitutions.append(('%llvmgcc_only', site_exp['llvmgcc']))
    158 for sub in ['llvmgcc', 'llvmgxx', 'emitir', 'compile_cxx', 'compile_c',
    159             'link', 'shlibext', 'ocamlopt', 'llvmdsymutil', 'llvmlibsdir',
    160             'llvmshlibdir',
    161             'bugpoint_topts']:
    162     if sub in ('llvmgcc', 'llvmgxx'):
    163         config.substitutions.append(('%' + sub,
    164                                      site_exp[sub] + ' %emitir -w'))
    165     # FIXME: This is a hack to avoid LLVMC tests failing due to a clang driver
    166     #        warning when passing in "-fexceptions -fno-exceptions".
    167     elif sub == 'compile_cxx':
    168         config.substitutions.append(('%' + sub,
    169                                   site_exp[sub].replace('-fno-exceptions', '')))
    170     else:
    171         config.substitutions.append(('%' + sub, site_exp[sub]))
    172 
    173 # For each occurrence of an llvm tool name as its own word, replace it
    174 # with the full path to the build directory holding that tool.  This
    175 # ensures that we are testing the tools just built and not some random
    176 # tools that might happen to be in the user's PATH.  Thus this list
    177 # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
    178 # (llvm_tools_dir in lit parlance).
    179                 # Don't match 'bugpoint-' or 'clang-'.
    180                 # Don't match '/clang' or '-clang'.
    181 if os.pathsep == ';':
    182     pathext = os.environ.get('PATHEXT', '').split(';')
    183 else:
    184     pathext = ['']
    185 for pattern in [r"\bbugpoint\b(?!-)",   r"(?<!/|-)\bclang\b(?!-)",
    186                 r"\bgold\b",
    187                 r"\bllc\b",             r"\blli\b",
    188                 r"\bllvm-ar\b",         r"\bllvm-as\b",
    189                 r"\bllvm-bcanalyzer\b", r"\bllvm-config\b",
    190                 r"\bllvm-diff\b",       r"\bllvm-dis\b",
    191                 r"\bllvm-extract\b",    r"\bllvm-ld\b",
    192                 r"\bllvm-link\b",       r"\bllvm-mc\b",
    193                 r"\bllvm-nm\b",         r"\bllvm-prof\b",
    194                 r"\bllvm-ranlib\b",     r"\bllvm-shlib\b",
    195                 r"\bllvm-stub\b",       r"\bllvm2cpp\b",
    196                 # Don't match '-llvmc'.
    197                 r"(?<!-)\bllvmc\b",     r"\blto\b",
    198                                         # Don't match '.opt', '-opt',
    199                                         # '^opt' or '/opt'.
    200                 r"\bmacho-dump\b",      r"(?<!\.|-|\^|/)\bopt\b",
    201                 r"\bllvm-tblgen\b",     r"\bFileCheck\b",
    202                 r"\bFileUpdate\b",      r"\bc-index-test\b",
    203                 r"\bfpcmp\b",           r"\bllvm-PerfectShuffle\b",
    204                 # Handle these specially as they are strings searched
    205                 # for during testing.
    206                 r"\| \bcount\b",         r"\| \bnot\b"]:
    207     # Extract the tool name from the pattern.  This relies on the tool
    208     # name being surrounded by \b word match operators.  If the
    209     # pattern starts with "| ", include it in the string to be
    210     # substituted.
    211     substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
    212                           r"\2" + llvm_tools_dir + "/" + r"\4",
    213                           pattern)
    214     for ext in pathext:
    215         substitution_ext = substitution + ext
    216         if os.path.exists(substitution_ext):
    217              substitution = substitution_ext
    218              break
    219     config.substitutions.append((pattern, substitution))
    220 
    221 excludes = []
    222 
    223 # Provide target_triple for use in XFAIL and XTARGET.
    224 config.target_triple = site_exp['target_triplet']
    225 
    226 # When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the
    227 # triple so we can check it with XFAIL and XTARGET.
    228 config.target_triple += lit.valgrindTriple
    229 
    230 # Provide llvm_supports_target for use in local configs.
    231 targets = set(site_exp["TARGETS_TO_BUILD"].split())
    232 def llvm_supports_target(name):
    233     return name in targets
    234 
    235 def llvm_supports_darwin_and_target(name):
    236     return 'darwin' in config.target_triple and llvm_supports_target(name)
    237 
    238 bindings = set([s.strip() for s in site_exp['llvm_bindings'].split(',')])
    239 def llvm_supports_binding(name):
    240     return name.strip() in bindings
    241 
    242 # Provide on_clone hook for reading 'dg.exp'.
    243 import os
    244 simpleLibData = re.compile(r"""load_lib llvm.exp
    245 
    246 RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]""",
    247                            re.MULTILINE)
    248 conditionalLibData = re.compile(r"""load_lib llvm.exp
    249 
    250 if.*\[ ?(llvm[^ ]*) ([^ ]*) ?\].*{
    251  *RunLLVMTests \[lsort \[glob -nocomplain \$srcdir/\$subdir/\*\.(.*)\]\]
    252 \}""", re.MULTILINE)
    253 def on_clone(parent, cfg, for_path):
    254     def addSuffixes(match):
    255         if match[0] == '{' and match[-1] == '}':
    256             cfg.suffixes = ['.' + s for s in match[1:-1].split(',')]
    257         else:
    258             cfg.suffixes = ['.' + match]
    259 
    260     libPath = os.path.join(os.path.dirname(for_path),
    261                            'dg.exp')
    262     if not os.path.exists(libPath):
    263         cfg.unsupported = True
    264         return
    265 
    266     # Reset unsupported, in case we inherited it.
    267     cfg.unsupported = False
    268     lib = open(libPath).read().strip()
    269 
    270     # Check for a simple library.
    271     m = simpleLibData.match(lib)
    272     if m:
    273         addSuffixes(m.group(1))
    274         return
    275 
    276     # Check for a conditional test set.
    277     m = conditionalLibData.match(lib)
    278     if m:
    279         funcname,arg,match = m.groups()
    280         addSuffixes(match)
    281 
    282         func = globals().get(funcname)
    283         if not func:
    284             lit.error('unsupported predicate %r' % funcname)
    285         elif not func(arg):
    286             cfg.unsupported = True
    287         return
    288     # Otherwise, give up.
    289     lit.error('unable to understand %r:\n%s' % (libPath, lib))
    290 
    291 config.on_clone = on_clone
    292 
    293 ### Features
    294 
    295 # Shell execution
    296 if sys.platform not in ['win32'] or lit.getBashPath() != '':
    297     config.available_features.add('shell')
    298 
    299 # Loadable module
    300 # FIXME: This should be supplied by Makefile or autoconf.
    301 if sys.platform in ['win32', 'cygwin']:
    302     loadable_module = (config.enable_shared == 1)
    303 else:
    304     loadable_module = True
    305 
    306 if loadable_module:
    307     config.available_features.add('loadable_module')
    308 
    309 if config.enable_assertions:
    310     config.available_features.add('asserts')
    311