1# Copyright 2019 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_python//python:proto.bzl", "py_proto_library") 16load( 17 "//pw_build:pigweed.bzl", 18 "pw_cc_binary", 19 "pw_cc_test", 20 "pw_facade", 21) 22load("//pw_build:selects.bzl", "TARGET_COMPATIBLE_WITH_HOST_SELECT") 23load("//pw_protobuf_compiler:pw_proto_library.bzl", "pw_proto_library") 24 25package(default_visibility = ["//visibility:public"]) 26 27licenses(["notice"]) 28 29label_flag( 30 name = "main", 31 build_setting_default = ":simple_printing_main", 32) 33 34cc_library( 35 name = "config", 36 hdrs = ["public/pw_unit_test/config.h"], 37 includes = ["public"], 38 deps = [ 39 ":config_override", 40 "//pw_polyfill", 41 ], 42) 43 44label_flag( 45 name = "config_override", 46 build_setting_default = "//pw_build:default_module_config", 47) 48 49pw_facade( 50 name = "pw_unit_test", 51 testonly = True, 52 hdrs = ["public/pw_unit_test/framework.h"], 53 backend = ":backend", 54 includes = ["public"], 55) 56 57label_flag( 58 name = "backend", 59 build_setting_default = ":light", 60) 61 62cc_library( 63 name = "light", 64 testonly = True, 65 srcs = ["framework_light.cc"], 66 hdrs = [ 67 "light_public_overrides/pw_unit_test/framework_backend.h", 68 # The facade header is included here since 69 # public_overrides/gtest/gtest.h includes it. This avoids a circular 70 # dependency in the build system. 71 "public/pw_unit_test/framework.h", 72 "public_overrides/gtest/gtest.h", 73 ], 74 includes = [ 75 "light_public_overrides", 76 "public", 77 "public_overrides", 78 ], 79 deps = [ 80 ":config", 81 ":event_handler", 82 "//pw_assert", 83 "//pw_bytes:alignment", 84 "//pw_polyfill", 85 "//pw_preprocessor", 86 "//pw_span", 87 "//pw_string", 88 ], 89) 90 91cc_library( 92 name = "googletest", 93 testonly = True, 94 hdrs = [ 95 "googletest_public_overrides/pw_unit_test/framework_backend.h", 96 ], 97 includes = ["googletest_public_overrides"], 98 # TODO: b/310957361 - gtest not supported on device 99 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT), 100 deps = [ 101 ":googletest_handler_adapter", 102 "@com_google_googletest//:gtest", 103 ], 104) 105 106# Identifies when the light framework is being used. 107config_setting( 108 name = "light_setting", 109 testonly = True, 110 flag_values = { 111 "@pigweed//pw_unit_test:backend": "@pigweed//pw_unit_test:light", 112 }, 113 # Do not depend on this config_setting outside upstream Pigweed. Config 114 # settings based on label flags are unreliable. See 115 # https://github.com/bazelbuild/bazel/issues/21189. 116 visibility = ["//:__subpackages__"], 117) 118 119config_setting( 120 name = "gtest_setting", 121 testonly = True, 122 flag_values = { 123 "@pigweed//pw_unit_test:backend": "@pigweed//pw_unit_test:googletest", 124 }, 125 # Do not depend on this config_setting outside upstream Pigweed. Config 126 # settings based on label flags are unreliable. See 127 # https://github.com/bazelbuild/bazel/issues/21189. 128 visibility = ["//:__subpackages__"], 129) 130 131cc_library( 132 name = "event_handler", 133 hdrs = ["public/pw_unit_test/event_handler.h"], 134 includes = ["public"], 135) 136 137cc_library( 138 name = "googletest_style_event_handler", 139 srcs = ["googletest_style_event_handler.cc"], 140 hdrs = ["public/pw_unit_test/googletest_style_event_handler.h"], 141 deps = [ 142 ":event_handler", 143 "//pw_preprocessor", 144 ], 145) 146 147cc_library( 148 name = "googletest_handler_adapter", 149 testonly = True, 150 srcs = ["googletest_handler_adapter.cc"], 151 hdrs = ["public/pw_unit_test/googletest_handler_adapter.h"], 152 includes = ["public"], 153 # TODO: b/310957361 - gtest not supported on device 154 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT), 155 deps = [ 156 ":event_handler", 157 "//pw_preprocessor", 158 "@com_google_googletest//:gtest", 159 ], 160) 161 162cc_library( 163 name = "googletest_test_matchers", 164 testonly = True, 165 hdrs = ["public/pw_unit_test/googletest_test_matchers.h"], 166 includes = ["public"], 167 # TODO: b/310957361 - gtest not supported on device 168 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT), 169 deps = [ 170 "//pw_result", 171 "//pw_status", 172 "@com_google_googletest//:gtest", 173 ], 174) 175 176pw_cc_test( 177 name = "googletest_test_matchers_test", 178 srcs = ["googletest_test_matchers_test.cc"], 179 deps = [ 180 ":googletest_test_matchers", 181 ], 182) 183 184cc_library( 185 name = "simple_printing_event_handler", 186 testonly = True, 187 srcs = ["simple_printing_event_handler.cc"], 188 hdrs = [ 189 "public/pw_unit_test/simple_printing_event_handler.h", 190 ], 191 includes = [ 192 "public", 193 ], 194 deps = [ 195 ":googletest_style_event_handler", 196 "//pw_preprocessor", 197 ], 198) 199 200cc_library( 201 name = "simple_printing_main", 202 testonly = True, 203 srcs = [ 204 "simple_printing_main.cc", 205 ], 206 deps = [ 207 ":pw_unit_test", 208 ":simple_printing_event_handler", 209 "//pw_span", 210 "//pw_sys_io", 211 ], 212) 213 214cc_library( 215 name = "printf_event_handler", 216 testonly = True, 217 hdrs = ["public/pw_unit_test/printf_event_handler.h"], 218 deps = [ 219 ":googletest_style_event_handler", 220 "//pw_preprocessor", 221 ], 222) 223 224cc_library( 225 name = "printf_main", 226 testonly = True, 227 srcs = ["printf_main.cc"], 228 deps = [ 229 ":printf_event_handler", 230 ":pw_unit_test", 231 ], 232) 233 234# TODO: b/324116813 - Remove this alias once no downstream project depends on 235# it. 236alias( 237 name = "logging_event_handler", 238 actual = "logging", 239) 240 241cc_library( 242 name = "logging", 243 testonly = True, 244 srcs = [ 245 "logging_event_handler.cc", 246 ], 247 hdrs = [ 248 "public/pw_unit_test/logging_event_handler.h", 249 ], 250 includes = [ 251 "public", 252 ], 253 deps = [ 254 ":googletest_style_event_handler", 255 "//pw_log", 256 ], 257) 258 259pw_cc_binary( 260 name = "logging_main", 261 testonly = True, 262 srcs = [ 263 "logging_main.cc", 264 ], 265 deps = [ 266 ":logging", 267 "//pw_unit_test", 268 ], 269) 270 271cc_library( 272 name = "multi_event_handler", 273 testonly = True, 274 hdrs = [ 275 "public/pw_unit_test/multi_event_handler.h", 276 ], 277 includes = [ 278 "public", 279 ], 280 deps = [ 281 ":event_handler", 282 ], 283) 284 285pw_cc_test( 286 name = "multi_event_handler_test", 287 srcs = ["multi_event_handler_test.cc"], 288 deps = [ 289 ":multi_event_handler", 290 ":pw_unit_test", 291 ], 292) 293 294cc_library( 295 name = "test_record_event_handler", 296 testonly = True, 297 srcs = ["public/pw_unit_test/internal/test_record_trie.h"], 298 hdrs = [ 299 "public/pw_unit_test/test_record_event_handler.h", 300 ], 301 includes = [ 302 "public", 303 ], 304 deps = [ 305 ":event_handler", 306 "//pw_assert", 307 "//pw_json:builder", 308 ], 309) 310 311pw_cc_test( 312 name = "test_record_event_handler_test", 313 srcs = ["test_record_event_handler_test.cc"], 314 deps = [ 315 ":pw_unit_test", 316 ":test_record_event_handler", 317 ], 318) 319 320proto_library( 321 name = "unit_test_proto", 322 srcs = ["pw_unit_test_proto/unit_test.proto"], 323 strip_import_prefix = "/pw_unit_test", 324) 325 326py_proto_library( 327 name = "unit_test_py_pb2", 328 deps = [":unit_test_proto"], 329) 330 331pw_proto_library( 332 name = "unit_test_cc", 333 deps = [":unit_test_proto"], 334) 335 336cc_library( 337 name = "rpc_service", 338 testonly = True, 339 srcs = ["unit_test_service.cc"] + select({ 340 ":light_setting": ["rpc_light_event_handler.cc"], 341 "//conditions:default": [":rpc_gtest_event_handler.cc"], 342 }), 343 hdrs = [ 344 "public/pw_unit_test/config.h", 345 "public/pw_unit_test/unit_test_service.h", 346 ] + select({ 347 ":light_setting": [ 348 "rpc_light_public/pw_unit_test/internal/rpc_event_handler.h", 349 ], 350 "//conditions:default": [ 351 "rpc_gtest_public/pw_unit_test/internal/rpc_event_handler.h", 352 ], 353 }), 354 includes = ["public"] + select({ 355 ":light_setting": ["rpc_light_public"], 356 "//conditions:default": ["rpc_gtest_public"], 357 }), 358 deps = [ 359 ":config", 360 ":event_handler", 361 ":pw_unit_test", 362 ":unit_test_cc.pwpb", 363 ":unit_test_cc.raw_rpc", 364 "//pw_log", 365 ], 366) 367 368cc_library( 369 name = "rpc_main", 370 testonly = True, 371 srcs = [ 372 "rpc_main.cc", 373 ], 374 deps = [ 375 ":pw_unit_test", 376 ":rpc_service", 377 "//pw_hdlc:default_addresses", 378 "//pw_log", 379 "//pw_rpc", 380 "//pw_rpc/system_server", 381 ], 382) 383 384cc_library( 385 name = "static_library_support", 386 testonly = True, 387 srcs = ["static_library_support.cc"], 388 hdrs = ["public/pw_unit_test/static_library_support.h"], 389 includes = ["public"], 390 # This library only works with the light backend 391 target_compatible_with = select({ 392 ":light_setting": [], 393 "//conditions:default": ["@platforms//:incompatible"], 394 }), 395 deps = [":pw_unit_test"], 396) 397 398cc_library( 399 name = "tests_in_archive", 400 testonly = True, 401 srcs = [ 402 "static_library_archived_tests.cc", 403 "static_library_missing_archived_tests.cc", 404 ], 405 linkstatic = True, 406 visibility = ["//visibility:private"], 407 deps = [":pw_unit_test"], 408) 409 410pw_cc_test( 411 name = "static_library_support_test", 412 srcs = ["static_library_support_test.cc"], 413 deps = [ 414 ":pw_unit_test", 415 ":static_library_support", 416 ":tests_in_archive", 417 "//pw_assert", 418 ], 419) 420 421pw_cc_test( 422 name = "framework_test", 423 srcs = ["framework_test.cc"], 424 deps = [ 425 ":pw_unit_test", 426 "//pw_assert", 427 "//pw_status", 428 ], 429) 430 431pw_cc_test( 432 name = "framework_light_test", 433 srcs = ["framework_light_test.cc"], 434 target_compatible_with = select({ 435 ":light_setting": [], 436 "//conditions:default": ["@platforms//:incompatible"], 437 }), 438 deps = [ 439 ":pw_unit_test", 440 "//pw_status", 441 "//pw_string", 442 ], 443) 444 445# TODO(hepler): Build this as a cc_binary and use it in integration tests. 446filegroup( 447 name = "test_rpc_server", 448 srcs = ["test_rpc_server.cc"], 449 # deps = [ 450 # ":pw_unit_test", 451 # ":rpc_service", 452 # "//pw_log", 453 # "//pw_rpc/system_server", 454 # ], 455) 456