Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 4af1a22

Browse files
author
Zachary Turner
committed
Resubmit "Add a shared llvm.lit module that all test suites can use."
There were some issues surrounding Py2 / Py3 compatibility, but I've now tested with both Py2 and Py3 and everything seems to work. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313467 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d0c8c61 commit 4af1a22

6 files changed

Lines changed: 171 additions & 157 deletions

File tree

cmake/modules/AddLLVM.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,10 @@ function(configure_lit_site_cfg input output)
11731173
set(TARGET_TRIPLE "\"+config.target_triple+\"")
11741174
endif()
11751175

1176+
string(CONCAT LIT_SITE_CFG_IN_FOOTER
1177+
"import lit.llvm\n"
1178+
"lit.llvm.initialize(lit_config, config)\n")
1179+
11761180
configure_file(${input} ${output} @ONLY)
11771181
get_filename_component(INPUT_DIR ${input} DIRECTORY)
11781182
if (EXISTS "${INPUT_DIR}/lit.cfg")

test/lit.cfg

Lines changed: 16 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,13 @@ import subprocess
1010

1111
import lit.util
1212
import lit.formats
13+
from lit.llvm import llvm_config
1314

1415
# name: The name of this test suite.
1516
config.name = 'LLVM'
1617

17-
# Tweak PATH for Win32 to decide to use bash.exe or not.
18-
if sys.platform in ['win32']:
19-
# Seek sane tools in directories and set to $PATH.
20-
path = getattr(config, 'lit_tools_dir', None)
21-
path = lit_config.getToolsPath(path,
22-
config.environment['PATH'],
23-
['cmp.exe', 'grep.exe', 'sed.exe'])
24-
if path is not None:
25-
path = os.path.pathsep.join((path,
26-
config.environment['PATH']))
27-
config.environment['PATH'] = path
28-
29-
# Choose between lit's internal shell pipeline runner and a real shell. If
30-
# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
31-
use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
32-
if use_lit_shell:
33-
# 0 is external, "" is default, and everything else is internal.
34-
execute_external = (use_lit_shell == "0")
35-
else:
36-
# Otherwise we default to internal on Windows and external elsewhere, as
37-
# bash on Windows is usually very slow.
38-
execute_external = (not sys.platform in ['win32'])
39-
4018
# testFormat: The test format to use to interpret tests.
41-
config.test_format = lit.formats.ShTest(execute_external)
19+
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
4220

4321
# suffixes: A list of file extensions to treat as test files. This is overriden
4422
# by individual lit.local.cfg files in the test subdirectories.
@@ -56,57 +34,27 @@ config.test_source_root = os.path.dirname(__file__)
5634
config.test_exec_root = os.path.join(config.llvm_obj_root, 'test')
5735

5836
# Tweak the PATH to include the tools dir.
59-
path = os.path.pathsep.join((config.llvm_tools_dir, config.environment['PATH']))
60-
config.environment['PATH'] = path
61-
62-
# Propagate 'HOME' through the environment.
63-
if 'HOME' in os.environ:
64-
config.environment['HOME'] = os.environ['HOME']
37+
llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
6538

