Files
clang-p2996/clang/test/bindings/python/tests/cindex/test_tls_kind.py
Jannick Kremer a75587d271 [clang][python][test] Move python binding tests to lit framework (#146486)
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-02 10:11:48 +02:00

71 lines
1.9 KiB
Python

import os
from clang.cindex import Config, TLSKind
if "CLANG_LIBRARY_PATH" in os.environ:
Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
import unittest
from .util import get_cursor, get_tu
class TestTLSKind(unittest.TestCase):
def test_tls_kind(self):
"""Ensure that thread-local storage kinds are available on cursors."""
tu = get_tu(
"""
int tls_none;
thread_local int tls_dynamic;
_Thread_local int tls_static;
""",
lang="cpp",
)
tls_none = get_cursor(tu.cursor, "tls_none")
self.assertEqual(tls_none.tls_kind, TLSKind.NONE)
tls_dynamic = get_cursor(tu.cursor, "tls_dynamic")
self.assertEqual(tls_dynamic.tls_kind, TLSKind.DYNAMIC)
tls_static = get_cursor(tu.cursor, "tls_static")
self.assertEqual(tls_static.tls_kind, TLSKind.STATIC)
# The following case tests '__declspec(thread)'. Since it is a Microsoft
# specific extension, specific flags are required for the parser to pick
# these up.
flags = [
"-fms-extensions",
"-target",
"x86_64-unknown-windows-win32",
"-fms-compatibility-version=18",
]
tu = get_tu(
"""
__declspec(thread) int tls_declspec_msvc18;
""",
lang="cpp",
flags=flags,
)
tls_declspec_msvc18 = get_cursor(tu.cursor, "tls_declspec_msvc18")
self.assertEqual(tls_declspec_msvc18.tls_kind, TLSKind.STATIC)
flags = [
"-fms-extensions",
"-target",
"x86_64-unknown-windows-win32",
"-fms-compatibility-version=19",
]
tu = get_tu(
"""
__declspec(thread) int tls_declspec_msvc19;
""",
lang="cpp",
flags=flags,
)
tls_declspec_msvc19 = get_cursor(tu.cursor, "tls_declspec_msvc19")
self.assertEqual(tls_declspec_msvc19.tls_kind, TLSKind.DYNAMIC)