Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: chromecast/build/tests/cast_test.gni

Issue 1382713003: [GN] Add a template which wraps generate_test_lists.py. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Corrected target typos, added checking for tests, clarified comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2015 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 # This file contains templates which are meant to simplify building and
6 # running test binaries with the Chromecast build infrastructure. See
7 # documentation above each template for specific use.
8 #
9 # Example Usage
10 #
11 # # This is a standard test() template from //testing/test.gni. This generates
12 # # a binary called foo_unittests.
13 # test("foo_unittests") {
14 # sources = [ "foo_unittest.cc" ]
15 #
16 # deps = [
17 # ":foo",
18 # "//testing/gtest",
19 # "//testing/gmock",
20 # ]
21 # }
22 #
23 # # And another standard test() target, which generates bar_unittests
24 # test("bar_unittests") {
25 # sources = [ "bar_unittest.cc" ]
26 #
27 # deps = [ ... ]
28 # }
29 #
30 # # This is an organizational target. This cannot be built directly.
31 # cast_test_group("cast_tests") {
32 # tests = [
33 # ":bar_unittests",
34 # "//path/to:foo_unittests",
35 # ]
36 # }
37 #
38 # # Here is another cast_test_group target which builds a bunch of other
39 # # test binaries, and wants to apply some filters.
40 # cast_test_group("external_tests") {
41 # tests = [
42 # "//path/to/widget:widget_unittests",
43 # "//even/more/foo:foo_unittests",
44 # ]
45 #
46 # filters = [
47 # "widget_unittests --gtest_filter=-WidgetTest.TestToBeFiltered",
48 # ]
49 # }
50 #
51 # # Build this to create build and run lists for bar and foo tests.
52 # cast_test_group_list("cast_test_lists") {
53 # test_groups = [
54 # ":cast_tests",
55 # ":external_tests",
56 # ]
57 #
58 # build_list_paths = "$root_out_dir/path/to/test/build_list.txt"
59 #
60 # run_list_path = "$root_out_dir/path/to/list/run_list.txt"
61 # }
62
63 import("//testing/test.gni")
64
65 # This directory must be the same for every cast_test_group instance.
66 _shared_dir = "$root_gen_dir/chromecast/tests"
67
68 # A group of test executables. Including test targets in this group makes it
69 # possible for Chromecast build infrastructure to build and run them with
70 # filters. To accomplish this, it defines two actions, one which generates a
71 # build list of all |tests|, and one which generates a run list of all |tests|.
72 # It also creates a group with dependencies on each test, to ensure that they
73 # are valid targets. Do not build these targets. Build cast_test_group_list
74 # instead.
75 #
76 # Parameters
77 # tests (required)
78 # A list of test targets included in the assembly. Do not include any
79 # other type of target. Each target's name must match the name of the
80 # executable it builds.
81 #
82 # filters (optional)
83 # A list of strings of format: "<test_name> --gtest_filter=<filter_logic>"
84 # The <test_name> used must correspond to a test in |tests|. Please see
85 # //chromecast/tools/build/generate_test_lists.py for more information.
86 # If this is not defined, no filters are applied.
87 #
88 # priority (optional)
89 # A string which takes any single-digit integer bewtween "1" and "9",
90 # inclusive. Assign this to prioritize filters applied by other
91 # cast_test_groups, where a higher number trumps a lower number.
92 # If not assigned, priority defaults to "1", the lowest priority.
93 #
94 template("cast_test_group") {
95 assert(defined(invoker.tests),
96 "$target_name needs 'tests' listing the test() targets")
97
98 # If a set of filters has not been defined, use the empty list.
99 _filters = []
100 if (defined(invoker.filters)) {
101 _filters = invoker.filters
102 }
103
104 # If priority has not been set, set the priority to "1", the lowest priority.
105 _priority = "1"
106 if (defined(invoker.priority)) {
107 _priority = invoker.priority
108 }
109
110 # Assert that |_priority| is an integer between "1" and "9", inclusive.
111 assert(_priority == "1" || _priority == "2" || _priority == "3" ||
112 _priority == "4" || _priority == "5" || _priority == "6" ||
113 _priority == "7" || _priority == "8" || _priority == "9")
114
115 # This will be the prefix of each output file.
116 _output_prefix = "$_shared_dir/$_priority-$target_name"
117
118 # Create a list of all the target names. These must correspond to the name of
119 # the test binary.
120 _test_names = []
121 foreach(_test, invoker.tests) {
122 _test_names += [ get_label_info(_test, "name") ]
123 }
124
125 # This action generates a list of target names to build and run. It will be
126 # depended upon by the "pack_build" action of the cast_test_group_list
127 # instance which depends on this cast_test_group.
128 action(target_name + "_create_list") {
129 script = "//chromecast/tools/build/generate_test_lists.py"
130
131 outputs = [
132 "$_output_prefix.tests",
133 ]
134
135 args = [
136 "-o",
137 rebase_path("$_output_prefix.tests"),
138 "create_list",
139 ]
140
141 args += _test_names
142 }
143
144 # This action generates a list of test filters, which will have a priority
145 # [1-9]. This will be depended upon by the "pack_run" action of the
146 # cast_test_group_list which depends on this group.
147 action(target_name + "_filters") {
148 script = "//chromecast/tools/build/generate_test_lists.py"
149
150 outputs = [
151 "$_output_prefix.filters",
152 ]
153
154 args = [
155 "-o",
156 rebase_path("$_output_prefix.filters"),
157 "create_list",
158 ]
159
160 args += _filters
161 }
162
163 # This target allows us to reference each test as a fully-qualified GN path,
164 # to ensure that each path is correct. If a test does not exist, gives a
165 # helpful error message at the line it is included. Do not build this target
166 # directly.
167 group(target_name + "_build_tests") {
168 testonly = true
169 deps = invoker.tests
170 }
171 }
172
173 # This template runs a script which generates lists of test to be built and run.
174 #
175 # Parameters
176 # test_groups (required)
177 # The cast_test_group() targets for which this binary is to be created.
178 # The targets referenced here must be cast_test_group targets, or buiding
179 # this target will fail.
180 #
181 # build_list_path (required)
182 # The absolute filepath of the output file which will hold the list of
183 # tests to be built.
184 #
185 # run_list_path (required)
186 # The absolute filepath of the output file which will hold the list of
187 # tests to be run, each with filters assigned by cast_groups.
188 #
189 # additional_options (optional)
190 # Options which are passed to the python script, and applied to every test
191 #
192 template("cast_test_group_list") {
193 assert(defined(invoker.test_groups), "$target_name needs 'test_groups'")
194 assert(defined(invoker.run_list_path), "$target_name needs 'run_list_path'")
195 assert(defined(invoker.build_list_path),
196 "$target_name needs 'build_list_path'")
197
198 _pack_build_action = target_name + "_pack_build"
199
200 # Generate a list of the "create_list" actions for each group. These will be
201 # depended upon to ensure they're run before the "pack_build" step.
202 _build_actions = []
203 foreach(_test_group, invoker.test_groups) {
204 _build_actions += [ _test_group + "_create_list" ]
205 }
206
207 # Generate a list of the "filter" actions for each group. These will be
208 # depended upon to ensure they're run before the "pack_run" step.
209 _filter_actions = []
210 foreach(_test_group, invoker.test_groups) {
211 _filter_actions += [ _test_group + "_filters" ]
212 }
213
214 # The "pack_build" step. This step looks in the common folder for files with
215 # the ".tests" extenstion, collecting these and packing them into an output
216 # file. The steps which create these files are depeneded upon, to ensure
217 # they're run before this step. Do not invoke this target directly.
218 action(_pack_build_action) {
219 script = "//chromecast/tools/build/generate_test_lists.py"
220
221 outputs = [
222 invoker.build_list_path,
223 ]
224
225 args = [
226 "-o",
227 rebase_path(invoker.build_list_path),
228 "-t",
229 rebase_path(_shared_dir),
230 "pack_build",
231 ]
232
233 deps = _build_actions
234 }
235
236 # The "pack_run" step. This step looks in the common folder for files with
237 # the ".tests" and ".filters" extensions, creating a script of tests to run,
238 # with filters and priorities. See
239 # //chromecast/tools/build/generate_test_lists.py for more information.
240 # Note that this target takes the name of the invoker, such that invoking the
241 # target runs this step.
242 action(target_name) {
243 script = "//chromecast/tools/build/generate_test_lists.py"
244
245 outputs = [
246 invoker.run_list_path,
247 ]
248
249 args = [
250 "-o",
251 rebase_path(invoker.run_list_path),
252 "-t",
253 rebase_path(_shared_dir),
254 "pack_run",
255 ]
256
257 # Add addtional options if they have been set.
258 if (defined(invoker.additional_options)) {
259 args += [ "-a" ]
260 args += invoker.additional_options
261 }
262
263 # Depend first on the "pack_build" step, so that the build lists are created .
264 deps = [
265 ":$_pack_build_action",
266 ]
267
268 # Next, depend on the filter steps, such that they are created before this
269 # script executes.
270 deps += _filter_actions
271 }
272 }
OLDNEW
« chromecast/BUILD.gn ('K') | « chromecast/BUILD.gn ('k') | chromecast/chromecast.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698