[clang] [llvm] [clang][python][test] Move python binding tests to lit framework (PR #142948)
Rainer Orth via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 12 00:55:35 PDT 2025
https://github.com/rorth updated https://github.com/llvm/llvm-project/pull/142948
>From e57e53c7e5abdb4c390a04b4ce9084dec9e71dd5 Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Thu, 5 Jun 2025 13:40:26 +0200
Subject: [PATCH 1/2] [clang][python][test] Move python binding tests to lit
framework
As discussed in PR #142353, the current testsuite of the `clang` Python
bindings has several issues:
- It `libclang.so` cannot be loaded into `python` to run the testsuite, the
whole `ninja check-all` aborts.
- The result of running the testsuite isn't report like the `lit`-based
tests, rendering them almost invisible.
- The testsuite is disabled in a non-obvious way (`RUN_PYTHON_TESTS`) in
`tests/CMakeLists.txt`, which again doesn't show up in the test results.
All these issues can be avoided by integrating the Python bindings tests
with `lit`, which is what this patch does:
- The actual test lives in `clang/test/bindings/python/bindings.sh` and is
run by `lit`.
- The current `clang/bindings/python/tests` directory (minus the
now-subperfluous `CMakeLists.txt`) is moved into the same directory.
- The check if `libclang` is loadable (originally from PR #142353) is now
handled via a new `lit` feature, `libclang-loadable`.
- The various ways to disable the tests have been turned into `XFAIL`s as
appropriate. This isn't complete and not completely tested yet.
Tested on `sparc-sun-solaris2.11`, `sparcv9-sun-solaris2.11`,
`i386-pc-solaris2.11`, `amd64-pc-solaris2.11`, `i686-pc-linux-gnu`, and
`x86_64-pc-linux-gnu`.
---
clang/CMakeLists.txt | 1 -
clang/bindings/python/tests/CMakeLists.txt | 66 -------------------
clang/test/bindings/python/bindings.sh | 48 ++++++++++++++
clang/test/bindings/python/lit.local.cfg | 22 +++++++
.../bindings/python/tests/__init__.py | 0
.../bindings/python/tests/cindex/INPUTS/a.inc | 0
.../bindings/python/tests/cindex/INPUTS/b.inc | 0
.../tests/cindex/INPUTS/compile_commands.json | 0
.../python/tests/cindex/INPUTS/header1.h | 0
.../python/tests/cindex/INPUTS/header2.h | 0
.../python/tests/cindex/INPUTS/header3.h | 0
.../python/tests/cindex/INPUTS/hello.cpp | 0
.../python/tests/cindex/INPUTS/include.cpp | 0
.../tests/cindex/INPUTS/parse_arguments.c | 0
.../python/tests/cindex/INPUTS/testfile.c | 0
.../bindings/python/tests/cindex/__init__.py | 0
.../tests/cindex/test_access_specifiers.py | 0
.../bindings/python/tests/cindex/test_cdb.py | 0
.../tests/cindex/test_code_completion.py | 0
.../python/tests/cindex/test_comment.py | 0
.../python/tests/cindex/test_cursor.py | 0
.../python/tests/cindex/test_cursor_kind.py | 0
.../python/tests/cindex/test_diagnostics.py | 0
.../python/tests/cindex/test_enums.py | 0
.../test_exception_specification_kind.py | 0
.../bindings/python/tests/cindex/test_file.py | 0
.../python/tests/cindex/test_index.py | 0
.../bindings/python/tests/cindex/test_lib.py | 0
.../python/tests/cindex/test_linkage.py | 0
.../python/tests/cindex/test_location.py | 0
.../python/tests/cindex/test_rewrite.py | 0
.../python/tests/cindex/test_source_range.py | 0
.../python/tests/cindex/test_tls_kind.py | 0
.../python/tests/cindex/test_token_kind.py | 0
.../python/tests/cindex/test_tokens.py | 0
.../tests/cindex/test_translation_unit.py | 0
.../bindings/python/tests/cindex/test_type.py | 0
.../bindings/python/tests/cindex/util.py | 0
38 files changed, 70 insertions(+), 67 deletions(-)
delete mode 100644 clang/bindings/python/tests/CMakeLists.txt
create mode 100755 clang/test/bindings/python/bindings.sh
create mode 100644 clang/test/bindings/python/lit.local.cfg
rename clang/{ => test}/bindings/python/tests/__init__.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/INPUTS/a.inc (100%)
rename clang/{ => test}/bindings/python/tests/cindex/INPUTS/b.inc (100%)
rename clang/{ => test}/bindings/python/tests/cindex/INPUTS/compile_commands.json (100%)
rename clang/{ => test}/bindings/python/tests/cindex/INPUTS/header1.h (100%)
rename clang/{ => test}/bindings/python/tests/cindex/INPUTS/header2.h (100%)
rename clang/{ => test}/bindings/python/tests/cindex/INPUTS/header3.h (100%)
rename clang/{ => test}/bindings/python/tests/cindex/INPUTS/hello.cpp (100%)
rename clang/{ => test}/bindings/python/tests/cindex/INPUTS/include.cpp (100%)
rename clang/{ => test}/bindings/python/tests/cindex/INPUTS/parse_arguments.c (100%)
rename clang/{ => test}/bindings/python/tests/cindex/INPUTS/testfile.c (100%)
rename clang/{ => test}/bindings/python/tests/cindex/__init__.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_access_specifiers.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_cdb.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_code_completion.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_comment.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_cursor.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_cursor_kind.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_diagnostics.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_enums.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_exception_specification_kind.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_file.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_index.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_lib.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_linkage.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_location.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_rewrite.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_source_range.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_tls_kind.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_token_kind.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_tokens.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_translation_unit.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/test_type.py (100%)
rename clang/{ => test}/bindings/python/tests/cindex/util.py (100%)
diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index ab2ac9bc6b9ad..5111953397d04 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -533,7 +533,6 @@ if( CLANG_INCLUDE_TESTS )
clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
)
add_subdirectory(test)
- add_subdirectory(bindings/python/tests)
if(CLANG_BUILT_STANDALONE)
umbrella_lit_testsuite_end(check-all)
diff --git a/clang/bindings/python/tests/CMakeLists.txt b/clang/bindings/python/tests/CMakeLists.txt
deleted file mode 100644
index a0ddabc21bb41..0000000000000
--- a/clang/bindings/python/tests/CMakeLists.txt
+++ /dev/null
@@ -1,66 +0,0 @@
-# Test target to run Python test suite from main build.
-
-# Avoid configurations including '-include' from interfering with
-# our tests by setting CLANG_NO_DEFAULT_CONFIG.
-add_custom_target(check-clang-python
- COMMAND ${CMAKE_COMMAND} -E env
- CLANG_NO_DEFAULT_CONFIG=1
- CLANG_LIBRARY_PATH=$<TARGET_FILE_DIR:libclang>
- "${Python3_EXECUTABLE}" -m unittest discover
- DEPENDS libclang
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
-
-set(RUN_PYTHON_TESTS TRUE)
-set_target_properties(check-clang-python PROPERTIES FOLDER "Clang/Tests")
-
-# Tests require libclang.so which is only built with LLVM_ENABLE_PIC=ON
-if(NOT LLVM_ENABLE_PIC)
- set(RUN_PYTHON_TESTS FALSE)
-endif()
-
-# Do not try to run if libclang was built with sanitizers because
-# the sanitizer library will likely be loaded too late to perform
-# interception and will then fail.
-# We could use LD_PRELOAD/DYLD_INSERT_LIBRARIES but this isn't
-# portable so its easier just to not run the tests when building
-# with ASan.
-if(NOT LLVM_USE_SANITIZER STREQUAL "")
- set(RUN_PYTHON_TESTS FALSE)
-endif()
-
-# Tests fail on Windows, and need someone knowledgeable to fix.
-# It's not clear whether it's a test or a valid binding problem.
-if(WIN32)
- set(RUN_PYTHON_TESTS FALSE)
-endif()
-
-# The Python FFI interface is broken on AIX: https://bugs.python.org/issue38628.
-if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
- set(RUN_PYTHON_TESTS FALSE)
-endif()
-
-# AArch64, Hexagon, and Sparc have known test failures that need to be
-# addressed.
-# SystemZ has broken Python/FFI interface:
-# https://reviews.llvm.org/D52840#1265716
-if(${LLVM_NATIVE_ARCH} MATCHES "^(AArch64|Hexagon|Sparc|SystemZ)$")
- set(RUN_PYTHON_TESTS FALSE)
-endif()
-
-# Tests will fail if cross-compiling for a different target, as tests will try
-# to use the host Python3_EXECUTABLE and make FFI calls to functions in target
-# libraries.
-if(CMAKE_CROSSCOMPILING)
- # FIXME: Consider a solution that allows better control over these tests in
- # a crosscompiling scenario. e.g. registering them with lit to allow them to
- # be explicitly skipped via appropriate LIT_ARGS, or adding a mechanism to
- # allow specifying a python interpreter compiled for the target that could
- # be executed using qemu-user.
- message(WARNING "check-clang-python not added to check-all as these tests fail in a cross-build setup")
- set(RUN_PYTHON_TESTS FALSE)
-endif()
-
-if(RUN_PYTHON_TESTS)
- set_property(GLOBAL APPEND PROPERTY
- LLVM_ALL_ADDITIONAL_TEST_TARGETS check-clang-python)
-endif()
diff --git a/clang/test/bindings/python/bindings.sh b/clang/test/bindings/python/bindings.sh
new file mode 100755
index 0000000000000..ec4ca55e41822
--- /dev/null
+++ b/clang/test/bindings/python/bindings.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+# UNSUPPORTED: !libclang-loadable
+
+# Tests require libclang.so which is only built with LLVM_ENABLE_PIC=ON
+#
+# Covered by libclang-loadable, may need to augment test for lack of
+# libclang.so.
+
+# Do not try to run if libclang was built with sanitizers because
+# the sanitizer library will likely be loaded too late to perform
+# interception and will then fail.
+# We could use LD_PRELOAD/DYLD_INSERT_LIBRARIES but this isn't
+# portable so its easier just to not run the tests when building
+# with ASan.
+#
+# FIXME: Handle !LLVM_USE_SANITIZER = "".
+# lit.site.cfg.py has config.llvm_use_sanitizer = ""
+
+# Tests fail on Windows, and need someone knowledgeable to fix.
+# It's not clear whether it's a test or a valid binding problem.
+# XFAIL: target={{.*windows.*}}
+
+# The Python FFI interface is broken on AIX: https://bugs.python.org/issue38628.
+# XFAIL: target={{.*-aix.*}}
+
+# AArch64, Hexagon, and Sparc have known test failures that need to be
+# addressed.
+# SystemZ has broken Python/FFI interface:
+# https://reviews.llvm.org/D52840#1265716
+# XFAIL: target={{(aarch64|hexagon|sparc*|s390x)-.*}}
+
+# Tests will fail if cross-compiling for a different target, as tests will try
+# to use the host Python3_EXECUTABLE and make FFI calls to functions in target
+# libraries.
+#
+# FIXME: Consider a solution that allows better control over these tests in
+# a crosscompiling scenario. e.g. registering them with lit to allow them to
+# be explicitly skipped via appropriate LIT_ARGS, or adding a mechanism to
+# allow specifying a python interpreter compiled for the target that could
+# be executed using qemu-user.
+#
+# FIXME: Handle CMAKE_CROSSCOMPILING.
+# Again, might already be handled by libclang-loadable.
+
+# RUN: env PYTHONPATH=%S/../../../bindings/python \
+# RUN: CLANG_LIBRARY_PATH=`llvm-config --libdir` \
+# RUN: %python -m unittest discover -s %S/tests
diff --git a/clang/test/bindings/python/lit.local.cfg b/clang/test/bindings/python/lit.local.cfg
new file mode 100644
index 0000000000000..d3608565f5aef
--- /dev/null
+++ b/clang/test/bindings/python/lit.local.cfg
@@ -0,0 +1,22 @@
+def is_libclang_loadable():
+ try:
+ sys.path.append(os.path.join(config.clang_src_dir, "bindings/python"))
+ from clang.cindex import Config
+ conf = Config()
+ Config.set_library_path(config.clang_lib_dir)
+ conf.lib
+ return True
+ except Exception as e:
+ # Benign error modes.
+ if "wrong ELF class: ELFCLASS32" in str(e):
+ return False
+ elif "No such file or directory" in str(e):
+ return False
+ # Unknown error modes.
+ else:
+ return True
+
+if is_libclang_loadable():
+ config.available_features.add("libclang-loadable")
+
+config.suffixes = ['.sh']
diff --git a/clang/bindings/python/tests/__init__.py b/clang/test/bindings/python/tests/__init__.py
similarity index 100%
rename from clang/bindings/python/tests/__init__.py
rename to clang/test/bindings/python/tests/__init__.py
diff --git a/clang/bindings/python/tests/cindex/INPUTS/a.inc b/clang/test/bindings/python/tests/cindex/INPUTS/a.inc
similarity index 100%
rename from clang/bindings/python/tests/cindex/INPUTS/a.inc
rename to clang/test/bindings/python/tests/cindex/INPUTS/a.inc
diff --git a/clang/bindings/python/tests/cindex/INPUTS/b.inc b/clang/test/bindings/python/tests/cindex/INPUTS/b.inc
similarity index 100%
rename from clang/bindings/python/tests/cindex/INPUTS/b.inc
rename to clang/test/bindings/python/tests/cindex/INPUTS/b.inc
diff --git a/clang/bindings/python/tests/cindex/INPUTS/compile_commands.json b/clang/test/bindings/python/tests/cindex/INPUTS/compile_commands.json
similarity index 100%
rename from clang/bindings/python/tests/cindex/INPUTS/compile_commands.json
rename to clang/test/bindings/python/tests/cindex/INPUTS/compile_commands.json
diff --git a/clang/bindings/python/tests/cindex/INPUTS/header1.h b/clang/test/bindings/python/tests/cindex/INPUTS/header1.h
similarity index 100%
rename from clang/bindings/python/tests/cindex/INPUTS/header1.h
rename to clang/test/bindings/python/tests/cindex/INPUTS/header1.h
diff --git a/clang/bindings/python/tests/cindex/INPUTS/header2.h b/clang/test/bindings/python/tests/cindex/INPUTS/header2.h
similarity index 100%
rename from clang/bindings/python/tests/cindex/INPUTS/header2.h
rename to clang/test/bindings/python/tests/cindex/INPUTS/header2.h
diff --git a/clang/bindings/python/tests/cindex/INPUTS/header3.h b/clang/test/bindings/python/tests/cindex/INPUTS/header3.h
similarity index 100%
rename from clang/bindings/python/tests/cindex/INPUTS/header3.h
rename to clang/test/bindings/python/tests/cindex/INPUTS/header3.h
diff --git a/clang/bindings/python/tests/cindex/INPUTS/hello.cpp b/clang/test/bindings/python/tests/cindex/INPUTS/hello.cpp
similarity index 100%
rename from clang/bindings/python/tests/cindex/INPUTS/hello.cpp
rename to clang/test/bindings/python/tests/cindex/INPUTS/hello.cpp
diff --git a/clang/bindings/python/tests/cindex/INPUTS/include.cpp b/clang/test/bindings/python/tests/cindex/INPUTS/include.cpp
similarity index 100%
rename from clang/bindings/python/tests/cindex/INPUTS/include.cpp
rename to clang/test/bindings/python/tests/cindex/INPUTS/include.cpp
diff --git a/clang/bindings/python/tests/cindex/INPUTS/parse_arguments.c b/clang/test/bindings/python/tests/cindex/INPUTS/parse_arguments.c
similarity index 100%
rename from clang/bindings/python/tests/cindex/INPUTS/parse_arguments.c
rename to clang/test/bindings/python/tests/cindex/INPUTS/parse_arguments.c
diff --git a/clang/bindings/python/tests/cindex/INPUTS/testfile.c b/clang/test/bindings/python/tests/cindex/INPUTS/testfile.c
similarity index 100%
rename from clang/bindings/python/tests/cindex/INPUTS/testfile.c
rename to clang/test/bindings/python/tests/cindex/INPUTS/testfile.c
diff --git a/clang/bindings/python/tests/cindex/__init__.py b/clang/test/bindings/python/tests/cindex/__init__.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/__init__.py
rename to clang/test/bindings/python/tests/cindex/__init__.py
diff --git a/clang/bindings/python/tests/cindex/test_access_specifiers.py b/clang/test/bindings/python/tests/cindex/test_access_specifiers.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_access_specifiers.py
rename to clang/test/bindings/python/tests/cindex/test_access_specifiers.py
diff --git a/clang/bindings/python/tests/cindex/test_cdb.py b/clang/test/bindings/python/tests/cindex/test_cdb.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_cdb.py
rename to clang/test/bindings/python/tests/cindex/test_cdb.py
diff --git a/clang/bindings/python/tests/cindex/test_code_completion.py b/clang/test/bindings/python/tests/cindex/test_code_completion.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_code_completion.py
rename to clang/test/bindings/python/tests/cindex/test_code_completion.py
diff --git a/clang/bindings/python/tests/cindex/test_comment.py b/clang/test/bindings/python/tests/cindex/test_comment.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_comment.py
rename to clang/test/bindings/python/tests/cindex/test_comment.py
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py b/clang/test/bindings/python/tests/cindex/test_cursor.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_cursor.py
rename to clang/test/bindings/python/tests/cindex/test_cursor.py
diff --git a/clang/bindings/python/tests/cindex/test_cursor_kind.py b/clang/test/bindings/python/tests/cindex/test_cursor_kind.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_cursor_kind.py
rename to clang/test/bindings/python/tests/cindex/test_cursor_kind.py
diff --git a/clang/bindings/python/tests/cindex/test_diagnostics.py b/clang/test/bindings/python/tests/cindex/test_diagnostics.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_diagnostics.py
rename to clang/test/bindings/python/tests/cindex/test_diagnostics.py
diff --git a/clang/bindings/python/tests/cindex/test_enums.py b/clang/test/bindings/python/tests/cindex/test_enums.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_enums.py
rename to clang/test/bindings/python/tests/cindex/test_enums.py
diff --git a/clang/bindings/python/tests/cindex/test_exception_specification_kind.py b/clang/test/bindings/python/tests/cindex/test_exception_specification_kind.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_exception_specification_kind.py
rename to clang/test/bindings/python/tests/cindex/test_exception_specification_kind.py
diff --git a/clang/bindings/python/tests/cindex/test_file.py b/clang/test/bindings/python/tests/cindex/test_file.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_file.py
rename to clang/test/bindings/python/tests/cindex/test_file.py
diff --git a/clang/bindings/python/tests/cindex/test_index.py b/clang/test/bindings/python/tests/cindex/test_index.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_index.py
rename to clang/test/bindings/python/tests/cindex/test_index.py
diff --git a/clang/bindings/python/tests/cindex/test_lib.py b/clang/test/bindings/python/tests/cindex/test_lib.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_lib.py
rename to clang/test/bindings/python/tests/cindex/test_lib.py
diff --git a/clang/bindings/python/tests/cindex/test_linkage.py b/clang/test/bindings/python/tests/cindex/test_linkage.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_linkage.py
rename to clang/test/bindings/python/tests/cindex/test_linkage.py
diff --git a/clang/bindings/python/tests/cindex/test_location.py b/clang/test/bindings/python/tests/cindex/test_location.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_location.py
rename to clang/test/bindings/python/tests/cindex/test_location.py
diff --git a/clang/bindings/python/tests/cindex/test_rewrite.py b/clang/test/bindings/python/tests/cindex/test_rewrite.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_rewrite.py
rename to clang/test/bindings/python/tests/cindex/test_rewrite.py
diff --git a/clang/bindings/python/tests/cindex/test_source_range.py b/clang/test/bindings/python/tests/cindex/test_source_range.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_source_range.py
rename to clang/test/bindings/python/tests/cindex/test_source_range.py
diff --git a/clang/bindings/python/tests/cindex/test_tls_kind.py b/clang/test/bindings/python/tests/cindex/test_tls_kind.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_tls_kind.py
rename to clang/test/bindings/python/tests/cindex/test_tls_kind.py
diff --git a/clang/bindings/python/tests/cindex/test_token_kind.py b/clang/test/bindings/python/tests/cindex/test_token_kind.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_token_kind.py
rename to clang/test/bindings/python/tests/cindex/test_token_kind.py
diff --git a/clang/bindings/python/tests/cindex/test_tokens.py b/clang/test/bindings/python/tests/cindex/test_tokens.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_tokens.py
rename to clang/test/bindings/python/tests/cindex/test_tokens.py
diff --git a/clang/bindings/python/tests/cindex/test_translation_unit.py b/clang/test/bindings/python/tests/cindex/test_translation_unit.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_translation_unit.py
rename to clang/test/bindings/python/tests/cindex/test_translation_unit.py
diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/test/bindings/python/tests/cindex/test_type.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/test_type.py
rename to clang/test/bindings/python/tests/cindex/test_type.py
diff --git a/clang/bindings/python/tests/cindex/util.py b/clang/test/bindings/python/tests/cindex/util.py
similarity index 100%
rename from clang/bindings/python/tests/cindex/util.py
rename to clang/test/bindings/python/tests/cindex/util.py
>From 050330183a500da518c04586485ebf7c47f3d23c Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Wed, 11 Jun 2025 13:52:11 +0200
Subject: [PATCH 2/2] - Adjust `libclang-python-tests.yml`. - Handle
`LLVM_USE_SANITIZER` in `lit.local.cfg`. - Fix SPARC handling, restrict to
Linux/sparc*. - Explain failure modes, log unhandled ones.
---
.github/workflows/libclang-python-tests.yml | 8 ++++---
clang/test/bindings/python/bindings.sh | 23 +++++----------------
clang/test/bindings/python/lit.local.cfg | 21 +++++++++++++++++--
3 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/.github/workflows/libclang-python-tests.yml b/.github/workflows/libclang-python-tests.yml
index 50ef4acf2feb1..0482135b8920e 100644
--- a/.github/workflows/libclang-python-tests.yml
+++ b/.github/workflows/libclang-python-tests.yml
@@ -10,15 +10,15 @@ on:
- 'main'
paths:
- 'clang/bindings/python/**'
+ - 'clang/test/bindings/python/**'
- 'clang/tools/libclang/**'
- - 'clang/CMakeList.txt'
- '.github/workflows/libclang-python-tests.yml'
- '.github/workflows/llvm-project-tests.yml'
pull_request:
paths:
- 'clang/bindings/python/**'
+ - 'clang/test/bindings/python/**'
- 'clang/tools/libclang/**'
- - 'clang/CMakeList.txt'
- '.github/workflows/libclang-python-tests.yml'
- '.github/workflows/llvm-project-tests.yml'
@@ -33,7 +33,9 @@ jobs:
python-version: ["3.8", "3.13"]
uses: ./.github/workflows/llvm-project-tests.yml
with:
- build_target: check-clang-python
+ build_target: libclang
+ run: |
+ llvm-lit -v tools/clang/test --filter=bindings.sh
projects: clang
# There is an issue running on "windows-2019".
# See https://github.com/llvm/llvm-project/issues/76601#issuecomment-1873049082.
diff --git a/clang/test/bindings/python/bindings.sh b/clang/test/bindings/python/bindings.sh
index ec4ca55e41822..aebf39e0a5c5c 100755
--- a/clang/test/bindings/python/bindings.sh
+++ b/clang/test/bindings/python/bindings.sh
@@ -2,21 +2,6 @@
# UNSUPPORTED: !libclang-loadable
-# Tests require libclang.so which is only built with LLVM_ENABLE_PIC=ON
-#
-# Covered by libclang-loadable, may need to augment test for lack of
-# libclang.so.
-
-# Do not try to run if libclang was built with sanitizers because
-# the sanitizer library will likely be loaded too late to perform
-# interception and will then fail.
-# We could use LD_PRELOAD/DYLD_INSERT_LIBRARIES but this isn't
-# portable so its easier just to not run the tests when building
-# with ASan.
-#
-# FIXME: Handle !LLVM_USE_SANITIZER = "".
-# lit.site.cfg.py has config.llvm_use_sanitizer = ""
-
# Tests fail on Windows, and need someone knowledgeable to fix.
# It's not clear whether it's a test or a valid binding problem.
# XFAIL: target={{.*windows.*}}
@@ -24,11 +9,13 @@
# The Python FFI interface is broken on AIX: https://bugs.python.org/issue38628.
# XFAIL: target={{.*-aix.*}}
-# AArch64, Hexagon, and Sparc have known test failures that need to be
-# addressed.
+# AArch64 and Hexagon have known test failures that need to be addressed.
# SystemZ has broken Python/FFI interface:
# https://reviews.llvm.org/D52840#1265716
-# XFAIL: target={{(aarch64|hexagon|sparc*|s390x)-.*}}
+# XFAIL: target={{(aarch64|hexagon|s390x)-.*}}
+# python SEGVs on Linux/sparc64 when loading libclang.so. Seems to be an FFI
+# issue, too.
+# XFAIL: target={{sparc.*-.*-linux.*}}
# Tests will fail if cross-compiling for a different target, as tests will try
# to use the host Python3_EXECUTABLE and make FFI calls to functions in target
diff --git a/clang/test/bindings/python/lit.local.cfg b/clang/test/bindings/python/lit.local.cfg
index d3608565f5aef..ec61489e74867 100644
--- a/clang/test/bindings/python/lit.local.cfg
+++ b/clang/test/bindings/python/lit.local.cfg
@@ -1,4 +1,12 @@
def is_libclang_loadable():
+ # Do not try to run if libclang was built with sanitizers because
+ # the sanitizer library will likely be loaded too late to perform
+ # interception and will then fail.
+ # We could use LD_PRELOAD/DYLD_INSERT_LIBRARIES but this isn't
+ # portable so its easier just to not run the tests when building
+ # with ASan.
+ if config.llvm_use_sanitizer != "":
+ return False
try:
sys.path.append(os.path.join(config.clang_src_dir, "bindings/python"))
from clang.cindex import Config
@@ -7,13 +15,22 @@ def is_libclang_loadable():
conf.lib
return True
except Exception as e:
- # Benign error modes.
+ # Expected failure modes are considered benign when nothing can be
+ # done about them.
+ #
+ # Cannot load a 32-bit libclang.so into a 64-bit python.
if "wrong ELF class: ELFCLASS32" in str(e):
return False
+ # If libclang.so is missing, it must have been disabled intentionally,
+ # e.g. by building with LLVM_ENABLE_PIC=OFF.
elif "No such file or directory" in str(e):
return False
- # Unknown error modes.
+ # Unexpected failure modes need to be investigated to either fix an
+ # underlying bug or accept the failure, so return True. This causes
+ # tests to run and FAIL, drawing developer attention.
else:
+ print("warning: unhandled failure in is_libclang_loadable: "
+ + str(e), file=sys.stderr)
return True
if is_libclang_loadable():
More information about the llvm-commits
mailing list