Chromium Code Reviews| OLD | NEW |
|---|---|
| (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. | |
|
alokp
2015/10/01 13:13:46
I did not understand the comment about not being b
slan
2015/10/01 14:08:56
There is no ninja target created with this name. I
| |
| 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 # An group of test executables. Including a test target in this group makes it | |
|
mbjorge
2015/10/01 17:11:40
nit: An -> A
slan
2015/10/01 20:08:03
Done.
| |
| 69 # possible for chrome It also defines an action which generates a build | |
|
mbjorge
2015/10/01 17:11:40
I think you a word here?
slan
2015/10/01 20:08:03
This guy.
| |
| 70 # list of all |tests|, and an action which generates a run list of all |tests|. | |
| 71 # Do not build these internal targets. Build cast_test_group_list instead. | |
|
mbjorge
2015/10/01 17:11:40
(This is basically the comment I want next to cast
slan
2015/10/01 20:08:03
Done.
| |
| 72 # | |
| 73 # Parameters | |
| 74 # tests (required) | |
| 75 # A list of cast_test targets included in the assembly. Do not include any | |
|
mbjorge
2015/10/01 17:11:40
list of cast_test targets, or just test targets?
slan
2015/10/01 20:08:03
Good catch, removed.
| |
| 76 # other type of target. Each target's name must match the name of the | |
| 77 # executable it builds. | |
| 78 # | |
| 79 # filters (optional) | |
| 80 # A list of strings of format: "<test_name> --gtest_filter=<filter_logic>" | |
| 81 # The <test_name> used must correspond to a test in |tests|. Please see | |
| 82 # //chromecast/tools/build/generate_test_lists.py for more information. | |
| 83 # If this is not defined, no filters are applied. | |
| 84 # | |
| 85 # priority (optional) | |
| 86 # A string which takes any single-digit integer bewtween "1" and "9", | |
| 87 # inclusive. Assign this to prioritize filters applied by other | |
| 88 # cast_test_groups, where a higher number trumps a lower number. | |
| 89 # If not assigned, priority defaults to "1", the lowest priority. | |
| 90 # | |
| 91 template("cast_test_group") { | |
| 92 assert(defined(invoker.tests), | |
| 93 "$target_name needs 'tests' listing the test() targets") | |
| 94 | |
| 95 # If a set of filters has not been defined, use the empty list. | |
| 96 _filters = [] | |
| 97 if (defined(invoker.filters)) { | |
| 98 _filters = invoker.filters | |
| 99 } | |
| 100 | |
| 101 # If priority has not been set, set the priority to "1", the lowest priority. | |
| 102 _priority = "1" | |
| 103 if (defined(invoker.priority)) { | |
| 104 _priority = invoker.priority | |
| 105 } | |
| 106 | |
| 107 # Assert that |_priority| is an integer between "1" and "9", inclusive. | |
| 108 assert(_priority == "1" || _priority == "2" || _priority == "3" || | |
| 109 _priority == "4" || _priority == "5" || _priority == "6" || | |
| 110 _priority == "7" || _priority == "8" || _priority == "9") | |
| 111 | |
| 112 # This will be the prefix of each output file. | |
| 113 _output_prefix = "$_shared_dir/$_priority-$target_name" | |
| 114 | |
| 115 # Create a list of all the target names. These must correspond to the name of | |
| 116 # the test binary. | |
| 117 _test_names = [] | |
| 118 foreach(_test, invoker.tests) { | |
| 119 _test_names += [ get_label_info(_test, "name") ] | |
| 120 } | |
| 121 | |
| 122 # This action generates a list of target names to build and run. It will be | |
| 123 # depended upon by the "pack_build" action of the cast_test_group_list | |
| 124 # instance which depends on this cast_test_group. | |
| 125 action(target_name + "_create_list") { | |
| 126 script = "//chromecast/tools/build/generate_test_lists.py" | |
| 127 | |
| 128 outputs = [ | |
| 129 "$_output_prefix.tests", | |
| 130 ] | |
| 131 | |
| 132 args = [ | |
| 133 "-o", | |
| 134 rebase_path("$_output_prefix.tests"), | |
| 135 "create_list", | |
| 136 ] | |
| 137 | |
| 138 args += _test_names | |
| 139 } | |
| 140 | |
| 141 # This action generates a list of test filters, which will have a priority | |
| 142 # [1-9]. This will be depended upon by the "pack_run" action of the | |
| 143 # cast_test_group_list which depends on this group. | |
| 144 action(target_name + "_filters") { | |
| 145 script = "//chromecast/tools/build/generate_test_lists.py" | |
| 146 | |
| 147 outputs = [ | |
| 148 "$_output_prefix.filters", | |
| 149 ] | |
| 150 | |
| 151 args = [ | |
| 152 "-o", | |
| 153 rebase_path("$_output_prefix.filters"), | |
| 154 "create_list", | |
| 155 ] | |
| 156 | |
| 157 args += _filters | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 # This template runs a script which generates lists of test to be built and run. | |
| 162 # | |
| 163 # Parameters | |
| 164 # test_groups (required) | |
| 165 # The cast_test_group() targets for which this binary is to be created. | |
| 166 # The targets referenced here must be cast_test_group targets, or buiding | |
| 167 # this target will fail. | |
| 168 # | |
| 169 # build_list_path (required) | |
| 170 # The absolute filepath of the output file which will hold the list of | |
| 171 # tests to be built. | |
| 172 # | |
| 173 # run_list_path (required) | |
| 174 # The absolute filepath of the output file which will hold the list of | |
| 175 # tests to be run, each with filters assigned by cast_groups. | |
| 176 # | |
| 177 # additional_options (optional) | |
| 178 # Options which are passed to the python script, and applied to every test | |
| 179 # | |
| 180 template("cast_test_group_list") { | |
| 181 assert(defined(invoker.test_groups), "$target_name needs 'test_groups'") | |
| 182 assert(defined(invoker.run_list_path), "$target_name needs 'run_list_path'") | |
| 183 assert(defined(invoker.build_list_path), | |
| 184 "$target_name needs 'build_list_path'") | |
| 185 | |
| 186 _pack_build_action = target_name + "_pack_build" | |
| 187 | |
| 188 # Generate a list of the "create_list" actions for each group. These will be | |
| 189 # depended upon to ensure they're run before the "pack_build" step. | |
| 190 _build_actions = [] | |
| 191 foreach(_test_group, invoker.test_groups) { | |
| 192 _build_actions += [ _test_group + "_create_list" ] | |
| 193 } | |
| 194 | |
| 195 # Generate a list of the "filter" actions for each group. These will be | |
| 196 # depended upon to ensure they're run before the "pack_run" step. | |
| 197 _filter_actions = [] | |
| 198 foreach(_test_group, invoker.test_groups) { | |
| 199 _filter_actions += [ _test_group + "_filters" ] | |
| 200 } | |
| 201 | |
| 202 # The "pack_build" step. This step looks in the common folder for files with | |
| 203 # the ".tests" extenstion, collecting these and packing them into an output | |
| 204 # file. The steps which create these files are depeneded upon, to ensure | |
| 205 # they're run before this step. Do not invoke this target directly. | |
| 206 action(_pack_build_action) { | |
| 207 script = "//chromecast/tools/build/generate_test_lists.py" | |
| 208 | |
| 209 outputs = [ | |
| 210 invoker.build_list_path, | |
| 211 ] | |
| 212 | |
| 213 args = [ | |
| 214 "-o", | |
| 215 rebase_path(invoker.build_list_path), | |
| 216 "-t", | |
| 217 rebase_path(_shared_dir), | |
| 218 "pack_build", | |
| 219 ] | |
| 220 | |
| 221 deps = _build_actions | |
| 222 } | |
| 223 | |
| 224 # The "pack_run" step. This step looks in the common folder for files with | |
| 225 # the ".tests" and ".filters" extensions, creating a script of tests to run, | |
| 226 # with filters and priorities. See | |
| 227 # //chromecast/tools/build/generate_test_lists.py for more information. | |
| 228 # Note that this target takes the name of the invoker, such that invoking the | |
| 229 # target runs this step. | |
| 230 action(target_name) { | |
| 231 script = "//chromecast/tools/build/generate_test_lists.py" | |
| 232 | |
| 233 outputs = [ | |
| 234 invoker.run_list_path, | |
| 235 ] | |
| 236 | |
| 237 args = [ | |
| 238 "-o", | |
| 239 rebase_path(invoker.run_list_path), | |
| 240 "-t", | |
| 241 rebase_path(_shared_dir), | |
| 242 "pack_run", | |
| 243 ] | |
| 244 | |
| 245 # Add addtional options if they have been set. | |
| 246 if (defined(invoker.additional_options)) { | |
| 247 args += [ "-a" ] | |
| 248 args += invoker.additional_options | |
| 249 } | |
| 250 | |
| 251 # Depend first on the "pack_build" step, so that the build lists are created . | |
| 252 deps = [ | |
| 253 ":$_pack_build_action", | |
| 254 ] | |
| 255 | |
| 256 # Next, depend on the filter steps, such that they are created before this | |
| 257 # script executes. | |
| 258 deps += _filter_actions | |
| 259 } | |
| 260 } | |
| OLD | NEW |