contrib: use c++ rather than c for binary tests

We don't actually use a c compiler as part of Core's build (only for secp).
We should be testing against what we're actually using instead.
This commit is contained in:
Cory Fields 2024-07-03 19:38:01 +00:00
parent 3714692644
commit a38c960005
3 changed files with 26 additions and 26 deletions

View file

@ -334,14 +334,14 @@ clean-local: clean-docs
test-security-check:
if TARGET_DARWIN
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_MACHO
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_MACHO
$(AM_V_at) CXX='$(CXX)' CXXFLAGS='$(CXXFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_MACHO
$(AM_V_at) CXX='$(CXX)' CXXFLAGS='$(CXXFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_MACHO
endif
if TARGET_WINDOWS
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_PE
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_PE
$(AM_V_at) CXX='$(CXX)' CXXFLAGS='$(CXXFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_PE
$(AM_V_at) CXX='$(CXX)' CXXFLAGS='$(CXXFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_PE
endif
if TARGET_LINUX
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_ELF
$(AM_V_at) CC='$(CC)' CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_ELF
$(AM_V_at) CXX='$(CXX)' CXXFLAGS='$(CXXFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_ELF
$(AM_V_at) CXX='$(CXX)' CXXFLAGS='$(CXXFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_ELF
endif

View file

@ -34,7 +34,7 @@ def env_flags() -> list[str]:
# See the definitions for ac_link in autoconf's lib/autoconf/c.m4 file for
# reference.
flags: list[str] = []
for var in ['CFLAGS', 'CPPFLAGS', 'LDFLAGS']:
for var in ['CXXFLAGS', 'CPPFLAGS', 'LDFLAGS']:
flags += filter(None, os.environ.get(var, '').split(' '))
return flags
@ -52,9 +52,9 @@ def get_arch(cc, source, executable):
class TestSecurityChecks(unittest.TestCase):
def test_ELF(self):
source = 'test1.c'
source = 'test1.cpp'
executable = 'test1'
cc = determine_wellknown_cmd('CC', 'gcc')
cc = determine_wellknown_cmd('CXX', 'g++')
write_testcode(source)
arch = get_arch(cc, source, executable)
@ -90,9 +90,9 @@ class TestSecurityChecks(unittest.TestCase):
clean_files(source, executable)
def test_PE(self):
source = 'test1.c'
source = 'test1.cpp'
executable = 'test1.exe'
cc = determine_wellknown_cmd('CC', 'x86_64-w64-mingw32-gcc')
cc = determine_wellknown_cmd('CXX', 'x86_64-w64-mingw32-g++')
write_testcode(source)
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--disable-nxcompat','-Wl,--disable-reloc-section','-Wl,--disable-dynamicbase','-Wl,--disable-high-entropy-va','-no-pie','-fno-PIE','-fno-stack-protector']),
@ -113,9 +113,9 @@ class TestSecurityChecks(unittest.TestCase):
clean_files(source, executable)
def test_MACHO(self):
source = 'test1.c'
source = 'test1.cpp'
executable = 'test1'
cc = determine_wellknown_cmd('CC', 'clang')
cc = determine_wellknown_cmd('CXX', 'clang++')
write_testcode(source)
arch = get_arch(cc, source, executable)

View file

@ -18,7 +18,7 @@ def call_symbol_check(cc: list[str], source, executable, options):
# See the definitions for ac_link in autoconf's lib/autoconf/c.m4 file for
# reference.
env_flags: list[str] = []
for var in ['CFLAGS', 'CPPFLAGS', 'LDFLAGS']:
for var in ['CXXFLAGS', 'CPPFLAGS', 'LDFLAGS']:
env_flags += filter(None, os.environ.get(var, '').split(' '))
subprocess.run([*cc,source,'-o',executable] + env_flags + options, check=True)
@ -29,13 +29,13 @@ def call_symbol_check(cc: list[str], source, executable, options):
class TestSymbolChecks(unittest.TestCase):
def test_ELF(self):
source = 'test1.c'
source = 'test1.cpp'
executable = 'test1'
cc = determine_wellknown_cmd('CC', 'gcc')
cc = determine_wellknown_cmd('CXX', 'g++')
# -lutil is part of the libc6 package so a safe bet that it's installed
# it's also out of context enough that it's unlikely to ever become a real dependency
source = 'test2.c'
source = 'test2.cpp'
executable = 'test2'
with open(source, 'w', encoding="utf8") as f:
f.write('''
@ -53,7 +53,7 @@ class TestSymbolChecks(unittest.TestCase):
executable + ': failed LIBRARY_DEPENDENCIES'))
# finally, check a simple conforming binary
source = 'test3.c'
source = 'test3.cpp'
executable = 'test3'
with open(source, 'w', encoding="utf8") as f:
f.write('''
@ -70,9 +70,9 @@ class TestSymbolChecks(unittest.TestCase):
(0, ''))
def test_MACHO(self):
source = 'test1.c'
source = 'test1.cpp'
executable = 'test1'
cc = determine_wellknown_cmd('CC', 'clang')
cc = determine_wellknown_cmd('CXX', 'clang++')
with open(source, 'w', encoding="utf8") as f:
f.write('''
@ -90,7 +90,7 @@ class TestSymbolChecks(unittest.TestCase):
(1, 'libexpat.1.dylib is not in ALLOWED_LIBRARIES!\n' +
f'{executable}: failed DYNAMIC_LIBRARIES MIN_OS SDK'))
source = 'test2.c'
source = 'test2.cpp'
executable = 'test2'
with open(source, 'w', encoding="utf8") as f:
f.write('''
@ -106,7 +106,7 @@ class TestSymbolChecks(unittest.TestCase):
self.assertEqual(call_symbol_check(cc, source, executable, ['-framework', 'CoreGraphics', '-Wl,-platform_version','-Wl,macos', '-Wl,11.4', '-Wl,11.4']),
(1, f'{executable}: failed MIN_OS SDK'))
source = 'test3.c'
source = 'test3.cpp'
executable = 'test3'
with open(source, 'w', encoding="utf8") as f:
f.write('''
@ -120,9 +120,9 @@ class TestSymbolChecks(unittest.TestCase):
(1, f'{executable}: failed SDK'))
def test_PE(self):
source = 'test1.c'
source = 'test1.cpp'
executable = 'test1.exe'
cc = determine_wellknown_cmd('CC', 'x86_64-w64-mingw32-gcc')
cc = determine_wellknown_cmd('CXX', 'x86_64-w64-mingw32-g++')
with open(source, 'w', encoding="utf8") as f:
f.write('''
@ -139,7 +139,7 @@ class TestSymbolChecks(unittest.TestCase):
(1, 'pdh.dll is not in ALLOWED_LIBRARIES!\n' +
executable + ': failed DYNAMIC_LIBRARIES'))
source = 'test2.c'
source = 'test2.cpp'
executable = 'test2.exe'
with open(source, 'w', encoding="utf8") as f:
@ -153,7 +153,7 @@ class TestSymbolChecks(unittest.TestCase):
self.assertEqual(call_symbol_check(cc, source, executable, ['-Wl,--major-subsystem-version', '-Wl,9', '-Wl,--minor-subsystem-version', '-Wl,9']),
(1, executable + ': failed SUBSYSTEM_VERSION'))
source = 'test3.c'
source = 'test3.cpp'
executable = 'test3.exe'
with open(source, 'w', encoding="utf8") as f:
f.write('''