forked from OSchip/llvm-project
[sanitizer] Use COMPILER_RT_EMULATOR with gtests
Differential Revision: https://reviews.llvm.org/D100998
This commit is contained in:
parent
43831d6279
commit
e25082961c
|
@ -8,9 +8,25 @@ import os
|
||||||
|
|
||||||
import lit.formats
|
import lit.formats
|
||||||
|
|
||||||
|
import shlex
|
||||||
|
|
||||||
|
# Copied from libcxx's config.py
|
||||||
|
def get_lit_conf(name, default=None):
|
||||||
|
# Allow overriding on the command line using --param=<name>=<val>
|
||||||
|
val = lit_config.params.get(name, None)
|
||||||
|
if val is None:
|
||||||
|
val = getattr(config, name, None)
|
||||||
|
if val is None:
|
||||||
|
val = default
|
||||||
|
return val
|
||||||
|
|
||||||
|
emulator = get_lit_conf('emulator', None)
|
||||||
|
if emulator:
|
||||||
|
emulator = shlex.split(emulator)
|
||||||
|
|
||||||
# Setup test format
|
# Setup test format
|
||||||
llvm_build_mode = getattr(config, "llvm_build_mode", "Debug")
|
llvm_build_mode = getattr(config, "llvm_build_mode", "Debug")
|
||||||
config.test_format = lit.formats.GoogleTest(llvm_build_mode, "Test")
|
config.test_format = lit.formats.GoogleTest(llvm_build_mode, "Test", emulator)
|
||||||
|
|
||||||
# Setup test suffixes.
|
# Setup test suffixes.
|
||||||
config.suffixes = []
|
config.suffixes = []
|
||||||
|
|
|
@ -12,6 +12,7 @@ config.host_arch = "@HOST_ARCH@"
|
||||||
config.host_os = "@HOST_OS@"
|
config.host_os = "@HOST_OS@"
|
||||||
config.llvm_lib_dir = "@LLVM_LIBRARY_DIR@"
|
config.llvm_lib_dir = "@LLVM_LIBRARY_DIR@"
|
||||||
config.gwp_asan = @COMPILER_RT_HAS_GWP_ASAN_PYBOOL@
|
config.gwp_asan = @COMPILER_RT_HAS_GWP_ASAN_PYBOOL@
|
||||||
|
config.emulator = "@COMPILER_RT_EMULATOR@"
|
||||||
|
|
||||||
# LLVM tools dir and build mode can be passed in lit parameters,
|
# LLVM tools dir and build mode can be passed in lit parameters,
|
||||||
# so try to apply substitution.
|
# so try to apply substitution.
|
||||||
|
|
|
@ -11,7 +11,7 @@ from .base import TestFormat
|
||||||
kIsWindows = sys.platform in ['win32', 'cygwin']
|
kIsWindows = sys.platform in ['win32', 'cygwin']
|
||||||
|
|
||||||
class GoogleTest(TestFormat):
|
class GoogleTest(TestFormat):
|
||||||
def __init__(self, test_sub_dirs, test_suffix):
|
def __init__(self, test_sub_dirs, test_suffix, run_under = []):
|
||||||
self.test_sub_dirs = str(test_sub_dirs).split(';')
|
self.test_sub_dirs = str(test_sub_dirs).split(';')
|
||||||
|
|
||||||
# On Windows, assume tests will also end in '.exe'.
|
# On Windows, assume tests will also end in '.exe'.
|
||||||
|
@ -21,6 +21,7 @@ class GoogleTest(TestFormat):
|
||||||
|
|
||||||
# Also check for .py files for testing purposes.
|
# Also check for .py files for testing purposes.
|
||||||
self.test_suffixes = {exe_suffix, test_suffix + '.py'}
|
self.test_suffixes = {exe_suffix, test_suffix + '.py'}
|
||||||
|
self.run_under = run_under
|
||||||
|
|
||||||
def getGTestTests(self, path, litConfig, localConfig):
|
def getGTestTests(self, path, litConfig, localConfig):
|
||||||
"""getGTestTests(path) - [name]
|
"""getGTestTests(path) - [name]
|
||||||
|
@ -32,7 +33,7 @@ class GoogleTest(TestFormat):
|
||||||
litConfig: LitConfig instance
|
litConfig: LitConfig instance
|
||||||
localConfig: TestingConfig instance"""
|
localConfig: TestingConfig instance"""
|
||||||
|
|
||||||
list_test_cmd = self.maybeAddPythonToCmd([path, '--gtest_list_tests'])
|
list_test_cmd = self.prepareCmd([path, '--gtest_list_tests'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(list_test_cmd,
|
output = subprocess.check_output(list_test_cmd,
|
||||||
|
@ -113,7 +114,7 @@ class GoogleTest(TestFormat):
|
||||||
testName = namePrefix + '/' + testName
|
testName = namePrefix + '/' + testName
|
||||||
|
|
||||||
cmd = [testPath, '--gtest_filter=' + testName]
|
cmd = [testPath, '--gtest_filter=' + testName]
|
||||||
cmd = self.maybeAddPythonToCmd(cmd)
|
cmd = self.prepareCmd(cmd)
|
||||||
if litConfig.useValgrind:
|
if litConfig.useValgrind:
|
||||||
cmd = litConfig.valgrindArgs + cmd
|
cmd = litConfig.valgrindArgs + cmd
|
||||||
|
|
||||||
|
@ -141,13 +142,17 @@ class GoogleTest(TestFormat):
|
||||||
|
|
||||||
return lit.Test.PASS,''
|
return lit.Test.PASS,''
|
||||||
|
|
||||||
def maybeAddPythonToCmd(self, cmd):
|
def prepareCmd(self, cmd):
|
||||||
"""Insert the python exe into the command if cmd[0] ends in .py
|
"""Insert interpreter if needed.
|
||||||
|
|
||||||
|
It inserts the python exe into the command if cmd[0] ends in .py or caller
|
||||||
|
specified run_under.
|
||||||
We cannot rely on the system to interpret shebang lines for us on
|
We cannot rely on the system to interpret shebang lines for us on
|
||||||
Windows, so add the python executable to the command if this is a .py
|
Windows, so add the python executable to the command if this is a .py
|
||||||
script.
|
script.
|
||||||
"""
|
"""
|
||||||
if cmd[0].endswith('.py'):
|
if cmd[0].endswith('.py'):
|
||||||
return [sys.executable] + cmd
|
cmd = [sys.executable] + cmd
|
||||||
|
if self.run_under:
|
||||||
|
cmd = self.run_under + cmd
|
||||||
return cmd
|
return cmd
|
||||||
|
|
Loading…
Reference in New Issue