• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 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
15load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
16load("@rules_cc//cc:cc_library.bzl", "cc_library")
17load("@rules_python//python:proto.bzl", "py_proto_library")
18load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
19load("//pw_build:compatibility.bzl", "incompatible_with_mcu")
20load("//pw_build:pw_cc_binary.bzl", "pw_cc_binary")
21load("//pw_build:pw_facade.bzl", "pw_facade")
22load(
23    "//pw_protobuf_compiler:pw_proto_library.bzl",
24    "pwpb_proto_library",
25    "raw_rpc_proto_library",
26)
27load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
28
29package(
30    default_visibility = ["//visibility:public"],
31    features = ["-layering_check"],
32)
33
34licenses(["notice"])
35
36label_flag(
37    name = "main",
38    build_setting_default = ":simple_printing_main",
39)
40
41cc_library(
42    name = "config",
43    hdrs = ["public/pw_unit_test/config.h"],
44    strip_include_prefix = "public",
45    deps = [
46        ":config_override",
47        "//pw_polyfill",
48    ],
49)
50
51label_flag(
52    name = "config_override",
53    build_setting_default = "//pw_build:default_module_config",
54)
55
56pw_facade(
57    name = "pw_unit_test",
58    testonly = True,
59    hdrs = ["public/pw_unit_test/framework.h"],
60    backend = ":backend",
61    strip_include_prefix = "public",
62    deps = [":status_macros"],
63)
64
65# TODO: https://pwbug.dev/390709187 - Remove this alias once no pw_cc_test has
66# an explicit direct dependency on //pw_unit_test.
67alias(
68    name = "pw_unit_test_alias_for_migration_only",
69    actual = "pw_unit_test",
70)
71
72label_flag(
73    name = "backend",
74    build_setting_default = ":light",
75)
76
77config_setting(
78    name = "backend_is_googletest",
79    testonly = True,
80    flag_values = {
81        ":backend": ":googletest",
82    },
83)
84
85cc_library(
86    name = "light",
87    testonly = True,
88    srcs = ["framework_light.cc"],
89    hdrs = [
90        "light_public_overrides/pw_unit_test/framework_backend.h",
91        "public_overrides/gtest/gtest.h",
92    ],
93    implementation_deps = ["//pw_assert:check"],
94    includes = [
95        "light_public_overrides",
96        "public_overrides",
97    ],
98    deps = [
99        ":config",
100        ":event_handler",
101        ":pw_unit_test.facade",
102        "//pw_bytes:alignment",
103        "//pw_polyfill",
104        "//pw_preprocessor",
105        "//pw_span",
106        "//pw_status",
107        "//pw_string:builder",
108    ],
109)
110
111cc_library(
112    name = "googletest",
113    testonly = True,
114    hdrs = [
115        "googletest_public_overrides/pw_unit_test/framework_backend.h",
116    ],
117    includes = ["googletest_public_overrides"],
118    # TODO: b/310957361 - gtest not supported on device
119    target_compatible_with = incompatible_with_mcu(),
120    deps = [
121        ":googletest_handler_adapter",
122        ":pw_unit_test.facade",
123        "//pw_result",
124        "//pw_status",
125        "@com_google_googletest//:gtest",
126    ],
127)
128
129# Identifies when the light framework is being used.
130config_setting(
131    name = "light_setting",
132    testonly = True,
133    flag_values = {
134        "//pw_unit_test:backend": "//pw_unit_test:light",
135    },
136    # Do not depend on this config_setting outside upstream Pigweed. Config
137    # settings based on label flags are unreliable. See
138    # https://github.com/bazelbuild/bazel/issues/21189.
139    visibility = ["//:__subpackages__"],
140)
141
142config_setting(
143    name = "gtest_setting",
144    testonly = True,
145    flag_values = {
146        "//pw_unit_test:backend": "//pw_unit_test:googletest",
147    },
148    # Do not depend on this config_setting outside upstream Pigweed. Config
149    # settings based on label flags are unreliable. See
150    # https://github.com/bazelbuild/bazel/issues/21189.
151    visibility = ["//:__subpackages__"],
152)
153
154cc_library(
155    name = "event_handler",
156    hdrs = ["public/pw_unit_test/event_handler.h"],
157    strip_include_prefix = "public",
158)
159
160cc_library(
161    name = "status_macros",
162    testonly = True,
163    hdrs = ["public/pw_unit_test/status_macros.h"],
164    strip_include_prefix = "public",
165    deps = [
166        "//pw_status",
167        "//third_party/fuchsia:stdcompat",
168    ],
169)
170
171cc_library(
172    name = "googletest_style_event_handler",
173    srcs = ["googletest_style_event_handler.cc"],
174    hdrs = ["public/pw_unit_test/googletest_style_event_handler.h"],
175    strip_include_prefix = "public",
176    deps = [
177        ":event_handler",
178        "//pw_preprocessor",
179    ],
180)
181
182cc_library(
183    name = "googletest_handler_adapter",
184    testonly = True,
185    srcs = ["googletest_handler_adapter.cc"],
186    hdrs = ["public/pw_unit_test/googletest_handler_adapter.h"],
187    strip_include_prefix = "public",
188    # TODO: b/310957361 - gtest not supported on device
189    target_compatible_with = incompatible_with_mcu(),
190    deps = [
191        ":event_handler",
192        "//pw_preprocessor",
193        "@com_google_googletest//:gtest",
194    ],
195)
196
197cc_library(
198    name = "googletest_test_matchers",
199    testonly = True,
200    hdrs = ["public/pw_unit_test/googletest_test_matchers.h"],
201    strip_include_prefix = "public",
202    # TODO: b/310957361 - gtest not supported on device
203    target_compatible_with = incompatible_with_mcu(),
204    deps = [
205        "//pw_result",
206        "//pw_status",
207        "@com_google_googletest//:gtest",
208    ],
209)
210
211pw_cc_test(
212    name = "googletest_test_matchers_test",
213    srcs = ["googletest_test_matchers_test.cc"],
214    deps = [
215        ":googletest_test_matchers",
216    ],
217)
218
219cc_library(
220    name = "simple_printing_event_handler",
221    testonly = True,
222    srcs = ["simple_printing_event_handler.cc"],
223    hdrs = [
224        "public/pw_unit_test/simple_printing_event_handler.h",
225    ],
226    strip_include_prefix = "public",
227    deps = [
228        ":event_handler",
229        ":googletest_style_event_handler",
230        "//pw_preprocessor",
231    ],
232)
233
234cc_library(
235    name = "simple_printing_main",
236    testonly = True,
237    srcs = [
238        "simple_printing_main.cc",
239    ],
240    deps = [
241        ":pw_unit_test",
242        ":simple_printing_event_handler",
243        "//pw_span",
244        "//pw_sys_io",
245    ],
246)
247
248cc_library(
249    name = "printf_event_handler",
250    testonly = True,
251    hdrs = ["public/pw_unit_test/printf_event_handler.h"],
252    strip_include_prefix = "public",
253    deps = [
254        ":googletest_style_event_handler",
255        "//pw_preprocessor",
256    ],
257)
258
259cc_library(
260    name = "printf_main",
261    testonly = True,
262    srcs = ["printf_main.cc"],
263    deps = [
264        ":printf_event_handler",
265        ":pw_unit_test",
266    ],
267)
268
269# TODO: b/324116813 - Remove this alias once no downstream project depends on
270# it.
271alias(
272    name = "logging_event_handler",
273    actual = "logging",
274)
275
276cc_library(
277    name = "logging",
278    testonly = True,
279    srcs = [
280        "logging_event_handler.cc",
281    ],
282    hdrs = [
283        "public/pw_unit_test/logging_event_handler.h",
284    ],
285    strip_include_prefix = "public",
286    deps = [
287        ":googletest_style_event_handler",
288        "//pw_log",
289    ],
290)
291
292pw_cc_binary(
293    name = "logging_main",
294    testonly = True,
295    srcs = [
296        "logging_main.cc",
297    ],
298    # TODO: b/353588407 - Won't build on RP2040 until //pw_libcxx is added to link_extra_lib.
299    target_compatible_with = select({
300        "//pw_build/constraints/chipset:rp2040": ["@platforms//:incompatible"],
301        "//conditions:default": [],
302    }),
303    deps = [
304        ":logging",
305        "//pw_unit_test",
306    ],
307)
308
309cc_library(
310    name = "constexpr",
311    hdrs = ["public/pw_unit_test/constexpr.h"],
312    includes = ["public"],
313    deps = [
314        "//pw_preprocessor",
315        "//third_party/fuchsia:stdcompat",
316    ],
317)
318
319pw_cc_test(
320    name = "constexpr_test",
321    srcs = ["constexpr_test.cc"],
322    deps = [
323        ":constexpr",
324        "//pw_compilation_testing:negative_compilation_testing",
325    ],
326)
327
328cc_library(
329    name = "multi_event_handler",
330    testonly = True,
331    hdrs = [
332        "public/pw_unit_test/multi_event_handler.h",
333    ],
334    strip_include_prefix = "public",
335    deps = [
336        ":event_handler",
337    ],
338)
339
340pw_cc_test(
341    name = "multi_event_handler_test",
342    srcs = ["multi_event_handler_test.cc"],
343    deps = [":multi_event_handler"],
344)
345
346cc_library(
347    name = "test_record_event_handler",
348    testonly = True,
349    hdrs = [
350        "public/pw_unit_test/internal/test_record_trie.h",
351        "public/pw_unit_test/test_record_event_handler.h",
352    ],
353    strip_include_prefix = "public",
354    deps = [
355        ":event_handler",
356        "//pw_assert:check",
357        "//pw_json:builder",
358    ],
359)
360
361pw_cc_test(
362    name = "test_record_event_handler_test",
363    srcs = ["test_record_event_handler_test.cc"],
364    deps = [
365        ":test_record_event_handler",
366        "//pw_assert:assert",
367    ],
368)
369
370proto_library(
371    name = "unit_test_proto",
372    srcs = ["pw_unit_test_proto/unit_test.proto"],
373    strip_import_prefix = "/pw_unit_test",
374)
375
376py_proto_library(
377    name = "unit_test_py_pb2",
378    deps = [":unit_test_proto"],
379)
380
381pwpb_proto_library(
382    name = "unit_test_pwpb",
383    deps = [":unit_test_proto"],
384)
385
386raw_rpc_proto_library(
387    name = "unit_test_raw_rpc",
388    deps = [":unit_test_proto"],
389)
390
391cc_library(
392    name = "rpc_service",
393    testonly = True,
394    srcs = ["unit_test_service.cc"] + select({
395        ":light_setting": ["rpc_light_event_handler.cc"],
396        "//conditions:default": [":rpc_gtest_event_handler.cc"],
397    }),
398    hdrs = [
399        "public/pw_unit_test/config.h",
400        "public/pw_unit_test/unit_test_service.h",
401    ] + select({
402        ":light_setting": [
403            "rpc_light_public/pw_unit_test/internal/rpc_event_handler.h",
404        ],
405        "//conditions:default": [
406            "rpc_gtest_public/pw_unit_test/internal/rpc_event_handler.h",
407        ],
408    }),
409    includes = ["public"] + select({
410        ":light_setting": ["rpc_light_public"],
411        "//conditions:default": ["rpc_gtest_public"],
412    }),
413    deps = [
414        ":config",
415        ":event_handler",
416        ":pw_unit_test",
417        ":unit_test_pwpb",
418        ":unit_test_raw_rpc",
419        "//pw_log",
420        "//pw_span",
421    ],
422)
423
424cc_library(
425    name = "rpc_main",
426    testonly = True,
427    srcs = [
428        "rpc_main.cc",
429    ],
430    implementation_deps = ["//pw_assert:check"],
431    deps = [
432        ":pw_unit_test",
433        ":rpc_service",
434        "//pw_hdlc:default_addresses",
435        "//pw_log",
436        "//pw_rpc",
437        "//pw_rpc/system_server",
438    ],
439)
440
441cc_library(
442    name = "static_library_support",
443    testonly = True,
444    srcs = ["static_library_support.cc"],
445    hdrs = ["public/pw_unit_test/static_library_support.h"],
446    strip_include_prefix = "public",
447    # This library only works with the light backend
448    target_compatible_with = select({
449        ":light_setting": [],
450        "//conditions:default": ["@platforms//:incompatible"],
451    }),
452    deps = [":pw_unit_test"],
453)
454
455cc_library(
456    name = "tests_in_archive",
457    testonly = True,
458    srcs = [
459        "static_library_archived_tests.cc",
460        "static_library_missing_archived_tests.cc",
461    ],
462    linkstatic = True,
463    visibility = ["//visibility:private"],
464    deps = [":pw_unit_test"],
465)
466
467pw_cc_test(
468    name = "static_library_support_test",
469    srcs = ["static_library_support_test.cc"],
470    deps = [
471        ":static_library_support",
472        ":tests_in_archive",
473        "//pw_assert:check",
474    ],
475)
476
477pw_cc_test(
478    name = "framework_test",
479    srcs = ["framework_test.cc"],
480    # TODO: https://pwbug.dev/325509758 - Passes but hangs on cleanup.
481    target_compatible_with = select({
482        "//pw_build/constraints/chipset:rp2040": ["@platforms//:incompatible"],
483        "//conditions:default": [],
484    }),
485    deps = [
486        "//pw_assert:check",
487        "//pw_result",
488        "//pw_status",
489    ],
490)
491
492pw_cc_test(
493    name = "framework_light_test",
494    srcs = ["framework_light_test.cc"],
495    target_compatible_with = select({
496        ":light_setting": [],
497        "//conditions:default": ["@platforms//:incompatible"],
498    }),
499    deps = [
500        "//pw_status",
501        "//pw_string",
502    ],
503)
504
505# TODO(hepler): Build this as a cc_binary and use it in integration tests.
506filegroup(
507    name = "test_rpc_server",
508    srcs = ["test_rpc_server.cc"],
509    # deps = [
510    #     ":pw_unit_test",
511    #     ":rpc_service",
512    #     "//pw_log",
513    #     "//pw_rpc/system_server",
514    # ],
515)
516
517filegroup(
518    name = "doxygen",
519    srcs = [
520        "light_public_overrides/pw_unit_test/framework_backend.h",
521        "public/pw_unit_test/config.h",
522        "public/pw_unit_test/constexpr.h",
523        "public/pw_unit_test/event_handler.h",
524        "public/pw_unit_test/googletest_handler_adapter.h",
525        "public/pw_unit_test/googletest_style_event_handler.h",
526        "public/pw_unit_test/logging_event_handler.h",
527        "public/pw_unit_test/multi_event_handler.h",
528        "public/pw_unit_test/printf_event_handler.h",
529        "public/pw_unit_test/simple_printing_event_handler.h",
530        "public/pw_unit_test/static_library_support.h",
531        "public/pw_unit_test/status_macros.h",
532        "public/pw_unit_test/test_record_event_handler.h",
533    ],
534)
535
536sphinx_docs_library(
537    name = "docs",
538    srcs = [
539        "constexpr_test.cc",
540        "docs.rst",
541    ],
542    prefix = "pw_unit_test/",
543    target_compatible_with = incompatible_with_mcu(),
544)
545