| # 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/python_action_test.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" ] |
| } |
| |
| config("light_public_overrides_include_path") { |
| include_dirs = [ "light_public_overrides" ] |
| } |
| |
| config("googletest_public_overrides_include_path") { |
| include_dirs = [ "googletest_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") { |
| testonly = pw_unit_test_TESTONLY |
| public = [ "public/pw_unit_test/framework.h" ] |
| public_configs = [ ":public_include_path" ] |
| public_deps = [ pw_unit_test_BACKEND ] |
| |
| # Temporarily redirect deprecated googletest pointer to new pointer. |
| if ("$pw_unit_test_GOOGLETEST_BACKEND" == "$dir_pw_third_party/googletest" && |
| "$pw_unit_test_MAIN" == "$dir_pw_third_party/googletest:gmock_main" && |
| "$pw_unit_test_BACKEND" == "$dir_pw_unit_test:light") { |
| print("Warning: pw_unit_test_GOOGLETEST_BACKEND is deprecated.") |
| print("Set pw_unit_test_BACKEND to //pw_unit_test:googletest.") |
| public_deps = [] # The list must be empty before overriding. |
| public_deps = [ ":googletest" ] |
| } |
| } |
| |
| # Lightweight unit test backend that implements a subset of GoogleTest. |
| pw_source_set("light") { |
| public_configs = [ |
| ":light_public_overrides_include_path", |
| ":public_include_path", |
| ":public_overrides_include_path", |
| ] |
| public_deps = [ |
| ":config", |
| ":event_handler", |
| "$dir_pw_bytes:alignment", |
| dir_pw_polyfill, |
| dir_pw_preprocessor, |
| dir_pw_span, |
| ] |
| |
| # 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 = [ |
| "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", |
| ] |
| sources = [ "framework_light.cc" ] |
| } |
| |
| # Unit test framework backend that redirects to GoogleTest. |
| if (pw_unit_test_BACKEND != "") { |
| pw_source_set("googletest") { |
| public_configs = [ ":googletest_public_overrides_include_path" ] |
| public = [ "googletest_public_overrides/pw_unit_test/framework_backend.h" ] |
| |
| public_deps = [ pw_unit_test_GOOGLETEST_BACKEND ] |
| } |
| } |
| |
| 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" ] |
| } |
| |
| pw_source_set("googletest_handler_adapter") { |
| public_configs = [ ":public_include_path" ] |
| public_deps = [ |
| ":event_handler", |
| "$dir_pw_third_party/googletest", |
| dir_pw_preprocessor, |
| ] |
| public = [ "public/pw_unit_test/googletest_handler_adapter.h" ] |
| sources = [ "googletest_handler_adapter.cc" ] |
| } |
| |
| pw_source_set("googletest_test_matchers") { |
| public_configs = [ ":public_include_path" ] |
| public = [ "public/pw_unit_test/googletest_test_matchers.h" ] |
| public_deps = [ |
| "$dir_pw_third_party/googletest", |
| dir_pw_result, |
| dir_pw_status, |
| ] |
| } |
| |
| pw_test("googletest_test_matchers_test") { |
| enable_if = pw_unit_test_BACKEND != "" && |
| pw_unit_test_BACKEND != "$dir_pw_unit_test:light" |
| sources = [ "googletest_test_matchers_test.cc" ] |
| deps = [ ":googletest_test_matchers" ] |
| } |
| |
| # 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") { |
| testonly = pw_unit_test_TESTONLY |
| deps = [ |
| ":pw_unit_test", |
| ":simple_printing_event_handler", |
| "$dir_pw_sys_io", |
| dir_pw_span, |
| ] |
| 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") { |
| testonly = pw_unit_test_TESTONLY |
| 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" ] |
| } |
| |
| # Provides logging to either the light framework or an external GoogleTest. |
| group("logging") { |
| public_deps = [ ":logging_event_handler" ] |
| deps = [] |
| if (pw_unit_test_BACKEND != "$dir_pw_unit_test:light") { |
| deps += [ ":googletest_handler_adapter" ] |
| } |
| } |
| |
| pw_source_set("logging_main") { |
| testonly = pw_unit_test_TESTONLY |
| deps = [ |
| ":logging", |
| ":pw_unit_test", |
| ] |
| sources = [ "logging_main.cc" ] |
| } |
| |
| # Library providing an event handler adapter that allows for multiple |
| # event handlers to be registered for a given test run |
| pw_source_set("multi_event_handler") { |
| public_deps = [ ":event_handler" ] |
| public = [ "public/pw_unit_test/multi_event_handler.h" ] |
| } |
| |
| pw_test("multi_event_handler_test") { |
| sources = [ "multi_event_handler_test.cc" ] |
| deps = [ |
| ":multi_event_handler", |
| ":pw_unit_test", |
| ] |
| } |
| |
| # Library providing an event handler which outputs a test summary artifact. |
| pw_source_set("test_record_event_handler") { |
| public_deps = [ |
| ":googletest_style_event_handler", |
| "$dir_pw_json:builder", |
| ] |
| deps = [ "$dir_pw_assert" ] |
| public = [ "public/pw_unit_test/test_record_event_handler.h" ] |
| sources = [ "public/pw_unit_test/internal/test_record_trie.h" ] |
| } |
| |
| pw_test("test_record_event_handler_test") { |
| sources = [ "test_record_event_handler_test.cc" ] |
| deps = [ |
| ":pw_unit_test", |
| ":test_record_event_handler", |
| ] |
| } |
| |
| config("rpc_service_backend_light") { |
| include_dirs = [ "rpc_light_public" ] |
| } |
| |
| config("rpc_service_backend_gtest") { |
| include_dirs = [ "rpc_gtest_public" ] |
| } |
| |
| pw_source_set("rpc_service") { |
| testonly = pw_unit_test_TESTONLY |
| public_configs = [ ":public_include_path" ] |
| public_deps = [ |
| ":config", |
| ":event_handler", |
| ":pw_unit_test", |
| ":unit_test_proto.pwpb", |
| ":unit_test_proto.raw_rpc", |
| "$dir_pw_containers:vector", |
| ] |
| deps = [ dir_pw_log ] |
| public = [ "public/pw_unit_test/unit_test_service.h" ] |
| sources = [ "unit_test_service.cc" ] |
| defines = [] |
| |
| if (pw_unit_test_BACKEND == "$dir_pw_unit_test:light") { |
| public_configs += [ ":rpc_service_backend_light" ] |
| sources += [ "rpc_light_event_handler.cc" ] |
| public += [ "rpc_light_public/pw_unit_test/internal/rpc_event_handler.h" ] |
| } else { |
| public_configs += [ ":rpc_service_backend_gtest" ] |
| sources += [ "rpc_gtest_event_handler.cc" ] |
| public += [ "rpc_gtest_public/pw_unit_test/internal/rpc_event_handler.h" ] |
| } |
| } |
| |
| pw_source_set("rpc_main") { |
| testonly = pw_unit_test_TESTONLY |
| public_deps = [ ":pw_unit_test" ] |
| deps = [ |
| ":rpc_service", |
| "$dir_pw_rpc/system_server", |
| dir_pw_log, |
| ] |
| sources = [ "rpc_main.cc" ] |
| } |
| |
| if (pw_unit_test_BACKEND == "$dir_pw_unit_test:light") { |
| pw_source_set("static_library_support") { |
| public_configs = [ ":public_include_path" ] |
| public_deps = [ pw_unit_test_BACKEND ] |
| public = [ "public/pw_unit_test/static_library_support.h" ] |
| sources = [ "static_library_support.cc" ] |
| } |
| } else { |
| group("static_library_support") { |
| } |
| } |
| |
| pw_executable("test_rpc_server") { |
| testonly = pw_unit_test_TESTONLY |
| 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" ] |
| other_deps = [ "py" ] |
| } |
| |
| pw_test("metadata_only_test") { |
| extra_metadata = { |
| extra_key = "extra_value" |
| } |
| } |
| |
| # pw_test_group produces the metadata file for its tests. |
| pw_test_group("metadata_only_group") { |
| tests = [ ":metadata_only_test" ] |
| output_metadata = true |
| } |
| |
| pw_python_action_test("test_group_metadata_test") { |
| testonly = pw_unit_test_TESTONLY |
| sources = [ "py/test_group_metadata_test.py" ] |
| args = [ |
| "--stamp-path", |
| "<TARGET_FILE(:metadata_only_group)>", |
| ] |
| deps = [ ":metadata_only_group" ] |
| } |
| |
| pw_test("framework_test") { |
| sources = [ "framework_test.cc" ] |
| deps = [ |
| dir_pw_assert, |
| dir_pw_status, |
| ] |
| |
| # TODO: https://pwbug.dev/325509758 - Passes but hangs on cleanup. |
| if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") { |
| enable_if = false |
| } |
| } |
| |
| pw_test("framework_light_test") { |
| enable_if = pw_unit_test_BACKEND == "$dir_pw_unit_test:light" |
| sources = [ "framework_light_test.cc" ] |
| deps = [ |
| "$dir_pw_string:builder", |
| dir_pw_status, |
| ] |
| } |
| |
| pw_static_library("tests_in_archive") { |
| testonly = pw_unit_test_TESTONLY |
| sources = [ |
| "static_library_archived_tests.cc", |
| "static_library_missing_archived_tests.cc", |
| ] |
| deps = [ ":pw_unit_test" ] |
| visibility = [ ":*" ] |
| } |
| |
| pw_test("static_library_support_test") { |
| enable_if = pw_unit_test_BACKEND == "$dir_pw_unit_test:light" |
| sources = [ "static_library_support_test.cc" ] |
| deps = [ |
| ":static_library_support", |
| ":tests_in_archive", |
| dir_pw_assert, |
| ] |
| } |
| |
| pw_test_group("tests") { |
| tests = [ |
| ":framework_test", |
| ":framework_light_test", |
| ":static_library_support_test", |
| ":multi_event_handler_test", |
| ":test_record_event_handler_test", |
| ] |
| if (dir_pw_third_party_googletest != "") { |
| tests += [ ":googletest_test_matchers_test" ] |
| } |
| } |