Skip to content

Commit e250829

Browse files
committed
[sanitizer] Use COMPILER_RT_EMULATOR with gtests
Differential Revision: https://reviews.llvm.org/D100998
1 parent 43831d6 commit e250829

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

compiler-rt/unittests/lit.common.unit.cfg.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,25 @@
88

99
import lit.formats
1010

11+
import shlex
12+
13+
# Copied from libcxx's config.py
14+
def get_lit_conf(name, default=None):
15+
# Allow overriding on the command line using --param=<name>=<val>
16+
val = lit_config.params.get(name, None)
17+
if val is None:
18+
val = getattr(config, name, None)
19+
if val is None:
20+
val = default
21+
return val
22+
23+
emulator = get_lit_conf('emulator', None)
24+
if emulator:
25+
emulator = shlex.split(emulator)
26+
1127
# Setup test format
1228
llvm_build_mode = getattr(config, "llvm_build_mode", "Debug")
13-
config.test_format = lit.formats.GoogleTest(llvm_build_mode, "Test")
29+
config.test_format = lit.formats.GoogleTest(llvm_build_mode, "Test", emulator)
1430

1531
# Setup test suffixes.
1632
config.suffixes = []

compiler-rt/unittests/lit.common.unit.configured.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ config.host_arch = "@HOST_ARCH@"
1212
config.host_os = "@HOST_OS@"
1313
config.llvm_lib_dir = "@LLVM_LIBRARY_DIR@"
1414
config.gwp_asan = @COMPILER_RT_HAS_GWP_ASAN_PYBOOL@
15+
config.emulator = "@COMPILER_RT_EMULATOR@"
1516

1617
# LLVM tools dir and build mode can be passed in lit parameters,
1718
# so try to apply substitution.

llvm/utils/lit/lit/formats/googletest.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
kIsWindows = sys.platform in ['win32', 'cygwin']
1212

1313
class GoogleTest(TestFormat):
14-
def __init__(self, test_sub_dirs, test_suffix):
14+
def __init__(self, test_sub_dirs, test_suffix, run_under = []):
1515
self.test_sub_dirs = str(test_sub_dirs).split(';')
1616

1717
# On Windows, assume tests will also end in '.exe'.
@@ -21,6 +21,7 @@ def __init__(self, test_sub_dirs, test_suffix):
2121

2222
# Also check for .py files for testing purposes.
2323
self.test_suffixes = {exe_suffix, test_suffix + '.py'}
24+
self.run_under = run_under
2425

2526
def getGTestTests(self, path, litConfig, localConfig):
2627
"""getGTestTests(path) - [name]
@@ -32,7 +33,7 @@ def getGTestTests(self, path, litConfig, localConfig):
3233
litConfig: LitConfig instance
3334
localConfig: TestingConfig instance"""
3435

35-
list_test_cmd = self.maybeAddPythonToCmd([path, '--gtest_list_tests'])
36+
list_test_cmd = self.prepareCmd([path, '--gtest_list_tests'])
3637

3738
try:
3839
output = subprocess.check_output(list_test_cmd,
@@ -113,7 +114,7 @@ def execute(self, test, litConfig):
113114
testName = namePrefix + '/' + testName
114115

115116
cmd = [testPath, '--gtest_filter=' + testName]
116-
cmd = self.maybeAddPythonToCmd(cmd)
117+
cmd = self.prepareCmd(cmd)
117118
if litConfig.useValgrind:
118119
cmd = litConfig.valgrindArgs + cmd
119120

@@ -141,13 +142,17 @@ def execute(self, test, litConfig):
141142

142143
return lit.Test.PASS,''
143144

144-
def maybeAddPythonToCmd(self, cmd):
145-
"""Insert the python exe into the command if cmd[0] ends in .py
145+
def prepareCmd(self, cmd):
146+
"""Insert interpreter if needed.
146147
148+
It inserts the python exe into the command if cmd[0] ends in .py or caller
149+
specified run_under.
147150
We cannot rely on the system to interpret shebang lines for us on
148151
Windows, so add the python executable to the command if this is a .py
149152
script.
150153
"""
151154
if cmd[0].endswith('.py'):
152-
return [sys.executable] + cmd
155+
cmd = [sys.executable] + cmd
156+
if self.run_under:
157+
cmd = self.run_under + cmd
153158
return cmd

0 commit comments

Comments
 (0)