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