66-
# Propagate 'INCLUDE' through the environment.
67-
if 'INCLUDE' in os.environ:
68-
config.environment['INCLUDE'] = os.environ['INCLUDE']
69-
70-
# Propagate 'LIB' through the environment.
71-
if 'LIB' in os.environ:
72-
config.environment['LIB'] = os.environ['LIB']
73-
74-
# Propagate the temp directory. Windows requires this because it uses \Windows\
75-
# if none of these are present.
76-
if 'TMP' in os.environ:
77-
config.environment['TMP'] = os.environ['TMP']
78-
if 'TEMP' in os.environ:
79-
config.environment['TEMP'] = os.environ['TEMP']
39+
# Propagate some variables from the host environment.
40+
llvm_config.with_system_environment(['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP', 'ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
8041

8142
# Propagate LLVM_SRC_ROOT into the environment.
8243
config.environment['LLVM_SRC_ROOT'] = config.llvm_src_root
8344

84-
# Propagate PYTHON_EXECUTABLE into the environment
85-
config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
86-
'')
87-
88-
# Propagate path to symbolizer for ASan/MSan.
89-
for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
90-
if symbolizer in os.environ:
91-
config.environment[symbolizer] = os.environ[symbolizer]
92-
9345
# Set up OCAMLPATH to include newly built OCaml libraries.
9446
top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml')
9547
llvm_ocaml_lib = os.path.join(top_ocaml_lib, 'llvm')
96-
ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, top_ocaml_lib))
97-
if 'OCAMLPATH' in os.environ:
98-
ocamlpath = os.path.pathsep.join((ocamlpath, os.environ['OCAMLPATH']))
99-
config.environment['OCAMLPATH'] = ocamlpath
100-
101-
if 'CAML_LD_LIBRARY_PATH' in os.environ:
102-
caml_ld_library_path = os.path.pathsep.join((llvm_ocaml_lib,
103-
os.environ['CAML_LD_LIBRARY_PATH']))
104-
config.environment['CAML_LD_LIBRARY_PATH'] = caml_ld_library_path
105-
else:
106-
config.environment['CAML_LD_LIBRARY_PATH'] = llvm_ocaml_lib
48+
49+
llvm_config.with_system_environment('OCAMLPATH')
50+
llvm_config.with_environment('OCAMLPATH', top_ocaml_lib, append_path=True)
51+
llvm_config.with_environment('OCAMLPATH', llvm_ocaml_lib, append_path=True)
52+
53+
llvm_config.with_system_environment('CAML_LD_LIBRARY_PATH')
54+
llvm_config.with_environment('CAML_LD_LIBRARY_PATH', llvm_ocaml_lib, append_path=True)
10755

10856
# Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
109-
config.environment['OCAMLRUNPARAM'] = 'b'
57+
llvm_config.with_environment('OCAMLRUNPARAM', 'b')
11058

11159
# Provide the path to asan runtime lib 'libclang_rt.asan_osx_dynamic.dylib' if
11260
# available. This is darwin specific since it's currently only needed on darwin.
@@ -300,10 +248,6 @@ for arch in config.targets_to_build.split():
300248

301249
### Features
302250

303-
# Shell execution
304-
if execute_external:
305-
config.available_features.add('shell')
306-
307251
# Others/can-execute.txt
308252
if sys.platform not in ['win32']:
309253
config.available_features.add('can-execute')
@@ -323,45 +267,14 @@ if loadable_module:
323267
if not config.build_shared_libs:
324268
config.available_features.add("static-libs")
325269

326-
# Sanitizers.
327-
if 'Address' in config.llvm_use_sanitizer:
328-
config.available_features.add("asan")
329-
else:
330-
config.available_features.add("not_asan")
331-
if 'Memory' in config.llvm_use_sanitizer:
332-
config.available_features.add("msan")
333-
else:
334-
config.available_features.add("not_msan")
335-
if 'Undefined' in config.llvm_use_sanitizer:
336-
config.available_features.add("ubsan")
337-
else:
338-
config.available_features.add("not_ubsan")
339-
340-
# Check if we should run long running tests.
341-
if lit_config.params.get("run_long_tests", None) == "true":
342-
config.available_features.add("long_tests")
343-
344270
# Direct object generation
345271
if not 'hexagon' in config.target_triple:
346272
config.available_features.add("object-emission")
347273

348-
if config.have_zlib:
349-
config.available_features.add("zlib")
350-
else:
351-
config.available_features.add("nozlib")
352-
353274
# LLVM can be configured with an empty default triple
354275
# Some tests are "generic" and require a valid default triple
355276
if config.target_triple:
356277
config.available_features.add("default_triple")
357-
if re.match(r'^x86_64.*-linux', config.target_triple):
358-
config.available_features.add("x86_64-linux")
359-
360-
# Native compilation: host arch == default triple arch
361-
# FIXME: Consider cases that target can be executed
362-
# even if host_triple were different from target_triple.
363-
if config.host_triple == config.target_triple:
364-
config.available_features.add("native")
365278

366279
import subprocess
367280

@@ -416,19 +329,9 @@ def have_ld64_plugin_support():
416329
if have_ld64_plugin_support():
417330
config.available_features.add('ld64_plugin')
418331

