1#!/usr/bin/env python 2# Copyright (c) 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"""This script is meant to be run on a Swarming bot.""" 7 8import argparse 9import os 10import subprocess 11import sys 12 13 14PARENT_DIR = os.path.dirname(os.path.realpath(__file__)) 15 16REPOS_BASE_DIR = os.path.normpath(os.path.join( 17 PARENT_DIR, os.pardir, os.pardir, os.pardir, os.pardir)) 18 19SKIA_SRC_DIR = os.path.join(REPOS_BASE_DIR, 'skia') 20 21 22def main(): 23 parser = argparse.ArgumentParser() 24 parser.add_argument('-s', '--slave_num', required=True, type=int, 25 help='The slave num of this CT run.') 26 parser.add_argument('-t', '--tool', required=True, 27 choices=['dm', 'nanobench', 'get_images_from_skps'], 28 help='The tool to run on the SKPs.') 29 parser.add_argument('-g', '--git_hash', required=True, 30 help='The Skia hash the tool was built at.') 31 parser.add_argument('-c', '--configuration', required=True, 32 help='The build configuration to use.') 33 parser.add_argument('-i', '--isolated_outdir', required=True, 34 help='Swarming will automatically upload to ' 35 'isolateserver all artifacts in this dir.') 36 parser.add_argument('-b', '--builder', required=True, 37 help='The name of the builder.') 38 parser.add_argument('-r', '--chromium_build', required=True, 39 help='The chromium build used to create the SKP repo.') 40 parser.add_argument('-p', '--page_type', required=True, 41 help='The CT page type.') 42 parser.add_argument('-n', '--num_slaves', required=True, 43 help='Total number of slaves used to run the build.') 44 args = parser.parse_args() 45 46 tool_path = os.path.join(PARENT_DIR, args.tool) 47 skps_dir = os.path.join( 48 REPOS_BASE_DIR, 'skps', args.chromium_build, args.page_type, 49 args.num_slaves, 'slave%d' % args.slave_num) 50 resource_path = os.path.join(SKIA_SRC_DIR, 'resources') 51 52 cmd = [tool_path] 53 if args.tool == 'dm': 54 # Add DM specific arguments. 55 cmd.extend([ 56 '--src', 'skp', 57 '--skps', skps_dir, 58 '--resourcePath', resource_path, 59 '--config', '8888', 60 '--verbose', 61 ]) 62 elif args.tool == 'nanobench': 63 # Add Nanobench specific arguments. 64 config = '8888' 65 cpu_or_gpu = 'CPU' 66 cpu_or_gpu_value = 'AVX2' 67 if 'GPU' in args.builder: 68 config = 'gl' 69 cpu_or_gpu = 'GPU' 70 cpu_or_gpu_value = 'QuadroP400' 71 72 out_results_file = os.path.join( 73 args.isolated_outdir, 'nanobench_%s_%s_slave%d.json' % ( 74 args.git_hash, config, args.slave_num)) 75 cmd.extend([ 76 '--skps', skps_dir, 77 '--match', 'skp', 78 '--resourcePath', resource_path, 79 '--config', config, 80 '--outResultsFile', out_results_file, 81 '--properties', 'gitHash', args.git_hash, 82 '--key', 'arch', 'x86_64', 83 'compiler', 'GCC', 84 'cpu_or_gpu', cpu_or_gpu, 85 'cpu_or_gpu_value', cpu_or_gpu_value, 86 'model', 'SWARM', 87 'os', 'Ubuntu', 88 '--verbose', 89 ]) 90 elif args.tool == 'get_images_from_skps': 91 # Add get_images_from_skps specific arguments. 92 img_out = os.path.join(args.isolated_outdir, 'img_out') 93 os.makedirs(img_out) 94 failures_json_out = os.path.join(args.isolated_outdir, 'failures.json') 95 cmd.extend([ 96 '--out', img_out, 97 '--skps', skps_dir, 98 '--failuresJsonPath', failures_json_out, 99 '--writeImages', 'false', 100 '--testDecode', 101 ]) 102 103 return subprocess.call(cmd) 104 105 106if __name__ == '__main__': 107 sys.exit(main()) 108