• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/python',
22  'recipe_engine/raw_io',
23  'recipe_engine/step',
24  'gold_upload',
25  'run',
26  'vars',
27]
28
29DM_JSON = 'dm.json'
30
31def test_steps(api):
32  """Run the DM test."""
33  do_upload = api.properties.get('do_upload') == 'true'
34  images = api.properties.get('images') == 'true'
35  lotties = api.properties.get('lotties') == 'true'
36  resources = api.properties.get('resources') == 'true'
37  skps = api.properties.get('skps') == 'true'
38  svgs = api.properties.get('svgs') == 'true'
39
40  api.flavor.install(
41      images=images,
42      lotties=lotties,
43      resources=resources,
44      skps=skps,
45      svgs=svgs,
46  )
47
48  use_hash_file = False
49  if do_upload:
50    host_dm_dir = str(api.flavor.host_dirs.dm_dir)
51    api.flavor.create_clean_host_dir(api.path['start_dir'].join('test'))
52    device_dm_dir = str(api.flavor.device_dirs.dm_dir)
53    if host_dm_dir != device_dm_dir:
54      api.flavor.create_clean_device_dir(device_dm_dir)
55
56    # Obtain the list of already-generated hashes.
57    hash_filename = 'uninteresting_hashes.txt'
58
59    host_hashes_file = api.vars.tmp_dir.join(hash_filename)
60    hashes_file = api.flavor.device_path_join(
61        api.flavor.device_dirs.tmp_dir, hash_filename)
62    api.run(
63        api.python.inline,
64        'get uninteresting hashes',
65        program="""
66import contextlib
67import math
68import socket
69import sys
70import time
71
72from urllib.request import urlopen
73
74HASHES_URL = sys.argv[1]
75RETRIES = 5
76TIMEOUT = 60
77WAIT_BASE = 15
78
79socket.setdefaulttimeout(TIMEOUT)
80for retry in range(RETRIES):
81  try:
82    with contextlib.closing(
83        urlopen(HASHES_URL, timeout=TIMEOUT)) as w:
84      hashes = w.read().decode('utf-8')
85      with open(sys.argv[2], 'w') as f:
86        f.write(hashes)
87        break
88  except Exception as e:
89    print('Failed to get uninteresting hashes from %s:' % HASHES_URL)
90    print(e)
91    if retry == RETRIES:
92      raise
93    waittime = WAIT_BASE * math.pow(2, retry)
94    print('Retry in %d seconds.' % waittime)
95    time.sleep(waittime)
96        """,
97        args=[api.properties['gold_hashes_url'], host_hashes_file],
98        # If this fails, we want to know about it because it means Gold is down
99        # and proceeding onwards would take a very long time, but be hard to notice.
100        abort_on_failure=True,
101        fail_build_on_failure=True,
102        infra_step=True)
103
104    if api.path.exists(host_hashes_file):
105      api.flavor.copy_file_to_device(host_hashes_file, hashes_file)
106      use_hash_file = True
107
108  # Find DM flags.
109  args = json.loads(api.properties['dm_flags'])
110  props = json.loads(api.properties['dm_properties'])
111  args.append('--properties')
112  # Map iteration order is arbitrary; in order to maintain a consistent step
113  # ordering, sort by key.
114  for k in sorted(props.keys()):
115    v = props[k]
116    if v == '${SWARMING_BOT_ID}':
117      v = api.vars.swarming_bot_id
118    elif v == '${SWARMING_TASK_ID}':
119      v = api.vars.swarming_task_id
120    if v != '':
121      args.extend([k, v])
122
123  # Paths to required resources.
124  if resources:
125    args.extend(['--resourcePath', api.flavor.device_dirs.resource_dir])
126  if skps:
127    args.extend(['--skps', api.flavor.device_dirs.skp_dir])
128  if images:
129    args.extend([
130        '--images', api.flavor.device_path_join(
131            api.flavor.device_dirs.images_dir, 'dm'),
132        '--colorImages', api.flavor.device_path_join(
133            api.flavor.device_dirs.images_dir, 'colorspace'),
134    ])
135  if svgs:
136    # svg_dir is the root of the SVG corpus. Within that directory,
137    # the *.svg inputs are in the 'svg' subdirectory. See skbug.com/11229
138    args.extend(['--svgs', api.flavor.device_path_join(
139      api.flavor.device_dirs.svg_dir, "svg")])
140  if lotties:
141    args.extend([
142      '--lotties',
143      api.flavor.device_path_join(
144          api.flavor.device_dirs.resource_dir, 'skottie'),
145      api.flavor.device_dirs.lotties_dir,
146    ])
147
148  if use_hash_file:
149    args.extend(['--uninterestingHashesFile', hashes_file])
150  if do_upload:
151    args.extend(['--writePath', api.flavor.device_dirs.dm_dir])
152
153  # Run DM.
154  api.run(api.flavor.step, 'dm', cmd=args, abort_on_failure=False)
155
156  if do_upload:
157    # Copy images and JSON to host machine if needed.
158    api.flavor.copy_directory_contents_to_host(
159        api.flavor.device_dirs.dm_dir, api.flavor.host_dirs.dm_dir)
160    # https://bugs.chromium.org/p/chromium/issues/detail?id=1192611
161    if 'Win' not in api.vars.builder_cfg.get('os', ''):
162      api.gold_upload.upload()
163
164
165def RunSteps(api):
166  api.vars.setup()
167  api.file.ensure_directory('makedirs tmp_dir', api.vars.tmp_dir)
168  api.flavor.setup('dm')
169
170  try:
171    test_steps(api)
172  finally:
173    api.flavor.cleanup_steps()
174  api.run.check_failure()
175
176
177TEST_BUILDERS = [
178  'Test-Android-Clang-Pixel2XL-GPU-Adreno540-arm-Debug-All-Android_ASAN',
179  'Test-Android-Clang-Pixel2XL-GPU-Adreno540-arm64-Debug-All-Android',
180  'Test-Debian10-Clang-GCE-CPU-AVX2-x86_64-Release-All-Lottie',
181  'Test-Win10-Clang-ShuttleC-GPU-GTX960-x86_64-Debug-All-ANGLE',
182]
183
184
185def GenTests(api):
186  for builder in TEST_BUILDERS:
187    props = dict(
188      buildername=builder,
189      buildbucket_build_id='123454321',
190      dm_flags='["dm","--example","--flags"]',
191      dm_properties=('{"key1":"value1","key2":"",'
192                     '"bot":"${SWARMING_BOT_ID}",'
193                     '"task":"${SWARMING_TASK_ID}"}'),
194      revision='abc123',
195      gs_bucket='skia-infra-gm',
196      patch_ref='89/456789/12',
197      patch_set=7,
198      patch_issue=1234,
199      path_config='kitchen',
200      gold_hashes_url='https://example.com/hashes.txt',
201      swarm_out_dir='[SWARM_OUT_DIR]',
202      task_id='task_12345',
203      resources='true',
204    )
205    if 'ASAN' not in builder:
206      props['do_upload'] = 'true'
207    if 'Lottie' in builder:
208      props['lotties'] = 'true'
209    else:
210      props['images'] = 'true'
211      props['skps'] = 'true'
212      props['svgs'] = 'true'
213    test = (
214      api.test(builder) +
215      api.properties(**props) +
216      api.path.exists(
217          api.path['start_dir'].join('skia'),
218          api.path['start_dir'].join('skia', 'infra', 'bots', 'assets',
219                                     'skimage', 'VERSION'),
220          api.path['start_dir'].join('skia', 'infra', 'bots', 'assets',
221                                     'skp', 'VERSION'),
222          api.path['start_dir'].join('skia', 'infra', 'bots', 'assets',
223                                     'svg', 'VERSION'),
224          api.path['start_dir'].join('tmp', 'uninteresting_hashes.txt')
225      ) +
226      api.step_data('get swarming bot id',
227          stdout=api.raw_io.output('skia-bot-123')) +
228      api.step_data('get swarming task id',
229          stdout=api.raw_io.output('123456'))
230    )
231    if 'Win' in builder:
232      test += api.platform('win', 64)
233
234    yield test
235