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