• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2024 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("@rules_cc//cc:cc_library.bzl", "cc_library")
16load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
17
18package(
19    default_visibility = ["//visibility:public"],
20    features = ["-layering_check"],
21)
22
23cc_library(
24    name = "testing",
25    testonly = True,
26    srcs = [
27        "inspect_util.cc",
28        "parse_args.cc",
29        "test_packets.cc",
30    ],
31    hdrs = [
32        "public/pw_bluetooth_sapphire/internal/host/testing/controller_test.h",
33        "public/pw_bluetooth_sapphire/internal/host/testing/inspect.h",
34        "public/pw_bluetooth_sapphire/internal/host/testing/inspect_util.h",
35        "public/pw_bluetooth_sapphire/internal/host/testing/parse_args.h",
36        "public/pw_bluetooth_sapphire/internal/host/testing/test_packets.h",
37    ],
38    copts = [
39        "-Wno-unused-parameter",
40    ],
41    implementation_deps = [
42        ":test_helpers",
43    ],
44    strip_include_prefix = "public",
45    tags = ["noclangtidy"],
46    deps = [
47        "//pw_async:fake_dispatcher_fixture",
48        "//pw_async:heap_dispatcher",
49        "//pw_bluetooth",
50        "//pw_bluetooth_sapphire:config",
51        "//pw_bluetooth_sapphire/fuchsia/lib/inspect_testing",
52        "//pw_bluetooth_sapphire/host/common",
53        "//pw_bluetooth_sapphire/host/gap:definitions",
54        "//pw_bluetooth_sapphire/host/hci-spec",
55        "//pw_bluetooth_sapphire/host/l2cap",
56        "//pw_bluetooth_sapphire/host/transport",
57    ],
58)
59
60cc_library(
61    name = "test_helpers",
62    testonly = True,
63    hdrs = [
64        "public/pw_bluetooth_sapphire/internal/host/testing/test_helpers.h",
65    ],
66    strip_include_prefix = "public",
67    deps = [
68        "//pw_bluetooth_sapphire/host/common",
69        "//pw_bluetooth_sapphire/lib/cpp-string",
70    ],
71)
72
73cc_library(
74    name = "gtest_helpers",
75    testonly = True,
76    hdrs = [
77        "public/pw_bluetooth_sapphire/internal/host/testing/gtest_helpers.h",
78    ],
79    strip_include_prefix = "public",
80    target_compatible_with = select({
81        "//pw_unit_test:backend_is_googletest": [],
82        "@platforms//os:fuchsia": [],
83        "//conditions:default": ["@platforms//:incompatible"],
84    }),
85    deps = [
86        "//pw_bluetooth_sapphire/host/common",
87        "//pw_unit_test:googletest",
88    ],
89)
90
91cc_library(
92    name = "controller_test_double_base",
93    testonly = True,
94    srcs = ["controller_test_double_base.cc"],
95    hdrs = [
96        "public/pw_bluetooth_sapphire/internal/host/testing/controller_test_double_base.h",
97    ],
98    copts = [
99        "-Wno-unused-parameter",
100    ],
101    strip_include_prefix = "public",
102    deps = [
103        "//pw_async:heap_dispatcher",
104        "//pw_bluetooth",
105        "//pw_bluetooth_sapphire/host/common",
106    ],
107)
108
109cc_library(
110    name = "mock_controller",
111    testonly = True,
112    srcs = ["mock_controller.cc"],
113    hdrs = [
114        "public/pw_bluetooth_sapphire/internal/host/testing/mock_controller.h",
115    ],
116    copts = [
117        "-Wno-unused-parameter",
118    ],
119    implementation_deps = [
120        ":gtest_helpers",
121        ":test_helpers",
122    ],
123    strip_include_prefix = "public",
124    deps = [
125        ":controller_test_double_base",
126        "//pw_bluetooth_sapphire/host/common",
127        "//pw_bluetooth_sapphire/host/hci-spec",
128        "//third_party/fuchsia:fit",
129    ],
130)
131
132# Target that includes Fake HCI emulation support. This should NOT depend on
133# gtest.
134cc_library(
135    name = "fake_controller",
136    testonly = True,
137    srcs = [
138        "fake_controller.cc",
139        "fake_dynamic_channel.cc",
140        "fake_gatt_server.cc",
141        "fake_l2cap.cc",
142        "fake_peer.cc",
143        "fake_sdp_server.cc",
144        "fake_signaling_server.cc",
145    ],
146    hdrs = [
147        "public/pw_bluetooth_sapphire/internal/host/testing/fake_controller.h",
148        "public/pw_bluetooth_sapphire/internal/host/testing/fake_dynamic_channel.h",
149        "public/pw_bluetooth_sapphire/internal/host/testing/fake_gatt_server.h",
150        "public/pw_bluetooth_sapphire/internal/host/testing/fake_l2cap.h",
151        "public/pw_bluetooth_sapphire/internal/host/testing/fake_peer.h",
152        "public/pw_bluetooth_sapphire/internal/host/testing/fake_sdp_server.h",
153        "public/pw_bluetooth_sapphire/internal/host/testing/fake_signaling_server.h",
154    ],
155    copts = [
156        "-Wno-unused-parameter",
157    ],
158    implementation_deps = [
159        "//pw_bluetooth:emboss_hci_android",
160        "//pw_bluetooth:emboss_hci_data",
161        "//pw_bluetooth:emboss_hci_events",
162        "//pw_bluetooth_sapphire/host/gap",
163        "//pw_bluetooth_sapphire/host/gatt:definitions",
164        "//pw_bytes",
165    ],
166    strip_include_prefix = "public",
167    deps = [
168        ":controller_test_double_base",
169        "//pw_bluetooth_sapphire/host/att:definitions",
170        "//pw_bluetooth_sapphire/host/common",
171        "//pw_bluetooth_sapphire/host/hci-spec",
172        "//pw_bluetooth_sapphire/host/l2cap:definitions",
173        "//pw_bluetooth_sapphire/host/l2cap:testing",
174        "//pw_bluetooth_sapphire/host/sdp",
175        "//third_party/fuchsia:fit",
176    ],
177)
178
179# Main entry point for host library unittests.
180cc_library(
181    name = "gtest_main",
182    testonly = True,
183    srcs = ["run_all_unittests.cc"],
184    implementation_deps = [
185        ":testing",
186        "//pw_bluetooth_sapphire/host/common",
187        "//pw_unit_test:googletest",
188    ],
189    target_compatible_with = select({
190        "//pw_unit_test:backend_is_googletest": [],
191        "@platforms//os:fuchsia": [],
192        "//conditions:default": ["@platforms//:incompatible"],
193    }),
194)
195
196cc_library(
197    name = "fuzzing",
198    testonly = True,
199    hdrs = [
200        "public/pw_bluetooth_sapphire/internal/host/testing/peer_fuzzer.h",
201    ],
202    strip_include_prefix = "public",
203    tags = ["noclangtidy"],
204    deps = ["//pw_bluetooth_sapphire/host/gap"],
205)
206
207cc_library(
208    name = "loop_fixture",
209    testonly = True,
210    hdrs = [
211        "public/pw_bluetooth_sapphire/internal/host/testing/loop_fixture.h",
212    ],
213    strip_include_prefix = "public",
214    target_compatible_with = select({
215        "//pw_unit_test:backend_is_googletest": [],
216        "@platforms//os:fuchsia": [],
217        "//conditions:default": ["@platforms//:incompatible"],
218    }),
219    deps = [
220        "//pw_unit_test:googletest",
221        "@fuchsia_sdk//pkg/async-testing",
222    ],
223)
224
225pw_cc_test(
226    name = "testing_test",
227    srcs = [
228        "fake_controller_test.cc",
229        "fake_dynamic_channel_test.cc",
230        "fake_l2cap_test.cc",
231        "fake_sdp_server_test.cc",
232        "fake_signaling_server_test.cc",
233        "inspect_util_test.cc",
234        "parse_args_test.cc",
235    ],
236    test_main = "//pw_bluetooth_sapphire/host/testing:gtest_main",
237    deps = [
238        ":fake_controller",
239        ":test_helpers",
240        ":testing",
241        "//pw_bluetooth_sapphire/host/l2cap:testing",
242    ],
243)
244