[Lldb-commits] [lldb] [lldb] Change test paths to resolve symlinks (PR #132053)
David Peixotto via lldb-commits
lldb-commits at lists.llvm.org
Thu Mar 20 12:48:26 PDT 2025
https://github.com/dmpots updated https://github.com/llvm/llvm-project/pull/132053
>From efde68cf06da2f668f4d2ecd638b826c7f4c5b70 Mon Sep 17 00:00:00 2001
From: David Peixotto <peix at meta.com>
Date: Wed, 19 Mar 2025 08:44:59 -0700
Subject: [PATCH 1/3] [lldb] Change test paths to resolve symlinks
This commit modifes the `getSourceDir()` and `getBuildDir()` functions
to use os.path.realpath to resolve symlinks in the Base test class used
for API tests.
A few tests were failing when the build and source directories were
located under a path that contained a symlink. These failures were
because of cases where the symlink would be resolve to its real path
in the source code, but the test code would try to match against
the path with the symbolic link.
Two failing tests were
TestProcessLaunch.test_target_launch_working_dir_prop
TestSourceManager.test_source_cache_dump_and_clear
The inferior used `TestProcessLaunch` prints out its working directory
using the `getcwd` function, which is not allowed to return symbolic
links in the path components. When testing against the output from
`getcwd` we should resolve the full path to match the expected output.
The `TestSourceManager` test sets a breakpoint on a main-copy.c file
that is copied into the build output directory. The source manager
resolves this file to its real location. When testing the output from
the source cache we need to resolve the expected path to remove
symlinks.
---
lldb/packages/Python/lldbsuite/test/lldbtest.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 570c36b5f9622..7ac7aa368cc01 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -722,15 +722,17 @@ def clean_working_directory():
def getSourceDir(self):
"""Return the full path to the current test."""
- return os.path.join(configuration.test_src_root, self.mydir)
+ return os.path.realpath(os.path.join(configuration.test_src_root, self.mydir))
def getBuildDirBasename(self):
return self.__class__.__module__ + "." + self.testMethodName
def getBuildDir(self):
"""Return the full path to the current test."""
- return os.path.join(
- configuration.test_build_dir, self.mydir, self.getBuildDirBasename()
+ return os.path.realpath(
+ os.path.join(
+ configuration.test_build_dir, self.mydir, self.getBuildDirBasename()
+ )
)
def makeBuildDir(self):
>From 36c6e195c0143c664c275cf5b549c8548c7293ac Mon Sep 17 00:00:00 2001
From: David Peixotto <peix at meta.com>
Date: Thu, 20 Mar 2025 12:46:09 -0700
Subject: [PATCH 2/3] Revert "[lldb] Change test paths to resolve symlinks"
This reverts commit efde68cf06da2f668f4d2ecd638b826c7f4c5b70.
---
lldb/packages/Python/lldbsuite/test/lldbtest.py | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 7ac7aa368cc01..570c36b5f9622 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -722,17 +722,15 @@ def clean_working_directory():
def getSourceDir(self):
"""Return the full path to the current test."""
- return os.path.realpath(os.path.join(configuration.test_src_root, self.mydir))
+ return os.path.join(configuration.test_src_root, self.mydir)
def getBuildDirBasename(self):
return self.__class__.__module__ + "." + self.testMethodName
def getBuildDir(self):
"""Return the full path to the current test."""
- return os.path.realpath(
- os.path.join(
- configuration.test_build_dir, self.mydir, self.getBuildDirBasename()
- )
+ return os.path.join(
+ configuration.test_build_dir, self.mydir, self.getBuildDirBasename()
)
def makeBuildDir(self):
>From 76c925847ab24b2cd5e32eadf94e96215e2c306f Mon Sep 17 00:00:00 2001
From: David Peixotto <peix at meta.com>
Date: Tue, 18 Mar 2025 22:21:39 -0700
Subject: [PATCH 3/3] [lldb] Fix tests to resolve symlinks when checking paths
The inferior used in the process launch test prints out its working
directory using the `getcwd` function, which is not allowed to return
symbolic links in the path components. When testing against the output
from `getcwd` we should resolve the full path to match the expected
output.
The source manager test sets a breakpoint on a main-copy.c file that is
copied into the build output directory. The source manager resolves this
path to its real location. When testing the output from the source cache
we need to resolve the expected path in the test to remove symlinks.
---
lldb/test/API/commands/process/launch/TestProcessLaunch.py | 2 +-
lldb/test/API/source-manager/TestSourceManager.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lldb/test/API/commands/process/launch/TestProcessLaunch.py b/lldb/test/API/commands/process/launch/TestProcessLaunch.py
index 2d23c0a48960e..92d0c468741e5 100644
--- a/lldb/test/API/commands/process/launch/TestProcessLaunch.py
+++ b/lldb/test/API/commands/process/launch/TestProcessLaunch.py
@@ -220,7 +220,7 @@ def test_target_launch_working_dir_prop(self):
mywd = "my_working_dir"
out_file_name = "my_working_dir_test.out"
- my_working_dir_path = self.getBuildArtifact(mywd)
+ my_working_dir_path = Path(self.getBuildArtifact(mywd)).resolve()
lldbutil.mkdir_p(my_working_dir_path)
out_file_path = os.path.join(my_working_dir_path, out_file_name)
another_working_dir_path = Path(
diff --git a/lldb/test/API/source-manager/TestSourceManager.py b/lldb/test/API/source-manager/TestSourceManager.py
index eca0dd5e6159f..3500dded815b9 100644
--- a/lldb/test/API/source-manager/TestSourceManager.py
+++ b/lldb/test/API/source-manager/TestSourceManager.py
@@ -35,7 +35,7 @@ def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break inside main().
- self.file = self.getBuildArtifact("main-copy.c")
+ self.file = os.path.realpath(self.getBuildArtifact("main-copy.c"))
self.line = line_number("main.c", "// Set break point at this line.")
def modify_content(self):
More information about the lldb-commits
mailing list