blob: 923fd9e54b9b29e99693bad8cae81619cc3dbd0f [file] [log] [blame]
# Copyright 2019 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
load("@rules_python//python:proto.bzl", "py_proto_library")
load(
"//pw_build:pigweed.bzl",
"pw_cc_binary",
"pw_cc_test",
"pw_facade",
)
load("//pw_build:selects.bzl", "TARGET_COMPATIBLE_WITH_HOST_SELECT")
load("//pw_protobuf_compiler:pw_proto_library.bzl", "pw_proto_library")
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
label_flag(
name = "main",
build_setting_default = ":simple_printing_main",
)
cc_library(
name = "config",
hdrs = ["public/pw_unit_test/config.h"],
includes = ["public"],
deps = [
":config_override",
"//pw_polyfill",
],
)
label_flag(
name = "config_override",
build_setting_default = "//pw_build:default_module_config",
)
pw_facade(
name = "pw_unit_test",
testonly = True,
hdrs = ["public/pw_unit_test/framework.h"],
backend = ":backend",
includes = ["public"],
)
label_flag(
name = "backend",
build_setting_default = ":light",
)
cc_library(
name = "light",
testonly = True,
srcs = ["framework_light.cc"],
hdrs = [
"light_public_overrides/pw_unit_test/framework_backend.h",
# The facade header is included here since
# public_overrides/gtest/gtest.h includes it. This avoids a circular
# dependency in the build system.
"public/pw_unit_test/framework.h",
"public_overrides/gtest/gtest.h",
],
includes = [
"light_public_overrides",
"public",
"public_overrides",
],
deps = [
":config",
":event_handler",
"//pw_assert",
"//pw_bytes:alignment",
"//pw_polyfill",
"//pw_preprocessor",
"//pw_span",
"//pw_string",
],
)
cc_library(
name = "googletest",
testonly = True,
hdrs = [
"googletest_public_overrides/pw_unit_test/framework_backend.h",
],
includes = ["googletest_public_overrides"],
# TODO: b/310957361 - gtest not supported on device
target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
deps = [
":googletest_handler_adapter",
"@com_google_googletest//:gtest",
],
)
# Identifies when the light framework is being used.
config_setting(
name = "light_setting",
testonly = True,
flag_values = {
"@pigweed//pw_unit_test:backend": "@pigweed//pw_unit_test:light",
},
# Do not depend on this config_setting outside upstream Pigweed. Config
# settings based on label flags are unreliable. See
# https://github.com/bazelbuild/bazel/issues/21189.
visibility = ["//:__subpackages__"],
)
config_setting(
name = "gtest_setting",
testonly = True,
flag_values = {
"@pigweed//pw_unit_test:backend": "@pigweed//pw_unit_test:googletest",
},
# Do not depend on this config_setting outside upstream Pigweed. Config
# settings based on label flags are unreliable. See
# https://github.com/bazelbuild/bazel/issues/21189.
visibility = ["//:__subpackages__"],
)
cc_library(
name = "event_handler",
hdrs = ["public/pw_unit_test/event_handler.h"],
includes = ["public"],
)
cc_library(
name = "googletest_style_event_handler",
srcs = ["googletest_style_event_handler.cc"],
hdrs = ["public/pw_unit_test/googletest_style_event_handler.h"],
deps = [
":event_handler",
"//pw_preprocessor",
],
)
cc_library(
name = "googletest_handler_adapter",
testonly = True,
srcs = ["googletest_handler_adapter.cc"],
hdrs = ["public/pw_unit_test/googletest_handler_adapter.h"],
includes = ["public"],
# TODO: b/310957361 - gtest not supported on device
target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
deps = [
":event_handler",
"//pw_preprocessor",
"@com_google_googletest//:gtest",
],
)
cc_library(
name = "googletest_test_matchers",
testonly = True,
hdrs = ["public/pw_unit_test/googletest_test_matchers.h"],
includes = ["public"],
# TODO: b/310957361 - gtest not supported on device
target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
deps = [
"//pw_result",
"//pw_status",
"@com_google_googletest//:gtest",
],
)
pw_cc_test(
name = "googletest_test_matchers_test",
srcs = ["googletest_test_matchers_test.cc"],
deps = [
":googletest_test_matchers",
],
)
cc_library(
name = "simple_printing_event_handler",
testonly = True,
srcs = ["simple_printing_event_handler.cc"],
hdrs = [
"public/pw_unit_test/simple_printing_event_handler.h",
],
includes = [
"public",
],
deps = [
":googletest_style_event_handler",
"//pw_preprocessor",
],
)
cc_library(
name = "simple_printing_main",
testonly = True,
srcs = [
"simple_printing_main.cc",
],
deps = [
":pw_unit_test",
":simple_printing_event_handler",
"//pw_span",
"//pw_sys_io",
],
)
cc_library(
name = "printf_event_handler",
testonly = True,
hdrs = ["public/pw_unit_test/printf_event_handler.h"],
deps = [
":googletest_style_event_handler",
"//pw_preprocessor",
],
)
cc_library(
name = "printf_main",
testonly = True,
srcs = ["printf_main.cc"],
deps = [
":printf_event_handler",
":pw_unit_test",
],
)
# TODO: b/324116813 - Remove this alias once no downstream project depends on
# it.
alias(
name = "logging_event_handler",
actual = "logging",
)
cc_library(
name = "logging",
testonly = True,
srcs = [
"logging_event_handler.cc",
],
hdrs = [
"public/pw_unit_test/logging_event_handler.h",
],
includes = [
"public",
],
deps = [
":googletest_style_event_handler",
"//pw_log",
],
)
pw_cc_binary(
name = "logging_main",
testonly = True,
srcs = [
"logging_main.cc",
],
deps = [
":logging",
"//pw_unit_test",
],
)
cc_library(
name = "multi_event_handler",
testonly = True,
hdrs = [
"public/pw_unit_test/multi_event_handler.h",
],
includes = [
"public",
],
deps = [
":event_handler",
],
)
pw_cc_test(
name = "multi_event_handler_test",
srcs = ["multi_event_handler_test.cc"],
deps = [
":multi_event_handler",
":pw_unit_test",
],
)
cc_library(
name = "test_record_event_handler",
testonly = True,
srcs = ["public/pw_unit_test/internal/test_record_trie.h"],
hdrs = [
"public/pw_unit_test/test_record_event_handler.h",
],
includes = [
"public",
],
deps = [
":event_handler",
"//pw_assert",
"//pw_json:builder",
],
)
pw_cc_test(
name = "test_record_event_handler_test",
srcs = ["test_record_event_handler_test.cc"],
deps = [
":pw_unit_test",
":test_record_event_handler",
],
)
proto_library(
name = "unit_test_proto",
srcs = ["pw_unit_test_proto/unit_test.proto"],
strip_import_prefix = "/pw_unit_test",
)
py_proto_library(
name = "unit_test_py_pb2",
deps = [":unit_test_proto"],
)
pw_proto_library(
name = "unit_test_cc",
deps = [":unit_test_proto"],
)
cc_library(
name = "rpc_service",
testonly = True,
srcs = ["unit_test_service.cc"] + select({
":light_setting": ["rpc_light_event_handler.cc"],
"//conditions:default": [":rpc_gtest_event_handler.cc"],
}),
hdrs = [
"public/pw_unit_test/config.h",
"public/pw_unit_test/unit_test_service.h",
] + select({
":light_setting": [
"rpc_light_public/pw_unit_test/internal/rpc_event_handler.h",
],
"//conditions:default": [
"rpc_gtest_public/pw_unit_test/internal/rpc_event_handler.h",
],
}),
includes = ["public"] + select({
":light_setting": ["rpc_light_public"],
"//conditions:default": ["rpc_gtest_public"],
}),
deps = [
":config",
":event_handler",
":pw_unit_test",
":unit_test_cc.pwpb",
":unit_test_cc.raw_rpc",
"//pw_log",
],
)
cc_library(
name = "rpc_main",
testonly = True,
srcs = [
"rpc_main.cc",
],
deps = [
":pw_unit_test",
":rpc_service",
"//pw_hdlc:default_addresses",
"//pw_log",
"//pw_rpc",
"//pw_rpc/system_server",
],
)
cc_library(
name = "static_library_support",
testonly = True,
srcs = ["static_library_support.cc"],
hdrs = ["public/pw_unit_test/static_library_support.h"],
includes = ["public"],
# This library only works with the light backend
target_compatible_with = select({
":light_setting": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = [":pw_unit_test"],
)
cc_library(
name = "tests_in_archive",
testonly = True,
srcs = [
"static_library_archived_tests.cc",
"static_library_missing_archived_tests.cc",
],
linkstatic = True,
visibility = ["//visibility:private"],
deps = [":pw_unit_test"],
)
pw_cc_test(
name = "static_library_support_test",
srcs = ["static_library_support_test.cc"],
deps = [
":pw_unit_test",
":static_library_support",
":tests_in_archive",
"//pw_assert",
],
)
pw_cc_test(
name = "framework_test",
srcs = ["framework_test.cc"],
# TODO: https://pwbug.dev/325509758 - Passes but hangs on cleanup.
target_compatible_with = select({
"//pw_build/constraints/chipset:rp2040": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
deps = [
":pw_unit_test",
"//pw_assert",
"//pw_status",
],
)
pw_cc_test(
name = "framework_light_test",
srcs = ["framework_light_test.cc"],
target_compatible_with = select({
":light_setting": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = [
":pw_unit_test",
"//pw_status",
"//pw_string",
],
)
# TODO(hepler): Build this as a cc_binary and use it in integration tests.
filegroup(
name = "test_rpc_server",
srcs = ["test_rpc_server.cc"],
# deps = [
# ":pw_unit_test",
# ":rpc_service",
# "//pw_log",
# "//pw_rpc/system_server",
# ],
)