borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 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 | |
Eric Boren | 43a8cc8 | 2020-03-02 10:05:23 -0500 | [diff] [blame] | 9 | import json |
| 10 | |
| 11 | |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 12 | DEPS = [ |
Eric Boren | 896af75 | 2017-04-24 13:22:56 -0400 | [diff] [blame] | 13 | 'env', |
| 14 | 'flavor', |
Robert Iannucci | 297a7ef | 2017-05-12 19:09:38 -0700 | [diff] [blame] | 15 | 'recipe_engine/context', |
Robert Iannucci | 8cd5041 | 2017-07-07 14:36:58 -0700 | [diff] [blame] | 16 | 'recipe_engine/file', |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 17 | 'recipe_engine/path', |
| 18 | 'recipe_engine/platform', |
| 19 | 'recipe_engine/properties', |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 20 | 'recipe_engine/python', |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 21 | 'recipe_engine/raw_io', |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 22 | 'recipe_engine/step', |
Weston Tracey | 9bb0b6e | 2021-03-29 10:29:40 -0400 | [diff] [blame] | 23 | 'gold_upload', |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 24 | 'run', |
| 25 | 'vars', |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 26 | ] |
| 27 | |
Weston Tracey | c98b2af | 2021-03-25 11:49:12 -0400 | [diff] [blame] | 28 | DM_JSON = 'dm.json' |
| 29 | |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 30 | def test_steps(api): |
| 31 | """Run the DM test.""" |
Eric Boren | 59e7496 | 2020-03-23 09:17:24 -0400 | [diff] [blame] | 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 | |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 47 | use_hash_file = False |
Eric Boren | 59e7496 | 2020-03-23 09:17:24 -0400 | [diff] [blame] | 48 | if do_upload: |
Eric Boren | 72f6668 | 2018-05-18 07:36:55 -0400 | [diff] [blame] | 49 | host_dm_dir = str(api.flavor.host_dirs.dm_dir) |
| 50 | api.flavor.create_clean_host_dir(api.path['start_dir'].join('test')) |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 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 | |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 58 | host_hashes_file = api.vars.tmp_dir.join(hash_filename) |
| 59 | hashes_file = api.flavor.device_path_join( |
| 60 | api.flavor.device_dirs.tmp_dir, hash_filename) |
| 61 | api.run( |
| 62 | api.python.inline, |
| 63 | 'get uninteresting hashes', |
| 64 | program=""" |
| 65 | import contextlib |
| 66 | import math |
| 67 | import socket |
| 68 | import sys |
| 69 | import time |
| 70 | import urllib2 |
| 71 | |
Stephan Altmüller | 64cc576 | 2018-08-02 08:51:38 +0200 | [diff] [blame] | 72 | HASHES_URL = sys.argv[1] |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 73 | RETRIES = 5 |
| 74 | TIMEOUT = 60 |
| 75 | WAIT_BASE = 15 |
| 76 | |
| 77 | socket.setdefaulttimeout(TIMEOUT) |
| 78 | for retry in range(RETRIES): |
| 79 | try: |
| 80 | with contextlib.closing( |
| 81 | urllib2.urlopen(HASHES_URL, timeout=TIMEOUT)) as w: |
| 82 | hashes = w.read() |
Stephan Altmüller | 64cc576 | 2018-08-02 08:51:38 +0200 | [diff] [blame] | 83 | with open(sys.argv[2], 'w') as f: |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 84 | f.write(hashes) |
| 85 | break |
| 86 | except Exception as e: |
| 87 | print 'Failed to get uninteresting hashes from %s:' % HASHES_URL |
| 88 | print e |
| 89 | if retry == RETRIES: |
| 90 | raise |
| 91 | waittime = WAIT_BASE * math.pow(2, retry) |
| 92 | print 'Retry in %d seconds.' % waittime |
| 93 | time.sleep(waittime) |
| 94 | """, |
Stephan Altmüller | 64cc576 | 2018-08-02 08:51:38 +0200 | [diff] [blame] | 95 | args=[api.properties['gold_hashes_url'], host_hashes_file], |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 96 | abort_on_failure=False, |
| 97 | fail_build_on_failure=False, |
| 98 | infra_step=True) |
| 99 | |
| 100 | if api.path.exists(host_hashes_file): |
| 101 | api.flavor.copy_file_to_device(host_hashes_file, hashes_file) |
| 102 | use_hash_file = True |
| 103 | |
Eric Boren | 43a8cc8 | 2020-03-02 10:05:23 -0500 | [diff] [blame] | 104 | # Find DM flags. |
| 105 | args = json.loads(api.properties['dm_flags']) |
| 106 | props = json.loads(api.properties['dm_properties']) |
| 107 | args.append('--properties') |
| 108 | # Map iteration order is arbitrary; in order to maintain a consistent step |
| 109 | # ordering, sort by key. |
| 110 | for k in sorted(props.keys()): |
| 111 | v = props[k] |
| 112 | if v == '${SWARMING_BOT_ID}': |
| 113 | v = api.vars.swarming_bot_id |
| 114 | elif v == '${SWARMING_TASK_ID}': |
| 115 | v = api.vars.swarming_task_id |
| 116 | if v != '': |
| 117 | args.extend([k, v]) |
| 118 | |
| 119 | # Paths to required resources. |
Eric Boren | 59e7496 | 2020-03-23 09:17:24 -0400 | [diff] [blame] | 120 | if resources: |
| 121 | args.extend(['--resourcePath', api.flavor.device_dirs.resource_dir]) |
| 122 | if skps: |
| 123 | args.extend(['--skps', api.flavor.device_dirs.skp_dir]) |
| 124 | if images: |
| 125 | args.extend([ |
| 126 | '--images', api.flavor.device_path_join( |
| 127 | api.flavor.device_dirs.images_dir, 'dm'), |
| 128 | '--colorImages', api.flavor.device_path_join( |
| 129 | api.flavor.device_dirs.images_dir, 'colorspace'), |
| 130 | ]) |
| 131 | if svgs: |
Tyler Denniston | ba9ec5f | 2021-02-01 09:30:03 -0500 | [diff] [blame] | 132 | # svg_dir is the root of the SVG corpus. Within that directory, |
| 133 | # the *.svg inputs are in the 'svg' subdirectory. See skbug.com/11229 |
| 134 | args.extend(['--svgs', api.flavor.device_path_join( |
| 135 | api.flavor.device_dirs.svg_dir, "svg")]) |
Eric Boren | 59e7496 | 2020-03-23 09:17:24 -0400 | [diff] [blame] | 136 | if lotties: |
Kevin Lubick | c499ec8 | 2020-02-12 15:41:10 -0500 | [diff] [blame] | 137 | args.extend([ |
| 138 | '--lotties', |
| 139 | api.flavor.device_path_join( |
| 140 | api.flavor.device_dirs.resource_dir, 'skottie'), |
Eric Boren | 07248d9 | 2020-02-28 14:07:15 -0500 | [diff] [blame] | 141 | api.flavor.device_dirs.lotties_dir, |
| 142 | ]) |
Kevin Lubick | 608c35a | 2018-01-16 16:15:57 -0500 | [diff] [blame] | 143 | |
| 144 | if use_hash_file: |
| 145 | args.extend(['--uninterestingHashesFile', hashes_file]) |
Eric Boren | 59e7496 | 2020-03-23 09:17:24 -0400 | [diff] [blame] | 146 | if do_upload: |
Kevin Lubick | 608c35a | 2018-01-16 16:15:57 -0500 | [diff] [blame] | 147 | args.extend(['--writePath', api.flavor.device_dirs.dm_dir]) |
Kevin Lubick | 2dafbd7 | 2017-08-31 10:39:05 -0400 | [diff] [blame] | 148 | |
Eric Boren | 43a8cc8 | 2020-03-02 10:05:23 -0500 | [diff] [blame] | 149 | # Run DM. |
Ben Wagner | 5655ba4 | 2017-10-02 10:48:32 -0400 | [diff] [blame] | 150 | api.run(api.flavor.step, 'dm', cmd=args, abort_on_failure=False) |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 151 | |
Eric Boren | 59e7496 | 2020-03-23 09:17:24 -0400 | [diff] [blame] | 152 | if do_upload: |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 153 | # Copy images and JSON to host machine if needed. |
| 154 | api.flavor.copy_directory_contents_to_host( |
Eric Boren | 72f6668 | 2018-05-18 07:36:55 -0400 | [diff] [blame] | 155 | api.flavor.device_dirs.dm_dir, api.flavor.host_dirs.dm_dir) |
Weston Tracey | c98b2af | 2021-03-25 11:49:12 -0400 | [diff] [blame] | 156 | # https://bugs.chromium.org/p/chromium/issues/detail?id=1192611 |
| 157 | if 'Win' not in api.vars.builder_cfg.get('os', ''): |
Weston Tracey | 9bb0b6e | 2021-03-29 10:29:40 -0400 | [diff] [blame] | 158 | api.gold_upload.upload() |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 159 | |
| 160 | |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 161 | def RunSteps(api): |
Eric Boren | b702316 | 2018-05-04 13:46:15 -0400 | [diff] [blame] | 162 | api.vars.setup() |
| 163 | api.file.ensure_directory('makedirs tmp_dir', api.vars.tmp_dir) |
Eric Boren | 7fb77c8 | 2020-02-27 12:19:46 -0500 | [diff] [blame] | 164 | api.flavor.setup('dm') |
Eric Boren | b702316 | 2018-05-04 13:46:15 -0400 | [diff] [blame] | 165 | |
Eric Boren | 7fb77c8 | 2020-02-27 12:19:46 -0500 | [diff] [blame] | 166 | try: |
Eric Boren | 7fb77c8 | 2020-02-27 12:19:46 -0500 | [diff] [blame] | 167 | test_steps(api) |
| 168 | finally: |
| 169 | api.flavor.cleanup_steps() |
| 170 | api.run.check_failure() |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 171 | |
| 172 | |
Eric Boren | f9aa9e5 | 2017-04-10 09:56:10 -0400 | [diff] [blame] | 173 | TEST_BUILDERS = [ |
Eric Boren | e5766b8 | 2021-06-28 11:11:21 -0400 | [diff] [blame] | 174 | 'Test-Android-Clang-Pixel2XL-GPU-Adreno540-arm-Debug-All-Android_ASAN', |
Brian Osman | 4af42fc | 2019-09-16 12:38:04 -0400 | [diff] [blame] | 175 | 'Test-Android-Clang-Pixel2XL-GPU-Adreno540-arm64-Debug-All-Android', |
Weston Tracey | 2462788 | 2020-04-06 21:27:14 -0400 | [diff] [blame] | 176 | 'Test-Debian10-Clang-GCE-CPU-AVX2-x86_64-Release-All-Lottie', |
Ben Wagner | b2fd61a | 2017-10-23 16:01:44 -0400 | [diff] [blame] | 177 | 'Test-Win10-Clang-ShuttleC-GPU-GTX960-x86_64-Debug-All-ANGLE', |
Eric Boren | f9aa9e5 | 2017-04-10 09:56:10 -0400 | [diff] [blame] | 178 | ] |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 179 | |
| 180 | |
| 181 | def GenTests(api): |
Eric Boren | f9aa9e5 | 2017-04-10 09:56:10 -0400 | [diff] [blame] | 182 | for builder in TEST_BUILDERS: |
Eric Boren | 59e7496 | 2020-03-23 09:17:24 -0400 | [diff] [blame] | 183 | props = dict( |
| 184 | buildername=builder, |
| 185 | buildbucket_build_id='123454321', |
Kevin Lubick | 2266380 | 2021-01-29 11:05:41 -0500 | [diff] [blame] | 186 | dm_flags='["dm","--example","--flags"]', |
Eric Boren | 59e7496 | 2020-03-23 09:17:24 -0400 | [diff] [blame] | 187 | dm_properties=('{"key1":"value1","key2":"",' |
| 188 | '"bot":"${SWARMING_BOT_ID}",' |
| 189 | '"task":"${SWARMING_TASK_ID}"}'), |
| 190 | revision='abc123', |
Weston Tracey | c98b2af | 2021-03-25 11:49:12 -0400 | [diff] [blame] | 191 | gs_bucket='skia-infra-gm', |
| 192 | patch_ref='89/456789/12', |
| 193 | patch_set=7, |
| 194 | patch_issue=1234, |
Eric Boren | 59e7496 | 2020-03-23 09:17:24 -0400 | [diff] [blame] | 195 | path_config='kitchen', |
| 196 | gold_hashes_url='https://example.com/hashes.txt', |
| 197 | swarm_out_dir='[SWARM_OUT_DIR]', |
| 198 | task_id='task_12345', |
| 199 | resources='true', |
| 200 | ) |
| 201 | if 'ASAN' not in builder: |
| 202 | props['do_upload'] = 'true' |
| 203 | if 'Lottie' in builder: |
| 204 | props['lotties'] = 'true' |
| 205 | else: |
| 206 | props['images'] = 'true' |
| 207 | props['skps'] = 'true' |
| 208 | props['svgs'] = 'true' |
Eric Boren | f9aa9e5 | 2017-04-10 09:56:10 -0400 | [diff] [blame] | 209 | test = ( |
| 210 | api.test(builder) + |
Eric Boren | 59e7496 | 2020-03-23 09:17:24 -0400 | [diff] [blame] | 211 | api.properties(**props) + |
Eric Boren | f9aa9e5 | 2017-04-10 09:56:10 -0400 | [diff] [blame] | 212 | api.path.exists( |
| 213 | api.path['start_dir'].join('skia'), |
| 214 | api.path['start_dir'].join('skia', 'infra', 'bots', 'assets', |
| 215 | 'skimage', 'VERSION'), |
| 216 | api.path['start_dir'].join('skia', 'infra', 'bots', 'assets', |
| 217 | 'skp', 'VERSION'), |
| 218 | api.path['start_dir'].join('skia', 'infra', 'bots', 'assets', |
| 219 | 'svg', 'VERSION'), |
| 220 | api.path['start_dir'].join('tmp', 'uninteresting_hashes.txt') |
Ben Wagner | f835c22 | 2017-04-30 11:14:51 -0400 | [diff] [blame] | 221 | ) + |
| 222 | api.step_data('get swarming bot id', |
| 223 | stdout=api.raw_io.output('skia-bot-123')) + |
| 224 | api.step_data('get swarming task id', |
| 225 | stdout=api.raw_io.output('123456')) |
Eric Boren | f9aa9e5 | 2017-04-10 09:56:10 -0400 | [diff] [blame] | 226 | ) |
Eric Boren | 942db50 | 2021-03-24 15:52:49 -0400 | [diff] [blame] | 227 | if 'Win' in builder: |
Eric Boren | f9aa9e5 | 2017-04-10 09:56:10 -0400 | [diff] [blame] | 228 | test += api.platform('win', 64) |
Eric Boren | 4c7754c | 2017-04-10 08:19:10 -0400 | [diff] [blame] | 229 | |
Eric Boren | f9aa9e5 | 2017-04-10 09:56:10 -0400 | [diff] [blame] | 230 | yield test |