419-
# Ask llvm-config about assertion mode.
420-
try:
421-
llvm_config_cmd = subprocess.Popen(
422-
[os.path.join(config.llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
423-
stdout = subprocess.PIPE,
424-
env=config.environment)
425-
except OSError:
426-
print("Could not find llvm-config in " + config.llvm_tools_dir)
427-
exit(42)
428-
429-
if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
430-
config.available_features.add('asserts')
431-
llvm_config_cmd.wait()
332+
# Ask llvm-config about asserts and global-isel.
333+
llvm_config.feature_config('--assertion-mode', 'asserts')
334+
llvm_config.feature_config('--has-global-isel', 'global-isel')
432335

433336
if 'darwin' == sys.platform:
434337
try:
@@ -441,56 +344,12 @@ if 'darwin' == sys.platform:
441344
config.available_features.add('fma3')
442345
sysctl_cmd.wait()
443346

444-
if platform.system() in ['Windows']:
445-
if re.match(r'.*-win32$', config.target_triple):
446-
config.available_features.add('target-windows')
447-
# For tests that require Windows to run.
448-
config.available_features.add('system-windows')
449-
450347
# .debug_frame is not emitted for targeting Windows x64.
451348
if not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
452349
config.available_features.add('debug_frame')
453350

454-
# Check if we should use gmalloc.
455-
use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
456-
if use_gmalloc_str is not None:
457-
if use_gmalloc_str.lower() in ('1', 'true'):
458-
use_gmalloc = True
459-
elif use_gmalloc_str.lower() in ('', '0', 'false'):
460-
use_gmalloc = False
461-
else:
462-
lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
463-
else:
464-
# Default to not using gmalloc
465-
use_gmalloc = False
466-
467-
# Allow use of an explicit path for gmalloc library.
468-
# Will default to '/usr/lib/libgmalloc.dylib' if not set.
469-
gmalloc_path_str = lit_config.params.get('gmalloc_path',
470-
'/usr/lib/libgmalloc.dylib')
471-
472-
if use_gmalloc:
473-
config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})
474-
475-
# Ask llvm-config about global-isel.
476-
try:
477-
llvm_config_cmd = subprocess.Popen(
478-
[os.path.join(config.llvm_tools_dir, 'llvm-config'), '--has-global-isel'],
479-
stdout = subprocess.PIPE,
480-
env=config.environment)
481-
except OSError:
482-
print("Could not find llvm-config in " + config.llvm_tools_dir)
483-
exit(42)
484-
485-
if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
486-
config.available_features.add('global-isel')
487-
llvm_config_cmd.wait()
488-
489351
if config.have_libxar:
490352
config.available_features.add('xar')
491353

492-
if config.enable_abi_breaking_checks == "1":
493-
config.available_features.add('abi-breaking-checks')
494-
495354
if config.llvm_libxml2_enabled == "1":
496355
config.available_features.add('libxml2')

test/lit.site.cfg.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,7 @@ except KeyError:
5252
key, = e.args
5353
lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
5454

55+
@LIT_SITE_CFG_IN_FOOTER@
56+
5557
# Let the main config do the real work.
5658
lit_config.load_config(config, "@LLVM_SOURCE_DIR@/test/lit.cfg")

utils/lit/lit/llvm/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
from lit.llvm import config
3+
4+
llvm_config = None
5+
6+
def initialize(lit_config, test_config):
7+
global llvm_config
8+
llvm_config = config.LLVMConfig(lit_config, test_config)
9+

