1# Copyright 2016 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 6# Recipe module for Skia Swarming test. 7 8 9import json 10 11PYTHON_VERSION_COMPATIBILITY = "PY3" 12 13DEPS = [ 14 'env', 15 'flavor', 16 'recipe_engine/context', 17 'recipe_engine/file', 18 'recipe_engine/path', 19 'recipe_engine/platform', 20 'recipe_engine/properties', 21 'recipe_engine/raw_io', 22 'recipe_engine/step', 23 'gold_upload', 24 'run', 25 'vars', 26] 27 28DM_JSON = 'dm.json' 29 30def test_steps(api): 31 """Run the DM test.""" 32 do_upload = api.properties.get('do_upload') == 'true' 33 images = api.properties.get('images') == 'true' 34 lotties = api.properties.get('lotties') == 'true' 35 resources = api.properties.get('resources') == 'true' 36 skps = api.properties.get('skps') == 'true' 37 svgs = api.properties.get('svgs') == 'true' 38 39 api.flavor.install( 40 images=images, 41 lotties=lotties, 42 resources=resources, 43 skps=skps, 44 svgs=svgs, 45 ) 46 47 use_hash_file = False 48 if do_upload: 49 host_dm_dir = str(api.flavor.host_dirs.dm_dir) 50 api.flavor.create_clean_host_dir(api.path.start_dir.joinpath('test')) 51 device_dm_dir = str(api.flavor.device_dirs.dm_dir) 52 if host_dm_dir != device_dm_dir: 53 api.flavor.create_clean_device_dir(device_dm_dir) 54 55 # Obtain the list of already-generated hashes. 56 hash_filename = 'uninteresting_hashes.txt' 57 58 host_hashes_file = api.vars.tmp_dir.joinpath(hash_filename) 59 hashes_file = api.flavor.device_path_join( 60 api.flavor.device_dirs.tmp_dir, hash_filename) 61 script = api.gold_upload.resource('get_uninteresting_hashes.py') 62 api.run( 63 api.step, 64 'get uninteresting hashes', 65 cmd=['python3', script, api.properties['gold_hashes_url'], 66 host_hashes_file], 67 # If this fails, we want to know about it because it means Gold is down 68 # and proceeding onwards would take a very long time, but be hard to notice. 69 abort_on_failure=True, 70 fail_build_on_failure=True, 71 infra_step=True) 72 73 if api.path.exists(host_hashes_file): 74 api.flavor.copy_file_to_device(host_hashes_file, hashes_file) 75 use_hash_file = True 76 77 # Find DM flags. 78 args = json.loads(api.properties['dm_flags']) 79 props = json.loads(api.properties['dm_properties']) 80 args.append('--properties') 81 # Map iteration order is arbitrary; in order to maintain a consistent step 82 # ordering, sort by key. 83 for k in sorted(props.keys()): 84 v = props[k] 85 if v == '${SWARMING_BOT_ID}': 86 v = api.vars.swarming_bot_id 87 elif v == '${SWARMING_TASK_ID}': 88 v = api.vars.swarming_task_id 89 if v != '': 90 args.extend([k, v]) 91 92 # Paths to required resources. 93 if resources: 94 args.extend(['--resourcePath', api.flavor.device_dirs.resource_dir]) 95 if skps: 96 args.extend(['--skps', api.flavor.device_dirs.skp_dir]) 97 if images: 98 args.extend([ 99 '--images', api.flavor.device_path_join( 100 api.flavor.device_dirs.images_dir, 'dm'), 101 '--colorImages', api.flavor.device_path_join( 102 api.flavor.device_dirs.images_dir, 'colorspace'), 103 ]) 104 if svgs: 105 # svg_dir is the root of the SVG corpus. Within that directory, 106 # the *.svg inputs are in the 'svg' subdirectory. See skbug.com/11229 107 args.extend(['--svgs', api.flavor.device_path_join( 108 api.flavor.device_dirs.svg_dir, "svg")]) 109 if lotties: 110 args.extend([ 111 '--lotties', 112 api.flavor.device_path_join( 113 api.flavor.device_dirs.resource_dir, 'skottie'), 114 api.flavor.device_dirs.lotties_dir, 115 ]) 116 if 'Fontations' in api.vars.builder_cfg.get('extra_config', []): 117 args.extend(['--fontTestDataPath', api.flavor.device_dirs.fonts_dir]) 118 119 if use_hash_file: 120 args.extend(['--uninterestingHashesFile', hashes_file]) 121 if do_upload: 122 args.extend(['--writePath', api.flavor.device_dirs.dm_dir]) 123 124 # Run DM. 125 api.run(api.flavor.step, 'dm', cmd=args, abort_on_failure=False) 126 127 if do_upload: 128 # Copy images and JSON to host machine if needed. 129 api.flavor.copy_directory_contents_to_host( 130 api.flavor.device_dirs.dm_dir, api.flavor.host_dirs.dm_dir) 131 # https://bugs.chromium.org/p/chromium/issues/detail?id=1192611 132 if 'Win' not in api.vars.builder_cfg.get('os', ''): 133 api.gold_upload.upload() 134 135 136def RunSteps(api): 137 api.vars.setup() 138 api.file.ensure_directory('makedirs tmp_dir', api.vars.tmp_dir) 139 api.flavor.setup('dm') 140 141 try: 142 test_steps(api) 143 finally: 144 api.flavor.cleanup_steps() 145 api.run.check_failure() 146 147 148TEST_BUILDERS = [ 149 'Test-Android12-Clang-Pixel5-GPU-Adreno620-arm64-Release-All-Android_Vulkan', 150 'Test-Debian10-Clang-GCE-CPU-AVX2-x86_64-Release-All-Lottie', 151 'Test-Win11-Clang-Dell3930-GPU-GTX1660-x86_64-Debug-All', 152 'Test-Debian10-Clang-GCE-CPU-AVX2-x86_64-Debug-All-Fontations', 153] 154 155 156def GenTests(api): 157 for builder in TEST_BUILDERS: 158 props = dict( 159 buildername=builder, 160 buildbucket_build_id='123454321', 161 dm_flags='["dm","--example","--flags"]', 162 dm_properties=('{"key1":"value1","key2":"",' 163 '"bot":"${SWARMING_BOT_ID}",' 164 '"task":"${SWARMING_TASK_ID}"}'), 165 revision='abc123', 166 gs_bucket='skia-infra-gm', 167 patch_ref='89/456789/12', 168 patch_set=7, 169 patch_issue=1234, 170 path_config='kitchen', 171 gold_hashes_url='https://example.com/hashes.txt', 172 swarm_out_dir='[SWARM_OUT_DIR]', 173 task_id='task_12345', 174 resources='true', 175 ) 176 if 'ASAN' not in builder: 177 props['do_upload'] = 'true' 178 if 'Lottie' in builder: 179 props['lotties'] = 'true' 180 else: 181 props['images'] = 'true' 182 props['skps'] = 'true' 183 props['svgs'] = 'true' 184 test = ( 185 api.test(builder) + 186 api.properties(**props) + 187 api.path.exists( 188 api.path.start_dir.joinpath('skia'), 189 api.path.start_dir.joinpath('skia', 'infra', 'bots', 'assets', 190 'skimage', 'VERSION'), 191 api.path.start_dir.joinpath('skia', 'infra', 'bots', 'assets', 192 'skp', 'VERSION'), 193 api.path.start_dir.joinpath('skia', 'infra', 'bots', 'assets', 194 'svg', 'VERSION'), 195 api.path.start_dir.joinpath('tmp', 'uninteresting_hashes.txt') 196 ) + 197 api.step_data('get swarming bot id', 198 stdout=api.raw_io.output('skia-bot-123')) + 199 api.step_data('get swarming task id', 200 stdout=api.raw_io.output('123456')) 201 ) 202 if 'Win' in builder: 203 test += api.platform('win', 64) 204 205 yield test 206