summaryrefslogtreecommitdiffstats
path: root/Tools/scripts
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2021-10-22 08:12:06 (GMT)
committerGitHub <noreply@github.com>2021-10-22 08:12:06 (GMT)
commit276468dddb46c54980c782c09cdb53bd90755752 (patch)
tree71c31b71af4822983c6e0f67612a844d16513a51 /Tools/scripts
parent843b890334ca30cf6af27dffe29cecd06b49f7d9 (diff)
downloadcpython-276468dddb46c54980c782c09cdb53bd90755752.zip
cpython-276468dddb46c54980c782c09cdb53bd90755752.tar.gz
cpython-276468dddb46c54980c782c09cdb53bd90755752.tar.bz2
bpo-43795: Add a test for Stable ABI symbol availability using ctypes (GH-26354)
This is a cross-platform check that the symbols are actually exported in the ABI, not e.g. hidden in a macro. Caveat: PyModule_Create2 & PyModule_FromDefAndSpec2 are skipped. These aren't exported on some of our buildbots. This is a bug (bpo-44133). This test now makes sure all the others don't regress.
Diffstat (limited to 'Tools/scripts')
-rwxr-xr-xTools/scripts/stable_abi.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Tools/scripts/stable_abi.py b/Tools/scripts/stable_abi.py
index 6cb310e..0179f3c 100755
--- a/Tools/scripts/stable_abi.py
+++ b/Tools/scripts/stable_abi.py
@@ -258,6 +258,44 @@ def gen_doc_annotations(manifest, args, outfile):
'added': item.added,
'ifdef_note': ifdef_note})
+@generator("ctypes_test", 'Lib/test/test_stable_abi_ctypes.py')
+def gen_ctypes_test(manifest, args, outfile):
+ """Generate/check the ctypes-based test for exported symbols"""
+ write = partial(print, file=outfile)
+ write(textwrap.dedent('''
+ # Generated by Tools/scripts/stable_abi.py
+
+ """Test that all symbols of the Stable ABI are accessible using ctypes
+ """
+
+ import unittest
+ from test.support.import_helper import import_module
+
+ ctypes_test = import_module('ctypes')
+
+ class TestStableABIAvailability(unittest.TestCase):
+ def test_available_symbols(self):
+ for symbol_name in SYMBOL_NAMES:
+ with self.subTest(symbol_name):
+ ctypes_test.pythonapi[symbol_name]
+
+ SYMBOL_NAMES = (
+ '''))
+ items = manifest.select(
+ {'function', 'data'},
+ include_abi_only=True,
+ ifdef=set())
+ for item in items:
+ if item.name in (
+ # Some symbols aren't exported on all platforms.
+ # This is a bug: https://bugs.python.org/issue44133
+ 'PyModule_Create2', 'PyModule_FromDefAndSpec2',
+ ):
+ continue
+ write(f' "{item.name}",')
+ write(")")
+
+
def generate_or_check(manifest, args, path, func):
"""Generate/check a file with a single generator