Home | History | Annotate | Download | only in win
      1 #!/usr/bin/env python
      2 
      3 # Copyright (c) 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 """
      8 Make sure msvs_large_pdb works correctly.
      9 """
     10 
     11 import TestGyp
     12 
     13 import struct
     14 import sys
     15 
     16 
     17 CHDIR = 'large-pdb'
     18 
     19 
     20 def CheckImageAndPdb(test, image_basename, expected_page_size,
     21                      pdb_basename=None):
     22   if not pdb_basename:
     23     pdb_basename = image_basename + '.pdb'
     24   test.built_file_must_exist(image_basename, chdir=CHDIR)
     25   test.built_file_must_exist(pdb_basename, chdir=CHDIR)
     26 
     27   # We expect the PDB to have the given page size. For full details of the
     28   # header look here: https://code.google.com/p/pdbparser/wiki/MSF_Format
     29   # We read the little-endian 4-byte unsigned integer at position 32 of the
     30   # file.
     31   pdb_path = test.built_file_path(pdb_basename, chdir=CHDIR)
     32   pdb_file = open(pdb_path, 'rb')
     33   pdb_file.seek(32, 0)
     34   page_size = struct.unpack('<I', pdb_file.read(4))[0]
     35   if page_size != expected_page_size:
     36     print "Expected page size of %d, got %d for PDB file `%s'." % (
     37         expected_page_size, page_size, pdb_path)
     38 
     39 
     40 if sys.platform == 'win32':
     41   test = TestGyp.TestGyp(formats=['msvs', 'ninja'])
     42 
     43   test.run_gyp('large-pdb.gyp', chdir=CHDIR)
     44 
     45   test.build('large-pdb.gyp', 'large_pdb_exe', chdir=CHDIR)
     46   CheckImageAndPdb(test, 'large_pdb_exe.exe', 4096)
     47 
     48   test.build('large-pdb.gyp', 'small_pdb_exe', chdir=CHDIR)
     49   CheckImageAndPdb(test, 'small_pdb_exe.exe', 1024)
     50 
     51   test.build('large-pdb.gyp', 'large_pdb_dll', chdir=CHDIR)
     52   CheckImageAndPdb(test, 'large_pdb_dll.dll', 4096)
     53 
     54   test.build('large-pdb.gyp', 'small_pdb_dll', chdir=CHDIR)
     55   CheckImageAndPdb(test, 'small_pdb_dll.dll', 1024)
     56 
     57   test.build('large-pdb.gyp', 'large_pdb_implicit_exe', chdir=CHDIR)
     58   CheckImageAndPdb(test, 'large_pdb_implicit_exe.exe', 4096)
     59 
     60   # This target has a different PDB name because it uses an
     61   # 'msvs_large_pdb_path' variable.
     62   test.build('large-pdb.gyp', 'large_pdb_variable_exe', chdir=CHDIR)
     63   CheckImageAndPdb(test, 'large_pdb_variable_exe.exe', 4096,
     64                    pdb_basename='foo.pdb')
     65 
     66   # This target has a different output name because it uses 'product_name'.
     67   test.build('large-pdb.gyp', 'large_pdb_product_exe', chdir=CHDIR)
     68   CheckImageAndPdb(test, 'bar.exe', 4096)
     69 
     70   test.pass_test()
     71