2 # Taken from utils/lit/tests in the LLVM tree and hacked together to support
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
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.
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.
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.
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).
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).
41 sys.path.insert(0, 'pydir')
42 from utils import FindBaseNaCl, shellcmd
44 # name: The name of this test suite.
45 config.name = 'subzero'
47 # testFormat: The test format to use to interpret tests.
48 config.test_format = lit.formats.ShTest()
50 # suffixes: A list of file extensions to treat as test files.
51 config.suffixes = ['.ll', '.test']
53 # test_source_root: The root path where tests are located.
54 config.test_source_root = os.path.dirname(__file__)
55 config.test_exec_root = config.test_source_root
56 config.target_triple = '(unused)'
58 src_root = os.path.join(FindBaseNaCl(), 'toolchain_build/src/subzero')
60 config.substitutions.append(('%{src_root}', src_root))
61 config.substitutions.append(('%{python}', sys.executable))
63 pydir = os.path.join(bin_root, 'pydir')
65 # Finding PNaCl binary tools. Tools used in the tests must be listed in the
67 pnaclbinpath = os.path.abspath(os.environ.get('PNACL_BIN_PATH'))
69 # Define the location of the pnacl-sz tool.
70 pnacl_sz_tool = os.path.join(bin_root, 'pnacl-sz')
71 pnacl_sz_atts = shellcmd(' '.join([pnacl_sz_tool, '--build-atts']),
74 # Add build attributes of pnacl-sz tool to the set of available features.
75 config.available_features.update(pnacl_sz_atts)
77 def if_cond_flag(Value):
78 return '--cond=true' if Value else '--cond=false'
80 # shell conditional commands.
81 if_atts = [os.path.join(pydir, 'if.py')]
82 if_atts_cmd = if_atts + ['--have=' + att for att in pnacl_sz_atts]
83 ifl2i_atts_cmd = if_atts + [if_cond_flag('allow_llvm_ir' in pnacl_sz_atts),
85 iflc2i_atts_cmd = if_atts + [if_cond_flag('allow_llvm_ir_as_input'
86 in pnacl_sz_atts), '--command']
88 # Base command for running pnacl-sz
89 pnacl_sz_cmd = [os.path.join(pydir, 'run-pnacl-sz.py'),
91 '--pnacl-sz', pnacl_sz_tool,
92 '--pnacl-bin-path', pnaclbinpath]
93 if 'FORCEASM' in lit_config.params:
94 pnacl_sz_cmd += ['--forceasm']
96 # Run commands only if corresponding build attributes apply, including
97 # for each compiler setup.
98 config.substitutions.append(('%ifp', ' '))
99 config.substitutions.append(('%iflc', ' '.join(iflc2i_atts_cmd)))
100 config.substitutions.append(('%ifl', ' '.join(ifl2i_atts_cmd)))
101 config.substitutions.append(('%if', ' '.join(if_atts_cmd)))
103 # Translate LLVM source for each compiler setup.
104 config.substitutions.append(('%p2i', ' '.join(pnacl_sz_cmd)))
105 config.substitutions.append(('%l2i', ' '.join(ifl2i_atts_cmd + pnacl_sz_cmd
107 config.substitutions.append(('%lc2i', ' '.join(iflc2i_atts_cmd + pnacl_sz_cmd
108 + ['--llvm-source'])))
110 config.substitutions.append(('%pnacl_sz', pnacl_sz_tool))
112 pnaclbintools = [r'\b' + x + r'\b' for x in
122 for tool in pnaclbintools:
123 # 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
128 substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
129 r"\2" + pnaclbinpath + "/" + r"\4",
131 config.substitutions.append((tool, substitution))
133 # Add a feature to detect the Python version.
134 config.available_features.add("python%d.%d" % (sys.version_info[0],
135 sys.version_info[1]))
141 dbg('bin_root = %s' % bin_root)
142 dbg('pnaclbinpath = %s' % pnaclbinpath)
143 dbg("Build attributes = %s" % pnacl_sz_atts)