1*61c4878aSAndroid Build Coastguard Worker# Copyright 2019 The Pigweed Authors 2*61c4878aSAndroid Build Coastguard Worker# 3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of 5*61c4878aSAndroid Build Coastguard Worker# the License at 6*61c4878aSAndroid Build Coastguard Worker# 7*61c4878aSAndroid Build Coastguard Worker# https://www.apache.org/licenses/LICENSE-2.0 8*61c4878aSAndroid Build Coastguard Worker# 9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under 13*61c4878aSAndroid Build Coastguard Worker# the License. 14*61c4878aSAndroid Build Coastguard Worker 15*61c4878aSAndroid Build Coastguard Workerimport("//build_overrides/pigweed.gni") 16*61c4878aSAndroid Build Coastguard Worker 17*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_build/python_action.gni") 18*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_build/target_types.gni") 19*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_build/test_info.gni") 20*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_compilation_testing/negative_compilation_test.gni") 21*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_toolchain/generate_toolchain.gni") 22*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_toolchain/host_clang/toolchains.gni") 23*61c4878aSAndroid Build Coastguard Worker 24*61c4878aSAndroid Build Coastguard Workerdeclare_args() { 25*61c4878aSAndroid Build Coastguard Worker # The unit test framework implementation. Defaults to 26*61c4878aSAndroid Build Coastguard Worker # pw_unit_test:light, which implements a subset of GoogleTest safe to run on 27*61c4878aSAndroid Build Coastguard Worker # device. Set to //pw_unit_test:googletest when using GoogleTest. 28*61c4878aSAndroid Build Coastguard Worker # 29*61c4878aSAndroid Build Coastguard Worker # Type: string (GN path to a source set) 30*61c4878aSAndroid Build Coastguard Worker # Usage: toolchain-controlled only 31*61c4878aSAndroid Build Coastguard Worker pw_unit_test_BACKEND = "$dir_pw_unit_test:light" 32*61c4878aSAndroid Build Coastguard Worker 33*61c4878aSAndroid Build Coastguard Worker # The GoogleTest library target. This is not a pw_unit_test backend (anymore). 34*61c4878aSAndroid Build Coastguard Worker # Use this to depend on the GoogleTest library directly *WITHOUT* using the 35*61c4878aSAndroid Build Coastguard Worker # pw_unit_test facade. The //pw_unit_test:googletest backend depends on this 36*61c4878aSAndroid Build Coastguard Worker # library target. 37*61c4878aSAndroid Build Coastguard Worker # Defaults to //third_party/googletest. 38*61c4878aSAndroid Build Coastguard Worker # 39*61c4878aSAndroid Build Coastguard Worker # Type: string (GN path to a source set) 40*61c4878aSAndroid Build Coastguard Worker # Usage: toolchain-controlled only 41*61c4878aSAndroid Build Coastguard Worker pw_unit_test_GOOGLETEST_BACKEND = "$dir_pw_third_party/googletest" 42*61c4878aSAndroid Build Coastguard Worker 43*61c4878aSAndroid Build Coastguard Worker # Implementation of a main function for ``pw_test`` unit test binaries. Must 44*61c4878aSAndroid Build Coastguard Worker # be set to an appropriate target for the pw_unit_test backend. 45*61c4878aSAndroid Build Coastguard Worker # 46*61c4878aSAndroid Build Coastguard Worker # Type: string (GN path to a source set) 47*61c4878aSAndroid Build Coastguard Worker # Usage: toolchain-controlled only 48*61c4878aSAndroid Build Coastguard Worker pw_unit_test_MAIN = "$dir_pw_unit_test:simple_printing_main" 49*61c4878aSAndroid Build Coastguard Worker 50*61c4878aSAndroid Build Coastguard Worker # Path to a test runner to automatically run unit tests after they are built. 51*61c4878aSAndroid Build Coastguard Worker # 52*61c4878aSAndroid Build Coastguard Worker # If set, a ``pw_test`` target's ``<target_name>.run`` action will invoke the 53*61c4878aSAndroid Build Coastguard Worker # test runner specified by this argument, passing the path to the unit test to 54*61c4878aSAndroid Build Coastguard Worker # run. If this is unset, the ``pw_test`` target's ``<target_name>.run`` step 55*61c4878aSAndroid Build Coastguard Worker # will do nothing. 56*61c4878aSAndroid Build Coastguard Worker # 57*61c4878aSAndroid Build Coastguard Worker # Targets that don't support parallelized execution of tests (e.g. a on-device 58*61c4878aSAndroid Build Coastguard Worker # test runner that must flash a device and run the test in serial) should 59*61c4878aSAndroid Build Coastguard Worker # set pw_unit_test_POOL_DEPTH to 1. 60*61c4878aSAndroid Build Coastguard Worker # 61*61c4878aSAndroid Build Coastguard Worker # Type: string (name of an executable on the PATH, or path to an executable) 62*61c4878aSAndroid Build Coastguard Worker # Usage: toolchain-controlled only 63*61c4878aSAndroid Build Coastguard Worker pw_unit_test_AUTOMATIC_RUNNER = "" 64*61c4878aSAndroid Build Coastguard Worker 65*61c4878aSAndroid Build Coastguard Worker # Optional list of arguments to forward to the automatic runner. 66*61c4878aSAndroid Build Coastguard Worker # 67*61c4878aSAndroid Build Coastguard Worker # Type: list of strings (args to pass to pw_unit_test_AUTOMATIC_RUNNER) 68*61c4878aSAndroid Build Coastguard Worker # Usage: toolchain-controlled only 69*61c4878aSAndroid Build Coastguard Worker pw_unit_test_AUTOMATIC_RUNNER_ARGS = [] 70*61c4878aSAndroid Build Coastguard Worker 71*61c4878aSAndroid Build Coastguard Worker # Optional timeout to apply when running tests via the automatic runner. 72*61c4878aSAndroid Build Coastguard Worker # Timeout is in seconds. Defaults to empty which means no timeout. 73*61c4878aSAndroid Build Coastguard Worker pw_unit_test_AUTOMATIC_RUNNER_TIMEOUT = "" 74*61c4878aSAndroid Build Coastguard Worker 75*61c4878aSAndroid Build Coastguard Worker # The maximum number of unit tests that may be run concurrently for the 76*61c4878aSAndroid Build Coastguard Worker # current toolchain. Setting this to 0 disables usage of a pool, allowing 77*61c4878aSAndroid Build Coastguard Worker # unlimited parallelization. 78*61c4878aSAndroid Build Coastguard Worker # 79*61c4878aSAndroid Build Coastguard Worker # Note: A single target with two toolchain configurations (e.g. release/debug) 80*61c4878aSAndroid Build Coastguard Worker # will use two separate test runner pools by default. Set 81*61c4878aSAndroid Build Coastguard Worker # pw_unit_test_POOL_TOOLCHAIN to the same toolchain for both targets to 82*61c4878aSAndroid Build Coastguard Worker # merge the pools and force serialization. 83*61c4878aSAndroid Build Coastguard Worker # 84*61c4878aSAndroid Build Coastguard Worker # Type: integer 85*61c4878aSAndroid Build Coastguard Worker # Usage: toolchain-controlled only 86*61c4878aSAndroid Build Coastguard Worker pw_unit_test_POOL_DEPTH = 0 87*61c4878aSAndroid Build Coastguard Worker 88*61c4878aSAndroid Build Coastguard Worker # The toolchain to use when referring to the pw_unit_test runner pool. When 89*61c4878aSAndroid Build Coastguard Worker # this is disabled, the current toolchain is used. This means that every 90*61c4878aSAndroid Build Coastguard Worker # toolchain will use its own pool definition. If two toolchains should share 91*61c4878aSAndroid Build Coastguard Worker # the same pool, this argument should be by one of the toolchains to the GN 92*61c4878aSAndroid Build Coastguard Worker # path of the other toolchain. 93*61c4878aSAndroid Build Coastguard Worker # 94*61c4878aSAndroid Build Coastguard Worker # Type: string (GN path to a toolchain) 95*61c4878aSAndroid Build Coastguard Worker # Usage: toolchain-controlled only 96*61c4878aSAndroid Build Coastguard Worker pw_unit_test_POOL_TOOLCHAIN = "" 97*61c4878aSAndroid Build Coastguard Worker 98*61c4878aSAndroid Build Coastguard Worker # The name of the GN target type used to build pw_unit_test executables. 99*61c4878aSAndroid Build Coastguard Worker # 100*61c4878aSAndroid Build Coastguard Worker # Type: string (name of a GN template) 101*61c4878aSAndroid Build Coastguard Worker # Usage: toolchain-controlled only 102*61c4878aSAndroid Build Coastguard Worker pw_unit_test_EXECUTABLE_TARGET_TYPE = "pw_executable" 103*61c4878aSAndroid Build Coastguard Worker 104*61c4878aSAndroid Build Coastguard Worker # The path to the .gni file that defines pw_unit_test_EXECUTABLE_TARGET_TYPE. 105*61c4878aSAndroid Build Coastguard Worker # 106*61c4878aSAndroid Build Coastguard Worker # If pw_unit_test_EXECUTABLE_TARGET_TYPE is not the default of 107*61c4878aSAndroid Build Coastguard Worker # `pw_executable`, this .gni file is imported to provide the template 108*61c4878aSAndroid Build Coastguard Worker # definition. 109*61c4878aSAndroid Build Coastguard Worker # 110*61c4878aSAndroid Build Coastguard Worker # Type: string (path to a .gni file) 111*61c4878aSAndroid Build Coastguard Worker # Usage: toolchain-controlled only 112*61c4878aSAndroid Build Coastguard Worker pw_unit_test_EXECUTABLE_TARGET_TYPE_FILE = "" 113*61c4878aSAndroid Build Coastguard Worker 114*61c4878aSAndroid Build Coastguard Worker # If true, the pw_unit_test target, pw_test targets, and pw_test_group targets 115*61c4878aSAndroid Build Coastguard Worker # will define `testonly = true`. This is false by default for backwards 116*61c4878aSAndroid Build Coastguard Worker # compatibility. 117*61c4878aSAndroid Build Coastguard Worker pw_unit_test_TESTONLY = false 118*61c4878aSAndroid Build Coastguard Worker} 119*61c4878aSAndroid Build Coastguard Worker 120*61c4878aSAndroid Build Coastguard Workerif (pw_unit_test_EXECUTABLE_TARGET_TYPE != "pw_executable" && 121*61c4878aSAndroid Build Coastguard Worker pw_unit_test_EXECUTABLE_TARGET_TYPE_FILE != "") { 122*61c4878aSAndroid Build Coastguard Worker import(pw_unit_test_EXECUTABLE_TARGET_TYPE_FILE) 123*61c4878aSAndroid Build Coastguard Worker} 124*61c4878aSAndroid Build Coastguard Worker 125*61c4878aSAndroid Build Coastguard Worker# Defines a target if enable_if is true. Otherwise, it defines that target as 126*61c4878aSAndroid Build Coastguard Worker# <target_name>.DISABLED and creates an empty <target_name> group. This can be 127*61c4878aSAndroid Build Coastguard Worker# used to conditionally create targets without having to conditionally add them 128*61c4878aSAndroid Build Coastguard Worker# to groups. This results in simpler BUILD.gn files. 129*61c4878aSAndroid Build Coastguard Workertemplate("pw_internal_disableable_target") { 130*61c4878aSAndroid Build Coastguard Worker assert(defined(invoker.enable_if), 131*61c4878aSAndroid Build Coastguard Worker "`enable_if` is required for pw_internal_disableable_target") 132*61c4878aSAndroid Build Coastguard Worker assert(defined(invoker.target_type), 133*61c4878aSAndroid Build Coastguard Worker "`target_type` is required for pw_internal_disableable_target") 134*61c4878aSAndroid Build Coastguard Worker 135*61c4878aSAndroid Build Coastguard Worker if (invoker.enable_if) { 136*61c4878aSAndroid Build Coastguard Worker _actual_target_name = target_name 137*61c4878aSAndroid Build Coastguard Worker } else { 138*61c4878aSAndroid Build Coastguard Worker _actual_target_name = target_name + ".DISABLED" 139*61c4878aSAndroid Build Coastguard Worker 140*61c4878aSAndroid Build Coastguard Worker # If the target is disabled, create an empty target in its place. Use an 141*61c4878aSAndroid Build Coastguard Worker # action with the original target's sources as inputs to ensure that 142*61c4878aSAndroid Build Coastguard Worker # the source files exist (even if they don't compile). 143*61c4878aSAndroid Build Coastguard Worker pw_python_action(target_name) { 144*61c4878aSAndroid Build Coastguard Worker script = "$dir_pw_build/py/pw_build/nop.py" 145*61c4878aSAndroid Build Coastguard Worker stamp = true 146*61c4878aSAndroid Build Coastguard Worker 147*61c4878aSAndroid Build Coastguard Worker inputs = [] 148*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.sources)) { 149*61c4878aSAndroid Build Coastguard Worker inputs += invoker.sources 150*61c4878aSAndroid Build Coastguard Worker } 151*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.public)) { 152*61c4878aSAndroid Build Coastguard Worker inputs += invoker.public 153*61c4878aSAndroid Build Coastguard Worker } 154*61c4878aSAndroid Build Coastguard Worker 155*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.source_gen_deps)) { 156*61c4878aSAndroid Build Coastguard Worker deps = invoker.source_gen_deps 157*61c4878aSAndroid Build Coastguard Worker } 158*61c4878aSAndroid Build Coastguard Worker } 159*61c4878aSAndroid Build Coastguard Worker } 160*61c4878aSAndroid Build Coastguard Worker 161*61c4878aSAndroid Build Coastguard Worker target(invoker.target_type, _actual_target_name) { 162*61c4878aSAndroid Build Coastguard Worker sources = [] 163*61c4878aSAndroid Build Coastguard Worker public_deps = [] 164*61c4878aSAndroid Build Coastguard Worker deps = [] 165*61c4878aSAndroid Build Coastguard Worker forward_variables_from(invoker, 166*61c4878aSAndroid Build Coastguard Worker "*", 167*61c4878aSAndroid Build Coastguard Worker [ 168*61c4878aSAndroid Build Coastguard Worker "enable_if", 169*61c4878aSAndroid Build Coastguard Worker "negative_compilation_tests", 170*61c4878aSAndroid Build Coastguard Worker "source_gen_deps", 171*61c4878aSAndroid Build Coastguard Worker "target_type", 172*61c4878aSAndroid Build Coastguard Worker "test_automatic_runner_args", 173*61c4878aSAndroid Build Coastguard Worker ]) 174*61c4878aSAndroid Build Coastguard Worker 175*61c4878aSAndroid Build Coastguard Worker # Remove "" from dependencies. This allows disabling targets if a variable 176*61c4878aSAndroid Build Coastguard Worker # (e.g. a backend) is empty. 177*61c4878aSAndroid Build Coastguard Worker public_deps += [ "" ] 178*61c4878aSAndroid Build Coastguard Worker public_deps -= [ "" ] 179*61c4878aSAndroid Build Coastguard Worker deps += [ "" ] 180*61c4878aSAndroid Build Coastguard Worker deps -= [ "" ] 181*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.source_gen_deps)) { 182*61c4878aSAndroid Build Coastguard Worker deps += invoker.source_gen_deps 183*61c4878aSAndroid Build Coastguard Worker foreach(source_gen_dep, invoker.source_gen_deps) { 184*61c4878aSAndroid Build Coastguard Worker sources += get_target_outputs(source_gen_dep) 185*61c4878aSAndroid Build Coastguard Worker } 186*61c4878aSAndroid Build Coastguard Worker } 187*61c4878aSAndroid Build Coastguard Worker } 188*61c4878aSAndroid Build Coastguard Worker} 189*61c4878aSAndroid Build Coastguard Worker 190*61c4878aSAndroid Build Coastguard Worker# Creates a library and an executable target for a unit test with pw_unit_test. 191*61c4878aSAndroid Build Coastguard Worker# 192*61c4878aSAndroid Build Coastguard Worker# <target_name>.lib contains the provided test sources as a library, which can 193*61c4878aSAndroid Build Coastguard Worker# then be linked into a test executable. 194*61c4878aSAndroid Build Coastguard Worker# <target_name> is a standalone executable which contains only the test sources 195*61c4878aSAndroid Build Coastguard Worker# specified in the pw_unit_test_template. 196*61c4878aSAndroid Build Coastguard Worker# 197*61c4878aSAndroid Build Coastguard Worker# If the pw_unit_test_AUTOMATIC_RUNNER variable is set, this template also 198*61c4878aSAndroid Build Coastguard Worker# creates a "${test_name}.run" target which runs the unit test executable after 199*61c4878aSAndroid Build Coastguard Worker# building it. 200*61c4878aSAndroid Build Coastguard Worker# 201*61c4878aSAndroid Build Coastguard Worker# Targets defined using this template will produce test metadata with a 202*61c4878aSAndroid Build Coastguard Worker# `test_type` of "unit_test" and an additional `test_directory` value describing 203*61c4878aSAndroid Build Coastguard Worker# the location of the test binary within the build output. 204*61c4878aSAndroid Build Coastguard Worker# 205*61c4878aSAndroid Build Coastguard Worker# Args: 206*61c4878aSAndroid Build Coastguard Worker# - enable_if: (optional) Conditionally enables or disables this test. The 207*61c4878aSAndroid Build Coastguard Worker# test target and *.run target do nothing when the test is disabled. The 208*61c4878aSAndroid Build Coastguard Worker# disabled test can still be built and run with the 209*61c4878aSAndroid Build Coastguard Worker# <target_name>.DISABLED and <target_name>.DISABLED.run targets. 210*61c4878aSAndroid Build Coastguard Worker# Defaults to true (enable_if). 211*61c4878aSAndroid Build Coastguard Worker# - envvars: (optional) A list of `var_name=value` strings to set as 212*61c4878aSAndroid Build Coastguard Worker# environment variables when running the target exectuable. 213*61c4878aSAndroid Build Coastguard Worker# - tags: (optional) List of strings to include in the test metadata. These 214*61c4878aSAndroid Build Coastguard Worker# have no effect on the build, but may be used by external tools to 215*61c4878aSAndroid Build Coastguard Worker# distinguish between tests. For example, a tool may want to skip tests 216*61c4878aSAndroid Build Coastguard Worker# tagged as "slow". 217*61c4878aSAndroid Build Coastguard Worker# - extra_metadata: (optional) Extra metadata to include in test group 218*61c4878aSAndroid Build Coastguard Worker# metadata output. This can be used to pass information about this test 219*61c4878aSAndroid Build Coastguard Worker# to later build tasks. 220*61c4878aSAndroid Build Coastguard Worker# - source_gen_deps: (optional) List of targets which generate `sources` for 221*61c4878aSAndroid Build Coastguard Worker# this test. These `deps` will be included even if the test is disabled. 222*61c4878aSAndroid Build Coastguard Worker# `get_target_outputs` is used to add the generated `sources` to the 223*61c4878aSAndroid Build Coastguard Worker# test's `sources` list, so these targets must appear earlier in the 224*61c4878aSAndroid Build Coastguard Worker# same build file. 225*61c4878aSAndroid Build Coastguard Worker# - All of the regular "executable" target args are accepted. 226*61c4878aSAndroid Build Coastguard Worker# 227*61c4878aSAndroid Build Coastguard Workertemplate("pw_test") { 228*61c4878aSAndroid Build Coastguard Worker # This is required in order to reference the pw_test template's target name 229*61c4878aSAndroid Build Coastguard Worker # within the test_metadata of the metadata group below. The group() definition 230*61c4878aSAndroid Build Coastguard Worker # creates a new scope where the "target_name" variable is set to its target, 231*61c4878aSAndroid Build Coastguard Worker # shadowing the one in this scope. 232*61c4878aSAndroid Build Coastguard Worker _test_target_name = target_name 233*61c4878aSAndroid Build Coastguard Worker 234*61c4878aSAndroid Build Coastguard Worker _test_is_enabled = !defined(invoker.enable_if) || invoker.enable_if 235*61c4878aSAndroid Build Coastguard Worker 236*61c4878aSAndroid Build Coastguard Worker if (pw_toolchain_COVERAGE_ENABLED) { 237*61c4878aSAndroid Build Coastguard Worker _profraw_path = "$target_out_dir/test/$_test_target_name.profraw" 238*61c4878aSAndroid Build Coastguard Worker } 239*61c4878aSAndroid Build Coastguard Worker 240*61c4878aSAndroid Build Coastguard Worker # Always set the output_dir as pigweed is not compatible with shared 241*61c4878aSAndroid Build Coastguard Worker # bin directories for tests. 242*61c4878aSAndroid Build Coastguard Worker _test_output_dir = "${target_out_dir}/test" 243*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.output_dir)) { 244*61c4878aSAndroid Build Coastguard Worker _test_output_dir = invoker.output_dir 245*61c4878aSAndroid Build Coastguard Worker } 246*61c4878aSAndroid Build Coastguard Worker 247*61c4878aSAndroid Build Coastguard Worker _test_main = pw_unit_test_MAIN 248*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.test_main)) { 249*61c4878aSAndroid Build Coastguard Worker _test_main = invoker.test_main 250*61c4878aSAndroid Build Coastguard Worker } 251*61c4878aSAndroid Build Coastguard Worker 252*61c4878aSAndroid Build Coastguard Worker # The unit test code as a source_set. 253*61c4878aSAndroid Build Coastguard Worker pw_internal_disableable_target("$target_name.lib") { 254*61c4878aSAndroid Build Coastguard Worker target_type = "pw_source_set" 255*61c4878aSAndroid Build Coastguard Worker enable_if = _test_is_enabled 256*61c4878aSAndroid Build Coastguard Worker testonly = pw_unit_test_TESTONLY 257*61c4878aSAndroid Build Coastguard Worker 258*61c4878aSAndroid Build Coastguard Worker # It is possible that the executable target type has been overriden by 259*61c4878aSAndroid Build Coastguard Worker # pw_unit_test_EXECUTABLE_TARGET_TYPE, which may allow for additional 260*61c4878aSAndroid Build Coastguard Worker # variables to be specified on the executable template. As such, we cannot 261*61c4878aSAndroid Build Coastguard Worker # forward all variables ("*") from the invoker to source_set library, as 262*61c4878aSAndroid Build Coastguard Worker # those additional variables would not be used and GN gen would error. 263*61c4878aSAndroid Build Coastguard Worker _source_set_relevant_variables = [ 264*61c4878aSAndroid Build Coastguard Worker # GN source_set variables 265*61c4878aSAndroid Build Coastguard Worker # https://gn.googlesource.com/gn/+/main/docs/reference.md#target-declarations-source_set_declare-a-source-set-target-variables 266*61c4878aSAndroid Build Coastguard Worker "asmflags", 267*61c4878aSAndroid Build Coastguard Worker "cflags", 268*61c4878aSAndroid Build Coastguard Worker "cflags_c", 269*61c4878aSAndroid Build Coastguard Worker "cflags_cc", 270*61c4878aSAndroid Build Coastguard Worker "cflags_objc", 271*61c4878aSAndroid Build Coastguard Worker "cflags_objcc", 272*61c4878aSAndroid Build Coastguard Worker "defines", 273*61c4878aSAndroid Build Coastguard Worker "include_dirs", 274*61c4878aSAndroid Build Coastguard Worker "inputs", 275*61c4878aSAndroid Build Coastguard Worker "ldflags", 276*61c4878aSAndroid Build Coastguard Worker "lib_dirs", 277*61c4878aSAndroid Build Coastguard Worker "libs", 278*61c4878aSAndroid Build Coastguard Worker "precompiled_header", 279*61c4878aSAndroid Build Coastguard Worker "precompiled_source", 280*61c4878aSAndroid Build Coastguard Worker "rustenv", 281*61c4878aSAndroid Build Coastguard Worker "rustflags", 282*61c4878aSAndroid Build Coastguard Worker "swiftflags", 283*61c4878aSAndroid Build Coastguard Worker "testonly", 284*61c4878aSAndroid Build Coastguard Worker "assert_no_deps", 285*61c4878aSAndroid Build Coastguard Worker "data_deps", 286*61c4878aSAndroid Build Coastguard Worker "deps", 287*61c4878aSAndroid Build Coastguard Worker "public_deps", 288*61c4878aSAndroid Build Coastguard Worker "runtime_deps", 289*61c4878aSAndroid Build Coastguard Worker "write_runtime_deps", 290*61c4878aSAndroid Build Coastguard Worker "all_dependent_configs", 291*61c4878aSAndroid Build Coastguard Worker "public_configs", 292*61c4878aSAndroid Build Coastguard Worker "check_includes", 293*61c4878aSAndroid Build Coastguard Worker "configs", 294*61c4878aSAndroid Build Coastguard Worker "data", 295*61c4878aSAndroid Build Coastguard Worker "friend", 296*61c4878aSAndroid Build Coastguard Worker "metadata", 297*61c4878aSAndroid Build Coastguard Worker "output_extension", 298*61c4878aSAndroid Build Coastguard Worker "output_name", 299*61c4878aSAndroid Build Coastguard Worker "public", 300*61c4878aSAndroid Build Coastguard Worker "sources", 301*61c4878aSAndroid Build Coastguard Worker "source_gen_deps", 302*61c4878aSAndroid Build Coastguard Worker "visibility", 303*61c4878aSAndroid Build Coastguard Worker 304*61c4878aSAndroid Build Coastguard Worker # pw_source_set variables 305*61c4878aSAndroid Build Coastguard Worker # https://pigweed.dev/pw_build/?highlight=pw_executable#target-types 306*61c4878aSAndroid Build Coastguard Worker "remove_configs", 307*61c4878aSAndroid Build Coastguard Worker "remove_public_deps", 308*61c4878aSAndroid Build Coastguard Worker ] 309*61c4878aSAndroid Build Coastguard Worker forward_variables_from(invoker, _source_set_relevant_variables) 310*61c4878aSAndroid Build Coastguard Worker 311*61c4878aSAndroid Build Coastguard Worker if (!defined(deps)) { 312*61c4878aSAndroid Build Coastguard Worker deps = [] 313*61c4878aSAndroid Build Coastguard Worker } 314*61c4878aSAndroid Build Coastguard Worker deps += [ dir_pw_unit_test ] 315*61c4878aSAndroid Build Coastguard Worker 316*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.negative_compilation_tests) && 317*61c4878aSAndroid Build Coastguard Worker invoker.negative_compilation_tests) { 318*61c4878aSAndroid Build Coastguard Worker deps += [ 319*61c4878aSAndroid Build Coastguard Worker ":$_test_target_name.nc_test", 320*61c4878aSAndroid Build Coastguard Worker "$dir_pw_compilation_testing:internal_pigweed_use_only", 321*61c4878aSAndroid Build Coastguard Worker ] 322*61c4878aSAndroid Build Coastguard Worker } 323*61c4878aSAndroid Build Coastguard Worker } 324*61c4878aSAndroid Build Coastguard Worker 325*61c4878aSAndroid Build Coastguard Worker # Metadata for this test when used as part of a pw_test_group target. 326*61c4878aSAndroid Build Coastguard Worker _test_metadata = "${target_name}.metadata" 327*61c4878aSAndroid Build Coastguard Worker _extra_metadata = { 328*61c4878aSAndroid Build Coastguard Worker forward_variables_from(invoker, [ "extra_metadata" ]) 329*61c4878aSAndroid Build Coastguard Worker test_directory = rebase_path(_test_output_dir, root_build_dir) 330*61c4878aSAndroid Build Coastguard Worker } 331*61c4878aSAndroid Build Coastguard Worker pw_test_info(_test_metadata) { 332*61c4878aSAndroid Build Coastguard Worker test_type = "unit_test" 333*61c4878aSAndroid Build Coastguard Worker test_name = _test_target_name 334*61c4878aSAndroid Build Coastguard Worker forward_variables_from(invoker, [ "tags" ]) 335*61c4878aSAndroid Build Coastguard Worker extra_metadata = _extra_metadata 336*61c4878aSAndroid Build Coastguard Worker } 337*61c4878aSAndroid Build Coastguard Worker 338*61c4878aSAndroid Build Coastguard Worker pw_internal_disableable_target(_test_target_name) { 339*61c4878aSAndroid Build Coastguard Worker target_type = pw_unit_test_EXECUTABLE_TARGET_TYPE 340*61c4878aSAndroid Build Coastguard Worker enable_if = _test_is_enabled 341*61c4878aSAndroid Build Coastguard Worker testonly = pw_unit_test_TESTONLY 342*61c4878aSAndroid Build Coastguard Worker 343*61c4878aSAndroid Build Coastguard Worker # Include configs, deps, etc. from the pw_test in the executable as well as 344*61c4878aSAndroid Build Coastguard Worker # the library to ensure that linker flags propagate to the executable. 345*61c4878aSAndroid Build Coastguard Worker deps = [] 346*61c4878aSAndroid Build Coastguard Worker forward_variables_from(invoker, 347*61c4878aSAndroid Build Coastguard Worker "*", 348*61c4878aSAndroid Build Coastguard Worker [ 349*61c4878aSAndroid Build Coastguard Worker "extra_metadata", 350*61c4878aSAndroid Build Coastguard Worker "metadata", 351*61c4878aSAndroid Build Coastguard Worker "sources", 352*61c4878aSAndroid Build Coastguard Worker "source_gen_deps", 353*61c4878aSAndroid Build Coastguard Worker "public", 354*61c4878aSAndroid Build Coastguard Worker ]) 355*61c4878aSAndroid Build Coastguard Worker deps += [ 356*61c4878aSAndroid Build Coastguard Worker ":$_test_metadata", 357*61c4878aSAndroid Build Coastguard Worker ":$_test_target_name.lib", 358*61c4878aSAndroid Build Coastguard Worker ] 359*61c4878aSAndroid Build Coastguard Worker if (_test_main != "") { 360*61c4878aSAndroid Build Coastguard Worker deps += [ _test_main ] 361*61c4878aSAndroid Build Coastguard Worker } 362*61c4878aSAndroid Build Coastguard Worker output_dir = _test_output_dir 363*61c4878aSAndroid Build Coastguard Worker 364*61c4878aSAndroid Build Coastguard Worker metadata = { 365*61c4878aSAndroid Build Coastguard Worker # N.B.: This is placed here instead of in $_test_target_name._run because 366*61c4878aSAndroid Build Coastguard Worker # pw_test_group only forwards the metadata from _test_target_name and not 367*61c4878aSAndroid Build Coastguard Worker # _test_target_name._run or _test_target_name.run. 368*61c4878aSAndroid Build Coastguard Worker if (pw_toolchain_COVERAGE_ENABLED) { 369*61c4878aSAndroid Build Coastguard Worker profraws = [ 370*61c4878aSAndroid Build Coastguard Worker { 371*61c4878aSAndroid Build Coastguard Worker type = "profraw" 372*61c4878aSAndroid Build Coastguard Worker path = rebase_path(_profraw_path, root_build_dir) 373*61c4878aSAndroid Build Coastguard Worker }, 374*61c4878aSAndroid Build Coastguard Worker ] 375*61c4878aSAndroid Build Coastguard Worker } 376*61c4878aSAndroid Build Coastguard Worker 377*61c4878aSAndroid Build Coastguard Worker # Only collect test metadata for the test itself. 378*61c4878aSAndroid Build Coastguard Worker test_barrier = [ ":$_test_metadata" ] 379*61c4878aSAndroid Build Coastguard Worker } 380*61c4878aSAndroid Build Coastguard Worker } 381*61c4878aSAndroid Build Coastguard Worker 382*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.negative_compilation_tests) && 383*61c4878aSAndroid Build Coastguard Worker invoker.negative_compilation_tests) { 384*61c4878aSAndroid Build Coastguard Worker pw_cc_negative_compilation_test("$target_name.nc_test") { 385*61c4878aSAndroid Build Coastguard Worker forward_variables_from(invoker, "*") 386*61c4878aSAndroid Build Coastguard Worker testonly = pw_unit_test_TESTONLY 387*61c4878aSAndroid Build Coastguard Worker 388*61c4878aSAndroid Build Coastguard Worker # Add a dependency on pw_unit_test since it is implied for pw_unit_test 389*61c4878aSAndroid Build Coastguard Worker # targets. 390*61c4878aSAndroid Build Coastguard Worker if (!defined(deps)) { 391*61c4878aSAndroid Build Coastguard Worker deps = [] 392*61c4878aSAndroid Build Coastguard Worker } 393*61c4878aSAndroid Build Coastguard Worker deps += [ dir_pw_unit_test ] 394*61c4878aSAndroid Build Coastguard Worker } 395*61c4878aSAndroid Build Coastguard Worker } 396*61c4878aSAndroid Build Coastguard Worker 397*61c4878aSAndroid Build Coastguard Worker if (pw_unit_test_AUTOMATIC_RUNNER != "") { 398*61c4878aSAndroid Build Coastguard Worker # When the automatic runner is set, create an action which runs the unit 399*61c4878aSAndroid Build Coastguard Worker # test executable using the test runner script. 400*61c4878aSAndroid Build Coastguard Worker if (_test_is_enabled) { 401*61c4878aSAndroid Build Coastguard Worker _test_to_run = _test_target_name 402*61c4878aSAndroid Build Coastguard Worker } else { 403*61c4878aSAndroid Build Coastguard Worker # Create a run target for the .DISABLED version of the test. 404*61c4878aSAndroid Build Coastguard Worker _test_to_run = _test_target_name + ".DISABLED" 405*61c4878aSAndroid Build Coastguard Worker 406*61c4878aSAndroid Build Coastguard Worker # Create a placeholder .run target for the regular version of the test. 407*61c4878aSAndroid Build Coastguard Worker group(_test_target_name + ".run") { 408*61c4878aSAndroid Build Coastguard Worker testonly = pw_unit_test_TESTONLY 409*61c4878aSAndroid Build Coastguard Worker deps = [ ":$_test_target_name" ] 410*61c4878aSAndroid Build Coastguard Worker } 411*61c4878aSAndroid Build Coastguard Worker } 412*61c4878aSAndroid Build Coastguard Worker 413*61c4878aSAndroid Build Coastguard Worker _test_automatic_runner_args = pw_unit_test_AUTOMATIC_RUNNER_ARGS 414*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.test_automatic_runner_args)) { 415*61c4878aSAndroid Build Coastguard Worker _test_automatic_runner_args = [] 416*61c4878aSAndroid Build Coastguard Worker _test_automatic_runner_args += invoker.test_automatic_runner_args 417*61c4878aSAndroid Build Coastguard Worker } 418*61c4878aSAndroid Build Coastguard Worker 419*61c4878aSAndroid Build Coastguard Worker pw_python_action(_test_to_run + "._run") { 420*61c4878aSAndroid Build Coastguard Worker # Optionally limit max test runner concurrency. 421*61c4878aSAndroid Build Coastguard Worker if (pw_unit_test_POOL_DEPTH != 0) { 422*61c4878aSAndroid Build Coastguard Worker _pool_toolchain = current_toolchain 423*61c4878aSAndroid Build Coastguard Worker if (pw_unit_test_POOL_TOOLCHAIN != "") { 424*61c4878aSAndroid Build Coastguard Worker _pool_toolchain = pw_unit_test_POOL_TOOLCHAIN 425*61c4878aSAndroid Build Coastguard Worker } 426*61c4878aSAndroid Build Coastguard Worker pool = "$dir_pw_unit_test:unit_test_pool($_pool_toolchain)" 427*61c4878aSAndroid Build Coastguard Worker } 428*61c4878aSAndroid Build Coastguard Worker 429*61c4878aSAndroid Build Coastguard Worker deps = [ ":$_test_target_name" ] 430*61c4878aSAndroid Build Coastguard Worker inputs = [ pw_unit_test_AUTOMATIC_RUNNER ] 431*61c4878aSAndroid Build Coastguard Worker module = "pw_unit_test.test_runner" 432*61c4878aSAndroid Build Coastguard Worker python_deps = [ 433*61c4878aSAndroid Build Coastguard Worker "$dir_pw_cli/py", 434*61c4878aSAndroid Build Coastguard Worker "$dir_pw_unit_test/py", 435*61c4878aSAndroid Build Coastguard Worker ] 436*61c4878aSAndroid Build Coastguard Worker args = [ 437*61c4878aSAndroid Build Coastguard Worker "--runner", 438*61c4878aSAndroid Build Coastguard Worker rebase_path(pw_unit_test_AUTOMATIC_RUNNER, root_build_dir), 439*61c4878aSAndroid Build Coastguard Worker "--test", 440*61c4878aSAndroid Build Coastguard Worker "<TARGET_FILE(:$_test_to_run)>", 441*61c4878aSAndroid Build Coastguard Worker ] 442*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.envvars)) { 443*61c4878aSAndroid Build Coastguard Worker foreach(envvars, envvars) { 444*61c4878aSAndroid Build Coastguard Worker args += [ 445*61c4878aSAndroid Build Coastguard Worker "--env", 446*61c4878aSAndroid Build Coastguard Worker envvar, 447*61c4878aSAndroid Build Coastguard Worker ] 448*61c4878aSAndroid Build Coastguard Worker } 449*61c4878aSAndroid Build Coastguard Worker } 450*61c4878aSAndroid Build Coastguard Worker if (pw_unit_test_AUTOMATIC_RUNNER_TIMEOUT != "") { 451*61c4878aSAndroid Build Coastguard Worker args += [ 452*61c4878aSAndroid Build Coastguard Worker "--timeout", 453*61c4878aSAndroid Build Coastguard Worker pw_unit_test_AUTOMATIC_RUNNER_TIMEOUT, 454*61c4878aSAndroid Build Coastguard Worker ] 455*61c4878aSAndroid Build Coastguard Worker } 456*61c4878aSAndroid Build Coastguard Worker if (pw_toolchain_COVERAGE_ENABLED) { 457*61c4878aSAndroid Build Coastguard Worker _llvm_profile_file = rebase_path(_profraw_path, root_build_dir) 458*61c4878aSAndroid Build Coastguard Worker args += [ 459*61c4878aSAndroid Build Coastguard Worker "--env", 460*61c4878aSAndroid Build Coastguard Worker "LLVM_PROFILE_FILE=" + _llvm_profile_file, 461*61c4878aSAndroid Build Coastguard Worker ] 462*61c4878aSAndroid Build Coastguard Worker } 463*61c4878aSAndroid Build Coastguard Worker 464*61c4878aSAndroid Build Coastguard Worker if (_test_automatic_runner_args != []) { 465*61c4878aSAndroid Build Coastguard Worker args += [ "--" ] + _test_automatic_runner_args 466*61c4878aSAndroid Build Coastguard Worker } 467*61c4878aSAndroid Build Coastguard Worker 468*61c4878aSAndroid Build Coastguard Worker outputs = [] 469*61c4878aSAndroid Build Coastguard Worker if (pw_toolchain_COVERAGE_ENABLED) { 470*61c4878aSAndroid Build Coastguard Worker outputs += [ _profraw_path ] 471*61c4878aSAndroid Build Coastguard Worker } 472*61c4878aSAndroid Build Coastguard Worker stamp = true 473*61c4878aSAndroid Build Coastguard Worker } 474*61c4878aSAndroid Build Coastguard Worker 475*61c4878aSAndroid Build Coastguard Worker group(_test_to_run + ".run") { 476*61c4878aSAndroid Build Coastguard Worker testonly = pw_unit_test_TESTONLY 477*61c4878aSAndroid Build Coastguard Worker public_deps = [ ":$_test_to_run._run" ] 478*61c4878aSAndroid Build Coastguard Worker } 479*61c4878aSAndroid Build Coastguard Worker } else { 480*61c4878aSAndroid Build Coastguard Worker group(_test_target_name + ".run") { 481*61c4878aSAndroid Build Coastguard Worker testonly = pw_unit_test_TESTONLY 482*61c4878aSAndroid Build Coastguard Worker public_deps = [ ":$_test_target_name" ] 483*61c4878aSAndroid Build Coastguard Worker } 484*61c4878aSAndroid Build Coastguard Worker } 485*61c4878aSAndroid Build Coastguard Worker} 486*61c4878aSAndroid Build Coastguard Worker 487*61c4878aSAndroid Build Coastguard Worker# Defines a related collection of unit tests. 488*61c4878aSAndroid Build Coastguard Worker# 489*61c4878aSAndroid Build Coastguard Worker# Targets defined using this template will produce test metadata with a 490*61c4878aSAndroid Build Coastguard Worker# `test_type` of "test_group" and an additional `deps` list describing the tests 491*61c4878aSAndroid Build Coastguard Worker# collected by this target. 492*61c4878aSAndroid Build Coastguard Worker# 493*61c4878aSAndroid Build Coastguard Worker# Args: 494*61c4878aSAndroid Build Coastguard Worker# - tests: List of pw_test targets for each of the tests in the group. 495*61c4878aSAndroid Build Coastguard Worker# - group_deps: (optional) pw_test_group targets on which this group depends. 496*61c4878aSAndroid Build Coastguard Worker# - enable_if: (optional) Conditionally enables or disables this test group. 497*61c4878aSAndroid Build Coastguard Worker# If false, an empty group is created. Defaults to true. 498*61c4878aSAndroid Build Coastguard Worker# - output_metadata: (optional) If true, generates a JSON file containing the 499*61c4878aSAndroid Build Coastguard Worker# test metadata for this group and all of its dependencies. Defaults to 500*61c4878aSAndroid Build Coastguard Worker# false. 501*61c4878aSAndroid Build Coastguard Worker# 502*61c4878aSAndroid Build Coastguard Workertemplate("pw_test_group") { 503*61c4878aSAndroid Build Coastguard Worker _group_target = target_name 504*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.tests)) { 505*61c4878aSAndroid Build Coastguard Worker _deps = invoker.tests 506*61c4878aSAndroid Build Coastguard Worker } else { 507*61c4878aSAndroid Build Coastguard Worker _deps = [] 508*61c4878aSAndroid Build Coastguard Worker } 509*61c4878aSAndroid Build Coastguard Worker 510*61c4878aSAndroid Build Coastguard Worker # Allow empty pw_test_groups with no tests or group_deps. 511*61c4878aSAndroid Build Coastguard Worker if (!defined(invoker.tests) && !defined(invoker.group_deps)) { 512*61c4878aSAndroid Build Coastguard Worker not_needed("*") 513*61c4878aSAndroid Build Coastguard Worker } 514*61c4878aSAndroid Build Coastguard Worker 515*61c4878aSAndroid Build Coastguard Worker _group_is_enabled = !defined(invoker.enable_if) || invoker.enable_if 516*61c4878aSAndroid Build Coastguard Worker 517*61c4878aSAndroid Build Coastguard Worker if (_group_is_enabled) { 518*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.group_deps)) { 519*61c4878aSAndroid Build Coastguard Worker _deps += invoker.group_deps 520*61c4878aSAndroid Build Coastguard Worker } 521*61c4878aSAndroid Build Coastguard Worker 522*61c4878aSAndroid Build Coastguard Worker group(_group_target + ".lib") { 523*61c4878aSAndroid Build Coastguard Worker testonly = pw_unit_test_TESTONLY 524*61c4878aSAndroid Build Coastguard Worker deps = [] 525*61c4878aSAndroid Build Coastguard Worker foreach(_target, _deps) { 526*61c4878aSAndroid Build Coastguard Worker _dep_target = get_label_info(_target, "label_no_toolchain") 527*61c4878aSAndroid Build Coastguard Worker _dep_toolchain = get_label_info(_target, "toolchain") 528*61c4878aSAndroid Build Coastguard Worker deps += [ "$_dep_target.lib($_dep_toolchain)" ] 529*61c4878aSAndroid Build Coastguard Worker } 530*61c4878aSAndroid Build Coastguard Worker } 531*61c4878aSAndroid Build Coastguard Worker 532*61c4878aSAndroid Build Coastguard Worker # Create a manifest entry to indicate which tests are a part of this group. 533*61c4878aSAndroid Build Coastguard Worker _test_group_metadata = "${target_name}_pw_test_group_metadata" 534*61c4878aSAndroid Build Coastguard Worker _extra_metadata = { 535*61c4878aSAndroid Build Coastguard Worker forward_variables_from(invoker, [ "extra_metadata" ]) 536*61c4878aSAndroid Build Coastguard Worker if (_deps != []) { 537*61c4878aSAndroid Build Coastguard Worker deps = [] 538*61c4878aSAndroid Build Coastguard Worker foreach(dep, _deps) { 539*61c4878aSAndroid Build Coastguard Worker deps += [ get_label_info(dep, "label_no_toolchain") ] 540*61c4878aSAndroid Build Coastguard Worker } 541*61c4878aSAndroid Build Coastguard Worker } 542*61c4878aSAndroid Build Coastguard Worker } 543*61c4878aSAndroid Build Coastguard Worker pw_test_info(_test_group_metadata) { 544*61c4878aSAndroid Build Coastguard Worker testonly = pw_unit_test_TESTONLY 545*61c4878aSAndroid Build Coastguard Worker build_label = _group_target 546*61c4878aSAndroid Build Coastguard Worker test_type = "test_group" 547*61c4878aSAndroid Build Coastguard Worker test_name = rebase_path(get_label_info(_group_target, "dir"), "//") 548*61c4878aSAndroid Build Coastguard Worker extra_metadata = _extra_metadata 549*61c4878aSAndroid Build Coastguard Worker deps = _deps 550*61c4878aSAndroid Build Coastguard Worker } 551*61c4878aSAndroid Build Coastguard Worker 552*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.output_metadata) && invoker.output_metadata) { 553*61c4878aSAndroid Build Coastguard Worker generated_file(_group_target) { 554*61c4878aSAndroid Build Coastguard Worker testonly = pw_unit_test_TESTONLY 555*61c4878aSAndroid Build Coastguard Worker outputs = [ "$target_out_dir/$target_name.testinfo.json" ] 556*61c4878aSAndroid Build Coastguard Worker data_keys = [ 557*61c4878aSAndroid Build Coastguard Worker "test_groups", 558*61c4878aSAndroid Build Coastguard Worker "unit_tests", 559*61c4878aSAndroid Build Coastguard Worker "action_tests", 560*61c4878aSAndroid Build Coastguard Worker "perf_tests", 561*61c4878aSAndroid Build Coastguard Worker "fuzz_tests", 562*61c4878aSAndroid Build Coastguard Worker ] 563*61c4878aSAndroid Build Coastguard Worker walk_keys = [ "test_barrier" ] 564*61c4878aSAndroid Build Coastguard Worker output_conversion = "json" 565*61c4878aSAndroid Build Coastguard Worker deps = [ ":$_test_group_metadata" ] 566*61c4878aSAndroid Build Coastguard Worker } 567*61c4878aSAndroid Build Coastguard Worker } else { 568*61c4878aSAndroid Build Coastguard Worker group(_group_target) { 569*61c4878aSAndroid Build Coastguard Worker testonly = pw_unit_test_TESTONLY 570*61c4878aSAndroid Build Coastguard Worker deps = [ ":$_test_group_metadata" ] 571*61c4878aSAndroid Build Coastguard Worker } 572*61c4878aSAndroid Build Coastguard Worker } 573*61c4878aSAndroid Build Coastguard Worker 574*61c4878aSAndroid Build Coastguard Worker # If automatic test running is enabled, create a *.run group that collects 575*61c4878aSAndroid Build Coastguard Worker # all of the individual *.run targets and groups. 576*61c4878aSAndroid Build Coastguard Worker if (pw_unit_test_AUTOMATIC_RUNNER != "") { 577*61c4878aSAndroid Build Coastguard Worker group(_group_target + ".run") { 578*61c4878aSAndroid Build Coastguard Worker testonly = pw_unit_test_TESTONLY 579*61c4878aSAndroid Build Coastguard Worker deps = [ ":$_group_target" ] 580*61c4878aSAndroid Build Coastguard Worker foreach(_target, _deps) { 581*61c4878aSAndroid Build Coastguard Worker _dep_target = get_label_info(_target, "label_no_toolchain") 582*61c4878aSAndroid Build Coastguard Worker _dep_toolchain = get_label_info(_target, "toolchain") 583*61c4878aSAndroid Build Coastguard Worker deps += [ "$_dep_target.run($_dep_toolchain)" ] 584*61c4878aSAndroid Build Coastguard Worker } 585*61c4878aSAndroid Build Coastguard Worker } 586*61c4878aSAndroid Build Coastguard Worker } 587*61c4878aSAndroid Build Coastguard Worker } else { # _group_is_enabled 588*61c4878aSAndroid Build Coastguard Worker # Create empty groups for the tests to avoid pulling in any dependencies. 589*61c4878aSAndroid Build Coastguard Worker group(_group_target) { 590*61c4878aSAndroid Build Coastguard Worker } 591*61c4878aSAndroid Build Coastguard Worker group(_group_target + ".lib") { 592*61c4878aSAndroid Build Coastguard Worker } 593*61c4878aSAndroid Build Coastguard Worker 594*61c4878aSAndroid Build Coastguard Worker if (pw_unit_test_AUTOMATIC_RUNNER != "") { 595*61c4878aSAndroid Build Coastguard Worker group(_group_target + ".run") { 596*61c4878aSAndroid Build Coastguard Worker } 597*61c4878aSAndroid Build Coastguard Worker } 598*61c4878aSAndroid Build Coastguard Worker 599*61c4878aSAndroid Build Coastguard Worker not_needed("*") 600*61c4878aSAndroid Build Coastguard Worker not_needed(invoker, "*") 601*61c4878aSAndroid Build Coastguard Worker } 602*61c4878aSAndroid Build Coastguard Worker 603*61c4878aSAndroid Build Coastguard Worker # All of the tests in this group and its dependencies bundled into a single 604*61c4878aSAndroid Build Coastguard Worker # test binary. 605*61c4878aSAndroid Build Coastguard Worker pw_test(_group_target + ".bundle") { 606*61c4878aSAndroid Build Coastguard Worker deps = [ ":$_group_target.lib" ] 607*61c4878aSAndroid Build Coastguard Worker enable_if = _group_is_enabled 608*61c4878aSAndroid Build Coastguard Worker } 609*61c4878aSAndroid Build Coastguard Worker} 610