1# Copyright 2022 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15load("@rules_cc//cc:cc_library.bzl", "cc_library") 16load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") 17load("//pw_build:compatibility.bzl", "host_backend_alias", "incompatible_with_mcu") 18load("//pw_build:pw_facade.bzl", "pw_facade") 19load("//pw_perf_test:pw_cc_perf_test.bzl", "pw_cc_perf_test") 20load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 21 22package( 23 default_visibility = ["//visibility:public"], 24 features = ["-layering_check"], 25) 26 27licenses(["notice"]) 28 29cc_library( 30 name = "pw_perf_test", 31 srcs = [ 32 "framework.cc", 33 "perf_test.cc", 34 "test_info.cc", 35 ], 36 hdrs = [ 37 "public/pw_perf_test/internal/framework.h", 38 "public/pw_perf_test/internal/test_info.h", 39 "public/pw_perf_test/perf_test.h", 40 ], 41 strip_include_prefix = "public", 42 deps = [ 43 ":event_handler", 44 ":state", 45 ":timer", 46 "//pw_preprocessor", 47 ], 48) 49 50cc_library( 51 name = "state", 52 srcs = [ 53 "state.cc", 54 ], 55 hdrs = [ 56 "public/pw_perf_test/state.h", 57 ], 58 strip_include_prefix = "public", 59 deps = [ 60 ":event_handler", 61 ":timer", 62 "//pw_assert:assert", 63 "//pw_log", 64 ], 65) 66 67pw_cc_test( 68 name = "state_test", 69 srcs = ["state_test.cc"], 70 deps = [":pw_perf_test"], 71) 72 73# Event handlers 74 75cc_library( 76 name = "event_handler", 77 hdrs = ["public/pw_perf_test/event_handler.h"], 78 strip_include_prefix = "public", 79 deps = [":timer"], 80) 81 82cc_library( 83 name = "logging_event_handler", 84 srcs = ["logging_event_handler.cc"], 85 hdrs = [ 86 "public/pw_perf_test/googletest_style_event_handler.h", 87 "public/pw_perf_test/logging_event_handler.h", 88 ], 89 strip_include_prefix = "public", 90 deps = [ 91 ":event_handler", 92 "//pw_log", 93 ], 94) 95 96cc_library( 97 name = "logging_main", 98 srcs = ["logging_main.cc"], 99 deps = [ 100 ":logging_event_handler", 101 ":pw_perf_test", 102 ], 103) 104 105# Timer facade 106 107cc_library( 108 name = "duration_unit", 109 hdrs = [ 110 "public/pw_perf_test/internal/duration_unit.h", 111 ], 112 strip_include_prefix = "public", 113 visibility = ["//visibility:private"], 114) 115 116pw_facade( 117 name = "timer", 118 hdrs = [ 119 "public/pw_perf_test/internal/timer.h", 120 ], 121 backend = ":test_timer_backend", 122 strip_include_prefix = "public", 123 deps = [ 124 ":duration_unit", 125 ], 126) 127 128label_flag( 129 name = "test_timer_backend", 130 build_setting_default = ":unspecified_backend", 131) 132 133host_backend_alias( 134 name = "unspecified_backend", 135 backend = ":chrono_timer", 136) 137 138pw_cc_test( 139 name = "timer_test", 140 srcs = ["timer_test.cc"], 141 deps = [ 142 ":timer", 143 "//pw_chrono:system_clock", 144 "//pw_thread:sleep", 145 ], 146) 147 148# Chrono timer facade implementation 149 150cc_library( 151 name = "chrono_timer", 152 hdrs = [ 153 "chrono_public_overrides/pw_perf_test_timer_backend/timer.h", 154 "public/pw_perf_test/internal/chrono_timer_interface.h", 155 ], 156 includes = [ 157 "chrono_public_overrides", 158 "public", 159 ], 160 target_compatible_with = incompatible_with_mcu(), 161 deps = [ 162 ":duration_unit", 163 ":timer.facade", 164 "//pw_chrono:system_clock", 165 ], 166) 167 168pw_cc_test( 169 name = "chrono_timer_test", 170 srcs = ["chrono_test.cc"], 171 deps = [ 172 ":chrono_timer", 173 "//pw_chrono:system_clock", 174 "//pw_thread:sleep", 175 ], 176) 177 178# ARM Cortex timer facade implementation 179 180cc_library( 181 name = "arm_cortex_timer", 182 hdrs = [ 183 "arm_cortex_cyccnt_public_overrides/pw_perf_test_timer_backend/timer.h", 184 "public/pw_perf_test/internal/cyccnt_timer_interface.h", 185 ], 186 includes = [ 187 "arm_cortex_cyccnt_public_overrides", 188 "public", 189 ], 190 target_compatible_with = incompatible_with_mcu(), 191 deps = [ 192 ":duration_unit", 193 ":timer.facade", 194 ], 195) 196 197# Module-level targets 198 199pw_cc_perf_test( 200 name = "example_perf_test", 201 srcs = ["examples/example_perf_test.cc"], 202) 203 204sphinx_docs_library( 205 name = "docs", 206 srcs = [ 207 "docs.rst", 208 "examples/example_perf_test.cc", 209 ], 210 prefix = "pw_perf_test/", 211 target_compatible_with = incompatible_with_mcu(), 212) 213 214filegroup( 215 name = "doxygen", 216 srcs = [ 217 "public/pw_perf_test/event_handler.h", 218 "public/pw_perf_test/perf_test.h", 219 ], 220) 221