1#!/usr/bin/env python3 2# Copyright 2018 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 6import os 7import shutil 8import subprocess 9import sys 10import timeit 11 12 13IS_WIN = sys.platform.startswith('win') 14 15 16def RemoveDir(d): 17 if os.path.isdir(d): 18 shutil.rmtree(d) 19 20 21def Trial(gn_path_to_use, save_out_dir=None): 22 bin_path = os.path.join('out', 'gntrial') 23 if not os.path.isdir(bin_path): 24 os.makedirs(bin_path) 25 gn_to_run = os.path.join(bin_path, 'gn' + ('.exe' if IS_WIN else '')) 26 shutil.copy2(gn_path_to_use, gn_to_run) 27 comp_dir = os.path.join('out', 'COMP') 28 subprocess.check_call([gn_to_run, 'gen', comp_dir, '-q', '--check']) 29 if save_out_dir: 30 RemoveDir(save_out_dir) 31 shutil.move(comp_dir, save_out_dir) 32 33 34def main(): 35 if len(sys.argv) < 3 or len(sys.argv) > 4: 36 print('Usage: full_test.py /chrome/tree/at/762a25542878 rel_gn_path [clean]') 37 return 1 38 39 if len(sys.argv) == 4: 40 RemoveDir('out') 41 42 subprocess.check_call([sys.executable, os.path.join('build', 'gen.py')]) 43 subprocess.check_call(['ninja', '-C', 'out']) 44 subprocess.check_call([os.path.join('out', 'gn_unittests')]) 45 orig_dir = os.getcwd() 46 47 in_chrome_tree_gn = sys.argv[2] 48 our_gn = os.path.join(orig_dir, 'out', 'gn' + ('.exe' if IS_WIN else '')) 49 50 os.chdir(sys.argv[1]) 51 52 # Check in-tree vs. ours. Uses: 53 # - Chromium tree at 762a25542878 in argv[1] (this can be off by a bit, but 54 # is roughly when GN was moved out of the Chrome tree, so matches in case GN 55 # semantics/ordering change after that.) 56 # - relative path to argv[1] built gn binary in argv[2] 57 58 # First, do a comparison to make sure the output between the two gn binaries 59 # actually matches. 60 print('Confirming output matches...') 61 dir_a = os.path.join('out', 'a') 62 dir_b = os.path.join('out', 'b') 63 Trial(in_chrome_tree_gn, dir_a) 64 Trial(our_gn, dir_b) 65 subprocess.check_call(['diff', '-r', dir_a, dir_b]) 66 67 # Then, some time trials. 68 TRIALS = 5 69 print('Comparing performance... (takes a while)') 70 time_a = timeit.timeit('Trial("%s")' % in_chrome_tree_gn, number=TRIALS, 71 setup='from __main__ import Trial') 72 time_b = timeit.timeit('Trial("%s")' % our_gn, number=TRIALS, 73 setup='from __main__ import Trial') 74 print('In-tree gn avg: %.3fs' % (time_a / TRIALS)) 75 print('Our gn avg: %.3fs' % (time_b / TRIALS)) 76 77 return 0 78 79 80if __name__ == '__main__': 81 sys.exit(main()) 82