blob: 35bd8156ce0fda5b509aa5aa384f2c425502e3e3 [file] [log] [blame]
borenet1ed2ae42016-07-26 11:52:17 -07001# 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 Boren43a8cc82020-03-02 10:05:23 -05009import json
10
11
borenet1ed2ae42016-07-26 11:52:17 -070012DEPS = [
Eric Boren896af752017-04-24 13:22:56 -040013 'env',
14 'flavor',
Robert Iannucci297a7ef2017-05-12 19:09:38 -070015 'recipe_engine/context',
Robert Iannucci8cd50412017-07-07 14:36:58 -070016 'recipe_engine/file',
borenet1ed2ae42016-07-26 11:52:17 -070017 'recipe_engine/path',
18 'recipe_engine/platform',
19 'recipe_engine/properties',
Eric Boren4c7754c2017-04-10 08:19:10 -040020 'recipe_engine/python',
borenet1ed2ae42016-07-26 11:52:17 -070021 'recipe_engine/raw_io',
Eric Boren4c7754c2017-04-10 08:19:10 -040022 'recipe_engine/step',
Weston Tracey9bb0b6e2021-03-29 10:29:40 -040023 'gold_upload',
Eric Boren4c7754c2017-04-10 08:19:10 -040024 'run',
25 'vars',
borenet1ed2ae42016-07-26 11:52:17 -070026]
27
Weston Traceyc98b2af2021-03-25 11:49:12 -040028DM_JSON = 'dm.json'
29
Eric Boren4c7754c2017-04-10 08:19:10 -040030def test_steps(api):
31 """Run the DM test."""
Eric Boren59e74962020-03-23 09:17:24 -040032 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 Boren4c7754c2017-04-10 08:19:10 -040047 use_hash_file = False
Eric Boren59e74962020-03-23 09:17:24 -040048 if do_upload:
Eric Boren72f66682018-05-18 07:36:55 -040049 host_dm_dir = str(api.flavor.host_dirs.dm_dir)
50 api.flavor.create_clean_host_dir(api.path['start_dir'].join('test'))
Eric Boren4c7754c2017-04-10 08:19:10 -040051 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 Boren4c7754c2017-04-10 08:19:10 -040058 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üller64cc5762018-08-02 08:51:38 +020072 HASHES_URL = sys.argv[1]
Eric Boren4c7754c2017-04-10 08:19:10 -040073 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üller64cc5762018-08-02 08:51:38 +020083 with open(sys.argv[2], 'w') as f:
Eric Boren4c7754c2017-04-10 08:19:10 -040084 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üller64cc5762018-08-02 08:51:38 +020095 args=[api.properties['gold_hashes_url'], host_hashes_file],
Eric Boren4c7754c2017-04-10 08:19:10 -040096 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 Boren43a8cc82020-03-02 10:05:23 -0500104 # 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 Boren59e74962020-03-23 09:17:24 -0400120 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 Dennistonba9ec5f2021-02-01 09:30:03 -0500132 # 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 Boren59e74962020-03-23 09:17:24 -0400136 if lotties:
Kevin Lubickc499ec82020-02-12 15:41:10 -0500137 args.extend([
138 '--lotties',
139 api.flavor.device_path_join(
140 api.flavor.device_dirs.resource_dir, 'skottie'),
Eric Boren07248d92020-02-28 14:07:15 -0500141 api.flavor.device_dirs.lotties_dir,
142 ])
Kevin Lubick608c35a2018-01-16 16:15:57 -0500143
144 if use_hash_file:
145 args.extend(['--uninterestingHashesFile', hashes_file])
Eric Boren59e74962020-03-23 09:17:24 -0400146 if do_upload:
Kevin Lubick608c35a2018-01-16 16:15:57 -0500147 args.extend(['--writePath', api.flavor.device_dirs.dm_dir])
Kevin Lubick2dafbd72017-08-31 10:39:05 -0400148
Eric Boren43a8cc82020-03-02 10:05:23 -0500149 # Run DM.
Ben Wagner5655ba42017-10-02 10:48:32 -0400150 api.run(api.flavor.step, 'dm', cmd=args, abort_on_failure=False)
Eric Boren4c7754c2017-04-10 08:19:10 -0400151
Eric Boren59e74962020-03-23 09:17:24 -0400152 if do_upload:
Eric Boren4c7754c2017-04-10 08:19:10 -0400153 # Copy images and JSON to host machine if needed.
154 api.flavor.copy_directory_contents_to_host(
Eric Boren72f66682018-05-18 07:36:55 -0400155 api.flavor.device_dirs.dm_dir, api.flavor.host_dirs.dm_dir)
Weston Traceyc98b2af2021-03-25 11:49:12 -0400156 # https://bugs.chromium.org/p/chromium/issues/detail?id=1192611
157 if 'Win' not in api.vars.builder_cfg.get('os', ''):
Weston Tracey9bb0b6e2021-03-29 10:29:40 -0400158 api.gold_upload.upload()
Eric Boren4c7754c2017-04-10 08:19:10 -0400159
160
borenet1ed2ae42016-07-26 11:52:17 -0700161def RunSteps(api):
Eric Borenb7023162018-05-04 13:46:15 -0400162 api.vars.setup()
163 api.file.ensure_directory('makedirs tmp_dir', api.vars.tmp_dir)
Eric Boren7fb77c82020-02-27 12:19:46 -0500164 api.flavor.setup('dm')
Eric Borenb7023162018-05-04 13:46:15 -0400165
Eric Boren7fb77c82020-02-27 12:19:46 -0500166 try:
Eric Boren7fb77c82020-02-27 12:19:46 -0500167 test_steps(api)
168 finally:
169 api.flavor.cleanup_steps()
170 api.run.check_failure()
Eric Boren4c7754c2017-04-10 08:19:10 -0400171
172
Eric Borenf9aa9e52017-04-10 09:56:10 -0400173TEST_BUILDERS = [
Eric Borene5766b82021-06-28 11:11:21 -0400174 'Test-Android-Clang-Pixel2XL-GPU-Adreno540-arm-Debug-All-Android_ASAN',
Brian Osman4af42fc2019-09-16 12:38:04 -0400175 'Test-Android-Clang-Pixel2XL-GPU-Adreno540-arm64-Debug-All-Android',
Weston Tracey24627882020-04-06 21:27:14 -0400176 'Test-Debian10-Clang-GCE-CPU-AVX2-x86_64-Release-All-Lottie',
Ben Wagnerb2fd61a2017-10-23 16:01:44 -0400177 'Test-Win10-Clang-ShuttleC-GPU-GTX960-x86_64-Debug-All-ANGLE',
Eric Borenf9aa9e52017-04-10 09:56:10 -0400178]
borenet1ed2ae42016-07-26 11:52:17 -0700179
180
181def GenTests(api):
Eric Borenf9aa9e52017-04-10 09:56:10 -0400182 for builder in TEST_BUILDERS:
Eric Boren59e74962020-03-23 09:17:24 -0400183 props = dict(
184 buildername=builder,
185 buildbucket_build_id='123454321',
Kevin Lubick22663802021-01-29 11:05:41 -0500186 dm_flags='["dm","--example","--flags"]',
Eric Boren59e74962020-03-23 09:17:24 -0400187 dm_properties=('{"key1":"value1","key2":"",'
188 '"bot":"${SWARMING_BOT_ID}",'
189 '"task":"${SWARMING_TASK_ID}"}'),
190 revision='abc123',
Weston Traceyc98b2af2021-03-25 11:49:12 -0400191 gs_bucket='skia-infra-gm',
192 patch_ref='89/456789/12',
193 patch_set=7,
194 patch_issue=1234,
Eric Boren59e74962020-03-23 09:17:24 -0400195 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 Borenf9aa9e52017-04-10 09:56:10 -0400209 test = (
210 api.test(builder) +
Eric Boren59e74962020-03-23 09:17:24 -0400211 api.properties(**props) +
Eric Borenf9aa9e52017-04-10 09:56:10 -0400212 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 Wagnerf835c222017-04-30 11:14:51 -0400221 ) +
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 Borenf9aa9e52017-04-10 09:56:10 -0400226 )
Eric Boren942db502021-03-24 15:52:49 -0400227 if 'Win' in builder:
Eric Borenf9aa9e52017-04-10 09:56:10 -0400228 test += api.platform('win', 64)
Eric Boren4c7754c2017-04-10 08:19:10 -0400229
Eric Borenf9aa9e52017-04-10 09:56:10 -0400230 yield test