Skip to content

Commit fcb0d81

Browse files
committed
[lldb/test] Use realpath consistently for test root file paths.
LLDB tests assume that tests are in the test tree (the `LLDB_TEST_SRC` env variable, configured by `dotest.py`). If this assertion doesn't hold, tests fail in strange ways. An early place this goes wrong is in `compute_mydir` which does a simple length-based substring to get the relative path. Later, we use that path to chdir to. If the test file and test tree don't agree in realpath-ness (and therefore length), this will be a cryptic error of chdir-ing to a directory that does not exist. The actual discrepency is that the places we look for `use_lldb_suite.py` don't use a realpath, but `dotest.py` does (see initialization of `configuration.testdirs`). It doesn't particularly matter whether we use realpath or abspath to canonicalize things, but many places end up with implicit dependencies on the canonicalized pwd being a realpath, so make them realpath consistently. Also, in the `compute_mydir` method mentioned, raise an error if the path types don't agree. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D85258
1 parent f879c9b commit fcb0d81

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lldb/packages/Python/lldbsuite/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77

88
def find_lldb_root():
9-
lldb_root = os.path.dirname(inspect.getfile(inspect.currentframe()))
9+
lldb_root = os.path.realpath(
10+
os.path.dirname(inspect.getfile(inspect.currentframe())))
1011
while True:
1112
parent = os.path.dirname(lldb_root)
1213
if parent == lldb_root: # dirname('/') == '/'

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,12 @@ def compute_mydir(test_file):
496496
mydir = TestBase.compute_mydir(__file__)
497497
'''
498498
# /abs/path/to/packages/group/subdir/mytest.py -> group/subdir
499-
rel_prefix = test_file[len(configuration.test_src_root) + 1:]
500-
return os.path.dirname(rel_prefix)
499+
lldb_test_src = configuration.test_src_root
500+
if not test_file.startswith(lldb_test_src):
501+
raise Exception(
502+
"Test file '%s' must reside within lldb_test_src "
503+
"(which is '%s')." % (test_file, lldb_test_src))
504+
return os.path.dirname(os.path.relpath(test_file, start=lldb_test_src))
501505

502506
def TraceOn(self):
503507
"""Returns True if we are in trace mode (tracing detailed test execution)."""

lldb/test/API/use_lldb_suite.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55

66
def find_lldb_root():
7-
lldb_root = os.path.dirname(
8-
os.path.abspath(inspect.getfile(inspect.currentframe()))
9-
)
7+
lldb_root = os.path.realpath(
8+
os.path.dirname(inspect.getfile(inspect.currentframe())))
109
while True:
1110
parent = os.path.dirname(lldb_root)
1211
if parent == lldb_root: # dirname('/') == '/'

0 commit comments

Comments
 (0)