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. |
| 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 # build_tests (optional) |
| 193 # Set this to true to build all of the tests included in |test_groups|. |
| 194 # Defaults to false. Note that if this is set to true, the test targets |
| 195 # will be built after all the lists are generated. |
| 196 # |
| 197 template("cast_test_group_list") { |
| 198 assert(defined(invoker.test_groups), "$target_name needs 'test_groups'") |
| 199 assert(defined(invoker.run_list_path), "$target_name needs 'run_list_path'") |
| 200 assert(defined(invoker.build_list_path), |
| 201 "$target_name needs 'build_list_path'") |
| 202 |
| 203 _pack_build_action = target_name + "_pack_build" |
| 204 |
| 205 # Generate a list of the "create_list" actions for each group. These will be |
| 206 # depended upon to ensure they're run before the "pack_build" step. |
| 207 _build_actions = [] |
| 208 foreach(_test_group, invoker.test_groups) { |
| 209 _build_actions += [ _test_group + "_create_list" ] |
| 210 } |
| 211 |
| 212 # Generate a list of the "filter" actions for each group. These will be |
| 213 # depended upon to ensure they're run before the "pack_run" step. |
| 214 _filter_actions = [] |
| 215 foreach(_test_group, invoker.test_groups) { |
| 216 _filter_actions += [ _test_group + "_filters" ] |
| 217 } |
| 218 |
| 219 # Generate a list of the groups of targets, so that they can be depended upon |
| 220 # by the "pack_run" step and built when this target is invoked. |
| 221 if (defined(invoker.build_tests) && invoker.build_tests) { |
| 222 _build_tests = [] |
| 223 foreach(_test_group, invoker.test_groups) { |
| 224 _build_tests += [ _test_group + "_build_tests" ] |
| 225 } |
| 226 } |
| 227 |
| 228 # The "pack_build" step. This step looks in the common folder for files with |
| 229 # the ".tests" extenstion, collecting these and packing them into an output |
| 230 # file. The steps which create these files are depeneded upon, to ensure |
| 231 # they're run before this step. Do not invoke this target directly. |
| 232 action(_pack_build_action) { |
| 233 script = "//chromecast/tools/build/generate_test_lists.py" |
| 234 |
| 235 outputs = [ |
| 236 invoker.build_list_path, |
| 237 ] |
| 238 |
| 239 args = [ |
| 240 "-o", |
| 241 rebase_path(invoker.build_list_path), |
| 242 "-t", |
| 243 rebase_path(_shared_dir), |
| 244 "pack_build", |
| 245 ] |
| 246 |
| 247 deps = _build_actions |
| 248 } |
| 249 |
| 250 # The "pack_run" step. This step looks in the common folder for files with |
| 251 # the ".tests" and ".filters" extensions, creating a script of tests to run, |
| 252 # with filters and priorities. See |
| 253 # //chromecast/tools/build/generate_test_lists.py for more information. |
| 254 # Note that this target takes the name of the invoker, such that invoking the |
| 255 # target runs this step. |
| 256 action(target_name) { |
| 257 testonly = true |
| 258 |
| 259 script = "//chromecast/tools/build/generate_test_lists.py" |
| 260 |
| 261 outputs = [ |
| 262 invoker.run_list_path, |
| 263 ] |
| 264 |
| 265 args = [ |
| 266 "-o", |
| 267 rebase_path(invoker.run_list_path), |
| 268 "-t", |
| 269 rebase_path(_shared_dir), |
| 270 "pack_run", |
| 271 ] |
| 272 |
| 273 # Add addtional options if they have been set. |
| 274 if (defined(invoker.additional_options)) { |
| 275 args += [ "-a" ] |
| 276 args += invoker.additional_options |
| 277 } |
| 278 |
| 279 # Depend first on the "pack_build" step, so that the build lists are created
. |
| 280 deps = [ |
| 281 ":$_pack_build_action", |
| 282 ] |
| 283 |
| 284 # Next, depend on the filter steps, such that they are created before this |
| 285 # script executes. |
| 286 deps += _filter_actions |
| 287 |
| 288 # If |build_tests| has been set to true, depend on the testing targets so |
| 289 # that the tests are built. |
| 290 if (defined(_build_tests)) { |
| 291 deps += _build_tests |
| 292 } |
| 293 } |
| 294 } |
OLD | NEW |