• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2
2#
3# Copyright 2019 The ANGLE Project Authors. 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# trigger.py:
8#   Helper script for triggering GPU tests on swarming.
9
10import argparse
11import hashlib
12import os
13import subprocess
14import sys
15
16
17def parse_args():
18    parser = argparse.ArgumentParser(os.path.basename(sys.argv[0]))
19    parser.add_argument('gn_path', help='path to GN. (e.g. out/Release)')
20    parser.add_argument('test', help='test name. (e.g. angle_end2end_tests)')
21    parser.add_argument('os_dim', help='OS dimension. (e.g. Windows-10)')
22    parser.add_argument('gpu_dim', help='GPU dimension. (e.g. intel-hd-630-win10-stable)')
23    parser.add_argument('-s', '--shards', default=1, help='number of shards', type=int)
24    parser.add_argument('-p', '--pool', default='Chrome-GPU', help='swarming pool')
25    return parser.parse_known_args()
26
27
28# Taken from:
29# https://chromium.googlesource.com/chromium/src/tools/mb/+/2192df66cd0ed214bcfbfd387ad0c5c8c0a21eb1/mb.py#586
30def add_base_software(swarming_args):
31    # HACK(iannucci): These packages SHOULD NOT BE HERE.
32    # Remove method once Swarming Pool Task Templates are implemented.
33    # crbug.com/812428
34
35    # Add in required base software. This should be kept in sync with the
36    # `chromium_swarming` recipe module in build.git. All references to
37    # `swarming_module` below are purely due to this.
38    cipd_packages = [
39        ('infra/python/cpython/${platform}', 'version:2.7.15.chromium14'),
40        ('infra/tools/luci/logdog/butler/${platform}',
41         'git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c'),
42        ('infra/tools/luci/vpython-native/${platform}',
43         'git_revision:e317c7d2c17d4c3460ee37524dfce4e1dee4306a'),
44        ('infra/tools/luci/vpython/${platform}',
45         'git_revision:e317c7d2c17d4c3460ee37524dfce4e1dee4306a'),
46    ]
47
48    for pkg, vers in cipd_packages:
49        swarming_args.append('--cipd-package=.swarming_module:%s=%s' % (pkg, vers))
50
51    # Add packages to $PATH
52    swarming_args.extend([
53        '--env-prefix',
54        'PATH=.swarming_module',
55        '--env-prefix',
56        'PATH=.swarming_module/bin',
57    ])
58
59    # Add cache directives for vpython.
60    vpython_cache_path = '.swarming_module_cache/vpython'
61    swarming_args.extend([
62        '--named-cache',
63        'swarming_module_cache_vpython=' + vpython_cache_path,
64        '--env-prefix',
65        'VPYTHON_VIRTUALENV_ROOT=' + vpython_cache_path,
66    ])
67
68
69def main():
70    args, unknown = parse_args()
71    path = args.gn_path.replace('\\', '/')
72    out_gn_path = '//' + path
73    out_file_path = os.path.join(*path.split('/'))
74
75    mb_script_path = os.path.join('tools', 'mb', 'mb.py')
76    subprocess.call(['python', mb_script_path, 'isolate', out_gn_path, args.test])
77
78    isolate_cmd_path = os.path.join('tools', 'luci-go', 'isolate')
79    isolate_file = os.path.join(out_file_path, '%s.isolate' % args.test)
80    isolated_file = os.path.join(out_file_path, '%s.isolated' % args.test)
81
82    isolate_args = [
83        isolate_cmd_path, 'archive', '-I', 'https://isolateserver.appspot.com', '-i', isolate_file,
84        '-s', isolated_file
85    ]
86    subprocess.check_call(isolate_args)
87    with open(isolated_file, 'rb') as f:
88        sha = hashlib.sha1(f.read()).hexdigest()
89
90    print('Got an isolated SHA of %s' % sha)
91    swarming_script_path = os.path.join('tools', 'luci-go', 'swarming')
92
93    swarming_args = [
94        swarming_script_path, 'trigger', '-S', 'chromium-swarm.appspot.com', '-I',
95        'https://isolateserver.appspot.com', '-d', 'os=' + args.os_dim, '-d', 'pool=' + args.pool,
96        '-d', 'gpu=' + args.gpu_dim, '-s', sha
97    ]
98
99    add_base_software(swarming_args)
100
101    for i in range(args.shards):
102        shard_args = swarming_args[:]
103        shard_args.extend([
104            '--env',
105            'GTEST_TOTAL_SHARDS=%d' % args.shards,
106            '--env',
107            'GTEST_SHARD_INDEX=%d' % i,
108        ])
109        if unknown:
110            shard_args += ["--"] + unknown
111
112        print(' '.join(shard_args))
113        subprocess.call(shard_args)
114    return 0
115
116
117if __name__ == '__main__':
118    sys.exit(main())
119