1*61c4878aSAndroid Build Coastguard Worker# Copyright 2022 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/target_types.gni") 18*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_build/test_info.gni") 19*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_compilation_testing/negative_compilation_test.gni") 20*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_toolchain/host_clang/toolchains.gni") 21*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_unit_test/test.gni") 22*61c4878aSAndroid Build Coastguard Worker 23*61c4878aSAndroid Build Coastguard Workerdeclare_args() { 24*61c4878aSAndroid Build Coastguard Worker # Chooses the backend for how the framework calculates time 25*61c4878aSAndroid Build Coastguard Worker pw_perf_test_TIMER_INTERFACE_BACKEND = "" 26*61c4878aSAndroid Build Coastguard Worker 27*61c4878aSAndroid Build Coastguard Worker # Chooses the EventHandler for running the perf tests 28*61c4878aSAndroid Build Coastguard Worker pw_perf_test_MAIN_FUNCTION = "$dir_pw_perf_test:logging_main" 29*61c4878aSAndroid Build Coastguard Worker 30*61c4878aSAndroid Build Coastguard Worker # Chooses the executable template for performance tests 31*61c4878aSAndroid Build Coastguard Worker pw_perf_test_EXECUTABLE_TARGET_TYPE = "pw_executable" 32*61c4878aSAndroid Build Coastguard Worker} 33*61c4878aSAndroid Build Coastguard Worker 34*61c4878aSAndroid Build Coastguard Worker# Creates a library and an executable target for a unit test with pw_unit_test. 35*61c4878aSAndroid Build Coastguard Worker# 36*61c4878aSAndroid Build Coastguard Worker# <target_name>.lib contains the provided test sources as a library, which can 37*61c4878aSAndroid Build Coastguard Worker# then be linked into a test executable. 38*61c4878aSAndroid Build Coastguard Worker# <target_name> is a standalone executable which contains only the test sources 39*61c4878aSAndroid Build Coastguard Worker# specified in the pw_perf_test_template. 40*61c4878aSAndroid Build Coastguard Worker# 41*61c4878aSAndroid Build Coastguard Worker# Targets defined using this template will produce test metadata with a 42*61c4878aSAndroid Build Coastguard Worker# `test_type` of "perf_test" and an additional `test_directory` value describing 43*61c4878aSAndroid Build Coastguard Worker# the location of the test binary within the build output. 44*61c4878aSAndroid Build Coastguard Worker# 45*61c4878aSAndroid Build Coastguard Worker# Args: 46*61c4878aSAndroid Build Coastguard Worker# - The following args have the same meaning as for `pw_test`: 47*61c4878aSAndroid Build Coastguard Worker# enable_if 48*61c4878aSAndroid Build Coastguard Worker# tags 49*61c4878aSAndroid Build Coastguard Worker# extra_metadata 50*61c4878aSAndroid Build Coastguard Worker# 51*61c4878aSAndroid Build Coastguard Worker# - All of the regular `executable` target args are accepted. 52*61c4878aSAndroid Build Coastguard Worker# 53*61c4878aSAndroid Build Coastguard Workertemplate("pw_perf_test") { 54*61c4878aSAndroid Build Coastguard Worker _test_target_name = target_name 55*61c4878aSAndroid Build Coastguard Worker 56*61c4878aSAndroid Build Coastguard Worker _test_is_enabled = !defined(invoker.enable_if) || invoker.enable_if 57*61c4878aSAndroid Build Coastguard Worker 58*61c4878aSAndroid Build Coastguard Worker _test_output_dir = "${target_out_dir}/test" 59*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.output_dir)) { 60*61c4878aSAndroid Build Coastguard Worker _test_output_dir = invoker.output_dir 61*61c4878aSAndroid Build Coastguard Worker } 62*61c4878aSAndroid Build Coastguard Worker 63*61c4878aSAndroid Build Coastguard Worker _test_main = pw_perf_test_MAIN_FUNCTION 64*61c4878aSAndroid Build Coastguard Worker if (defined(invoker.test_main)) { 65*61c4878aSAndroid Build Coastguard Worker _test_main = invoker.test_main 66*61c4878aSAndroid Build Coastguard Worker } 67*61c4878aSAndroid Build Coastguard Worker 68*61c4878aSAndroid Build Coastguard Worker pw_internal_disableable_target("$target_name.lib") { 69*61c4878aSAndroid Build Coastguard Worker target_type = "pw_source_set" 70*61c4878aSAndroid Build Coastguard Worker enable_if = _test_is_enabled 71*61c4878aSAndroid Build Coastguard Worker forward_variables_from(invoker, "*", [ "metadata" ]) 72*61c4878aSAndroid Build Coastguard Worker 73*61c4878aSAndroid Build Coastguard Worker if (!defined(deps)) { 74*61c4878aSAndroid Build Coastguard Worker deps = [] 75*61c4878aSAndroid Build Coastguard Worker } 76*61c4878aSAndroid Build Coastguard Worker deps += [ dir_pw_perf_test ] 77*61c4878aSAndroid Build Coastguard Worker } 78*61c4878aSAndroid Build Coastguard Worker 79*61c4878aSAndroid Build Coastguard Worker _test_metadata = "${target_name}.metadata" 80*61c4878aSAndroid Build Coastguard Worker _extra_metadata = { 81*61c4878aSAndroid Build Coastguard Worker forward_variables_from(invoker, [ "extra_metadata" ]) 82*61c4878aSAndroid Build Coastguard Worker test_directory = rebase_path(_test_output_dir, root_build_dir) 83*61c4878aSAndroid Build Coastguard Worker } 84*61c4878aSAndroid Build Coastguard Worker pw_test_info(_test_metadata) { 85*61c4878aSAndroid Build Coastguard Worker test_type = "perf_test" 86*61c4878aSAndroid Build Coastguard Worker test_name = _test_target_name 87*61c4878aSAndroid Build Coastguard Worker forward_variables_from(invoker, [ "tags" ]) 88*61c4878aSAndroid Build Coastguard Worker extra_metadata = _extra_metadata 89*61c4878aSAndroid Build Coastguard Worker } 90*61c4878aSAndroid Build Coastguard Worker 91*61c4878aSAndroid Build Coastguard Worker pw_internal_disableable_target(_test_target_name) { 92*61c4878aSAndroid Build Coastguard Worker target_type = pw_perf_test_EXECUTABLE_TARGET_TYPE 93*61c4878aSAndroid Build Coastguard Worker enable_if = _test_is_enabled 94*61c4878aSAndroid Build Coastguard Worker 95*61c4878aSAndroid Build Coastguard Worker deps = [ 96*61c4878aSAndroid Build Coastguard Worker ":$_test_metadata", 97*61c4878aSAndroid Build Coastguard Worker ":$_test_target_name.lib", 98*61c4878aSAndroid Build Coastguard Worker ] 99*61c4878aSAndroid Build Coastguard Worker if (_test_main != "") { 100*61c4878aSAndroid Build Coastguard Worker deps += [ _test_main ] 101*61c4878aSAndroid Build Coastguard Worker } 102*61c4878aSAndroid Build Coastguard Worker 103*61c4878aSAndroid Build Coastguard Worker output_dir = _test_output_dir 104*61c4878aSAndroid Build Coastguard Worker } 105*61c4878aSAndroid Build Coastguard Worker} 106