• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/module_config.gni")
18import("$dir_pw_build/target_types.gni")
19import("$dir_pw_docgen/docs.gni")
20import("$dir_pw_protobuf_compiler/proto.gni")
21import("$dir_pw_toolchain/traits.gni")
22import("$dir_pw_unit_test/test.gni")
23
24declare_args() {
25  # The build target that overrides the default configuration options for this
26  # module. This should point to a source set that provides defines through a
27  # public config (which may -include a file or add defines directly).
28  pw_unit_test_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
29}
30
31# This pool limits the maximum number of unit tests that may run in parallel.
32# Despite the fact that this is a single GN "target", each toolchain owns its
33# own version of this pool, meaning pw_unit_test_POOL_DEPTH may be set
34# differently across targets in a single build, and build steps in one toolchain
35# will not consume pool resources of steps from another toolchain.
36pool("unit_test_pool") {
37  depth = pw_unit_test_POOL_DEPTH
38}
39
40config("public_include_path") {
41  include_dirs = [ "public" ]
42}
43
44config("public_overrides_include_path") {
45  include_dirs = [ "public_overrides" ]
46}
47
48pw_source_set("config") {
49  public = [ "public/pw_unit_test/config.h" ]
50  public_configs = [ ":public_include_path" ]
51  public_deps = [
52    dir_pw_polyfill,
53    pw_unit_test_CONFIG,
54  ]
55  visibility = [ ":*" ]
56}
57
58# pw_unit_test facade. This provides a GoogleTest-compatible test framework.
59pw_source_set("pw_unit_test") {
60  public_deps = [ pw_unit_test_GOOGLETEST_BACKEND ]
61}
62
63# Lightweight unit test backend that implements a subset of GoogleTest.
64pw_source_set("light") {
65  public_configs = [
66    ":public_include_path",
67    ":public_overrides_include_path",
68  ]
69  public_deps = [
70    ":config",
71    ":event_handler",
72    dir_pw_polyfill,
73    dir_pw_preprocessor,
74    dir_pw_span,
75  ]
76
77  # If C++17 is supported, depend on StringBuilder.
78  if (pw_toolchain_CXX_STANDARD >= pw_toolchain_STANDARD.CXX17) {
79    public_deps += [ "$dir_pw_string:builder" ]
80  }
81
82  deps = [ dir_pw_assert ]
83
84  public = [ "public_overrides/gtest/gtest.h" ]
85  sources = [
86    "framework.cc",
87    "public/pw_unit_test/internal/framework.h",
88  ]
89}
90
91pw_source_set("event_handler") {
92  public_configs = [ ":public_include_path" ]
93  public = [ "public/pw_unit_test/event_handler.h" ]
94}
95
96# Unit test event handler that provides GoogleTest-style output.
97pw_source_set("googletest_style_event_handler") {
98  public_deps = [
99    ":event_handler",
100    dir_pw_preprocessor,
101  ]
102  public = [ "public/pw_unit_test/googletest_style_event_handler.h" ]
103  sources = [ "googletest_style_event_handler.cc" ]
104}
105
106pw_source_set("googletest_handler_adapter") {
107  public_configs = [ ":public_include_path" ]
108  public_deps = [
109    ":logging_event_handler",
110    "$dir_pw_third_party/googletest",
111    dir_pw_preprocessor,
112  ]
113  public = [ "public/pw_unit_test/googletest_handler_adapter.h" ]
114  sources = [ "googletest_handler_adapter.cc" ]
115}
116
117# Library providing an event handler which outputs human-readable text.
118pw_source_set("simple_printing_event_handler") {
119  public_deps = [
120    ":googletest_style_event_handler",
121    "$dir_pw_preprocessor",
122  ]
123  public = [ "public/pw_unit_test/simple_printing_event_handler.h" ]
124  sources = [ "simple_printing_event_handler.cc" ]
125}
126
127# Library providing a standard desktop main function for the pw_unit_test
128# framework. Unit test files can link against this library to build runnable
129# unit test executables.
130pw_source_set("simple_printing_main") {
131  deps = [
132    ":pw_unit_test",
133    ":simple_printing_event_handler",
134    "$dir_pw_sys_io",
135    dir_pw_span,
136  ]
137  sources = [ "simple_printing_main.cc" ]
138}
139
140pw_source_set("printf_event_handler") {
141  public_deps = [
142    ":googletest_style_event_handler",
143    dir_pw_preprocessor,
144  ]
145  public = [ "public/pw_unit_test/printf_event_handler.h" ]
146}
147
148pw_source_set("printf_main") {
149  deps = [
150    ":printf_event_handler",
151    ":pw_unit_test",
152  ]
153  sources = [ "printf_main.cc" ]
154}
155
156# Library providing an event handler which logs using pw_log.
157pw_source_set("logging_event_handler") {
158  public_deps = [
159    ":googletest_style_event_handler",
160    dir_pw_log,
161  ]
162  public = [ "public/pw_unit_test/logging_event_handler.h" ]
163  sources = [ "logging_event_handler.cc" ]
164}
165
166pw_source_set("logging_main") {
167  deps = [
168    ":logging_event_handler",
169    ":pw_unit_test",
170  ]
171  sources = [ "logging_main.cc" ]
172}
173
174config("rpc_service_backend_light") {
175  include_dirs = [ "rpc_light_public" ]
176}
177
178config("rpc_service_backend_gtest") {
179  include_dirs = [ "rpc_gtest_public" ]
180}
181
182pw_source_set("rpc_service") {
183  public_configs = [ ":public_include_path" ]
184  public_deps = [
185    ":event_handler",
186    ":pw_unit_test",
187    ":unit_test_proto.pwpb",
188    ":unit_test_proto.raw_rpc",
189    "$dir_pw_containers:vector",
190  ]
191  deps = [ dir_pw_log ]
192  public = [ "public/pw_unit_test/unit_test_service.h" ]
193  sources = [ "unit_test_service.cc" ]
194  defines = []
195
196  if (pw_unit_test_GOOGLETEST_BACKEND == "$dir_pw_unit_test:light") {
197    public_configs += [ ":rpc_service_backend_light" ]
198    sources += [ "rpc_light_event_handler.cc" ]
199    public += [ "rpc_light_public/pw_unit_test/internal/rpc_event_handler.h" ]
200  } else {
201    public_configs += [ ":rpc_service_backend_gtest" ]
202    sources += [ "rpc_gtest_event_handler.cc" ]
203    public += [ "rpc_gtest_public/pw_unit_test/internal/rpc_event_handler.h" ]
204  }
205}
206
207pw_source_set("rpc_main") {
208  public_deps = [ ":pw_unit_test" ]
209  deps = [
210    ":rpc_service",
211    "$dir_pw_rpc/system_server",
212    dir_pw_log,
213  ]
214  sources = [ "rpc_main.cc" ]
215}
216
217pw_source_set("static_library_support") {
218  public_configs = [ ":public_include_path" ]
219  public_deps = [ ":light" ]  # This library only works with the light backend
220  public = [ "public/pw_unit_test/static_library_support.h" ]
221  sources = [ "static_library_support.cc" ]
222}
223
224pw_executable("test_rpc_server") {
225  sources = [ "test_rpc_server.cc" ]
226  deps = [
227    ":pw_unit_test",
228    ":rpc_service",
229    "$dir_pw_rpc/system_server",
230    "$dir_pw_rpc/system_server:socket",
231    dir_pw_log,
232  ]
233}
234
235pw_proto_library("unit_test_proto") {
236  sources = [ "pw_unit_test_proto/unit_test.proto" ]
237}
238
239pw_doc_group("docs") {
240  sources = [ "docs.rst" ]
241}
242
243pw_test("metadata_only_test") {
244  extra_metadata = {
245    extra_key = "extra_value"
246  }
247}
248
249# pw_test_group produces the metadata file for its tests.
250pw_test_group("metadata_only_group") {
251  tests = [ ":metadata_only_test" ]
252}
253
254pw_python_script("test_group_metadata_test") {
255  sources = [ "py/test_group_metadata_test.py" ]
256  action = {
257    args = [
258      "--stamp-path",
259      "<TARGET_FILE(:metadata_only_group)>",
260    ]
261    deps = [ ":metadata_only_group" ]
262    stamp = true
263  }
264}
265
266pw_test("framework_test") {
267  sources = [ "framework_test.cc" ]
268  deps = [ dir_pw_assert ]
269}
270
271pw_static_library("tests_in_archive") {
272  sources = [
273    "static_library_archived_tests.cc",
274    "static_library_missing_archived_tests.cc",
275  ]
276  deps = [ ":pw_unit_test" ]
277  visibility = [ ":*" ]
278}
279
280pw_test("static_library_support_test") {
281  sources = [ "static_library_support_test.cc" ]
282  deps = [
283    ":static_library_support",
284    ":tests_in_archive",
285    dir_pw_assert,
286  ]
287}
288
289pw_test_group("tests") {
290  tests = [
291    ":framework_test",
292    ":static_library_support_test",
293  ]
294}
295