Skip to content

Commit e57e53c

Browse files
committed
[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`.
1 parent e3a0cb8 commit e57e53c

38 files changed

+70
-67
lines changed

clang/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ if( CLANG_INCLUDE_TESTS )
533533
clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
534534
)
535535
add_subdirectory(test)
536-
add_subdirectory(bindings/python/tests)
537536

538537
if(CLANG_BUILT_STANDALONE)
539538
umbrella_lit_testsuite_end(check-all)

clang/bindings/python/tests/CMakeLists.txt

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
3+
# UNSUPPORTED: !libclang-loadable
4+
5+
# Tests require libclang.so which is only built with LLVM_ENABLE_PIC=ON
6+
#
7+
# Covered by libclang-loadable, may need to augment test for lack of
8+
# libclang.so.
9+
10+
# Do not try to run if libclang was built with sanitizers because
11+
# the sanitizer library will likely be loaded too late to perform
12+
# interception and will then fail.
13+
# We could use LD_PRELOAD/DYLD_INSERT_LIBRARIES but this isn't
14+
# portable so its easier just to not run the tests when building
15+
# with ASan.
16+
#
17+
# FIXME: Handle !LLVM_USE_SANITIZER = "".
18+
# lit.site.cfg.py has config.llvm_use_sanitizer = ""
19+
20+
# Tests fail on Windows, and need someone knowledgeable to fix.
21+
# It's not clear whether it's a test or a valid binding problem.
22+
# XFAIL: target={{.*windows.*}}
23+
24+
# The Python FFI interface is broken on AIX: https://bugs.python.org/issue38628.
25+
# XFAIL: target={{.*-aix.*}}
26+
27+
# AArch64, Hexagon, and Sparc have known test failures that need to be
28+
# addressed.
29+
# SystemZ has broken Python/FFI interface:
30+
# https://reviews.llvm.org/D52840#1265716
31+
# XFAIL: target={{(aarch64|hexagon|sparc*|s390x)-.*}}
32+
33+
# Tests will fail if cross-compiling for a different target, as tests will try
34+
# to use the host Python3_EXECUTABLE and make FFI calls to functions in target
35+
# libraries.
36+
#
37+
# FIXME: Consider a solution that allows better control over these tests in
38+
# a crosscompiling scenario. e.g. registering them with lit to allow them to
39+
# be explicitly skipped via appropriate LIT_ARGS, or adding a mechanism to
40+
# allow specifying a python interpreter compiled for the target that could
41+
# be executed using qemu-user.
42+
#
43+
# FIXME: Handle CMAKE_CROSSCOMPILING.
44+
# Again, might already be handled by libclang-loadable.
45+
46+
# RUN: env PYTHONPATH=%S/../../../bindings/python \
47+
# RUN: CLANG_LIBRARY_PATH=`llvm-config --libdir` \
48+
# RUN: %python -m unittest discover -s %S/tests
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def is_libclang_loadable():
2+
try:
3+
sys.path.append(os.path.join(config.clang_src_dir, "bindings/python"))
4+
from clang.cindex import Config
5+
conf = Config()
6+
Config.set_library_path(config.clang_lib_dir)
7+
conf.lib
8+
return True
9+
except Exception as e:
10+
# Benign error modes.
11+
if "wrong ELF class: ELFCLASS32" in str(e):
12+
return False
13+
elif "No such file or directory" in str(e):
14+
return False
15+
# Unknown error modes.
16+
else:
17+
return True
18+
19+
if is_libclang_loadable():
20+
config.available_features.add("libclang-loadable")
21+
22+
config.suffixes = ['.sh']

0 commit comments

Comments
 (0)