summaryrefslogtreecommitdiffstats
path: root/llvm/utils
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-09-16 18:46:21 +0000
committerZachary Turner <zturner@google.com>2017-09-16 18:46:21 +0000
commitc3023d1bd19d02fa00b9a09dbcfbea112990b694 (patch)
tree6b801fa33c0da5d8954df4a94c968fc49d278044 /llvm/utils
parentd6bca1c54948025bcadaeba6eafb3427c9a1155f (diff)
downloadbcm5719-llvm-c3023d1bd19d02fa00b9a09dbcfbea112990b694.tar.gz
bcm5719-llvm-c3023d1bd19d02fa00b9a09dbcfbea112990b694.zip
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. llvm-svn: 313467
Diffstat (limited to 'llvm/utils')
-rw-r--r--llvm/utils/lit/lit/llvm/__init__.py9
-rw-r--r--llvm/utils/lit/lit/llvm/config.py117
-rw-r--r--llvm/utils/lit/lit/util.py23
3 files changed, 149 insertions, 0 deletions
diff --git a/llvm/utils/lit/lit/llvm/__init__.py b/llvm/utils/lit/lit/llvm/__init__.py
new file mode 100644
index 00000000000..c4cad04649f
--- /dev/null
+++ b/llvm/utils/lit/lit/llvm/__init__.py
@@ -0,0 +1,9 @@
+
+from lit.llvm import config
+
+llvm_config = None
+
+def initialize(lit_config, test_config):
+ global llvm_config
+ llvm_config = config.LLVMConfig(lit_config, test_config)
+
diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py
new file mode 100644
index 00000000000..835fd8ec3f8
--- /dev/null
+++ b/llvm/utils/lit/lit/llvm/config.py
@@ -0,0 +1,117 @@
+import os
+import re
+import subprocess
+import sys
+
+import lit.util
+
+# Choose between lit's internal shell pipeline runner and a real shell. If
+# LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
+litshenv = os.environ.get("LIT_USE_INTERNAL_SHELL")
+litsh = lit.util.pythonize_bool(litshenv) if litshenv else (sys.platform == 'win32')
+
+def binary_feature(on, feature, off_prefix):
+ return feature if on else off_prefix + feature
+
+class LLVMConfig(object):
+
+ def __init__(self, lit_config, config):
+ self.lit_config = lit_config
+ self.config = config
+
+ features = config.available_features
+
+ # Tweak PATH for Win32 to decide to use bash.exe or not.
+ if sys.platform == 'win32':
+ # For tests that require Windows to run.
+ features.add('system-windows')
+
+ # Seek sane tools in directories and set to $PATH.
+ path = self.lit_config.getToolsPath(config.lit_tools_dir,
+ config.environment['PATH'],
+ ['cmp.exe', 'grep.exe', 'sed.exe'])
+ self.with_environment('PATH', path, append_path=True)
+
+ self.use_lit_shell = litsh
+ if not self.use_lit_shell:
+ features.add('shell')
+
+ # Native compilation: host arch == default triple arch
+ # FIXME: Consider cases that target can be executed
+ # even if host_triple were different from target_triple.
+ if config.host_triple == config.target_triple:
+ features.add("native")
+
+ # Sanitizers.
+ sanitizers = frozenset(x.lower() for x in getattr(config, 'llvm_use_sanitizer', []).split(';'))
+ features.add(binary_feature('address' in sanitizers, 'asan', 'not_'))
+ features.add(binary_feature('memory' in sanitizers, 'msan', 'not_'))
+ features.add(binary_feature('undefined' in sanitizers, 'ubsan', 'not_'))
+
+ have_zlib = getattr(config, 'have_zlib', None)
+ features.add(binary_feature(have_zlib, 'zlib', 'no'))
+
+ # Check if we should run long running tests.
+ long_tests = lit_config.params.get("run_long_tests", None)
+ if lit.util.pythonize_bool(long_tests):
+ features.add("long_tests")
+
+ target_triple = getattr(config, 'target_triple', None)
+ if target_triple:
+ if re.match(r'^x86_64.*-linux', target_triple):
+ features.add("x86_64-linux")
+ if re.match(r'.*-win32$', target_triple):
+ features.add('target-windows')
+
+ use_gmalloc = lit_config.params.get('use_gmalloc', None)
+ if lit.util.pythonize_bool(use_gmalloc):
+ # Allow use of an explicit path for gmalloc library.
+ # Will default to '/usr/lib/libgmalloc.dylib' if not set.
+ gmalloc_path_str = lit_config.params.get('gmalloc_path',
+ '/usr/lib/libgmalloc.dylib')
+ if gmalloc_path_str is not None:
+ self.with_environment('DYLD_INSERT_LIBRARIES', gmalloc_path_str)
+
+ breaking_checks = getattr(config, 'enable_abi_breaking_checks', None)
+ if lit.util.pythonize_bool(breaking_checks):
+ features.add('abi-breaking-checks')
+
+ def with_environment(self, variable, value, append_path = False):
+ if append_path and variable in self.config.environment:
+ def norm(x):
+ return os.path.normcase(os.path.normpath(x))
+
+ # Move it to the front if it already exists, otherwise insert it at the
+ # beginning.
+ value = norm(value)
+ current_value = self.config.environment[variable]
+ items = [norm(x) for x in current_value.split(os.path.pathsep)]
+ try:
+ items.remove(value)
+ except ValueError:
+ pass
+ value = os.path.pathsep.join([value] + items)
+ self.config.environment[variable] = value
+
+
+ def with_system_environment(self, variables, append_path = False):
+ if lit.util.is_string(variables):
+ variables = [variables]
+ for v in variables:
+ value = os.environ.get(v)
+ if value:
+ self.with_environment(v, value, append_path)
+
+ def feature_config(self, flag, feature):
+ # Ask llvm-config about assertion mode.
+ try:
+ llvm_config_cmd = subprocess.Popen(
+ [os.path.join(self.config.llvm_tools_dir, 'llvm-config'), flag],
+ stdout = subprocess.PIPE,
+ env=self.config.environment)
+ except OSError:
+ self.lit_config.fatal("Could not find llvm-config in " + self.config.llvm_tools_dir)
+
+ output, _ = llvm_config_cmd.communicate()
+ if re.search(r'ON', output.decode('ascii')):
+ self.config.available_features.add(feature)
diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py
index 1819d4d1c34..bdd407b57d5 100644
--- a/llvm/utils/lit/lit/util.py
+++ b/llvm/utils/lit/lit/util.py
@@ -1,6 +1,7 @@
import errno
import itertools
import math
+import numbers
import os
import platform
import signal
@@ -8,6 +9,28 @@ import subprocess
import sys
import threading
+def is_string(value):
+ try:
+ # Python 2 and Python 3 are different here.
+ return isinstance(value, basestring)
+ except NameError:
+ return isinstance(value, str)
+
+def pythonize_bool(value):
+ if value is None:
+ return False
+ if type(value) is bool:
+ return value
+ if isinstance(value, numbers.Number):
+ return value != 0
+ if is_string(value):
+ if value.lower() in ('1', 'true', 'on', 'yes'):
+ return True
+ if value.lower() in ('', '0', 'false', 'off', 'no'):
+ return False
+ raise ValueError('"{}" is not a valid boolean'.format(value))
+
+
def to_bytes(s):
"""Return the parameter as type 'bytes', possibly encoding it.
OpenPOWER on IntegriCloud