Jannick Kremer ec149d5ef8
[clang][python][test] Move python binding tests to lit framework (#148802)
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`.

Co-authored-by: Rainer Orth <ro@gcc.gnu.org>
2025-07-15 12:48:24 +02:00

39 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# UNSUPPORTED: !libclang-loadable
# 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.*}}
# Hexagon has known test failures that need to be addressed.
# https://reviews.llvm.org/D52840#1265716
# XFAIL: target={{hexagon-.*}}
# 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
# 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.
# REQUIRES: native
# SystemZ has broken Python/FFI interface
# according to https://reviews.llvm.org/D52840#1265716
# This leads to failures only when Clang is built with GCC apparently, see:
# https://github.com/llvm/llvm-project/pull/146844#issuecomment-3048291798
# REQUIRES: !target={{s390x-.*}}
# RUN: env PYTHONPATH=%S/../../../bindings/python \
# RUN: CLANG_LIBRARY_PATH=%libdir \
# RUN: %python -m unittest discover -s %S/tests