From c5c0c467fedb909c1cfe7547abe477fdabb5526c Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 15 Jan 2020 12:30:11 +0530 Subject: [PATCH] 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. --- .../windows/16 gui app/gui_app_tester.py | 29 +++++++------------ test cases/windows/16 gui app/meson.build | 9 ++---- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/test cases/windows/16 gui app/gui_app_tester.py b/test cases/windows/16 gui app/gui_app_tester.py index 9cba806f0..53e76493f 100644 --- a/test cases/windows/16 gui app/gui_app_tester.py +++ b/test cases/windows/16 gui app/gui_app_tester.py @@ -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) diff --git a/test cases/windows/16 gui app/meson.build b/test cases/windows/16 gui app/meson.build index 224d708ee..157055532 100644 --- a/test cases/windows/16 gui app/meson.build +++ b/test cases/windows/16 gui app/meson.build @@ -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'])