blob: 73d22b04b2b02637e251367c439bb69709c6f2d5 [file] [log] [blame]
# Copyright 2020 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.
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/module_config.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_protobuf_compiler/proto.gni")
import("$dir_pw_toolchain/traits.gni")
import("$dir_pw_unit_test/test.gni")
declare_args() {
# The build target that overrides the default configuration options for this
# module. This should point to a source set that provides defines through a
# public config (which may -include a file or add defines directly).
pw_unit_test_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
}
# This pool limits the maximum number of unit tests that may run in parallel.
# Despite the fact that this is a single GN "target", each toolchain owns its
# own version of this pool, meaning pw_unit_test_POOL_DEPTH may be set
# differently across targets in a single build, and build steps in one toolchain
# will not consume pool resources of steps from another toolchain.
pool("unit_test_pool") {
depth = pw_unit_test_POOL_DEPTH
}
config("public_include_path") {
include_dirs = [ "public" ]
}
config("public_overrides_include_path") {
include_dirs = [ "public_overrides" ]
}
pw_source_set("config") {
public = [ "public/pw_unit_test/config.h" ]
public_configs = [ ":public_include_path" ]
public_deps = [
dir_pw_polyfill,
pw_unit_test_CONFIG,
]
visibility = [ ":*" ]
}
# pw_unit_test facade. This provides a GoogleTest-compatible test framework.
pw_source_set("pw_unit_test") {
if (pw_unit_test_PUBLIC_DEPS == []) {
# TODO(b/233073669): For now, use pw_unit_test_GOOGLETEST_BACKEND only if
# pw_unit_test_PUBLIC_DEPS is not set. Remove pw_unit_test_PUBLIC_DEPS
# when projects have migrated. There is an assert in test.gni that
# ensures both variables are not set.
public_deps = [ pw_unit_test_GOOGLETEST_BACKEND ]
} else {
public_deps = pw_unit_test_PUBLIC_DEPS
}
}
# Lightweight unit test backend that implements a subset of GoogleTest.
pw_source_set("light") {
public_configs = [
":public_include_path",
":public_overrides_include_path",
]
public_deps = [
":config",
":event_handler",
dir_pw_polyfill,
dir_pw_preprocessor,
]
# If C++17 is supported, depend on StringBuilder.
if (pw_toolchain_CXX_STANDARD >= pw_toolchain_STANDARD.CXX17) {
public_deps += [ "$dir_pw_string:builder" ]
}
deps = [ dir_pw_assert ]
public = [ "public_overrides/gtest/gtest.h" ]
sources = [
"framework.cc",
"public/pw_unit_test/internal/framework.h",
]
}
pw_source_set("event_handler") {
public_configs = [ ":public_include_path" ]
public = [ "public/pw_unit_test/event_handler.h" ]
}
# Unit test event handler that provides GoogleTest-style output.
pw_source_set("googletest_style_event_handler") {
public_deps = [
":event_handler",
dir_pw_preprocessor,
]
public = [ "public/pw_unit_test/googletest_style_event_handler.h" ]
sources = [ "googletest_style_event_handler.cc" ]
}
# Library providing an event handler which outputs human-readable text.
pw_source_set("simple_printing_event_handler") {
public_deps = [
":googletest_style_event_handler",
"$dir_pw_preprocessor",
]
public = [ "public/pw_unit_test/simple_printing_event_handler.h" ]
sources = [ "simple_printing_event_handler.cc" ]
}
# Library providing a standard desktop main function for the pw_unit_test
# framework. Unit test files can link against this library to build runnable
# unit test executables.
pw_source_set("simple_printing_main") {
deps = [
":pw_unit_test",
":simple_printing_event_handler",
"$dir_pw_sys_io",
]
sources = [ "simple_printing_main.cc" ]
}
pw_source_set("printf_event_handler") {
public_deps = [
":googletest_style_event_handler",
dir_pw_preprocessor,
]
public = [ "public/pw_unit_test/printf_event_handler.h" ]
}
pw_source_set("printf_main") {
deps = [
":printf_event_handler",
":pw_unit_test",
]
sources = [ "printf_main.cc" ]
}
# Library providing an event handler which logs using pw_log.
pw_source_set("logging_event_handler") {
public_deps = [
":googletest_style_event_handler",
dir_pw_log,
]
public = [ "public/pw_unit_test/logging_event_handler.h" ]
sources = [ "logging_event_handler.cc" ]
}
pw_source_set("logging_main") {
deps = [
":logging_event_handler",
":pw_unit_test",
"$dir_pw_sys_io",
]
sources = [ "logging_main.cc" ]
}
pw_build_assert("require_light_test_backend") {
# TODO(b/233073669): Simplify once pw_unit_test_PUBLIC_DEPS is removed.
condition = (pw_unit_test_PUBLIC_DEPS == [] &&
pw_unit_test_GOOGLETEST_BACKEND == "$dir_pw_unit_test:light") ||
filter_include(pw_unit_test_PUBLIC_DEPS,
[ "$dir_pw_unit_test:light" ]) != []
message = "The pw_unit_test RPC service only works with the 'light' test " +
"backend.\n(pw_unit_test_GOOGLETEST_BACKEND = " +
"$pw_unit_test_GOOGLETEST_BACKEND)\n" +
"(pw_unit_test_PUBLIC_DEPS = $pw_unit_test_PUBLIC_DEPS)"
visibility = [ ":*" ]
}
pw_source_set("rpc_service") {
public_configs = [ ":public_include_path" ]
public_deps = [
":pw_unit_test",
":unit_test_proto.pwpb",
":unit_test_proto.raw_rpc",
"$dir_pw_containers:vector",
]
deps = [
":require_light_test_backend",
dir_pw_log,
]
public = [
"public/pw_unit_test/internal/rpc_event_handler.h",
"public/pw_unit_test/unit_test_service.h",
]
sources = [
"rpc_event_handler.cc",
"unit_test_service.cc",
]
}
pw_source_set("rpc_main") {
public_deps = [ ":pw_unit_test" ]
deps = [
":rpc_service",
"$dir_pw_rpc/system_server",
dir_pw_log,
]
sources = [ "rpc_main.cc" ]
}
pw_source_set("static_library_support") {
public_configs = [ ":public_include_path" ]
public_deps = [ ":light" ] # This library only works with the light backend
public = [ "public/pw_unit_test/static_library_support.h" ]
sources = [ "static_library_support.cc" ]
}
pw_executable("test_rpc_server") {
sources = [ "test_rpc_server.cc" ]
deps = [
":pw_unit_test",
":rpc_service",
"$dir_pw_rpc/system_server",
"$dir_pw_rpc/system_server:socket",
dir_pw_log,
]
}
pw_proto_library("unit_test_proto") {
sources = [ "pw_unit_test_proto/unit_test.proto" ]
}
pw_doc_group("docs") {
sources = [ "docs.rst" ]
}
pw_test("framework_test") {
sources = [ "framework_test.cc" ]
deps = [ dir_pw_assert ]
}
pw_static_library("tests_in_archive") {
sources = [
"static_library_archived_tests.cc",
"static_library_missing_archived_tests.cc",
]
deps = [ ":pw_unit_test" ]
visibility = [ ":*" ]
}
pw_test("static_library_support_test") {
sources = [ "static_library_support_test.cc" ]
deps = [
":static_library_support",
":tests_in_archive",
dir_pw_assert,
]
}
pw_test_group("tests") {
tests = [
":framework_test",
":static_library_support_test",
]
}