blob: 1b94bd301c25162c26de96c2e362010e15b1c32a [file] [log] [blame]
Karl Schimpfb262c5e2014-10-27 14:41:57 -07001# -*- Python -*-
Jim Stichnothf7c9a142014-04-29 10:52:43 -07002# Taken from utils/lit/tests in the LLVM tree and hacked together to support
3# our tests.
Karl Schimpfb262c5e2014-10-27 14:41:57 -07004#
5# Note: This configuration has simple commands to run Subzero's translator.
6# They have the form %X2i (i.e. %p2i, %l2i, and %lc2i) where X is defined
7# as follows:
8#
9# p : Run Subzero's translator, building ICE from PNaCl bitcode directly.
10# l : Run Subzero's translator, converting the .ll file to a PNaCl bitcode
11# file, reading in the bitcode file and generating LLVM IR, and
12# then convert LLVM IR to ICE IR.
13# lc : Run Subzero's translator, directly parsing the .ll file into LLVM IR,
14# and then convert it to ICE IR.
15#
16# These commands can be used in RUN lines by FileCheck. If the Subzero
17# build being tested lacks any required attributes (e.g., the ability
18# to parse .ll files), the command will simply return successfully,
19# generating no output. This allows translation tests to be able to
20# conditionally test the translator, based on the translator built.
21#
22# This conditional handling of translation introduces potential problems
23# when the output is piped to another command on a RUN line. Executables
24# like FileCheck expect non-empty input.
25#
26# To handle the problem that the pipe is conditional, any command that
27# doesn't accept empty input should be prefixed by a corresponding
28# %ifX (i.e. %p2i, %ifl, or %ifpc). Note: %p2i should always work, and
29# hence %ifp is not necessary (i.e. it is a nop).
30#
31# If you need to check other build attributes (other than the
32# existence of %l2i and %lc2i), you can use the %if command (which is
33# a short hand for using pydir/ifatts.py).
Jim Stichnothf7c9a142014-04-29 10:52:43 -070034
35import os
Jim Stichnothcc27a532014-06-26 13:32:27 -070036import re
Jim Stichnothf7c9a142014-04-29 10:52:43 -070037import sys
38
39import lit.formats
40
Jim Stichnoth7076c882014-09-08 12:57:52 -070041sys.path.insert(0, 'pydir')
Karl Schimpf6af63362014-10-29 14:55:00 -070042from utils import FindBaseNaCl, shellcmd
Jim Stichnoth7076c882014-09-08 12:57:52 -070043
Jim Stichnothf7c9a142014-04-29 10:52:43 -070044# name: The name of this test suite.
45config.name = 'subzero'
46
47# testFormat: The test format to use to interpret tests.
48config.test_format = lit.formats.ShTest()
49
50# suffixes: A list of file extensions to treat as test files.
Karl Schimpf6c17dd82015-06-30 10:25:27 -070051config.suffixes = ['.ll', '.test']
Jim Stichnothf7c9a142014-04-29 10:52:43 -070052
53# test_source_root: The root path where tests are located.
54config.test_source_root = os.path.dirname(__file__)
55config.test_exec_root = config.test_source_root
56config.target_triple = '(unused)'
57
Jim Stichnoth7076c882014-09-08 12:57:52 -070058src_root = os.path.join(FindBaseNaCl(), 'toolchain_build/src/subzero')
Jim Stichnothf7c9a142014-04-29 10:52:43 -070059bin_root = src_root
60config.substitutions.append(('%{src_root}', src_root))
61config.substitutions.append(('%{python}', sys.executable))
62
Jim Stichnoth7076c882014-09-08 12:57:52 -070063pydir = os.path.join(bin_root, 'pydir')
64
Jim Stichnoth0a9e1262015-04-21 09:59:21 -070065# Finding PNaCl binary tools. Tools used in the tests must be listed in the
66# pnaclbintools list.
67pnaclbinpath = os.path.abspath(os.environ.get('PNACL_BIN_PATH'))
Jan Vounga2703ae2015-02-19 11:27:44 -080068
Jim Stichnothfa0cfa52015-02-26 09:42:36 -080069# Define the location of the pnacl-sz tool.
70pnacl_sz_tool = os.path.join(bin_root, 'pnacl-sz')
71pnacl_sz_atts = shellcmd(' '.join([pnacl_sz_tool, '--build-atts']),
Karl Schimpf6af63362014-10-29 14:55:00 -070072 echo=False).split()
Karl Schimpf2a5324a2014-09-25 09:37:49 -070073
Jim Stichnothfa0cfa52015-02-26 09:42:36 -080074# Add build attributes of pnacl-sz tool to the set of available features.
75config.available_features.update(pnacl_sz_atts)
Karl Schimpf2a5324a2014-09-25 09:37:49 -070076
Karl Schimpf6af63362014-10-29 14:55:00 -070077def if_cond_flag(Value):
78 return '--cond=true' if Value else '--cond=false'
79
80# shell conditional commands.
81if_atts = [os.path.join(pydir, 'if.py')]
Jim Stichnothfa0cfa52015-02-26 09:42:36 -080082if_atts_cmd = if_atts + ['--have=' + att for att in pnacl_sz_atts]
83ifl2i_atts_cmd = if_atts + [if_cond_flag('allow_llvm_ir' in pnacl_sz_atts),
Karl Schimpf6af63362014-10-29 14:55:00 -070084 '--command']
85iflc2i_atts_cmd = if_atts + [if_cond_flag('allow_llvm_ir_as_input'
Jim Stichnothfa0cfa52015-02-26 09:42:36 -080086 in pnacl_sz_atts), '--command']
Karl Schimpf2a5324a2014-09-25 09:37:49 -070087
Jim Stichnothfa0cfa52015-02-26 09:42:36 -080088# Base command for running pnacl-sz
89pnacl_sz_cmd = [os.path.join(pydir, 'run-pnacl-sz.py'),
Reed Kotlerd91d3692016-01-21 18:47:28 -080090 '--echo-cmd',
Jim Stichnothfa0cfa52015-02-26 09:42:36 -080091 '--pnacl-sz', pnacl_sz_tool,
Jim Stichnoth0a9e1262015-04-21 09:59:21 -070092 '--pnacl-bin-path', pnaclbinpath]
David Sehrb19d39c2016-01-13 14:17:37 -080093if 'FORCEASM' in lit_config.params:
94 pnacl_sz_cmd += ['--forceasm']
Karl Schimpfb262c5e2014-10-27 14:41:57 -070095
96# Run commands only if corresponding build attributes apply, including
97# for each compiler setup.
98config.substitutions.append(('%ifp', ' '))
99config.substitutions.append(('%iflc', ' '.join(iflc2i_atts_cmd)))
100config.substitutions.append(('%ifl', ' '.join(ifl2i_atts_cmd)))
101config.substitutions.append(('%if', ' '.join(if_atts_cmd)))
102
103# Translate LLVM source for each compiler setup.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800104config.substitutions.append(('%p2i', ' '.join(pnacl_sz_cmd)))
105config.substitutions.append(('%l2i', ' '.join(ifl2i_atts_cmd + pnacl_sz_cmd
Karl Schimpfb262c5e2014-10-27 14:41:57 -0700106 + ['--llvm'])))
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800107config.substitutions.append(('%lc2i', ' '.join(iflc2i_atts_cmd + pnacl_sz_cmd
Karl Schimpfb262c5e2014-10-27 14:41:57 -0700108 + ['--llvm-source'])))
Karl Schimpf2a5324a2014-09-25 09:37:49 -0700109
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800110config.substitutions.append(('%pnacl_sz', pnacl_sz_tool))
Jim Stichnothf7c9a142014-04-29 10:52:43 -0700111
Karl Schimpf6c17dd82015-06-30 10:25:27 -0700112pnaclbintools = [r'\b' + x + r'\b' for x in
113 ['FileCheck',
Karl Schimpf6c17dd82015-06-30 10:25:27 -0700114 'llvm-as',
115 'llvm-mc',
116 'llvm-readobj',
117 'not',
118 'pnacl-bcdis',
119 'pnacl-bcfuzz',
120 'pnacl-freeze']]
Jim Stichnothf7c9a142014-04-29 10:52:43 -0700121
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700122for tool in pnaclbintools:
Jim Stichnothcc27a532014-06-26 13:32:27 -0700123 # The re.sub() line is adapted from one of LLVM's lit.cfg files.
124 # Extract the tool name from the pattern. This relies on the tool
125 # name being surrounded by \b word match operators. If the
126 # pattern starts with "| ", include it in the string to be
127 # substituted.
128 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700129 r"\2" + pnaclbinpath + "/" + r"\4",
Jan Vounga2703ae2015-02-19 11:27:44 -0800130 tool)
131 config.substitutions.append((tool, substitution))
132
Jim Stichnothf7c9a142014-04-29 10:52:43 -0700133# Add a feature to detect the Python version.
134config.available_features.add("python%d.%d" % (sys.version_info[0],
135 sys.version_info[1]))
136
137# Debugging output
138def dbg(s):
139 print '[DBG] %s' % s
140
141dbg('bin_root = %s' % bin_root)
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700142dbg('pnaclbinpath = %s' % pnaclbinpath)
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800143dbg("Build attributes = %s" % pnacl_sz_atts)