tests/windows/16: Use pefile module instead of objdump/dumpbin

The pefile module is a CI dependency now, so we can use that instead
of objdump/dumpbin which greatly simplifies the test. Of course, this
module is also cross-platform so it will work if we add cross-win32 CI
at some point.
This commit is contained in:
Nirbheek Chauhan 2020-01-15 12:30:11 +05:30 committed by Nirbheek Chauhan
parent bd17c9ad4f
commit c5c0c467fe
2 changed files with 13 additions and 25 deletions

View File

@ -1,26 +1,19 @@
#!/usr/bin/env python3
import re
import subprocess
import os
import sys
try:
import pefile
except ImportError:
if 'CI' in os.environ:
raise
# Skip the test if not on CI
sys.exit(77)
tool = sys.argv[1]
executable = sys.argv[2]
expected = int(sys.argv[3])
actual = -1
executable = sys.argv[1]
expected = int(sys.argv[2])
if 'objdump' in tool:
result = subprocess.check_output([tool, '-p', executable]).decode()
match = re.search(r'^Subsystem\s+(\d+)', result, re.MULTILINE)
elif 'dumpbin' in tool:
result = subprocess.check_output([tool, '/headers', executable]).decode()
match = re.search(r'^\s*(\d+) subsystem(?! version)', result, re.MULTILINE)
else:
print('unknown tool')
sys.exit(1)
if match:
actual = int(match.group(1))
actual = pefile.PE(executable).dump_dict()['OPTIONAL_HEADER']['Subsystem']['Value']
print('subsystem expected: %d, actual: %d' % (expected, actual))
sys.exit(0 if (expected == actual) else 1)

View File

@ -17,10 +17,5 @@ console_prog = executable('console_prog', 'console_prog.c', gui_app: false)
tester = find_program('gui_app_tester.py')
tool = find_program('objdump', 'dumpbin', required: false)
# TODO: when 'llvm-objdump -f' emits the subsystem type, we could use that also
if tool.found()
test('is_gui', tester, args: [tool.path(), gui_prog, '2'])
test('not_gui', tester, args: [tool.path(), console_prog, '3'])
endif
test('is_gui', tester, args: [gui_prog, '2'])
test('not_gui', tester, args: [console_prog, '3'])