diff options
author | Ben <benlawson@google.com> | 2023-09-26 00:14:24 +0000 |
---|---|---|
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-09-26 00:14:24 +0000 |
commit | 70ba43b50112cfb09ab32debb72f4bfd71045736 (patch) | |
tree | 7177833c59fb685bd401e608a1f39469d1b0c3c1 /pw_unit_test | |
parent | a836c804dc553983816f053ff500b2e0cee63c75 (diff) | |
download | pigweed-70ba43b50112cfb09ab32debb72f4bfd71045736.tar.gz |
pw_unit_test: Add pw_unit_test_TESTONLY build arg
Add pw_unit_test_TESTONLY build argument that controls the testonly
variable in pw_test, pw_test_group, and miscellaneous test targets.
This is required to support pw_unit_test_GOOGLETEST_BACKEND and
pw_unit_test_MAIN arguments configured with a testonly target.
This argument is false by default to avoid breaking existing
clients.
Bug: 234873207
Test: built with Fuchsia, which has a testonly googletest target
Change-Id: I73d4cd69286b0173dbe4b5b361cdd9c4b16d59f7
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/171970
Reviewed-by: Aaron Green <aarongreen@google.com>
Commit-Queue: Ben Lawson <benlawson@google.com>
Diffstat (limited to 'pw_unit_test')
-rw-r--r-- | pw_unit_test/BUILD.gn | 9 | ||||
-rw-r--r-- | pw_unit_test/docs.rst | 7 | ||||
-rw-r--r-- | pw_unit_test/py/BUILD.gn | 2 | ||||
-rw-r--r-- | pw_unit_test/test.gni | 17 |
4 files changed, 34 insertions, 1 deletions
diff --git a/pw_unit_test/BUILD.gn b/pw_unit_test/BUILD.gn index 8797d2f09..ba516e113 100644 --- a/pw_unit_test/BUILD.gn +++ b/pw_unit_test/BUILD.gn @@ -58,6 +58,7 @@ pw_source_set("config") { # pw_unit_test facade. This provides a GoogleTest-compatible test framework. pw_source_set("pw_unit_test") { + testonly = pw_unit_test_TESTONLY public_deps = [ pw_unit_test_GOOGLETEST_BACKEND ] } @@ -129,6 +130,7 @@ pw_source_set("simple_printing_event_handler") { # 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", @@ -147,6 +149,7 @@ pw_source_set("printf_event_handler") { } pw_source_set("printf_main") { + testonly = pw_unit_test_TESTONLY deps = [ ":printf_event_handler", ":pw_unit_test", @@ -174,6 +177,7 @@ group("logging") { } pw_source_set("logging_main") { + testonly = pw_unit_test_TESTONLY deps = [ ":logging", ":pw_unit_test", @@ -190,6 +194,7 @@ config("rpc_service_backend_gtest") { } pw_source_set("rpc_service") { + testonly = pw_unit_test_TESTONLY public_configs = [ ":public_include_path" ] public_deps = [ ":event_handler", @@ -215,6 +220,7 @@ pw_source_set("rpc_service") { } pw_source_set("rpc_main") { + testonly = pw_unit_test_TESTONLY public_deps = [ ":pw_unit_test" ] deps = [ ":rpc_service", @@ -232,6 +238,7 @@ pw_source_set("static_library_support") { } pw_executable("test_rpc_server") { + testonly = pw_unit_test_TESTONLY sources = [ "test_rpc_server.cc" ] deps = [ ":pw_unit_test", @@ -264,6 +271,7 @@ pw_test_group("metadata_only_group") { } pw_python_action_test("test_group_metadata_test") { + testonly = pw_unit_test_TESTONLY sources = [ "py/test_group_metadata_test.py" ] args = [ "--stamp-path", @@ -279,6 +287,7 @@ pw_test("framework_test") { } pw_static_library("tests_in_archive") { + testonly = pw_unit_test_TESTONLY sources = [ "static_library_archived_tests.cc", "static_library_missing_archived_tests.cc", diff --git a/pw_unit_test/docs.rst b/pw_unit_test/docs.rst index 7b1959436..c8c139d30 100644 --- a/pw_unit_test/docs.rst +++ b/pw_unit_test/docs.rst @@ -429,6 +429,13 @@ Build arguments Controls whether to build and run facade tests. Facade tests add considerably to build time, so they are disabled by default. +.. option:: pw_unit_test_TESTONLY <boolean> + + Controls the `testonly` variable in pw_test, pw_test_group, and + miscellaneous testing targets. This is useful if your test libraries (e.g. + GoogleTest) used by pw_unit_test have the `testonly` flag set. False by + default for backwards compatibility. + CMake ----- pw_add_test function diff --git a/pw_unit_test/py/BUILD.gn b/pw_unit_test/py/BUILD.gn index c29196e4e..0864be24c 100644 --- a/pw_unit_test/py/BUILD.gn +++ b/pw_unit_test/py/BUILD.gn @@ -17,6 +17,7 @@ import("//build_overrides/pigweed.gni") import("$dir_pw_build/python.gni") import("$dir_pw_build/python_action_test.gni") import("$dir_pw_rpc/internal/integration_test_ports.gni") +import("$dir_pw_unit_test/test.gni") pw_python_package("py") { setup = [ @@ -39,6 +40,7 @@ pw_python_package("py") { } pw_python_action_test("rpc_service_test") { + testonly = pw_unit_test_TESTONLY sources = [ "rpc_service_test.py" ] python_deps = [ ":py", diff --git a/pw_unit_test/test.gni b/pw_unit_test/test.gni index 0719e7de6..ead5044e0 100644 --- a/pw_unit_test/test.gni +++ b/pw_unit_test/test.gni @@ -100,6 +100,11 @@ declare_args() { # Type: string (path to a .gni file) # Usage: toolchain-controlled only pw_unit_test_EXECUTABLE_TARGET_TYPE_FILE = "" + + # If true, the pw_unit_test target, pw_test targets, and pw_test_group targets + # will define `testonly = true`. This is false by default for backwards + # compatibility. + pw_unit_test_TESTONLY = false } if (pw_unit_test_EXECUTABLE_TARGET_TYPE != "pw_executable" && @@ -238,6 +243,7 @@ template("pw_test") { pw_internal_disableable_target("$target_name.lib") { target_type = "pw_source_set" enable_if = _test_is_enabled + testonly = pw_unit_test_TESTONLY # It is possible that the executable target type has been overriden by # pw_unit_test_EXECUTABLE_TARGET_TYPE, which may allow for additional @@ -284,7 +290,6 @@ template("pw_test") { "public", "sources", "source_gen_deps", - "testonly", "visibility", # pw_source_set variables @@ -324,6 +329,7 @@ template("pw_test") { pw_internal_disableable_target(_test_target_name) { target_type = pw_unit_test_EXECUTABLE_TARGET_TYPE enable_if = _test_is_enabled + testonly = pw_unit_test_TESTONLY # Include configs, deps, etc. from the pw_test in the executable as well as # the library to ensure that linker flags propagate to the executable. @@ -368,6 +374,7 @@ template("pw_test") { invoker.negative_compilation_tests) { pw_cc_negative_compilation_test("$target_name.nc_test") { forward_variables_from(invoker, "*") + testonly = pw_unit_test_TESTONLY # Add a dependency on pw_unit_test since it is implied for pw_unit_test # targets. @@ -389,6 +396,7 @@ template("pw_test") { # Create a placeholder .run target for the regular version of the test. group(_test_target_name + ".run") { + testonly = pw_unit_test_TESTONLY deps = [ ":$_test_target_name" ] } } @@ -456,10 +464,12 @@ template("pw_test") { } group(_test_to_run + ".run") { + testonly = pw_unit_test_TESTONLY public_deps = [ ":$_test_to_run._run" ] } } else { group(_test_target_name + ".run") { + testonly = pw_unit_test_TESTONLY public_deps = [ ":$_test_target_name" ] } } @@ -501,6 +511,7 @@ template("pw_test_group") { } group(_group_target + ".lib") { + testonly = pw_unit_test_TESTONLY deps = [] foreach(_target, _deps) { _dep_target = get_label_info(_target, "label_no_toolchain") @@ -521,6 +532,7 @@ template("pw_test_group") { } } pw_test_info(_test_group_metadata) { + testonly = pw_unit_test_TESTONLY build_label = _group_target test_type = "test_group" test_name = rebase_path(get_label_info(_group_target, "dir"), "//") @@ -530,6 +542,7 @@ template("pw_test_group") { if (defined(invoker.output_metadata) && invoker.output_metadata) { generated_file(_group_target) { + testonly = pw_unit_test_TESTONLY outputs = [ "$target_out_dir/$target_name.testinfo.json" ] data_keys = [ "test_groups", @@ -544,6 +557,7 @@ template("pw_test_group") { } } else { group(_group_target) { + testonly = pw_unit_test_TESTONLY deps = [ ":$_test_group_metadata" ] } } @@ -552,6 +566,7 @@ template("pw_test_group") { # all of the individual *.run targets and groups. if (pw_unit_test_AUTOMATIC_RUNNER != "") { group(_group_target + ".run") { + testonly = pw_unit_test_TESTONLY deps = [ ":$_group_target" ] foreach(_target, _deps) { _dep_target = get_label_info(_target, "label_no_toolchain") |