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.
This commit is contained in:
Petr Viktorin 2021-10-22 10:12:06 +02:00 committed by GitHub
parent 843b890334
commit 276468dddb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 881 additions and 0 deletions

View file

@ -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