Merge #20608: contrib: add symbol check test for PE binaries

ae9b48995b contrib: add symbol check test for PE (fanquake)

Pull request description:

  Follow up to #20476. Adds a test for the PE symbol check. One failing case where we link against `-lpdh` and a pass case.

ACKs for top commit:
  laanwj:
    Code review ACK ae9b48995b
  dongcarl:
    Code Review ACK ae9b48995b

Tree-SHA512: 14109d2c7cb98fb445fe1a7f3078e1e88c49fd29583529c53c75bb625f3060d43df0c64542df72272cff81e1b073f74ce6e437ad0e6617ba2bcccacfd1dc8e53
This commit is contained in:
fanquake 2020-12-10 11:27:32 +08:00
commit 054710615c
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1
2 changed files with 38 additions and 0 deletions

View file

@ -350,6 +350,7 @@ if TARGET_DARWIN
endif
if TARGET_WINDOWS
$(AM_V_at) $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_PE
$(AM_V_at) $(PYTHON) $(top_srcdir)/contrib/devtools/test-symbol-check.py TestSymbolChecks.test_PE
endif
if TARGET_LINUX
$(AM_V_at) $(PYTHON) $(top_srcdir)/contrib/devtools/test-security-check.py TestSecurityChecks.test_ELF

View file

@ -120,6 +120,43 @@ class TestSymbolChecks(unittest.TestCase):
self.assertEqual(call_symbol_check(cc, source, executable, ['-framework', 'CoreGraphics']),
(0, ''))
def test_PE(self):
source = 'test1.c'
executable = 'test1.exe'
cc = 'x86_64-w64-mingw32-gcc'
with open(source, 'w', encoding="utf8") as f:
f.write('''
#include <pdh.h>
int main()
{
PdhConnectMachineA(NULL);
return 0;
}
''')
self.assertEqual(call_symbol_check(cc, source, executable, ['-lpdh']),
(1, 'pdh.dll is not in ALLOWED_LIBRARIES!\n' +
executable + ': failed DYNAMIC_LIBRARIES'))
source = 'test2.c'
executable = 'test2.exe'
with open(source, 'w', encoding="utf8") as f:
f.write('''
#include <windows.h>
int main()
{
CoFreeUnusedLibrariesEx(0,0);
return 0;
}
''')
self.assertEqual(call_symbol_check(cc, source, executable, ['-lole32']),
(0, ''))
if __name__ == '__main__':
unittest.main()