From b785ad69b4fe9ed8414b8169f0c7ebf2f116393d Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Mon, 17 Mar 2025 15:02:42 -0700 Subject: [PATCH 1/2] [debuginfo-tests] Use built lldb for testing if available The cross-project-tests's debuginfo-tests don't rely on lldb being built to run. While this is a good, a bug in the system lldb can cause a test to fail with no way of fixing it. This patch makes it so the tests use the built lldb instead if it's available. --- cross-project-tests/debuginfo-tests/llgdb-tests/llgdb.py | 8 ++++++++ .../debuginfo-tests/llgdb-tests/test_debuginfo.pl | 2 +- cross-project-tests/lit.cfg.py | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cross-project-tests/debuginfo-tests/llgdb-tests/llgdb.py b/cross-project-tests/debuginfo-tests/llgdb-tests/llgdb.py index 6795d3b989a30..024c9a93fb06a 100755 --- a/cross-project-tests/debuginfo-tests/llgdb-tests/llgdb.py +++ b/cross-project-tests/debuginfo-tests/llgdb-tests/llgdb.py @@ -8,6 +8,14 @@ # Auto-detect lldb python module. import subprocess, platform, os, sys +# Set the path to look first for the built lldb (in case it exists). +llvm_libs_dir = os.environ["LLVM_LIBS_DIR"] +built_lldb_path = os.path.join( + llvm_libs_dir, + f"python{sys.version_info.major}.{sys.version_info.minor}", + "site-packages", +) +sys.path.insert(0, built_lldb_path) try: # Just try for LLDB in case PYTHONPATH is already correctly setup. import lldb diff --git a/cross-project-tests/debuginfo-tests/llgdb-tests/test_debuginfo.pl b/cross-project-tests/debuginfo-tests/llgdb-tests/test_debuginfo.pl index fa52a5037c219..39adb77a9f98a 100755 --- a/cross-project-tests/debuginfo-tests/llgdb-tests/test_debuginfo.pl +++ b/cross-project-tests/debuginfo-tests/llgdb-tests/test_debuginfo.pl @@ -56,7 +56,7 @@ if (!$my_debugger) { if ($use_lldb) { my $path = dirname(Cwd::abs_path($0)); - $my_debugger = "/usr/bin/xcrun python3 $path/llgdb.py"; + $my_debugger = "LLVM_LIBS_DIR=$ENV{'LLVM_LIBS_DIR'} /usr/bin/xcrun python3 $path/llgdb.py"; } else { $my_debugger = "gdb"; } diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py index 66fdd63632885..e4f2cad9300ac 100644 --- a/cross-project-tests/lit.cfg.py +++ b/cross-project-tests/lit.cfg.py @@ -37,7 +37,10 @@ tools = [ ToolSubst( "%test_debuginfo", - command=os.path.join( + command="LLVM_LIBS_DIR=" + + config.llvm_libs_dir + + " " + + os.path.join( config.cross_project_tests_src_root, "debuginfo-tests", "llgdb-tests", From 29142766308f4de02cf9c3ceedbb624dc6583f96 Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Tue, 18 Mar 2025 15:30:24 -0700 Subject: [PATCH 2/2] Thread python executable path --- .../debuginfo-tests/llgdb-tests/llgdb.py | 11 ++++------- .../debuginfo-tests/llgdb-tests/test_debuginfo.pl | 6 +++++- cross-project-tests/lit.cfg.py | 12 ++++++++++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cross-project-tests/debuginfo-tests/llgdb-tests/llgdb.py b/cross-project-tests/debuginfo-tests/llgdb-tests/llgdb.py index 024c9a93fb06a..f3146f794e1eb 100755 --- a/cross-project-tests/debuginfo-tests/llgdb-tests/llgdb.py +++ b/cross-project-tests/debuginfo-tests/llgdb-tests/llgdb.py @@ -9,13 +9,10 @@ import subprocess, platform, os, sys # Set the path to look first for the built lldb (in case it exists). -llvm_libs_dir = os.environ["LLVM_LIBS_DIR"] -built_lldb_path = os.path.join( - llvm_libs_dir, - f"python{sys.version_info.major}.{sys.version_info.minor}", - "site-packages", -) -sys.path.insert(0, built_lldb_path) +lldb_python_path = os.environ["LLDB_PYTHON_PATH"] +if len(lldb_python_path) > 0: + sys.path.insert(0, lldb_python_path) + try: # Just try for LLDB in case PYTHONPATH is already correctly setup. import lldb diff --git a/cross-project-tests/debuginfo-tests/llgdb-tests/test_debuginfo.pl b/cross-project-tests/debuginfo-tests/llgdb-tests/test_debuginfo.pl index 39adb77a9f98a..9c922bc8ac921 100755 --- a/cross-project-tests/debuginfo-tests/llgdb-tests/test_debuginfo.pl +++ b/cross-project-tests/debuginfo-tests/llgdb-tests/test_debuginfo.pl @@ -56,7 +56,11 @@ if (!$my_debugger) { if ($use_lldb) { my $path = dirname(Cwd::abs_path($0)); - $my_debugger = "LLVM_LIBS_DIR=$ENV{'LLVM_LIBS_DIR'} /usr/bin/xcrun python3 $path/llgdb.py"; + my $python_exec_path = $ENV{'PYTHON_EXEC_PATH'}; + if (!$python_exec_path) { + $python_exec_path = 'python3'; + } + $my_debugger = "LLDB_PYTHON_PATH=$ENV{'LLDB_PYTHON_PATH'} /usr/bin/xcrun $python_exec_path $path/llgdb.py"; } else { $my_debugger = "gdb"; } diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py index e4f2cad9300ac..ccd3d01023c9a 100644 --- a/cross-project-tests/lit.cfg.py +++ b/cross-project-tests/lit.cfg.py @@ -34,11 +34,19 @@ llvm_config.use_default_substitutions() +lldb_python_path = os.path.join( + config.llvm_libs_dir, + f"python{sys.version_info.major}.{sys.version_info.minor}", + "site-packages", +) +python_exec_path = sys.executable tools = [ ToolSubst( "%test_debuginfo", - command="LLVM_LIBS_DIR=" - + config.llvm_libs_dir + command="PYTHON_EXEC_PATH=" + + python_exec_path + + " LLDB_PYTHON_PATH=" + + lldb_python_path + " " + os.path.join( config.cross_project_tests_src_root,