xref: /aosp_15_r20/external/pigweed/pw_bluetooth_sapphire/fuchsia.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_bluetooth_sapphire-fuchsia:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker===================
4*61c4878aSAndroid Build Coastguard WorkerFuchsia development
5*61c4878aSAndroid Build Coastguard Worker===================
6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module-subpage::
7*61c4878aSAndroid Build Coastguard Worker   :name: pw_bluetooth_sapphire
8*61c4878aSAndroid Build Coastguard Worker
9*61c4878aSAndroid Build Coastguard Worker``//pw_bluetooth_sapphire/fuchsia`` currently contains the Fuchsia build
10*61c4878aSAndroid Build Coastguard Workertargets for building, running, and testing the ``bt-host`` and
11*61c4878aSAndroid Build Coastguard Worker``bt-hci-virtual`` packages.
12*61c4878aSAndroid Build Coastguard Worker
13*61c4878aSAndroid Build Coastguard WorkerFuchsia's Sapphire Bluetooth stack integration uses the ``bt-host`` core
14*61c4878aSAndroid Build Coastguard Workerpackage which is built from Pigweed CI, uploaded to CIPD, and rolled
15*61c4878aSAndroid Build Coastguard Workerautomatically. The ``bt-host`` package is assembled into products in any
16*61c4878aSAndroid Build Coastguard WorkerFuchsia build which uses Bluetooth. The ``bt-hci-virtual`` package is included
17*61c4878aSAndroid Build Coastguard Workerin some builds for testing. See `bt-host README
18*61c4878aSAndroid Build Coastguard Worker<https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/src/connectivity/bluetooth/core/bt-host/README.md>`__
19*61c4878aSAndroid Build Coastguard Workerfor more details on product assembly.
20*61c4878aSAndroid Build Coastguard Worker
21*61c4878aSAndroid Build Coastguard Worker.. note::
22*61c4878aSAndroid Build Coastguard Worker   Every ``bazelisk`` invocation needs ``--config=fuchsia`` whenever the target
23*61c4878aSAndroid Build Coastguard Worker   is a fuchsia-specific target.
24*61c4878aSAndroid Build Coastguard Worker   These fuchsia-specific targets are disabled (marked incompatible with the
25*61c4878aSAndroid Build Coastguard Worker   target platform) by default to avoid polluting/conflicting with non-fuchsia
26*61c4878aSAndroid Build Coastguard Worker   pigweed builds.
27*61c4878aSAndroid Build Coastguard Worker   Specifying ``--config=fuchsia`` also allows ``@fuchsia_sdk`` backends to be
28*61c4878aSAndroid Build Coastguard Worker   specified for Pigweed dependencies.
29*61c4878aSAndroid Build Coastguard Worker
30*61c4878aSAndroid Build Coastguard Worker----------------------------------------
31*61c4878aSAndroid Build Coastguard WorkerAccessing ffx from a Pigweed environment
32*61c4878aSAndroid Build Coastguard Worker----------------------------------------
33*61c4878aSAndroid Build Coastguard WorkerThe ``ffx`` command is available as a subcommand of ``pw``:
34*61c4878aSAndroid Build Coastguard Worker
35*61c4878aSAndroid Build Coastguard Worker.. code-block:: console
36*61c4878aSAndroid Build Coastguard Worker
37*61c4878aSAndroid Build Coastguard Worker   pw ffx help
38*61c4878aSAndroid Build Coastguard Worker
39*61c4878aSAndroid Build Coastguard Worker-------
40*61c4878aSAndroid Build Coastguard WorkerTesting
41*61c4878aSAndroid Build Coastguard Worker-------
42*61c4878aSAndroid Build Coastguard Worker
43*61c4878aSAndroid Build Coastguard WorkerRunning tests
44*61c4878aSAndroid Build Coastguard Worker=============
45*61c4878aSAndroid Build Coastguard WorkerFirst, ensure the emulator is running or hardware running Fuchsia is
46*61c4878aSAndroid Build Coastguard Workerconnected. Then run a test package with:
47*61c4878aSAndroid Build Coastguard Worker
48*61c4878aSAndroid Build Coastguard Worker.. code-block:: console
49*61c4878aSAndroid Build Coastguard Worker
50*61c4878aSAndroid Build Coastguard Worker   bazelisk run --config=fuchsia //pw_bluetooth_sapphire/fuchsia/host/l2cap:test_pkg
51*61c4878aSAndroid Build Coastguard Worker
52*61c4878aSAndroid Build Coastguard WorkerFlags can also be passed to the test binary:
53*61c4878aSAndroid Build Coastguard Worker
54*61c4878aSAndroid Build Coastguard Worker.. code-block:: console
55*61c4878aSAndroid Build Coastguard Worker
56*61c4878aSAndroid Build Coastguard Worker   bazelisk run --config=fuchsia //pw_bluetooth_sapphire/fuchsia/host/l2cap:test_pkg \
57*61c4878aSAndroid Build Coastguard Worker     -- --gtest-filter="*Example" --severity=DEBUG
58*61c4878aSAndroid Build Coastguard Worker
59*61c4878aSAndroid Build Coastguard Worker.. note::
60*61c4878aSAndroid Build Coastguard Worker   If the test is unable to connect to the emulator, run ``pw ffx target
61*61c4878aSAndroid Build Coastguard Worker   remove --all`` first to clean your machine's target list.
62*61c4878aSAndroid Build Coastguard Worker
63*61c4878aSAndroid Build Coastguard WorkerYou can also run the presubmit step that will start an emulator and run
64*61c4878aSAndroid Build Coastguard Workerall tests, but this is slow:
65*61c4878aSAndroid Build Coastguard Worker
66*61c4878aSAndroid Build Coastguard Worker.. code-block:: console
67*61c4878aSAndroid Build Coastguard Worker
68*61c4878aSAndroid Build Coastguard Worker   pw presubmit --step bthost_package
69*61c4878aSAndroid Build Coastguard Worker
70*61c4878aSAndroid Build Coastguard WorkerEmulator
71*61c4878aSAndroid Build Coastguard Worker========
72*61c4878aSAndroid Build Coastguard WorkerTo start the emulator, use one of the following commands:
73*61c4878aSAndroid Build Coastguard Worker
74*61c4878aSAndroid Build Coastguard Worker.. code-block::
75*61c4878aSAndroid Build Coastguard Worker
76*61c4878aSAndroid Build Coastguard Worker   bazelisk run @fuchsia_products//:core.x64.emu -- --headless
77*61c4878aSAndroid Build Coastguard Worker   # OR
78*61c4878aSAndroid Build Coastguard Worker   bazelisk run @fuchsia_products//:minimal.arm64.emu -- --headless
79*61c4878aSAndroid Build Coastguard Worker
80*61c4878aSAndroid Build Coastguard WorkerTo stop the running emulator, use the following command:
81*61c4878aSAndroid Build Coastguard Worker
82*61c4878aSAndroid Build Coastguard Worker.. code-block::
83*61c4878aSAndroid Build Coastguard Worker
84*61c4878aSAndroid Build Coastguard Worker   pw ffx emu stop --all
85*61c4878aSAndroid Build Coastguard Worker
86*61c4878aSAndroid Build Coastguard Worker--------
87*61c4878aSAndroid Build Coastguard WorkerBuilding
88*61c4878aSAndroid Build Coastguard Worker--------
89*61c4878aSAndroid Build Coastguard Worker.. note::
90*61c4878aSAndroid Build Coastguard Worker   See the main :ref:`Building <module-pw_bluetooth_sapphire-building>` section
91*61c4878aSAndroid Build Coastguard Worker   for instructions on building for your host machine (producing Linux/macOS
92*61c4878aSAndroid Build Coastguard Worker   test binaries).
93*61c4878aSAndroid Build Coastguard Worker
94*61c4878aSAndroid Build Coastguard WorkerTo build the ``bt-host`` package, use one of the following commands:
95*61c4878aSAndroid Build Coastguard Worker
96*61c4878aSAndroid Build Coastguard Worker.. tab-set::
97*61c4878aSAndroid Build Coastguard Worker
98*61c4878aSAndroid Build Coastguard Worker   .. tab-item:: arm64
99*61c4878aSAndroid Build Coastguard Worker
100*61c4878aSAndroid Build Coastguard Worker      .. code-block::
101*61c4878aSAndroid Build Coastguard Worker
102*61c4878aSAndroid Build Coastguard Worker         bazelisk build --config=fuchsia //pw_bluetooth_sapphire/fuchsia/bt_host:pkg.arm64
103*61c4878aSAndroid Build Coastguard Worker
104*61c4878aSAndroid Build Coastguard Worker   .. tab-item:: x64
105*61c4878aSAndroid Build Coastguard Worker
106*61c4878aSAndroid Build Coastguard Worker      .. code-block::
107*61c4878aSAndroid Build Coastguard Worker
108*61c4878aSAndroid Build Coastguard Worker         bazelisk build --config=fuchsia //pw_bluetooth_sapphire/fuchsia/bt_host:pkg.x64
109*61c4878aSAndroid Build Coastguard Worker
110*61c4878aSAndroid Build Coastguard WorkerThe ``bt-host.far`` package will end up in a Bazel build directory that will be
111*61c4878aSAndroid Build Coastguard Workerprinted in the command output. For example:
112*61c4878aSAndroid Build Coastguard Worker``bazel-out/aarch64-fastbuild-e2b/bin/pw_bluetooth_sapphire/fuchsia/bt_host/bt-host.far``.
113*61c4878aSAndroid Build Coastguard WorkerNote that ``bazel-out`` is symlinked from the root Pigweed directory.
114*61c4878aSAndroid Build Coastguard Worker
115*61c4878aSAndroid Build Coastguard WorkerUse the prebuilt in fuchsia.git
116*61c4878aSAndroid Build Coastguard Worker===============================
117*61c4878aSAndroid Build Coastguard Workerfuchsia.git developers can copy/link the ``bt-host.far`` file to
118*61c4878aSAndroid Build Coastguard Worker``//prebuilt/connectivity/bluetooth/bt-host/<arch>/`` and rename it to
119*61c4878aSAndroid Build Coastguard Worker``bt-host`` to replace the prebuilt that Fuchsia uses.
120*61c4878aSAndroid Build Coastguard Worker
121*61c4878aSAndroid Build Coastguard Worker--------------------
122*61c4878aSAndroid Build Coastguard WorkerWorking with devices
123*61c4878aSAndroid Build Coastguard Worker--------------------
124*61c4878aSAndroid Build Coastguard Worker
125*61c4878aSAndroid Build Coastguard WorkerInspect
126*61c4878aSAndroid Build Coastguard Worker=======
127*61c4878aSAndroid Build Coastguard WorkerTo query the current state of the ``bt-host`` component Inspect hierarchy, run:
128*61c4878aSAndroid Build Coastguard Worker
129*61c4878aSAndroid Build Coastguard Worker#. ``pw ffx inspect list | grep bt-host`` to find the component's ``<moniker>``
130*61c4878aSAndroid Build Coastguard Worker
131*61c4878aSAndroid Build Coastguard Worker#. ``pw ffx inspect show "<moniker>"``
132*61c4878aSAndroid Build Coastguard Worker
133*61c4878aSAndroid Build Coastguard Worker   * Note that the full moniker from step 2 should be in quotations, e.g.
134*61c4878aSAndroid Build Coastguard Worker     ``pw ffx inspect show "core/bluetooth-core/bt-host-collection\:bt-host_000"``.
135*61c4878aSAndroid Build Coastguard Worker
136*61c4878aSAndroid Build Coastguard Worker   * Wildcards can be passed into the selector as needed, e.g.
137*61c4878aSAndroid Build Coastguard Worker     ``pw ffx inspect show "core/bluetooth-core/bt-host-collection*"``.
138*61c4878aSAndroid Build Coastguard Worker
139*61c4878aSAndroid Build Coastguard Worker--------------------
140*61c4878aSAndroid Build Coastguard WorkerEditor configuration
141*61c4878aSAndroid Build Coastguard Worker--------------------
142*61c4878aSAndroid Build Coastguard Worker
143*61c4878aSAndroid Build Coastguard WorkerClangd
144*61c4878aSAndroid Build Coastguard Worker======
145*61c4878aSAndroid Build Coastguard WorkerCurrently some manual steps are required to get clangd working with Fuchsia
146*61c4878aSAndroid Build Coastguard Workercode (for example, for FIDL server files).
147*61c4878aSAndroid Build Coastguard Worker
148*61c4878aSAndroid Build Coastguard Worker#. Execute the following command to generate ``compile_commands.json``. This
149*61c4878aSAndroid Build Coastguard Worker   needs to be done whenever the build graph changes.
150*61c4878aSAndroid Build Coastguard Worker
151*61c4878aSAndroid Build Coastguard Worker   .. code-block:: console
152*61c4878aSAndroid Build Coastguard Worker
153*61c4878aSAndroid Build Coastguard Worker      bazelisk run //:refresh_compile_commands_for_fuchsia_sdk
154*61c4878aSAndroid Build Coastguard Worker
155*61c4878aSAndroid Build Coastguard Worker#. Add this flag to your clangd configuration, fixing the full path to your
156*61c4878aSAndroid Build Coastguard Worker   Pigweed checkout:
157*61c4878aSAndroid Build Coastguard Worker
158*61c4878aSAndroid Build Coastguard Worker   .. code-block:: console
159*61c4878aSAndroid Build Coastguard Worker
160*61c4878aSAndroid Build Coastguard Worker      --compile-commands-dir=/path/to/pigweed/.compile_commands/fuchsia
161*61c4878aSAndroid Build Coastguard Worker
162*61c4878aSAndroid Build Coastguard Worker--------------
163*61c4878aSAndroid Build Coastguard WorkerInfrastructure
164*61c4878aSAndroid Build Coastguard Worker--------------
165*61c4878aSAndroid Build Coastguard Worker
166*61c4878aSAndroid Build Coastguard WorkerRun Fuchsia presubmit tests
167*61c4878aSAndroid Build Coastguard Worker===========================
168*61c4878aSAndroid Build Coastguard WorkerPresubmits for ``bt-host`` are captured in a dedicated separate builder,
169*61c4878aSAndroid Build Coastguard Worker``pigweed-linux-bazel-bthost``, rather than existing ones such as
170*61c4878aSAndroid Build Coastguard Worker``pigweed-linux-bazel-noenv``.
171*61c4878aSAndroid Build Coastguard Worker
172*61c4878aSAndroid Build Coastguard WorkerOn the builder invocation console, there are a number of useful artifacts for
173*61c4878aSAndroid Build Coastguard Workerexamining the environment during test failures. Here are some notable examples:
174*61c4878aSAndroid Build Coastguard Worker
175*61c4878aSAndroid Build Coastguard Worker* ``bt_host_package`` ``stdout``: Combined ``stdout``/``stderr`` of the entire test orchestration and execution.
176*61c4878aSAndroid Build Coastguard Worker* ``subrunner.log``: Combined test ``stdout``/``stderr`` of test execution only.
177*61c4878aSAndroid Build Coastguard Worker* ``target.log``: The ``ffx`` target device's logs.
178*61c4878aSAndroid Build Coastguard Worker* ``ffx_config.txt``: The ``ffx`` configuration used for provisioning and testing.
179*61c4878aSAndroid Build Coastguard Worker* ``ffx.log``: The ``ffx`` host logs.
180*61c4878aSAndroid Build Coastguard Worker* ``ffx_daemon.log``: The ``ffx`` daemon's logs.
181*61c4878aSAndroid Build Coastguard Worker* ``env.dump.txt``: The environment variables when test execution started.
182*61c4878aSAndroid Build Coastguard Worker* ``ssh.log``: The SSH logs when communicating with the target device.
183*61c4878aSAndroid Build Coastguard Worker
184*61c4878aSAndroid Build Coastguard WorkerThese presubmits can be also be replicated locally with the following command:
185*61c4878aSAndroid Build Coastguard Worker
186*61c4878aSAndroid Build Coastguard Worker.. code-block::
187*61c4878aSAndroid Build Coastguard Worker
188*61c4878aSAndroid Build Coastguard Worker   bazelisk run --config=fuchsia //pw_bluetooth_sapphire/fuchsia:infra.test_all
189*61c4878aSAndroid Build Coastguard Worker
190*61c4878aSAndroid Build Coastguard Worker.. note::
191*61c4878aSAndroid Build Coastguard Worker   Existing package servers must be stopped before running this command. To
192*61c4878aSAndroid Build Coastguard Worker   check for any existing package servers run ``lsof -i :8083`` and make sure
193*61c4878aSAndroid Build Coastguard Worker   each of those processes are killed.
194*61c4878aSAndroid Build Coastguard Worker
195*61c4878aSAndroid Build Coastguard Worker.. note::
196*61c4878aSAndroid Build Coastguard Worker   You do not need to start an emulator beforehand to to run all tests this way.
197*61c4878aSAndroid Build Coastguard Worker   This test target will automatically provision one before running all tests.
198*61c4878aSAndroid Build Coastguard Worker
199*61c4878aSAndroid Build Coastguard WorkerAdd a test to presubmit
200*61c4878aSAndroid Build Coastguard Worker=======================
201*61c4878aSAndroid Build Coastguard WorkerFuchsia test packages are those defined with a Fuchsia SDK rule like
202*61c4878aSAndroid Build Coastguard Worker``fuchsia_unittest_package``. All Fuchsia test packages need to be added to the
203*61c4878aSAndroid Build Coastguard WorkerFuchsia presubmit step or they will not be tested.
204*61c4878aSAndroid Build Coastguard Worker
205*61c4878aSAndroid Build Coastguard WorkerTo add new Fuchsia test packages to presubmit, add the test package targets to
206*61c4878aSAndroid Build Coastguard Worker``//pw_bluetooth_sapphire/fuchsia/BUILD.bazel``.
207*61c4878aSAndroid Build Coastguard Worker
208*61c4878aSAndroid Build Coastguard WorkerExample:
209*61c4878aSAndroid Build Coastguard Worker
210*61c4878aSAndroid Build Coastguard Worker.. code-block::
211*61c4878aSAndroid Build Coastguard Worker
212*61c4878aSAndroid Build Coastguard Worker   # pw_bluetooth_sapphire/fuchsia/BUILD.bazel
213*61c4878aSAndroid Build Coastguard Worker
214*61c4878aSAndroid Build Coastguard Worker   qemu_tests = [
215*61c4878aSAndroid Build Coastguard Worker       "//pw_bluetooth_sapphire/fuchsia/bt_host:integration_test_pkg",
216*61c4878aSAndroid Build Coastguard Worker       ...
217*61c4878aSAndroid Build Coastguard Worker   ]
218*61c4878aSAndroid Build Coastguard Worker
219*61c4878aSAndroid Build Coastguard WorkerUploading to CIPD
220*61c4878aSAndroid Build Coastguard Worker=================
221*61c4878aSAndroid Build Coastguard WorkerPigweed infrastructure uploads ``bt-host`` artifacts to
222*61c4878aSAndroid Build Coastguard Worker`fuchsia/prebuilt/bt-host`_ and `fuchsia/prebuilt/bt-hci-virtual`_ via the
223*61c4878aSAndroid Build Coastguard Worker`pigweed-linux-bazel-bthost`_ builder by building the top level infra target:
224*61c4878aSAndroid Build Coastguard Worker
225*61c4878aSAndroid Build Coastguard Worker.. code-block::
226*61c4878aSAndroid Build Coastguard Worker
227*61c4878aSAndroid Build Coastguard Worker   # Ensure all dependencies are built.
228*61c4878aSAndroid Build Coastguard Worker   bazelisk build --config=fuchsia //pw_bluetooth_sapphire/fuchsia:infra
229*61c4878aSAndroid Build Coastguard Worker
230*61c4878aSAndroid Build Coastguard Worker   # Get builder manifest file.
231*61c4878aSAndroid Build Coastguard Worker   bazelisk build --config=fuchsia --output_groups=builder_manifest //pw_bluetooth_sapphire/fuchsia:infra
232*61c4878aSAndroid Build Coastguard Worker
233*61c4878aSAndroid Build Coastguard WorkerThe resulting file contains a ``cipd_manifests`` JSON field which references a
234*61c4878aSAndroid Build Coastguard Workersequence of JSON files specifying the CIPD package path and package file
235*61c4878aSAndroid Build Coastguard Workercontents.
236*61c4878aSAndroid Build Coastguard Worker
237*61c4878aSAndroid Build Coastguard Worker.. _fuchsia/prebuilt/bt-host: https://chrome-infra-packages.appspot.com/p/fuchsia/prebuilt/bt-host
238*61c4878aSAndroid Build Coastguard Worker.. _fuchsia/prebuilt/bt-hci-virtual: https://chrome-infra-packages.appspot.com/p/fuchsia/prebuilt/bt-hci-virtual
239*61c4878aSAndroid Build Coastguard Worker.. _pigweed-linux-bazel-bthost: https://ci.chromium.org/ui/p/pigweed/builders/pigweed.ci/pigweed-linux-bazel-bthost
240