1# Copyright 2018 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5# Recipe which runs the PathKit tests using docker 6 7DEPS = [ 8 'checkout', 9 'env', 10 'infra', 11 'recipe_engine/file', 12 'recipe_engine/path', 13 'recipe_engine/properties', 14 'recipe_engine/python', 15 'recipe_engine/step', 16 'run', 17 'vars', 18] 19 20 21DOCKER_IMAGE = 'gcr.io/skia-public/gold-karma-chrome-tests:68.0.3440.106_v6' 22INNER_KARMA_SCRIPT = '/SRC/skia/infra/pathkit/test_pathkit.sh' 23 24 25def RunSteps(api): 26 api.vars.setup() 27 checkout_root = api.checkout.default_checkout_root 28 out_dir = api.vars.swarming_out_dir 29 api.checkout.bot_update(checkout_root=checkout_root) 30 31 # Make sure this exists, otherwise Docker will make it with root permissions. 32 api.file.ensure_directory('mkdirs out_dir', out_dir, mode=0777) 33 34 # The karma script is configured to look in ./npm-(asmjs|wasm)/bin/test/ for 35 # the test files to load, so we must copy them there (see Set up for docker). 36 copy_dest = checkout_root.join('skia', 'modules', 'pathkit', 37 'npm-wasm', 'bin', 'test') 38 if 'asmjs' in api.vars.builder_name: 39 copy_dest = checkout_root.join('skia', 'modules', 'pathkit', 40 'npm-asmjs', 'bin', 'test') 41 42 base_dir = api.vars.build_dir 43 bundle_name = 'pathkit.wasm' 44 if 'asmjs' in api.vars.builder_name: 45 # release mode has a .js.mem file that needs to come with. 46 # debug mode has an optional .map file, but we can omit that for tests 47 if 'Debug' in api.vars.builder_name: 48 bundle_name = '' 49 else: 50 bundle_name = 'pathkit.js.mem' 51 52 api.python.inline( 53 name='Set up for docker', 54 program='''import errno 55import os 56import shutil 57import sys 58 59copy_dest = sys.argv[1] 60base_dir = sys.argv[2] 61bundle_name = sys.argv[3] 62out_dir = sys.argv[4] 63 64# Clean out old binaries (if any) 65try: 66 shutil.rmtree(copy_dest) 67except OSError as e: 68 if e.errno != errno.ENOENT: 69 raise 70 71# Make folder 72try: 73 os.makedirs(copy_dest) 74except OSError as e: 75 if e.errno != errno.EEXIST: 76 raise 77 78# Copy binaries (pathkit.js and pathkit.wasm) to where the karma tests 79# expect them ($SKIA_ROOT/modules/pathkit/npm-wasm/bin/test/) 80dest = os.path.join(copy_dest, 'pathkit.js') 81shutil.copyfile(os.path.join(base_dir, 'pathkit.js'), dest) 82os.chmod(dest, 0o644) # important, otherwise non-privileged docker can't read. 83 84if bundle_name: 85 dest = os.path.join(copy_dest, bundle_name) 86 shutil.copyfile(os.path.join(base_dir, bundle_name), dest) 87 os.chmod(dest, 0o644) # important, otherwise non-privileged docker can't read. 88 89# Prepare output folder, api.file.ensure_directory doesn't touch 90# the permissions of the out directory if it already exists. 91os.chmod(out_dir, 0o777) # important, otherwise non-privileged docker can't write. 92''', 93 args=[copy_dest, base_dir, bundle_name, out_dir], 94 infra_step=True) 95 96 97 cmd = ['docker', 'run', '--shm-size=2gb', '--rm', 98 '--volume', '%s:/SRC' % checkout_root, 99 '--volume', '%s:/OUT' % out_dir] 100 101 if 'asmjs' in api.vars.builder_name: 102 cmd.extend(['--env', 'ASM_JS=1']) 103 104 cmd.extend([ 105 DOCKER_IMAGE, INNER_KARMA_SCRIPT, 106 '--builder', api.vars.builder_name, 107 '--git_hash', api.properties['revision'], 108 '--buildbucket_build_id', api.properties.get('buildbucket_build_id', 109 ''), 110 '--bot_id', api.vars.swarming_bot_id, 111 '--task_id', api.vars.swarming_task_id, 112 '--browser', 'Chrome', 113 '--config', api.vars.configuration, 114 '--source_type', 'pathkit', 115 ]) 116 117 if 'asmjs' in api.vars.builder_name: 118 cmd.extend(['--compiled_language', 'asmjs']) # the default is wasm 119 120 if api.vars.is_trybot: 121 cmd.extend([ 122 '--issue', api.vars.issue, 123 '--patchset', api.vars.patchset, 124 ]) 125 126 # Override DOCKER_CONFIG set by Kitchen. 127 env = {'DOCKER_CONFIG': '/home/chrome-bot/.docker'} 128 with api.env(env): 129 api.run( 130 api.step, 131 'Test PathKit with Docker', 132 cmd=cmd) 133 134 135def GenTests(api): 136 yield ( 137 api.test('Test-Debian9-EMCC-GCE-CPU-AVX2-wasm-Debug-All-PathKit') + 138 api.properties(buildername=('Test-Debian9-EMCC-GCE-CPU-AVX2' 139 '-wasm-Debug-All-PathKit'), 140 repository='https://skia.googlesource.com/skia.git', 141 revision='abc123', 142 path_config='kitchen', 143 swarm_out_dir='[SWARM_OUT_DIR]') 144 ) 145 146 yield ( 147 api.test('Test-Debian9-EMCC-GCE-CPU-AVX2-asmjs-Debug-All-PathKit') + 148 api.properties(buildername=('Test-Debian9-EMCC-GCE-CPU-AVX2' 149 '-asmjs-Debug-All-PathKit'), 150 repository='https://skia.googlesource.com/skia.git', 151 revision='abc123', 152 path_config='kitchen', 153 swarm_out_dir='[SWARM_OUT_DIR]') 154 ) 155 156 yield ( 157 api.test('Test-Debian9-EMCC-GCE-CPU-AVX2-asmjs-Release-All-PathKit') + 158 api.properties(buildername=('Test-Debian9-EMCC-GCE-CPU-AVX2' 159 '-asmjs-Release-All-PathKit'), 160 repository='https://skia.googlesource.com/skia.git', 161 revision='abc123', 162 path_config='kitchen', 163 swarm_out_dir='[SWARM_OUT_DIR]') 164 ) 165 166 yield ( 167 api.test('pathkit_trybot') + 168 api.properties(buildername=('Test-Debian9-EMCC-GCE-CPU-AVX2' 169 '-wasm-Debug-All-PathKit'), 170 repository='https://skia.googlesource.com/skia.git', 171 revision='abc123', 172 path_config='kitchen', 173 swarm_out_dir='[SWARM_OUT_DIR]', 174 patch_ref='89/456789/12', 175 patch_repo='https://skia.googlesource.com/skia.git', 176 patch_storage='gerrit', 177 patch_set=7, 178 patch_issue=1234, 179 gerrit_project='skia', 180 gerrit_url='https://skia-review.googlesource.com/') 181 ) 182