summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-01-15 12:30:11 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2020-01-15 12:30:11 +0530
commit2c96569374cb8f87564c4fab2560b8aee4a4d263 (patch)
treec2be6eb69ba869a80ddc5f99351b8b3c89512570
parente017147d2199a85e1c6664fb8d8f39f32a389e8b (diff)
downloadmeson-fix-pe-format-repro.tar.gz
tests/windows/16: Use pefile module instead of objdump/dumpbinfix-pe-format-repro
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.
-rw-r--r--test cases/windows/16 gui app/gui_app_tester.py29
-rw-r--r--test cases/windows/16 gui app/meson.build9
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'])