Skip to content

Commit

Permalink
contrib: use c++ rather than c for binary tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
theuni authored and hebasto committed Jul 11, 2024
1 parent 439ceb0 commit 19307f5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions contrib/devtools/test-security-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -90,9 +90,9 @@ def test_ELF(self):
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']),
Expand All @@ -113,9 +113,9 @@ def test_PE(self):
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)

Expand Down
26 changes: 13 additions & 13 deletions contrib/devtools/test-symbol-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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('''
Expand All @@ -53,7 +53,7 @@ def test_ELF(self):
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('''
Expand All @@ -70,9 +70,9 @@ def test_ELF(self):
(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('''
Expand All @@ -90,7 +90,7 @@ def test_MACHO(self):
(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('''
Expand All @@ -106,7 +106,7 @@ def test_MACHO(self):
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('''
Expand All @@ -120,9 +120,9 @@ def test_MACHO(self):
(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('''
Expand All @@ -139,7 +139,7 @@ def test_PE(self):
(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:
Expand All @@ -153,7 +153,7 @@ def test_PE(self):
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('''
Expand Down

0 comments on commit 19307f5

Please sign in to comment.