• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 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# TODO(borenet): This module was copied from build.git and heavily modified to
7# remove dependencies on other modules in build.git.  It belongs in a different
8# repo. Remove this once it has been moved.
9
10
11from recipe_engine.recipe_api import Property
12
13DEPS = [
14  'isolate',
15  'recipe_engine/json',
16  'recipe_engine/path',
17  'recipe_engine/properties',
18  'recipe_engine/step',
19  'swarming_client',
20]
21
22PROPERTIES = {
23  'always_use_exparchive': Property(
24    kind=bool, help="Force usage of exparchive.", default=False),
25}
26
27
28def RunSteps(api, always_use_exparchive):
29  # 'isolate_tests' step needs swarming checkout.
30  api.swarming_client.checkout('master')
31
32  # Code coverage for isolate_server property.
33  api.isolate.isolate_server = 'https://isolateserver-dev.appspot.com'
34  assert api.isolate.isolate_server == 'https://isolateserver-dev.appspot.com'
35
36  # That would read a list of files to search for, generated in GenTests.
37  step_result = api.step('read test spec', ['cat'], stdout=api.json.output())
38  expected_targets = step_result.stdout
39
40  build_path = api.isolate.package_repo_resource()
41  # Generates code coverage for find_isolated_tests corner cases.
42  # TODO(vadimsh): This step doesn't actually make any sense when the recipe
43  # is running for real via run_recipe.py.
44  api.isolate.find_isolated_tests(build_path, expected_targets)
45
46  # Code coverage for 'isolate_tests'. 'isolated_test' doesn't support discovery
47  # of isolated targets in build directory, so skip if 'expected_targets' is
48  # None.
49  if expected_targets is not None:
50    api.isolate.isolate_tests(
51        build_path, expected_targets,
52        always_use_exparchive=always_use_exparchive)
53
54
55def GenTests(api):
56  def make_test(
57          name,
58          expected_batcharchive_targets,
59          expected_exparchive_targets,
60          discovered_targets):
61
62    if expected_batcharchive_targets or expected_exparchive_targets:
63      all_expected_targets = (
64          (expected_batcharchive_targets or []) +
65          (expected_exparchive_targets or []))
66    else:
67      all_expected_targets = None
68
69    missing = set(all_expected_targets or []) - set(discovered_targets or [])
70    output = (
71        api.test(name) +
72        api.step_data(
73            'read test spec',
74            stdout=api.json.output(all_expected_targets)) +
75        api.override_step_data(
76            'find isolated tests',
77            api.isolate.output_json(discovered_targets))
78    )
79
80    # See comment around 'if expected_targets is not None' above.
81    if all_expected_targets:
82      for target in sorted(expected_exparchive_targets):
83        output += api.override_step_data(
84            'isolate %s' % target,
85            api.isolate.output_json([target], missing))
86
87      if expected_batcharchive_targets:
88        output += api.override_step_data(
89            'isolate tests',
90            api.isolate.output_json(expected_batcharchive_targets, missing))
91
92    return output
93
94  # Expected targets == found targets.
95  yield make_test(
96      'basic', ['test1', 'test2'], [], ['test1', 'test2'])
97  # No expectations, just discovering what's there returned by default mock.
98  yield make_test(
99      'discover', None, None, None)
100  # Found more than expected.
101  yield make_test(
102      'extra', ['test1', 'test2'], [], ['test1', 'test2', 'extra_test'])
103  # Didn't find something.
104  yield (
105      make_test('missing', ['test1', 'test2'], [], ['test1']) +
106      api.properties.generic(buildername='Windows Swarm Test'))
107  # No expectations, and nothing has been found, produces warning.
108  yield make_test('none', None, None, [])
109  # Test the `exparchive` cases
110  # Only exparchive
111  yield make_test(
112      'exparchive', [], ['test_exparchive'], ['test_exparchive'])
113  yield make_test(
114      'exparchive-miss', [], ['test_exparchive'], [])
115  yield make_test(
116      'exparchive-multi',
117      [],
118      ['test1_exparchive', 'test2_exparchive'],
119      ['test1_exparchive', 'test2_exparchive'])
120  yield make_test(
121      'exparchive-multi-miss',
122      [],
123      ['test1_exparchive', 'test2_exparchive'],
124      ['test1_exparchive'])
125  # Mixed
126  yield make_test(
127      'exparchive-batch',
128      ['test1', 'test2'],
129      ['test_exparchive'],
130      ['test1', 'test2', 'test_exparchive'])
131  yield make_test(
132      'exparchive-batch-bmiss',
133      ['test1', 'test2'],
134      ['test_exparchive'],
135      ['test1', 'test_exparchive'])
136  yield make_test(
137      'exparchive-batch-emiss',
138      ['test1', 'test2'],
139      ['test_exparchive'],
140      ['test1', 'test2'])
141  # Use force-exparchive
142  yield make_test(
143      'always-use-exparchive',
144      [],
145      ['test_exparchive', 'test1', 'test2'],
146      ['test_exparchive', 'test1', 'test2']) + api.properties(
147          always_use_exparchive=True)
148