71 lines · python
1import os2 3from clang.cindex import Config, TLSKind4 5if "CLANG_LIBRARY_PATH" in os.environ:6 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])7 8import unittest9 10from .util import get_cursor, get_tu11 12 13class TestTLSKind(unittest.TestCase):14 def test_tls_kind(self):15 """Ensure that thread-local storage kinds are available on cursors."""16 17 tu = get_tu(18 """19int tls_none;20thread_local int tls_dynamic;21_Thread_local int tls_static;22""",23 lang="cpp",24 )25 26 tls_none = get_cursor(tu.cursor, "tls_none")27 self.assertEqual(tls_none.tls_kind, TLSKind.NONE)28 29 tls_dynamic = get_cursor(tu.cursor, "tls_dynamic")30 self.assertEqual(tls_dynamic.tls_kind, TLSKind.DYNAMIC)31 32 tls_static = get_cursor(tu.cursor, "tls_static")33 self.assertEqual(tls_static.tls_kind, TLSKind.STATIC)34 35 # The following case tests '__declspec(thread)'. Since it is a Microsoft36 # specific extension, specific flags are required for the parser to pick37 # these up.38 flags = [39 "-fms-extensions",40 "-target",41 "x86_64-unknown-windows-win32",42 "-fms-compatibility-version=18",43 ]44 tu = get_tu(45 """46__declspec(thread) int tls_declspec_msvc18;47""",48 lang="cpp",49 flags=flags,50 )51 52 tls_declspec_msvc18 = get_cursor(tu.cursor, "tls_declspec_msvc18")53 self.assertEqual(tls_declspec_msvc18.tls_kind, TLSKind.STATIC)54 55 flags = [56 "-fms-extensions",57 "-target",58 "x86_64-unknown-windows-win32",59 "-fms-compatibility-version=19",60 ]61 tu = get_tu(62 """63__declspec(thread) int tls_declspec_msvc19;64""",65 lang="cpp",66 flags=flags,67 )68 69 tls_declspec_msvc19 = get_cursor(tu.cursor, "tls_declspec_msvc19")70 self.assertEqual(tls_declspec_msvc19.tls_kind, TLSKind.DYNAMIC)71