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