xref: /aosp_15_r20/external/pigweed/pw_unit_test/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker# Copyright 2020 The Pigweed Authors
2*61c4878aSAndroid Build Coastguard Worker#
3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of
5*61c4878aSAndroid Build Coastguard Worker# the License at
6*61c4878aSAndroid Build Coastguard Worker#
7*61c4878aSAndroid Build Coastguard Worker#     https://www.apache.org/licenses/LICENSE-2.0
8*61c4878aSAndroid Build Coastguard Worker#
9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under
13*61c4878aSAndroid Build Coastguard Worker# the License.
14*61c4878aSAndroid Build Coastguard Worker
15*61c4878aSAndroid Build Coastguard Workerimport("//build_overrides/pigweed.gni")
16*61c4878aSAndroid Build Coastguard Worker
17*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_build/module_config.gni")
18*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_build/python_action_test.gni")
19*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_build/target_types.gni")
20*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_docgen/docs.gni")
21*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_protobuf_compiler/proto.gni")
22*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_toolchain/traits.gni")
23*61c4878aSAndroid Build Coastguard Workerimport("$dir_pw_unit_test/test.gni")
24*61c4878aSAndroid Build Coastguard Worker
25*61c4878aSAndroid Build Coastguard Workerdeclare_args() {
26*61c4878aSAndroid Build Coastguard Worker  # The build target that overrides the default configuration options for this
27*61c4878aSAndroid Build Coastguard Worker  # module. This should point to a source set that provides defines through a
28*61c4878aSAndroid Build Coastguard Worker  # public config (which may -include a file or add defines directly).
29*61c4878aSAndroid Build Coastguard Worker  pw_unit_test_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
30*61c4878aSAndroid Build Coastguard Worker}
31*61c4878aSAndroid Build Coastguard Worker
32*61c4878aSAndroid Build Coastguard Worker# This pool limits the maximum number of unit tests that may run in parallel.
33*61c4878aSAndroid Build Coastguard Worker# Despite the fact that this is a single GN "target", each toolchain owns its
34*61c4878aSAndroid Build Coastguard Worker# own version of this pool, meaning pw_unit_test_POOL_DEPTH may be set
35*61c4878aSAndroid Build Coastguard Worker# differently across targets in a single build, and build steps in one toolchain
36*61c4878aSAndroid Build Coastguard Worker# will not consume pool resources of steps from another toolchain.
37*61c4878aSAndroid Build Coastguard Workerpool("unit_test_pool") {
38*61c4878aSAndroid Build Coastguard Worker  depth = pw_unit_test_POOL_DEPTH
39*61c4878aSAndroid Build Coastguard Worker}
40*61c4878aSAndroid Build Coastguard Worker
41*61c4878aSAndroid Build Coastguard Workerconfig("public_include_path") {
42*61c4878aSAndroid Build Coastguard Worker  include_dirs = [ "public" ]
43*61c4878aSAndroid Build Coastguard Worker}
44*61c4878aSAndroid Build Coastguard Worker
45*61c4878aSAndroid Build Coastguard Workerconfig("public_overrides_include_path") {
46*61c4878aSAndroid Build Coastguard Worker  include_dirs = [ "public_overrides" ]
47*61c4878aSAndroid Build Coastguard Worker}
48*61c4878aSAndroid Build Coastguard Worker
49*61c4878aSAndroid Build Coastguard Workerconfig("light_public_overrides_include_path") {
50*61c4878aSAndroid Build Coastguard Worker  include_dirs = [ "light_public_overrides" ]
51*61c4878aSAndroid Build Coastguard Worker}
52*61c4878aSAndroid Build Coastguard Worker
53*61c4878aSAndroid Build Coastguard Workerconfig("googletest_public_overrides_include_path") {
54*61c4878aSAndroid Build Coastguard Worker  include_dirs = [ "googletest_public_overrides" ]
55*61c4878aSAndroid Build Coastguard Worker}
56*61c4878aSAndroid Build Coastguard Worker
57*61c4878aSAndroid Build Coastguard Workerpw_source_set("config") {
58*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/config.h" ]
59*61c4878aSAndroid Build Coastguard Worker  public_configs = [ ":public_include_path" ]
60*61c4878aSAndroid Build Coastguard Worker  public_deps = [
61*61c4878aSAndroid Build Coastguard Worker    dir_pw_polyfill,
62*61c4878aSAndroid Build Coastguard Worker    pw_unit_test_CONFIG,
63*61c4878aSAndroid Build Coastguard Worker  ]
64*61c4878aSAndroid Build Coastguard Worker  visibility = [ ":*" ]
65*61c4878aSAndroid Build Coastguard Worker}
66*61c4878aSAndroid Build Coastguard Worker
67*61c4878aSAndroid Build Coastguard Worker# pw_unit_test facade. This provides a GoogleTest-compatible test framework.
68*61c4878aSAndroid Build Coastguard Workerpw_source_set("pw_unit_test") {
69*61c4878aSAndroid Build Coastguard Worker  testonly = pw_unit_test_TESTONLY
70*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/framework.h" ]
71*61c4878aSAndroid Build Coastguard Worker  public_configs = [ ":public_include_path" ]
72*61c4878aSAndroid Build Coastguard Worker  public_deps = [
73*61c4878aSAndroid Build Coastguard Worker    ":status_macros",
74*61c4878aSAndroid Build Coastguard Worker    pw_unit_test_BACKEND,
75*61c4878aSAndroid Build Coastguard Worker  ]
76*61c4878aSAndroid Build Coastguard Worker
77*61c4878aSAndroid Build Coastguard Worker  # Temporarily redirect deprecated googletest pointer to new pointer.
78*61c4878aSAndroid Build Coastguard Worker  if ("$pw_unit_test_GOOGLETEST_BACKEND" == "$dir_pw_third_party/googletest" &&
79*61c4878aSAndroid Build Coastguard Worker      "$pw_unit_test_MAIN" == "$dir_pw_third_party/googletest:gmock_main" &&
80*61c4878aSAndroid Build Coastguard Worker      "$pw_unit_test_BACKEND" == "$dir_pw_unit_test:light") {
81*61c4878aSAndroid Build Coastguard Worker    print("Warning: pw_unit_test_GOOGLETEST_BACKEND is deprecated.")
82*61c4878aSAndroid Build Coastguard Worker    print("Set pw_unit_test_BACKEND to //pw_unit_test:googletest.")
83*61c4878aSAndroid Build Coastguard Worker    public_deps = []  # The list must be empty before overriding.
84*61c4878aSAndroid Build Coastguard Worker    public_deps = [ ":googletest" ]
85*61c4878aSAndroid Build Coastguard Worker  }
86*61c4878aSAndroid Build Coastguard Worker}
87*61c4878aSAndroid Build Coastguard Worker
88*61c4878aSAndroid Build Coastguard Worker# Lightweight unit test backend that implements a subset of GoogleTest.
89*61c4878aSAndroid Build Coastguard Workerpw_source_set("light") {
90*61c4878aSAndroid Build Coastguard Worker  public_configs = [
91*61c4878aSAndroid Build Coastguard Worker    ":light_public_overrides_include_path",
92*61c4878aSAndroid Build Coastguard Worker    ":public_include_path",
93*61c4878aSAndroid Build Coastguard Worker    ":public_overrides_include_path",
94*61c4878aSAndroid Build Coastguard Worker  ]
95*61c4878aSAndroid Build Coastguard Worker  public_deps = [
96*61c4878aSAndroid Build Coastguard Worker    ":config",
97*61c4878aSAndroid Build Coastguard Worker    ":event_handler",
98*61c4878aSAndroid Build Coastguard Worker    ":status_macros",
99*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_bytes:alignment",
100*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_string:builder",
101*61c4878aSAndroid Build Coastguard Worker    dir_pw_polyfill,
102*61c4878aSAndroid Build Coastguard Worker    dir_pw_preprocessor,
103*61c4878aSAndroid Build Coastguard Worker    dir_pw_span,
104*61c4878aSAndroid Build Coastguard Worker    dir_pw_status,
105*61c4878aSAndroid Build Coastguard Worker  ]
106*61c4878aSAndroid Build Coastguard Worker
107*61c4878aSAndroid Build Coastguard Worker  deps = [ dir_pw_assert ]
108*61c4878aSAndroid Build Coastguard Worker
109*61c4878aSAndroid Build Coastguard Worker  public = [
110*61c4878aSAndroid Build Coastguard Worker    "light_public_overrides/pw_unit_test/framework_backend.h",
111*61c4878aSAndroid Build Coastguard Worker
112*61c4878aSAndroid Build Coastguard Worker    # The facade header is included here since public_overrides/gtest/gtest.h
113*61c4878aSAndroid Build Coastguard Worker    # includes it. This avoids a circular dependency in the build system.
114*61c4878aSAndroid Build Coastguard Worker    "public/pw_unit_test/framework.h",
115*61c4878aSAndroid Build Coastguard Worker    "public_overrides/gtest/gtest.h",
116*61c4878aSAndroid Build Coastguard Worker  ]
117*61c4878aSAndroid Build Coastguard Worker  sources = [ "framework_light.cc" ]
118*61c4878aSAndroid Build Coastguard Worker}
119*61c4878aSAndroid Build Coastguard Worker
120*61c4878aSAndroid Build Coastguard Worker# Unit test framework backend that redirects to GoogleTest.
121*61c4878aSAndroid Build Coastguard Workerif (pw_unit_test_BACKEND != "") {
122*61c4878aSAndroid Build Coastguard Worker  pw_source_set("googletest") {
123*61c4878aSAndroid Build Coastguard Worker    public_configs = [ ":googletest_public_overrides_include_path" ]
124*61c4878aSAndroid Build Coastguard Worker    public = [ "googletest_public_overrides/pw_unit_test/framework_backend.h" ]
125*61c4878aSAndroid Build Coastguard Worker
126*61c4878aSAndroid Build Coastguard Worker    public_deps = [
127*61c4878aSAndroid Build Coastguard Worker      dir_pw_result,
128*61c4878aSAndroid Build Coastguard Worker      dir_pw_status,
129*61c4878aSAndroid Build Coastguard Worker      pw_unit_test_GOOGLETEST_BACKEND,
130*61c4878aSAndroid Build Coastguard Worker    ]
131*61c4878aSAndroid Build Coastguard Worker  }
132*61c4878aSAndroid Build Coastguard Worker}
133*61c4878aSAndroid Build Coastguard Worker
134*61c4878aSAndroid Build Coastguard Workerpw_source_set("event_handler") {
135*61c4878aSAndroid Build Coastguard Worker  public_configs = [ ":public_include_path" ]
136*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/event_handler.h" ]
137*61c4878aSAndroid Build Coastguard Worker}
138*61c4878aSAndroid Build Coastguard Worker
139*61c4878aSAndroid Build Coastguard Workerpw_source_set("status_macros") {
140*61c4878aSAndroid Build Coastguard Worker  public_configs = [ ":public_include_path" ]
141*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/status_macros.h" ]
142*61c4878aSAndroid Build Coastguard Worker}
143*61c4878aSAndroid Build Coastguard Worker
144*61c4878aSAndroid Build Coastguard Worker# Unit test event handler that provides GoogleTest-style output.
145*61c4878aSAndroid Build Coastguard Workerpw_source_set("googletest_style_event_handler") {
146*61c4878aSAndroid Build Coastguard Worker  public_deps = [
147*61c4878aSAndroid Build Coastguard Worker    ":event_handler",
148*61c4878aSAndroid Build Coastguard Worker    dir_pw_preprocessor,
149*61c4878aSAndroid Build Coastguard Worker  ]
150*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/googletest_style_event_handler.h" ]
151*61c4878aSAndroid Build Coastguard Worker  sources = [ "googletest_style_event_handler.cc" ]
152*61c4878aSAndroid Build Coastguard Worker}
153*61c4878aSAndroid Build Coastguard Worker
154*61c4878aSAndroid Build Coastguard Workerpw_source_set("googletest_handler_adapter") {
155*61c4878aSAndroid Build Coastguard Worker  public_configs = [ ":public_include_path" ]
156*61c4878aSAndroid Build Coastguard Worker  public_deps = [
157*61c4878aSAndroid Build Coastguard Worker    ":event_handler",
158*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_third_party/googletest",
159*61c4878aSAndroid Build Coastguard Worker    dir_pw_preprocessor,
160*61c4878aSAndroid Build Coastguard Worker  ]
161*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/googletest_handler_adapter.h" ]
162*61c4878aSAndroid Build Coastguard Worker  sources = [ "googletest_handler_adapter.cc" ]
163*61c4878aSAndroid Build Coastguard Worker}
164*61c4878aSAndroid Build Coastguard Worker
165*61c4878aSAndroid Build Coastguard Workerpw_source_set("googletest_test_matchers") {
166*61c4878aSAndroid Build Coastguard Worker  public_configs = [ ":public_include_path" ]
167*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/googletest_test_matchers.h" ]
168*61c4878aSAndroid Build Coastguard Worker  public_deps = [
169*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_third_party/googletest",
170*61c4878aSAndroid Build Coastguard Worker    dir_pw_result,
171*61c4878aSAndroid Build Coastguard Worker    dir_pw_status,
172*61c4878aSAndroid Build Coastguard Worker  ]
173*61c4878aSAndroid Build Coastguard Worker}
174*61c4878aSAndroid Build Coastguard Worker
175*61c4878aSAndroid Build Coastguard Workerpw_test("googletest_test_matchers_test") {
176*61c4878aSAndroid Build Coastguard Worker  enable_if = pw_unit_test_BACKEND != "" &&
177*61c4878aSAndroid Build Coastguard Worker              pw_unit_test_BACKEND != "$dir_pw_unit_test:light"
178*61c4878aSAndroid Build Coastguard Worker  sources = [ "googletest_test_matchers_test.cc" ]
179*61c4878aSAndroid Build Coastguard Worker  deps = [ ":googletest_test_matchers" ]
180*61c4878aSAndroid Build Coastguard Worker}
181*61c4878aSAndroid Build Coastguard Worker
182*61c4878aSAndroid Build Coastguard Worker# Library providing an event handler which outputs human-readable text.
183*61c4878aSAndroid Build Coastguard Workerpw_source_set("simple_printing_event_handler") {
184*61c4878aSAndroid Build Coastguard Worker  public_deps = [
185*61c4878aSAndroid Build Coastguard Worker    ":googletest_style_event_handler",
186*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_preprocessor",
187*61c4878aSAndroid Build Coastguard Worker  ]
188*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/simple_printing_event_handler.h" ]
189*61c4878aSAndroid Build Coastguard Worker  sources = [ "simple_printing_event_handler.cc" ]
190*61c4878aSAndroid Build Coastguard Worker}
191*61c4878aSAndroid Build Coastguard Worker
192*61c4878aSAndroid Build Coastguard Worker# Library providing a standard desktop main function for the pw_unit_test
193*61c4878aSAndroid Build Coastguard Worker# framework. Unit test files can link against this library to build runnable
194*61c4878aSAndroid Build Coastguard Worker# unit test executables.
195*61c4878aSAndroid Build Coastguard Workerpw_source_set("simple_printing_main") {
196*61c4878aSAndroid Build Coastguard Worker  testonly = pw_unit_test_TESTONLY
197*61c4878aSAndroid Build Coastguard Worker  deps = [
198*61c4878aSAndroid Build Coastguard Worker    ":pw_unit_test",
199*61c4878aSAndroid Build Coastguard Worker    ":simple_printing_event_handler",
200*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_sys_io",
201*61c4878aSAndroid Build Coastguard Worker    dir_pw_span,
202*61c4878aSAndroid Build Coastguard Worker  ]
203*61c4878aSAndroid Build Coastguard Worker  sources = [ "simple_printing_main.cc" ]
204*61c4878aSAndroid Build Coastguard Worker}
205*61c4878aSAndroid Build Coastguard Worker
206*61c4878aSAndroid Build Coastguard Workerpw_source_set("printf_event_handler") {
207*61c4878aSAndroid Build Coastguard Worker  public_deps = [
208*61c4878aSAndroid Build Coastguard Worker    ":googletest_style_event_handler",
209*61c4878aSAndroid Build Coastguard Worker    dir_pw_preprocessor,
210*61c4878aSAndroid Build Coastguard Worker  ]
211*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/printf_event_handler.h" ]
212*61c4878aSAndroid Build Coastguard Worker}
213*61c4878aSAndroid Build Coastguard Worker
214*61c4878aSAndroid Build Coastguard Workerpw_source_set("printf_main") {
215*61c4878aSAndroid Build Coastguard Worker  testonly = pw_unit_test_TESTONLY
216*61c4878aSAndroid Build Coastguard Worker  deps = [
217*61c4878aSAndroid Build Coastguard Worker    ":printf_event_handler",
218*61c4878aSAndroid Build Coastguard Worker    ":pw_unit_test",
219*61c4878aSAndroid Build Coastguard Worker  ]
220*61c4878aSAndroid Build Coastguard Worker  sources = [ "printf_main.cc" ]
221*61c4878aSAndroid Build Coastguard Worker}
222*61c4878aSAndroid Build Coastguard Worker
223*61c4878aSAndroid Build Coastguard Worker# Library providing an event handler which logs using pw_log.
224*61c4878aSAndroid Build Coastguard Workerpw_source_set("logging_event_handler") {
225*61c4878aSAndroid Build Coastguard Worker  public_deps = [
226*61c4878aSAndroid Build Coastguard Worker    ":googletest_style_event_handler",
227*61c4878aSAndroid Build Coastguard Worker    dir_pw_log,
228*61c4878aSAndroid Build Coastguard Worker  ]
229*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/logging_event_handler.h" ]
230*61c4878aSAndroid Build Coastguard Worker  sources = [ "logging_event_handler.cc" ]
231*61c4878aSAndroid Build Coastguard Worker}
232*61c4878aSAndroid Build Coastguard Worker
233*61c4878aSAndroid Build Coastguard Worker# Provides logging to either the light framework or an external GoogleTest.
234*61c4878aSAndroid Build Coastguard Workergroup("logging") {
235*61c4878aSAndroid Build Coastguard Worker  public_deps = [ ":logging_event_handler" ]
236*61c4878aSAndroid Build Coastguard Worker  deps = []
237*61c4878aSAndroid Build Coastguard Worker  if (pw_unit_test_BACKEND != "$dir_pw_unit_test:light") {
238*61c4878aSAndroid Build Coastguard Worker    deps += [ ":googletest_handler_adapter" ]
239*61c4878aSAndroid Build Coastguard Worker  }
240*61c4878aSAndroid Build Coastguard Worker}
241*61c4878aSAndroid Build Coastguard Worker
242*61c4878aSAndroid Build Coastguard Workerpw_source_set("logging_main") {
243*61c4878aSAndroid Build Coastguard Worker  testonly = pw_unit_test_TESTONLY
244*61c4878aSAndroid Build Coastguard Worker  deps = [
245*61c4878aSAndroid Build Coastguard Worker    ":logging",
246*61c4878aSAndroid Build Coastguard Worker    ":pw_unit_test",
247*61c4878aSAndroid Build Coastguard Worker  ]
248*61c4878aSAndroid Build Coastguard Worker  sources = [ "logging_main.cc" ]
249*61c4878aSAndroid Build Coastguard Worker}
250*61c4878aSAndroid Build Coastguard Worker
251*61c4878aSAndroid Build Coastguard Worker# Library providing an event handler adapter that allows for multiple
252*61c4878aSAndroid Build Coastguard Worker# event handlers to be registered for a given test run
253*61c4878aSAndroid Build Coastguard Workerpw_source_set("multi_event_handler") {
254*61c4878aSAndroid Build Coastguard Worker  public_deps = [ ":event_handler" ]
255*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/multi_event_handler.h" ]
256*61c4878aSAndroid Build Coastguard Worker}
257*61c4878aSAndroid Build Coastguard Worker
258*61c4878aSAndroid Build Coastguard Workerpw_test("multi_event_handler_test") {
259*61c4878aSAndroid Build Coastguard Worker  sources = [ "multi_event_handler_test.cc" ]
260*61c4878aSAndroid Build Coastguard Worker  deps = [
261*61c4878aSAndroid Build Coastguard Worker    ":multi_event_handler",
262*61c4878aSAndroid Build Coastguard Worker    ":pw_unit_test",
263*61c4878aSAndroid Build Coastguard Worker  ]
264*61c4878aSAndroid Build Coastguard Worker}
265*61c4878aSAndroid Build Coastguard Worker
266*61c4878aSAndroid Build Coastguard Worker# Library providing an event handler which outputs a test summary artifact.
267*61c4878aSAndroid Build Coastguard Workerpw_source_set("test_record_event_handler") {
268*61c4878aSAndroid Build Coastguard Worker  public_deps = [
269*61c4878aSAndroid Build Coastguard Worker    ":googletest_style_event_handler",
270*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_json:builder",
271*61c4878aSAndroid Build Coastguard Worker  ]
272*61c4878aSAndroid Build Coastguard Worker  deps = [ "$dir_pw_assert" ]
273*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/test_record_event_handler.h" ]
274*61c4878aSAndroid Build Coastguard Worker  sources = [ "public/pw_unit_test/internal/test_record_trie.h" ]
275*61c4878aSAndroid Build Coastguard Worker}
276*61c4878aSAndroid Build Coastguard Worker
277*61c4878aSAndroid Build Coastguard Workerpw_test("test_record_event_handler_test") {
278*61c4878aSAndroid Build Coastguard Worker  sources = [ "test_record_event_handler_test.cc" ]
279*61c4878aSAndroid Build Coastguard Worker  deps = [
280*61c4878aSAndroid Build Coastguard Worker    ":pw_unit_test",
281*61c4878aSAndroid Build Coastguard Worker    ":test_record_event_handler",
282*61c4878aSAndroid Build Coastguard Worker  ]
283*61c4878aSAndroid Build Coastguard Worker}
284*61c4878aSAndroid Build Coastguard Worker
285*61c4878aSAndroid Build Coastguard Workerconfig("rpc_service_backend_light") {
286*61c4878aSAndroid Build Coastguard Worker  include_dirs = [ "rpc_light_public" ]
287*61c4878aSAndroid Build Coastguard Worker}
288*61c4878aSAndroid Build Coastguard Worker
289*61c4878aSAndroid Build Coastguard Workerconfig("rpc_service_backend_gtest") {
290*61c4878aSAndroid Build Coastguard Worker  include_dirs = [ "rpc_gtest_public" ]
291*61c4878aSAndroid Build Coastguard Worker}
292*61c4878aSAndroid Build Coastguard Worker
293*61c4878aSAndroid Build Coastguard Workerpw_source_set("rpc_service") {
294*61c4878aSAndroid Build Coastguard Worker  testonly = pw_unit_test_TESTONLY
295*61c4878aSAndroid Build Coastguard Worker  public_configs = [ ":public_include_path" ]
296*61c4878aSAndroid Build Coastguard Worker  public_deps = [
297*61c4878aSAndroid Build Coastguard Worker    ":config",
298*61c4878aSAndroid Build Coastguard Worker    ":event_handler",
299*61c4878aSAndroid Build Coastguard Worker    ":pw_unit_test",
300*61c4878aSAndroid Build Coastguard Worker    ":unit_test_proto.pwpb",
301*61c4878aSAndroid Build Coastguard Worker    ":unit_test_proto.raw_rpc",
302*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_containers:vector",
303*61c4878aSAndroid Build Coastguard Worker  ]
304*61c4878aSAndroid Build Coastguard Worker  deps = [ dir_pw_log ]
305*61c4878aSAndroid Build Coastguard Worker  public = [ "public/pw_unit_test/unit_test_service.h" ]
306*61c4878aSAndroid Build Coastguard Worker  sources = [ "unit_test_service.cc" ]
307*61c4878aSAndroid Build Coastguard Worker  defines = []
308*61c4878aSAndroid Build Coastguard Worker
309*61c4878aSAndroid Build Coastguard Worker  if (pw_unit_test_BACKEND == "$dir_pw_unit_test:light") {
310*61c4878aSAndroid Build Coastguard Worker    public_configs += [ ":rpc_service_backend_light" ]
311*61c4878aSAndroid Build Coastguard Worker    sources += [ "rpc_light_event_handler.cc" ]
312*61c4878aSAndroid Build Coastguard Worker    public += [ "rpc_light_public/pw_unit_test/internal/rpc_event_handler.h" ]
313*61c4878aSAndroid Build Coastguard Worker  } else {
314*61c4878aSAndroid Build Coastguard Worker    public_configs += [ ":rpc_service_backend_gtest" ]
315*61c4878aSAndroid Build Coastguard Worker    sources += [ "rpc_gtest_event_handler.cc" ]
316*61c4878aSAndroid Build Coastguard Worker    public += [ "rpc_gtest_public/pw_unit_test/internal/rpc_event_handler.h" ]
317*61c4878aSAndroid Build Coastguard Worker  }
318*61c4878aSAndroid Build Coastguard Worker}
319*61c4878aSAndroid Build Coastguard Worker
320*61c4878aSAndroid Build Coastguard Workerpw_source_set("rpc_main") {
321*61c4878aSAndroid Build Coastguard Worker  testonly = pw_unit_test_TESTONLY
322*61c4878aSAndroid Build Coastguard Worker  public_deps = [ ":pw_unit_test" ]
323*61c4878aSAndroid Build Coastguard Worker  deps = [
324*61c4878aSAndroid Build Coastguard Worker    ":rpc_service",
325*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_rpc/system_server",
326*61c4878aSAndroid Build Coastguard Worker    dir_pw_log,
327*61c4878aSAndroid Build Coastguard Worker  ]
328*61c4878aSAndroid Build Coastguard Worker  sources = [ "rpc_main.cc" ]
329*61c4878aSAndroid Build Coastguard Worker}
330*61c4878aSAndroid Build Coastguard Worker
331*61c4878aSAndroid Build Coastguard Workerif (pw_unit_test_BACKEND == "$dir_pw_unit_test:light") {
332*61c4878aSAndroid Build Coastguard Worker  pw_source_set("static_library_support") {
333*61c4878aSAndroid Build Coastguard Worker    public_configs = [ ":public_include_path" ]
334*61c4878aSAndroid Build Coastguard Worker    public_deps = [ pw_unit_test_BACKEND ]
335*61c4878aSAndroid Build Coastguard Worker    public = [ "public/pw_unit_test/static_library_support.h" ]
336*61c4878aSAndroid Build Coastguard Worker    sources = [ "static_library_support.cc" ]
337*61c4878aSAndroid Build Coastguard Worker  }
338*61c4878aSAndroid Build Coastguard Worker} else {
339*61c4878aSAndroid Build Coastguard Worker  group("static_library_support") {
340*61c4878aSAndroid Build Coastguard Worker  }
341*61c4878aSAndroid Build Coastguard Worker}
342*61c4878aSAndroid Build Coastguard Worker
343*61c4878aSAndroid Build Coastguard Workerpw_executable("test_rpc_server") {
344*61c4878aSAndroid Build Coastguard Worker  testonly = pw_unit_test_TESTONLY
345*61c4878aSAndroid Build Coastguard Worker  sources = [ "test_rpc_server.cc" ]
346*61c4878aSAndroid Build Coastguard Worker  deps = [
347*61c4878aSAndroid Build Coastguard Worker    ":pw_unit_test",
348*61c4878aSAndroid Build Coastguard Worker    ":rpc_service",
349*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_rpc/system_server",
350*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_rpc/system_server:socket",
351*61c4878aSAndroid Build Coastguard Worker    dir_pw_log,
352*61c4878aSAndroid Build Coastguard Worker  ]
353*61c4878aSAndroid Build Coastguard Worker}
354*61c4878aSAndroid Build Coastguard Worker
355*61c4878aSAndroid Build Coastguard Workerpw_proto_library("unit_test_proto") {
356*61c4878aSAndroid Build Coastguard Worker  sources = [ "pw_unit_test_proto/unit_test.proto" ]
357*61c4878aSAndroid Build Coastguard Worker}
358*61c4878aSAndroid Build Coastguard Worker
359*61c4878aSAndroid Build Coastguard Workerpw_doc_group("docs") {
360*61c4878aSAndroid Build Coastguard Worker  sources = [ "docs.rst" ]
361*61c4878aSAndroid Build Coastguard Worker  other_deps = [ "py" ]
362*61c4878aSAndroid Build Coastguard Worker}
363*61c4878aSAndroid Build Coastguard Worker
364*61c4878aSAndroid Build Coastguard Workerpw_test("metadata_only_test") {
365*61c4878aSAndroid Build Coastguard Worker  extra_metadata = {
366*61c4878aSAndroid Build Coastguard Worker    extra_key = "extra_value"
367*61c4878aSAndroid Build Coastguard Worker  }
368*61c4878aSAndroid Build Coastguard Worker}
369*61c4878aSAndroid Build Coastguard Worker
370*61c4878aSAndroid Build Coastguard Worker# pw_test_group produces the metadata file for its tests.
371*61c4878aSAndroid Build Coastguard Workerpw_test_group("metadata_only_group") {
372*61c4878aSAndroid Build Coastguard Worker  tests = [ ":metadata_only_test" ]
373*61c4878aSAndroid Build Coastguard Worker  output_metadata = true
374*61c4878aSAndroid Build Coastguard Worker}
375*61c4878aSAndroid Build Coastguard Worker
376*61c4878aSAndroid Build Coastguard Workerpw_python_action_test("test_group_metadata_test") {
377*61c4878aSAndroid Build Coastguard Worker  _metadata_path =
378*61c4878aSAndroid Build Coastguard Worker      rebase_path(get_label_info(":metadata_only_group", "target_out_dir")) +
379*61c4878aSAndroid Build Coastguard Worker      "/metadata_only_group.testinfo.json"
380*61c4878aSAndroid Build Coastguard Worker  testonly = pw_unit_test_TESTONLY
381*61c4878aSAndroid Build Coastguard Worker  sources = [ "py/test_group_metadata_test.py" ]
382*61c4878aSAndroid Build Coastguard Worker  args = [
383*61c4878aSAndroid Build Coastguard Worker    "--metadata-path",
384*61c4878aSAndroid Build Coastguard Worker    "$_metadata_path",
385*61c4878aSAndroid Build Coastguard Worker  ]
386*61c4878aSAndroid Build Coastguard Worker  deps = [ ":metadata_only_group" ]
387*61c4878aSAndroid Build Coastguard Worker}
388*61c4878aSAndroid Build Coastguard Worker
389*61c4878aSAndroid Build Coastguard Workerpw_test("framework_test") {
390*61c4878aSAndroid Build Coastguard Worker  sources = [ "framework_test.cc" ]
391*61c4878aSAndroid Build Coastguard Worker  deps = [
392*61c4878aSAndroid Build Coastguard Worker    dir_pw_assert,
393*61c4878aSAndroid Build Coastguard Worker    dir_pw_result,
394*61c4878aSAndroid Build Coastguard Worker    dir_pw_status,
395*61c4878aSAndroid Build Coastguard Worker  ]
396*61c4878aSAndroid Build Coastguard Worker
397*61c4878aSAndroid Build Coastguard Worker  # TODO: https://pwbug.dev/325509758 - Passes but hangs on cleanup.
398*61c4878aSAndroid Build Coastguard Worker  if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") {
399*61c4878aSAndroid Build Coastguard Worker    enable_if = false
400*61c4878aSAndroid Build Coastguard Worker  }
401*61c4878aSAndroid Build Coastguard Worker}
402*61c4878aSAndroid Build Coastguard Worker
403*61c4878aSAndroid Build Coastguard Workerpw_test("framework_light_test") {
404*61c4878aSAndroid Build Coastguard Worker  enable_if = pw_unit_test_BACKEND == "$dir_pw_unit_test:light"
405*61c4878aSAndroid Build Coastguard Worker  sources = [ "framework_light_test.cc" ]
406*61c4878aSAndroid Build Coastguard Worker  deps = [
407*61c4878aSAndroid Build Coastguard Worker    "$dir_pw_string:builder",
408*61c4878aSAndroid Build Coastguard Worker    dir_pw_status,
409*61c4878aSAndroid Build Coastguard Worker  ]
410*61c4878aSAndroid Build Coastguard Worker}
411*61c4878aSAndroid Build Coastguard Worker
412*61c4878aSAndroid Build Coastguard Workerpw_static_library("tests_in_archive") {
413*61c4878aSAndroid Build Coastguard Worker  testonly = pw_unit_test_TESTONLY
414*61c4878aSAndroid Build Coastguard Worker  sources = [
415*61c4878aSAndroid Build Coastguard Worker    "static_library_archived_tests.cc",
416*61c4878aSAndroid Build Coastguard Worker    "static_library_missing_archived_tests.cc",
417*61c4878aSAndroid Build Coastguard Worker  ]
418*61c4878aSAndroid Build Coastguard Worker  deps = [ ":pw_unit_test" ]
419*61c4878aSAndroid Build Coastguard Worker  visibility = [ ":*" ]
420*61c4878aSAndroid Build Coastguard Worker}
421*61c4878aSAndroid Build Coastguard Worker
422*61c4878aSAndroid Build Coastguard Workerpw_test("static_library_support_test") {
423*61c4878aSAndroid Build Coastguard Worker  enable_if = pw_unit_test_BACKEND == "$dir_pw_unit_test:light"
424*61c4878aSAndroid Build Coastguard Worker  sources = [ "static_library_support_test.cc" ]
425*61c4878aSAndroid Build Coastguard Worker  deps = [
426*61c4878aSAndroid Build Coastguard Worker    ":static_library_support",
427*61c4878aSAndroid Build Coastguard Worker    ":tests_in_archive",
428*61c4878aSAndroid Build Coastguard Worker    dir_pw_assert,
429*61c4878aSAndroid Build Coastguard Worker  ]
430*61c4878aSAndroid Build Coastguard Worker}
431*61c4878aSAndroid Build Coastguard Worker
432*61c4878aSAndroid Build Coastguard Workerpw_test_group("tests") {
433*61c4878aSAndroid Build Coastguard Worker  tests = [
434*61c4878aSAndroid Build Coastguard Worker    ":framework_test",
435*61c4878aSAndroid Build Coastguard Worker    ":framework_light_test",
436*61c4878aSAndroid Build Coastguard Worker    ":static_library_support_test",
437*61c4878aSAndroid Build Coastguard Worker    ":multi_event_handler_test",
438*61c4878aSAndroid Build Coastguard Worker    ":test_record_event_handler_test",
439*61c4878aSAndroid Build Coastguard Worker  ]
440*61c4878aSAndroid Build Coastguard Worker  if (dir_pw_third_party_googletest != "") {
441*61c4878aSAndroid Build Coastguard Worker    tests += [ ":googletest_test_matchers_test" ]
442*61c4878aSAndroid Build Coastguard Worker  }
443*61c4878aSAndroid Build Coastguard Worker}
444