#!/usr/bin/python3
# Check header contents against the given standard.
# Copyright (C) 2018-2025 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
#
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, see
# <https://www.gnu.org/licenses/>.
import argparse
import fnmatch
import os.path
import re
import subprocess
import sys
import tempfile
import glibcconform
class CompileSubTest(object):
"""A compilation subtest."""
def __init__(self, name, text):
"""Initialize a CompileSubTest object."""
self.run_early = False
self.name = name
self.text = text
def run(self, header_tests):
"""Run a compilation subtest."""
header_tests.compile_test(self.name, self.text)
class ExecuteSubTest(object):
"""An execution subtest."""
def __init__(self, name, text):
"""Initialize an ExecuteSubTest object."""
self.run_early = False
self.name = name
self.text = text
def run(self, header_tests):
"""Run an execution subtest."""
header_tests.execute_test(self.name, self.text)
class ElementTest(object):
"""Test for an element of a structure or union type."""
def __init__(self, dummy, type_name, member_type, member_name, *rest):
"""Initialize an ElementTest object."""
self.type_name = type_name
self.member_type = member_type
self.member_name = member_name
self.rest = ' '.join(rest)
self.allow_name = self.member_name
def gen_subtests(self):
"""Generate subtests for an ElementTest."""
text = ('%(type_name)s a_%(num)d;\n'
'%(type_name)s b_%(num)d;\n'
'extern void xyzzy_%(num)d '
'(__typeof__ (&b_%(num)d.%(member_name)s), '
'__typeof__ (&a_%(num)d.%(member_name)s), unsigned);\n'
'void foobarbaz_%(num)d (void) {\n'
'xyzzy_%(num)d (&a_%(num)d.%(member_name)s, '
'&b_%(num)d.%(member_name)s, '
'sizeof (a_%(num)d.%(member_name)s));\n'
'}\n'
% vars(self))
self.subtests.append(CompileSubTest(
'Availability of member %s' % self.member_name,
text))
text = ('%(type_name)s a2_%(num)d;\n'
'extern %(member_type)s b2_%(num)d%(rest)s;\n'
'extern __typeof__ (a2_%(num)d.%(member_name)s) b2_%(num)d;\n'
% vars(self))
self.subtests.append(CompileSubTest(
'Type of member %s' % self.member_name,
text))
class ConstantTest(object):
"""Test for a macro or constant."""
def __init__(self, symbol_type, symbol, extra1=<