OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. 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 import argparse |
| 7 import hashlib |
| 8 import os |
| 9 import subprocess |
| 10 import sys |
| 11 import tempfile |
| 12 |
| 13 SNAPSHOT_TEST_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 14 SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname( |
| 15 SNAPSHOT_TEST_DIR)))) |
| 16 DART_DIR = os.path.join(SRC_ROOT, 'dart') |
| 17 |
| 18 VM_SNAPSHOT_FILES=[ |
| 19 # Header files. |
| 20 'datastream.h', |
| 21 'object.h', |
| 22 'raw_object.h', |
| 23 'snapshot.h', |
| 24 'snapshot_ids.h', |
| 25 'symbols.h', |
| 26 # Source files. |
| 27 'dart.cc', |
| 28 'dart_api_impl.cc', |
| 29 'object.cc', |
| 30 'raw_object.cc', |
| 31 'raw_object_snapshot.cc', |
| 32 'snapshot.cc', |
| 33 'symbols.cc', |
| 34 ] |
| 35 |
| 36 def makeSnapshotHashString(): |
| 37 vmhash = hashlib.md5() |
| 38 for vmfilename in VM_SNAPSHOT_FILES: |
| 39 vmfilepath = os.path.join(DART_DIR, 'runtime', 'vm', vmfilename) |
| 40 with open(vmfilepath) as vmfile: |
| 41 vmhash.update(vmfile.read()) |
| 42 return vmhash.hexdigest() |
| 43 |
| 44 def main(): |
| 45 parser = argparse.ArgumentParser(description='Tests Dart snapshotting') |
| 46 parser.add_argument("--build-dir", |
| 47 dest="build_dir", |
| 48 metavar="<build-directory>", |
| 49 type=str, |
| 50 required=True, |
| 51 help="The directory containing the Mojo build.") |
| 52 args = parser.parse_args() |
| 53 dart_snapshotter = os.path.join(args.build_dir, 'dart_snapshotter') |
| 54 package_root = os.path.join(args.build_dir, 'gen', 'dart-pkg', 'packages') |
| 55 main_dart = os.path.join( |
| 56 args.build_dir, 'gen', 'dart-pkg', 'mojo_dart_hello', 'main.dart') |
| 57 snapshot = tempfile.mktemp() |
| 58 |
| 59 if not os.path.isfile(dart_snapshotter): |
| 60 print "file not found: " + dart_snapshotter |
| 61 return 1 |
| 62 subprocess.check_call([ |
| 63 dart_snapshotter, |
| 64 main_dart, |
| 65 '--package-root=%s' % package_root, |
| 66 '--snapshot=%s' % snapshot, |
| 67 ]) |
| 68 if not os.path.isfile(snapshot): |
| 69 return 1 |
| 70 |
| 71 expected_hash = makeSnapshotHashString() |
| 72 actual_hash = "" |
| 73 with open(snapshot) as snapshot_file: |
| 74 snapshot_file.seek(16) |
| 75 actual_hash = snapshot_file.read(32) |
| 76 if not actual_hash == expected_hash: |
| 77 print ('wrong hash: actual = %s, expected = %s' |
| 78 % (actual_hash, expected_hash)) |
| 79 return 1 |
| 80 return 0 |
| 81 |
| 82 if __name__ == '__main__': |
| 83 sys.exit(main()) |
OLD | NEW |