gyptest-link-base-address.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python
  2. # Copyright 2013 Google Inc. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """
  6. Make sure the base address setting is extracted properly.
  7. """
  8. import TestGyp
  9. import re
  10. import sys
  11. if sys.platform == 'win32':
  12. test = TestGyp.TestGyp(formats=['msvs', 'ninja'])
  13. CHDIR = 'linker-flags'
  14. test.run_gyp('base-address.gyp', chdir=CHDIR)
  15. test.build('base-address.gyp', test.ALL, chdir=CHDIR)
  16. def GetHeaders(exe):
  17. full_path = test.built_file_path(exe, chdir=CHDIR)
  18. return test.run_dumpbin('/headers', full_path)
  19. # Extract the image base address from the headers output.
  20. image_base_reg_ex = re.compile(r'.*\s+([0-9]+) image base.*', re.DOTALL)
  21. exe_headers = GetHeaders('test_base_specified_exe.exe')
  22. exe_match = image_base_reg_ex.match(exe_headers)
  23. if not exe_match or not exe_match.group(1):
  24. test.fail_test()
  25. if exe_match.group(1) != '420000':
  26. test.fail_test()
  27. dll_headers = GetHeaders('test_base_specified_dll.dll')
  28. dll_match = image_base_reg_ex.match(dll_headers)
  29. if not dll_match or not dll_match.group(1):
  30. test.fail_test()
  31. if dll_match.group(1) != '10420000':
  32. test.fail_test()
  33. default_exe_headers = GetHeaders('test_base_default_exe.exe')
  34. default_exe_match = image_base_reg_ex.match(default_exe_headers)
  35. if not default_exe_match or not default_exe_match.group(1):
  36. test.fail_test()
  37. if default_exe_match.group(1) != '400000':
  38. test.fail_test()
  39. default_dll_headers = GetHeaders('test_base_default_dll.dll')
  40. default_dll_match = image_base_reg_ex.match(default_dll_headers)
  41. if not default_dll_match or not default_dll_match.group(1):
  42. test.fail_test()
  43. if default_dll_match.group(1) != '10000000':
  44. test.fail_test()
  45. test.pass_test()