aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-01-15 12:30:11 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2020-01-22 19:34:05 +0530
commitc5c0c467fedb909c1cfe7547abe477fdabb5526c (patch)
tree8fa0d52b94e1648db69d55c8d53f11bfa2a63954
parentbd17c9ad4f75dde2dd65a06d7cba0dec7ee09c15 (diff)
downloadmeson-c5c0c467fedb909c1cfe7547abe477fdabb5526c.zip
meson-c5c0c467fedb909c1cfe7547abe477fdabb5526c.tar.gz
meson-c5c0c467fedb909c1cfe7547abe477fdabb5526c.tar.bz2
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.
-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 9cba806..53e7649 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 224d708..1570555 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'])