| # Taken from utils/lit/tests in the LLVM tree and hacked together to support |
| # our tests. |
| |
| # -*- Python -*- |
| |
| import os |
| import re |
| import sys |
| |
| import lit.formats |
| |
| sys.path.insert(0, 'pydir') |
| from utils import FindBaseNaCl |
| |
| # name: The name of this test suite. |
| config.name = 'subzero' |
| |
| # testFormat: The test format to use to interpret tests. |
| config.test_format = lit.formats.ShTest() |
| |
| # suffixes: A list of file extensions to treat as test files. |
| config.suffixes = ['.ll'] |
| |
| # test_source_root: The root path where tests are located. |
| config.test_source_root = os.path.dirname(__file__) |
| config.test_exec_root = config.test_source_root |
| config.target_triple = '(unused)' |
| |
| src_root = os.path.join(FindBaseNaCl(), 'toolchain_build/src/subzero') |
| bin_root = src_root |
| config.substitutions.append(('%{src_root}', src_root)) |
| config.substitutions.append(('%{python}', sys.executable)) |
| |
| pydir = os.path.join(bin_root, 'pydir') |
| |
| # Finding LLVM binary tools. All tools used in the tests must be listed in |
| # the llvmbintools list. |
| llvmbinpath = os.path.abspath(os.environ.get('LLVM_BIN_PATH')) |
| |
| # Finding Subzero tools |
| llvm2icetool = os.path.join(bin_root, 'llvm2ice') |
| |
| # Convert LLVM source to PNaCl bitcode, read using the |
| # Subzero bitcode reader, and then translate. |
| config.substitutions.append( |
| ('%p2i', ' '.join([os.path.join(pydir, 'run-llvm2ice.py'), |
| '--llvm2ice', llvm2icetool, |
| '--llvm-bin-path', llvmbinpath |
| ]))) |
| |
| # Convert LLVM source to PNaCl bitcode, read using the PNaCl bitcode reader, |
| # convert to ICE using the ICE Converter, and then translate. |
| # TODO(kschimpf) Deprecated, remove once p2i working. |
| config.substitutions.append( |
| ('%l2i', ' '.join([os.path.join(pydir, 'run-llvm2ice.py'), |
| '--llvm', '--llvm2ice', llvm2icetool, |
| '--llvm-bin-path', llvmbinpath |
| ]))) |
| |
| # Read LLVM source, convert to ICE using the ICE converter, and then translate. |
| # Note: l2i is preferred over lc2i, since it uses PNaCl bitcode. |
| # TODO(kschimpf) Deprecated, remove once p2i working. |
| config.substitutions.append( |
| ('%lc2i', ' '.join([os.path.join(pydir, 'run-llvm2ice.py'), |
| '--llvm-source', '--llvm2ice', llvm2icetool, |
| '--llvm-bin-path', llvmbinpath |
| ]))) |
| |
| config.substitutions.append(('%llvm2ice', llvm2icetool)) |
| config.substitutions.append(('%szdiff', os.path.join(pydir, 'szdiff.py'))) |
| |
| llvmbintools = [r"\bFileCheck\b", r"\bllvm-as\b", r"\bllvm-mc\b", |
| r"\bllvm-objdump\b", r"\bnot\b", r"\bpnacl-freeze\b", |
| r"\bpnacl-bcdis\b"] |
| |
| for tool in llvmbintools: |
| # The re.sub() line is adapted from one of LLVM's lit.cfg files. |
| # Extract the tool name from the pattern. This relies on the tool |
| # name being surrounded by \b word match operators. If the |
| # pattern starts with "| ", include it in the string to be |
| # substituted. |
| substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$", |
| r"\2" + llvmbinpath + "/" + r"\4", |
| tool) |
| config.substitutions.append((tool, substitution)) |
| |
| # Add a feature to detect the Python version. |
| config.available_features.add("python%d.%d" % (sys.version_info[0], |
| sys.version_info[1])) |
| |
| # Debugging output |
| def dbg(s): |
| print '[DBG] %s' % s |
| |
| dbg('bin_root = %s' % bin_root) |
| dbg('llvmbinpath = %s' % llvmbinpath) |