utils/lit/lit/llvm/config.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import os
2+
import re
3+
import subprocess
4+
import sys
5+
6+
import lit.util
7+
8+
# Choose between lit's internal shell pipeline runner and a real shell. If
9+
# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
10+
litshenv = os.environ.get("LIT_USE_INTERNAL_SHELL")
11+
litsh = lit.util.pythonize_bool(litshenv) if litshenv else (sys.platform == 'win32')
12+
13+
def binary_feature(on, feature, off_prefix):
14+
return feature if on else off_prefix + feature
15+
16+
class LLVMConfig(object):
17+
18+
def __init__(self, lit_config, config):
19+
self.lit_config = lit_config
20+
self.config = config
21+
22+
features = config.available_features
23+
24+
# Tweak PATH for Win32 to decide to use bash.exe or not.
25+
if sys.platform == 'win32':
26+
# For tests that require Windows to run.
27+
features.add('system-windows')
28+
29+
# Seek sane tools in directories and set to $PATH.
30+
path = self.lit_config.getToolsPath(config.lit_tools_dir,
31+
config.environment['PATH'],
32+
['cmp.exe', 'grep.exe', 'sed.exe'])
33+
self.with_environment('PATH', path, append_path=True)
34+
35+
self.use_lit_shell = litsh
36+
if not self.use_lit_shell:
37+
features.add('shell')
38+
39+
# Native compilation: host arch == default triple arch
40+
# FIXME: Consider cases that target can be executed
41+
# even if host_triple were different from target_triple.
42+
if config.host_triple == config.target_triple:
43+
features.add("native")
44+
45+
# Sanitizers.
46+
sanitizers = frozenset(x.lower() for x in getattr(config, 'llvm_use_sanitizer', []).split(';'))
47+
features.add(binary_feature('address' in sanitizers, 'asan', 'not_'))
48+
features.add(binary_feature('memory' in sanitizers, 'msan', 'not_'))
49+
features.add(binary_feature('undefined' in sanitizers, 'ubsan', 'not_'))
50+
51+
have_zlib = getattr(config, 'have_zlib', None)
52+
features.add(binary_feature(have_zlib, 'zlib', 'no'))
53+
54+
# Check if we should run long running tests.
55+
long_tests = lit_config.params.get("run_long_tests", None)
56+
if lit.util.pythonize_bool(long_tests):
57+
features.add("long_tests")
58+
59+
target_triple = getattr(config, 'target_triple', None)
60+
if target_triple:
61+
if re.match(r'^x86_64.*-linux', target_triple):
62+
features.add("x86_64-linux")
63+
if re.match(r'.*-win32$', target_triple):
64+
features.add('target-windows')
65+
66+
use_gmalloc = lit_config.params.get('use_gmalloc', None)
67+
if lit.util.pythonize_bool(use_gmalloc):
68+
# Allow use of an explicit path for gmalloc library.
69+
# Will default to '/usr/lib/libgmalloc.dylib' if not set.
70+
gmalloc_path_str = lit_config.params.get('gmalloc_path',
71+
'/usr/lib/libgmalloc.dylib')
72+
if gmalloc_path_str is not None:
73+
self.with_environment('DYLD_INSERT_LIBRARIES', gmalloc_path_str)
74+
75+
breaking_checks = getattr(config, 'enable_abi_breaking_checks', None)
76+
if lit.util.pythonize_bool(breaking_checks):
77+
features.add('abi-breaking-checks')
78+
79+
def with_environment(self, variable, value, append_path = False):
80+
if append_path and variable in self.config.environment:
81+
def norm(x):
82+
return os.path.normcase(os.path.normpath(x))
83+
84+
# Move it to the front if it already exists, otherwise insert it at the
85+
# beginning.
86+
value = norm(value)
87+
current_value = self.config.environment[variable]
88+
items = [norm(x) for x in current_value.split(os.path.pathsep)]
89+
try:
90+
items.remove(value)
91+
except ValueError:
92+
pass
93+
value = os.path.pathsep.join([value] + items)
94+
self.config.environment[variable] = value
95+
96+
97+
def with_system_environment(self, variables, append_path = False):
98+
if lit.util.is_string(variables):
99+
variables = [variables]
100+
for v in variables:
101+
value = os.environ.get(v)
102+
if value:
103+
self.with_environment(v, value, append_path)
104+
105+
def feature_config(self, flag, feature):
106+
# Ask llvm-config about assertion mode.
107+
try:
108+
llvm_config_cmd = subprocess.Popen(
109+
[os.path.join(self.config.llvm_tools_dir, 'llvm-config'), flag],
110+
stdout = subprocess.PIPE,
111+
env=self.config.environment)
112+
except OSError:
113+
self.lit_config.fatal("Could not find llvm-config in " + self.config.llvm_tools_dir)
114+
115+
output, _ = llvm_config_cmd.communicate()
116+
if re.search(r'ON', output.decode('ascii')):
117+
self.config.available_features.add(feature)

0 commit comments

Comments
 (0)