Add functional tests for A2DP and BAP
Subsystems (2)
Luiz Augusto von Dentz
maintainercover Add functional tests for A2DP and BAP
From: Luiz Augusto von Dentz <[email protected]>
This adds functional tests for A2DP and BAP, driven through bluetoothctl, together with the endpoint registration scripts they use and the documentation describing what each of them does.
The test documentation is reworked to describe every case as setup, steps, expected outcome and notes, so a test can be reproduced and reviewed without reading its source, and the reason behind the way it is written is not lost. The setup of each case includes a topology diagram showing how many hosts are used and the role each of them takes. Tests of a profile need more context than the core ones, so they are documented separately, in doc/functional-<profile>.rst.
The cases added are:
- A2DP: a transport is created on both sides once the stream is configured, and the central can acquire it.
- BAP unicast: the initiator configures the remote PAC Sink endpoint, a transport is created per audio location, and acquiring all of them establishes the CIS. All the transports of a CIG have to be acquired, as the CIS are only created once every CIS of the CIG is ready.
- BAP broadcast: a Broadcast Sink scans, syncs to a Broadcast Source on its own and acquires a transport, for a plain broadcast and for a Public Broadcast Profile one.
- BAP broadcast assistant: a Broadcast Assistant colocated with a Broadcast Source shares its own broadcast with a Scan Delegator, which syncs using PAST. The topology where the assistant relays a source it scanned, which does not use PAST, needs the assistant on a third host and can be added later.
Writing the tests exposed two issues, which are fixed here as well:
- Registering an A2DP endpoint prompted for Locations, Supported Context, Context, CIG and CIS, which are LE Audio specific and have no meaning for A2DP. Answering Locations with a single location also pushes an LC3_CHAN_COUNT LTV into the capabilities, corrupting the SBC capabilities.
- A Broadcast Sink established a PA sync to read the BASE, closed it, and established a new one to sync to the BIG, delaying the start of the stream. The sync is now reused, but only while there is nothing else to discover, and it is released once another Broadcast Source is probed or after a grace timeout.
The broadcast tests also depend on the following kernel fix, without which the BIS connections are not notified to the listening socket and the transport acquire never completes:
Bluetooth: ISO: set BT_LISTEN before requesting a BIG sync
Note that the broadcast tests are still occasionally slow: the first LE BIG Create Sync may expire after 20 seconds and only the retry succeeds, which is being looked at separately.
Luiz Augusto von Dentz (12):
build: add doc/test-functional.rst to EXTRA_DIST
doc: describe the functional test cases
client: do not prompt for LE Audio settings on A2DP endpoints
client: add A2DP endpoint registration scripts
test: functional: add A2DP tests
client: rename media endpoint scripts to include the codec
client: add BAP endpoint registration scripts
doc: bluetoothctl: document init script option and scripts
test: functional: add BAP unicast tests
test: functional: add BAP broadcast tests
test: functional: add BAP broadcast assistant test
bap: reuse the PA sync established to discover a Broadcast Source
Makefile.am | 6 + client/player.c | 15 +- client/scripts/a2dp-sink-sbc.bt | 19 ++ client/scripts/a2dp-source-sbc.bt | 24 +++ client/scripts/bap-sink-lc3.bt | 32 +++ client/scripts/bap-source-lc3.bt | 34 +++ doc/bluetoothctl.rst | 105 +++++++++ doc/functional-a2dp.rst | 99 +++++++++ doc/functional-avrcp.rst | 64 ++++++ doc/functional-bap.rst | 290 +++++++++++++++++++++++++ doc/functional-obex.rst | 90 ++++++++ doc/functional-testing.rst | 340 ++++++++++++++++++++++++++++++ profiles/audio/bap.c | 115 +++++++++- test/functional/test_a2dp.py | 144 +++++++++++++ test/functional/test_bap.py | 318 ++++++++++++++++++++++++++++ 15 files changed, 1685 insertions(+), 10 deletions(-) create mode 100644 client/scripts/a2dp-sink-sbc.bt create mode 100644 client/scripts/a2dp-source-sbc.bt create mode 100644 client/scripts/bap-sink-lc3.bt create mode 100644 client/scripts/bap-source-lc3.bt create mode 100644 doc/functional-a2dp.rst create mode 100644 doc/functional-avrcp.rst create mode 100644 doc/functional-bap.rst create mode 100644 doc/functional-obex.rst create mode 100644 doc/functional-testing.rst create mode 100644 test/functional/test_a2dp.py create mode 100644 test/functional/test_bap.py
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH 1/12 build: add doc/test-functional.rst to EXTRA_DIST
From: Luiz Augusto von Dentz <[email protected]>
The functional testing documentation was not distributed with the tarball, unlike the other documents in doc/.
--- Makefile.am | 1 + 1 file changed, 1 insertion(+)
Makefile.am +1 -0
@@ -496,6 +496,7 @@ EXTRA_DIST += SECURITY.md EXTRA_DIST += doc/assigned-numbers.rst doc/supported-features.txt \ doc/test-coverage.txt \ doc/test-runner.rst \ + doc/test-functional.rst \ doc/settings-storage.txt EXTRA_DIST += doc/hci-protocol.rst doc/mgmt-protocol.rst \
Signature · 1 line
2.55.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1161557/
---Test result---
Test Summary:
CheckPatch PASS 4.46 seconds GitLint FAIL 3.25 seconds BuildEll PASS 19.50 seconds BluezMake PASS 369.07 seconds MakeCheck PASS 14.09 seconds MakeDistcheck PASS 141.29 seconds CheckValgrind PASS 230.79 seconds CheckSmatch PASS 283.43 seconds bluezmakeextell PASS 92.19 seconds IncrementalBuild PASS 432.57 seconds ScanBuild PASS 1019.97 seconds
Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[BlueZ,v1,12/12] bap: reuse the PA sync established to discover a Broadcast Source
1: T1 Title exceeds max length (82>80): "[BlueZ,v1,12/12] bap: reuse the PA sync established to discover a Broadcast Source"
https://github.com/bluez/bluez/pull/2516
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerPATCH 2/12 doc: describe the functional test cases
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add doc/functional-testing.rst describing the test cases under test/functional as setup, steps, expected outcome and notes, so a test can be reproduced and reviewed without reading its source, and the reason behind the way it is written is not lost. The setup of each test includes a topology diagram showing how many hosts are used and the role each of them takes.
It also documents the pytest markers (vm, sa, tester) and the convention of naming security advisory regression tests after their GHSA id.
Tests for a specific profile need more context than the core ones, so they are documented separately, in doc/functional-<profile>.rst.
--- Makefile.am | 3 + doc/functional-avrcp.rst | 64 +++++++ doc/functional-obex.rst | 90 ++++++++++ doc/functional-testing.rst | 338 +++++++++++++++++++++++++++++++++++++ 4 files changed, 495 insertions(+) create mode 100644 doc/functional-avrcp.rst create mode 100644 doc/functional-obex.rst create mode 100644 doc/functional-testing.rst
Makefile.am +3 -0
@@ -497,6 +497,9 @@ EXTRA_DIST += doc/assigned-numbers.rst doc/supported-features.txt \ doc/test-coverage.txt \ doc/test-runner.rst \ doc/test-functional.rst \ + doc/functional-testing.rst \ + doc/functional-avrcp.rst \ + doc/functional-obex.rst \ doc/settings-storage.txt EXTRA_DIST += doc/hci-protocol.rst doc/mgmt-protocol.rst \
doc/functional-avrcp.rst new file +64 -0
64 lines not on this page · raw message
doc/functional-obex.rst new file +90 -0
90 lines not on this page · raw message
doc/functional-testing.rst new file +338 -0
338 lines not on this page · raw message
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH 3/12 client: do not prompt for LE Audio settings on A2DP endpoints
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Registering an A2DP endpoint prompted for Locations, Supported Context, Context, CIG and CIS, which are LE Audio/ISO specific and have no meaning for A2DP. Worse, answering Locations with a single location pushes an LC3_CHAN_COUNT LTV into the capabilities, which corrupts the SBC capabilities.
Register A2DP endpoints right after Max Transports instead, and use the same helper in endpoint_init_defaults(), which compared against A2DP_SOURCE_UUID twice and therefore left A2DP Sink endpoints with ISO and broadcast defaults.
--- client/player.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
client/player.c +13 -2
@@ -3506,6 +3506,12 @@ static void endpoint_locations(const char *input, void *user_data) endpoint_supported_context, ep); } +static bool endpoint_is_a2dp (struct endpoint *ep) +{ +return !strcasecmp (ep->uuid,A2DP_SOURCE_UUID ) || + !strcasecmp (ep->uuid,A2DP_SINK_UUID ); +} +static void endpoint_max_transports (const char *input,void *user_data) {struct endpoint *ep = user_data;
@@ -3525,6 +3531,12 @@ static void endpoint_max_transports(const char *input, void *user_data) ep->max_transports = value; } +/* Locations, contexts and ISO settings only apply to LE Audio */ +if (endpoint_is_a2dp (ep)) { +endpoint_register (ep); +return ; + } +bt_shell_prompt_input (ep->path,"Locations:" , endpoint_locations, ep); }
@@ -4629,8 +4641,7 @@ static void endpoint_init_defaults(struct endpoint *ep) ep->max_transports =UINT8_MAX ; ep->auto_accept = true; -if (!strcmp (ep->uuid,A2DP_SOURCE_UUID ) || - !strcmp (ep->uuid,A2DP_SOURCE_UUID )) +if (endpoint_is_a2dp (ep))return ; ep->iso_group =BT_ISO_QOS_GROUP_UNSET ;
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH 4/12 client: add A2DP endpoint registration scripts
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add scripts registering an A2DP Source and an A2DP Sink endpoint with SBC, so a peer can be set up with a single command:
bluetoothctl --init-script client/scripts/a2dp-source.bt
--- client/scripts/a2dp-sink.bt | 19 +++++++++++++++++++ client/scripts/a2dp-source.bt | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 client/scripts/a2dp-sink.bt create mode 100644 client/scripts/a2dp-source.bt
client/scripts/a2dp-sink.bt new file +19 -0
@@ -0,0 +1,19 @@ +power on +# +# +# Register an A2DP Sink endpoint with SBC, to act as the device +# receiving audio, e.g. a speaker. +# +endpoint.register 0000110b-0000-1000-8000-00805f9b34fb 0x00 +# Auto Accept: accept the configuration chosen by the peer +y +# Max Transports: no limit +a +# +# +# The endpoint has to be registered before pairing, so the SDP record +# is in place when the peer resolves the services. +# +# A transport is created once the peer configures the stream, and it is +# the peer, as the A2DP Source, that acquires it to start the stream. +#
client/scripts/a2dp-source.bt new file +24 -0
@@ -0,0 +1,24 @@ +power on +# +# +# Register an A2DP Source endpoint with SBC, to act as the device +# sending audio, e.g. a phone. +# +endpoint.register 0000110a-0000-1000-8000-00805f9b34fb 0x00 +# Auto Accept: accept the configuration chosen by the peer +y +# Max Transports: no limit +a +# +# +# The endpoint has to be registered before pairing, so the SDP record +# is in place when the peer resolves the services, otherwise connecting +# fails with org.bluez.Error.BREDR.ProfileUnavailable. +# +# Once connected, the stream is configured and a transport is created: +# +# [NEW] Transport /org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx/sep1/fd0 +# +# Acquire it to start the stream: +# +# transport.acquire /org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx/sep1/fd0
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH 5/12 test: functional: add A2DP tests
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add tests covering A2DP via bluetoothctl: the central registers an A2DP Source endpoint and the peripheral an A2DP Sink endpoint, using the endpoint registration scripts. The endpoints are registered before pairing so the SDP records are in place when the peer resolves the services.
test_a2dp_transport_created checks a MediaTransport1 object is created on both sides with the expected endpoint, codec and state, and test_a2dp_transport_acquire checks the central can acquire it.
--- Makefile.am | 1 + doc/functional-a2dp.rst | 99 ++++++++++++++++++++++++ doc/functional-testing.rst | 1 + test/functional/test_a2dp.py | 144 +++++++++++++++++++++++++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 doc/functional-a2dp.rst create mode 100644 test/functional/test_a2dp.py
Makefile.am +1 -0
@@ -498,6 +498,7 @@ EXTRA_DIST += doc/assigned-numbers.rst doc/supported-features.txt \ doc/test-runner.rst \ doc/test-functional.rst \ doc/functional-testing.rst \ + doc/functional-a2dp.rst \ doc/functional-avrcp.rst \ doc/functional-obex.rst \ doc/settings-storage.txt
doc/functional-a2dp.rst new file +99 -0
99 lines not on this page · raw message
doc/functional-testing.rst +1 -0
@@ -12,6 +12,7 @@ configure and run the suite, see **test-functional(1)**. This document covers the core test cases. Tests for a specific profile are documented separately: +- **functional-a2dp(7)**: `test/functional/test_a2dp.py` - **functional-avrcp(7)**: `test/functional/test_avrcp.py` - **functional-obex(7)**: `test/functional/test_obex.py`
test/functional/test_a2dp.py new file +144 -0
144 lines not on this page · raw message
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH 6/12 client: rename media endpoint scripts to include the codec
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Name the scripts registering a media endpoint <profile>-<role>-<codec>[-<preset>].bt, so it is clear what they set up without having to read them.
---
client/scripts/{a2dp-sink.bt => a2dp-sink-sbc.bt} | 0
client/scripts/{a2dp-source.bt => a2dp-source-sbc.bt} | 0
doc/functional-a2dp.rst | 6 +++---
test/functional/test_a2dp.py | 4 ++--
4 files changed, 5 insertions(+), 5 deletions(-)
rename client/scripts/{a2dp-sink.bt => a2dp-sink-sbc.bt} (100%)
rename client/scripts/{a2dp-source.bt => a2dp-source-sbc.bt} (100%)client/scripts/a2dp-sink-sbc.bt renamed from client/scripts/a2dp-sink.bt +0 -0
client/scripts/a2dp-source-sbc.bt renamed from client/scripts/a2dp-source.bt +0 -0
doc/functional-a2dp.rst +3 -3
@@ -20,7 +20,7 @@ Two hosts, connected over BR/EDR: | host0 | BR/EDR | host1 | | central | --------------> | peripheral | | bluetoothctl | | bluetoothctl | - | a2dp-source.bt | AVDTP (SBC) | a2dp-sink.bt | + | a2dp-source-sbc.bt | AVDTP (SBC) | a2dp-sink-sbc.bt | | A2DP Source endpoint | ==============> | A2DP Sink endpoint | +------------------------+ +------------------------+
@@ -28,12 +28,12 @@ Two hosts, connected over BR/EDR: Both hosts start `bluetoothctl` with an endpoint registration script: -``client/scripts/a2dp-source.bt`` on host0 +``client/scripts/a2dp-source-sbc.bt`` on host0 Registers a local A2DP Source endpoint (``0000110a-0000-1000-8000-00805f9b34fb``) with SBC. host0 is the central, i.e. the device sending audio. -``client/scripts/a2dp-sink.bt`` on host1 +``client/scripts/a2dp-sink-sbc.bt`` on host1 Registers a local A2DP Sink endpoint (``0000110b-0000-1000-8000-00805f9b34fb``) with SBC. host1 is the peripheral, i.e. the device receiving audio.
test/functional/test_a2dp.py +2 -2
@@ -93,8 +93,8 @@ def a2dp_hosts(hosts): """ host0, host1 = hosts - source = start_bluetoothctl(host0, "a2dp-source.bt") - sink = start_bluetoothctl(host1, "a2dp-sink.bt") + source = start_bluetoothctl(host0, "a2dp-source-sbc.bt") + sink = start_bluetoothctl(host1, "a2dp-sink-sbc.bt") pair(host0, source, host1, sink)
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH 7/12 client: add BAP endpoint registration scripts
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add scripts registering a local PAC Source and a local PAC Sink endpoint with LC3, to set up the two sides of a BAP unicast stream:
bluetoothctl --init-script client/scripts/bap-source-lc3.bt
The locations and contexts match the ones bluetoothctl uses when registering the endpoints itself, so that the metadata of a stream is not rejected.
--- client/scripts/bap-sink-lc3.bt | 32 ++++++++++++++++++++++++++++++ client/scripts/bap-source-lc3.bt | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 client/scripts/bap-sink-lc3.bt create mode 100644 client/scripts/bap-source-lc3.bt
client/scripts/bap-sink-lc3.bt new file +32 -0
@@ -0,0 +1,32 @@ +power on +# +# +# Register a PAC Sink endpoint with LC3, to act as the acceptor +# receiving audio, e.g. a headset. +# +endpoint.register 00002bc9-0000-1000-8000-00805f9b34fb 0x06 +# Auto Accept: accept the configuration chosen by the peer +y +# Max Transports: no limit +a +# Locations: Front Left and Front Right +3 +# Supported Context: same as the contexts bluetoothctl registers with +0x0fff +# Context +0x0fff +# CIG: assigned automatically +a +# CIS: assigned automatically +a +# +# +# With narrower Supported Contexts the Enable is rejected with Invalid +# Metadata, as the metadata of a stream carries the Unspecified +# context. +# +# Advertise and wait for the initiator to connect and configure the +# streams. The transports do not have to be acquired for the CIS to be +# established, as bluetoothd sets up the ISO listener on its own: +# +# advertise on
client/scripts/bap-source-lc3.bt new file +34 -0
@@ -0,0 +1,34 @@ +power on +# +# +# Register a PAC Source endpoint with LC3, to act as the initiator +# sending audio, e.g. a phone. +# +endpoint.register 00002bcb-0000-1000-8000-00805f9b34fb 0x06 +# Auto Accept: accept the configuration chosen by the peer +y +# Max Transports: no limit +a +# Locations: Front Left and Front Right +3 +# Supported Context: same as the contexts bluetoothctl registers with +0x000f +# Context +0x000f +# CIG: assigned automatically +a +# CIS: assigned automatically +a +# +# +# After pairing, configure a remote PAC Sink endpoint with a preset: +# +# endpoint.config /org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx/pac_sink0 \ +# /local/endpoint/ep0 16_2_1 +# +# A stream is created per audio location, each with its own CIS in the +# same CIG, and all of the transports have to be acquired, as the CIS +# are only created once every CIS of the CIG is ready: +# +# transport.acquire /org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx/pac_sink0/fd0 \ +# /org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx/pac_sink0/fd1
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH 8/12 doc: bluetoothctl: document init script option and scripts
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The --init-script option was not documented. Document it, along with the scripts shipped in client/scripts and the roles they set up.
--- doc/bluetoothctl.rst | 105 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+)
doc/bluetoothctl.rst +105 -0
@@ -38,6 +38,7 @@ OPTIONS -a capability, --agent capability Register agent handler: <capability> -e, --endpoints Register Media endpoints -m, --monitor Enable monitor output +-s file, --init-script file Run the commands in the given script file -t seconds, --timeout seconds Timeout in seconds for non-interactive mode -v, --version Display version -h, --help Display help
@@ -589,6 +590,110 @@ Using Here Docs to show information about the Bluetooth controller. show EOF +Commands can also be read from a file with the **--init-script** option. +The tool stays interactive after the script has been executed, which is +useful to set up a role and then drive it by hand: + +.. code:: + + bluetoothctl --init-script client/scripts/power-on.bt + +Lines starting with **#** are comments, and lines are also used to answer +the prompts of the commands, in the order the prompts appear. + +SCRIPTS +======= + +The scripts shipped in **client/scripts** set up common roles. Scripts +registering a media endpoint are named +*<profile>-<role>-<codec>[-<preset>].bt*, where the preset is only part +of the name if the script also configures the stream. + +Controller setup +---------------- + +``power-on.bt``, ``power-on-off.bt`` + Power the controller on, or power it off and on again. + +``scan-on.bt``, ``scan-on-off.bt``, ``scan-le.bt``, ``scan-bredr.bt`` + Start discovery, optionally restricted to a transport. + +``advertise-on.bt``, ``advertise-peripheral.bt``, ``advertise-broadcast.bt``, ``advertise-rsi.bt`` + Start advertising with the given type. + +A2DP +---- + +``a2dp-source-sbc.bt`` + Register a local A2DP Source endpoint (``0000110a-...``) with SBC, + i.e. act as the device sending audio, such as a phone. + +``a2dp-sink-sbc.bt`` + Register a local A2DP Sink endpoint (``0000110b-...``) with SBC, + i.e. act as the device receiving audio, such as a speaker. + +Once connected, the stream is configured automatically and a transport +is created, which can be acquired with **transport.acquire**. + +BAP unicast +----------- + +``bap-source-lc3.bt`` + Register a local PAC Source endpoint (``00002bcb-...``) with LC3, + i.e. act as the initiator sending audio. + +``bap-sink-lc3.bt`` + Register a local PAC Sink endpoint (``00002bc9-...``) with LC3, + i.e. act as the acceptor receiving audio. + +The initiator configures a remote endpoint with **endpoint.config**, +choosing a preset, which creates the transport: + +.. code:: + + endpoint.config /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_snk0 \ + /local/endpoint/ep0 16_2_1 + +``preset-custom.bt`` + Add a custom LC3 preset, instead of using one of the presets + defined by the specification. + +BAP broadcast +------------- + +``broadcast-source.bt``, ``broadcast-source-2bis.bt``, ``broadcast-source-pbp.bt`` + Register a Broadcast Source endpoint (``00001852-...``) with LC3, + configure it with the 16_2_1 preset and acquire the transport, + which starts the broadcast. The variants set up two BISes and the + Public Broadcast Profile respectively. + +``broadcast-sink.bt`` + Register a Broadcast Sink endpoint (``00001851-...``) with LC3 and + scan, to sync to a Broadcast Source without the help of a + Broadcast Assistant. + +``scan-delegator.bt``, ``broadcast-delegator.bt`` + Register a Broadcast Sink endpoint and advertise, to be used as + Scan Delegator by a Broadcast Assistant. The stream is then synced + using PAST, and the transport moved to broadcasting with + **transport.select** before it is acquired. + +``broadcast-assistant.bt`` + Scan, to discover a Scan Delegator to connect to and Broadcast + Sources to offer it with **assistant.push**. + +Channel Sounding +---------------- + +``cs-initiator.bt``, ``cs-reflector.bt`` + Set up the two sides of a Channel Sounding procedure. + +GATT +---- + +``gatt-batt.bt`` + Register a Battery Service with a notifiable Battery Level + characteristic. RESOURCES =========
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH 9/12 test: functional: add BAP unicast tests
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add tests covering BAP unicast via bluetoothctl: the initiator registers a PAC Source endpoint, the acceptor a PAC Sink endpoint, and after pairing the initiator configures the remote endpoint with a preset.
test_bap_unicast_transport_created checks a MediaTransport1 object is created on both sides with the expected endpoint, codec and state, and test_bap_unicast_transport_acquire checks the initiator can acquire them.
The endpoints are configured for stereo, so a stream is created per location, each with its own CIS in the same CIG. All the transports have to be acquired, as the CIS are only created once every CIS of the CIG is ready.
--- Makefile.am | 1 + doc/functional-bap.rst | 109 +++++++++++++++++++++++ doc/functional-testing.rst | 1 + test/functional/test_bap.py | 169 ++++++++++++++++++++++++++++++++++++ 4 files changed, 280 insertions(+) create mode 100644 doc/functional-bap.rst create mode 100644 test/functional/test_bap.py
Makefile.am +1 -0
@@ -500,6 +500,7 @@ EXTRA_DIST += doc/assigned-numbers.rst doc/supported-features.txt \ doc/functional-testing.rst \ doc/functional-a2dp.rst \ doc/functional-avrcp.rst \ + doc/functional-bap.rst \ doc/functional-obex.rst \ doc/settings-storage.txt
doc/functional-bap.rst new file +109 -0
109 lines not on this page · raw message
doc/functional-testing.rst +1 -0
@@ -14,6 +14,7 @@ are documented separately: - **functional-a2dp(7)**: `test/functional/test_a2dp.py` - **functional-avrcp(7)**: `test/functional/test_avrcp.py` +- **functional-bap(7)**: `test/functional/test_bap.py` - **functional-obex(7)**: `test/functional/test_obex.py` Each test case is described as:
test/functional/test_bap.py new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH 10/12 test: functional: add BAP broadcast tests
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add tests covering BAP broadcast via bluetoothctl: the Broadcast Source registers a BCAA endpoint, configures it and starts the broadcast, while the Broadcast Sink registers a BAA endpoint and scans, syncing to the periodic advertising on its own, without a Broadcast Assistant. Run them for a plain broadcast and for a Public Broadcast Profile one.
test_bap_broadcast_transport_created checks a MediaTransport1 object is created for each BIS of the BASE, and test_bap_broadcast_transport_acquire checks selecting the transport with the broadcast code moves it to broadcasting and acquiring it succeeds.
--- doc/functional-bap.rst | 121 +++++++++++++++++++++++++++++++----- test/functional/test_bap.py | 68 ++++++++++++++++++++ 2 files changed, 172 insertions(+), 17 deletions(-)
doc/functional-bap.rst +104 -17
@@ -13,6 +13,23 @@ suite. SETUP ===== +BAP requires the ISO socket support, so all hosts run `bluetoothd` +with: + +.. code-block:: + + [General] + Experimental = true + KernelExperimental = true + ControllerMode = le + +`bluetoothctl` is started with ``-a auto``, so pairing and service +authorization are accepted without prompting, and with an endpoint +registration script from `client/scripts`. + +UNICAST +======= + Two hosts, connected over LE: .. code-block::
@@ -31,20 +48,6 @@ Two hosts, connected over LE: --> connection is initiated by ==> audio flows towards -BAP requires the ISO socket support, so all hosts run `bluetoothd` -with: - -.. code-block:: - - [General] - Experimental = true - KernelExperimental = true - ControllerMode = le - -`bluetoothctl` is started with ``-a auto``, so pairing and service -authorization are accepted without prompting, and with an endpoint -registration script: - ``client/scripts/bap-source-lc3.bt`` on host0 Registers a local PAC Source endpoint (``00002bcb-0000-1000-8000-00805f9b34fb``) with LC3. host0 is the
@@ -55,9 +58,6 @@ registration script: (``00002bc9-0000-1000-8000-00805f9b34fb``) with LC3. host1 is the acceptor, i.e. the device receiving audio. -TEST CASES -========== - test_bap_unicast_transport_created ----------------------------------
@@ -107,3 +107,90 @@ test_bap_unicast_transport_acquire The acceptor does not have to acquire its transports for the CIS to be established, as `bluetoothd` sets up the ISO listener on its own when the stream is enabled. + +BROADCAST +========= + +Two hosts, with no connection between them: + +.. code-block:: + + +------------------------+ +------------------------+ + | host0 | extended + | host1 | + | Broadcast Source | periodic | Broadcast Sink | + | bluetoothctl -a auto | advertising | bluetoothctl -a auto | + | broadcast-source.bt | --------------> | broadcast-sink.bt | + | or -pbp variant | | | + | BCAA endpoint (0x1852) | BIS 0 (LC3) | BAA endpoint (0x1851) | + | | ==============> | | + +------------------------+ +------------------------+ + + no ACL is established: the sink syncs to the periodic advertising, + reads the BASE from it and then syncs to the BIG + + --> advertising is scanned by ==> audio flows towards + +``client/scripts/broadcast-source.bt`` on host0 + Registers a Broadcast Source endpoint + (``00001852-0000-1000-8000-00805f9b34fb``) with LC3, configures it + with the 16_2_1 preset and acquires the transport, which starts + the broadcast. The stream is encrypted with the broadcast code + `bluetoothctl` uses by default. + +``client/scripts/broadcast-source-pbp.bt`` on host0 + As above, but adds the Public Broadcast Announcement service + (``0x1856``) to the extended advertising first, so the broadcast + is a Public Broadcast Profile one. + +``client/scripts/broadcast-sink.bt`` on host1 + Registers a Broadcast Sink endpoint + (``00001851-0000-1000-8000-00805f9b34fb``) with LC3 and scans. + +Both test cases run for each source, i.e. with the ``lc3`` parameter +for a plain broadcast and with ``pbp`` for a Public Broadcast Profile +one. + +test_bap_broadcast_transport_created[lc3|pbp] +--------------------------------------------- + +:Setup: As above. + +:Steps: + 1. Start `bluetoothctl` with the source script on host0. + 2. Start `bluetoothctl` with the sink script on host1. + 3. Sink: ``transport.show <transport>``. + +:Expected: + 1. ``Endpoint /local/endpoint/ep0 registered``, then + ``Acquire successful: fd <fd> MTU <read>:<write>`` on the + source, i.e. it is broadcasting. + 2. The sink syncs to the periodic advertising on its own and + creates a transport per BIS described by the BASE, under + ``/org/bluez/hci0/dev_XX/sidN/bisM/fdK``. + 3. The transport reports ``Codec: 0x06`` for LC3 and + ``State: idle``. + +:Notes: The sink does not need a Broadcast Assistant here: it scans, + finds the Broadcast Source and syncs by itself. + +test_bap_broadcast_transport_acquire[lc3|pbp] +--------------------------------------------- + +:Setup: As above, with the transport already created. + +:Steps: + 1. Sink: ``transport.select <transport>``. + 2. Answer ``Enter bcode[value/no]:`` with the broadcast code the + source used. + +:Expected: + 1. The transport moves to ``State: broadcasting``, i.e. the sink + synced to the BIG. + 2. ``Acquire successful: fd <fd> MTU <read>:<write>`` and the + transport moves to ``State: active``. + +:Notes: Selecting the transport is what moves it out of idle, and + `bluetoothctl` starts acquiring it right after, so the test does + not issue ``transport.acquire`` itself. The broadcast code has to + match the one the source encrypted the BIG with, otherwise the + sink cannot decrypt the stream.
test/functional/test_bap.py +68 -0
71 lines not on this page · raw message
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH 11/12 test: functional: add BAP broadcast assistant test
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add a test covering the Broadcast Assistant sharing a broadcast with a Scan Delegator, with the Broadcast Source and the Broadcast Assistant colocated so the assistant shares its own broadcast. The delegator receives the periodic advertising sync over the connection to the assistant (PAST), instead of scanning the source itself.
The topology where the assistant relays a source it scanned, which does not use PAST, needs the assistant on a third host and can be added later.
--- doc/functional-bap.rst | 94 +++++++++++++++++++++++++++++ test/functional/test_bap.py | 115 ++++++++++++++++++++++++++++++------ 2 files changed, 192 insertions(+), 17 deletions(-)
doc/functional-bap.rst +94 -0
@@ -194,3 +194,97 @@ test_bap_broadcast_transport_acquire[lc3|pbp] not issue ``transport.acquire`` itself. The broadcast code has to match the one the source encrypted the BIG with, otherwise the sink cannot decrypt the stream. + +BROADCAST ASSISTANT +=================== + +Two hosts, with the Broadcast Source and the Broadcast Assistant +colocated on host0, sharing its own broadcast with the Scan Delegator: + +.. code-block:: + + +------------------------+ +------------------------+ + | host0 | | host1 | + | Broadcast Source | extended + | Scan Delegator | + | + Broadcast Assistant | periodic adv | (Broadcast Sink) | + | bluetoothctl -a auto | --------------> | bluetoothctl -a auto | + | broadcast-source.bt | | broadcast-delegator.bt | + | BCAA endpoint (0x1852) | BIG (BIS 1) | BAA endpoint (0x1851) | + | | ==============> | | + | | ACL, BASS, PAST | | + | | --------------> | | + +------------------------+ +------------------------+ + + --> advertising is scanned by ==> audio flows towards + + The assistant connects to the delegator over ACL and shares the + local broadcast with it: the delegator receives the periodic + advertising sync over that connection (PAST), rather than scanning + the source itself. + +``client/scripts/broadcast-source.bt`` on host0 + Registers a Broadcast Source endpoint + (``00001852-0000-1000-8000-00805f9b34fb``) with LC3, configures it + with the 16_2_1 preset and acquires the transport, which starts + the broadcast. The stream is encrypted with the broadcast code + `bluetoothctl` uses by default. + +``client/scripts/broadcast-delegator.bt`` on host1 + Registers a Broadcast Sink endpoint + (``00001851-0000-1000-8000-00805f9b34fb``) with LC3, enables + automatic transport selection and acquisition, and advertises, so + the Broadcast Assistant can discover it and connect. + +The local broadcast of host0 is exposed as a MediaAssistant object in +the ``local`` state, under the adapter path, e.g. +``/org/bluez/hci0/sid0/bis1``. The push is driven through the commands +of the assistant submenu, see **bluetoothctl-assistant(1)**. + +test_bass_past_transport_acquire +-------------------------------- + +:Setup: As above. + +:Steps: + 1. Start `bluetoothctl` with the source script on host0 and the + delegator script on host1. + 2. Assistant: ``scan on``, wait for the delegator device, then + ``connect`` it. + 3. Assistant: ``assistant.push <local assistant path>``, answering + the device prompt with the delegator device path and, if asked, + the broadcast code prompt with the code the stream is encrypted + with. + +:Expected: + 1. ``Acquire successful: fd <fd> MTU <read>:<write>`` on the + source, i.e. it is broadcasting, and the local stream is + exposed as ``[NEW] Assistant <adapter>/sid0/bis1``. On the + delegator, ``Advertising object registered``. + 2. ``Connection successful``, with the delegator authorizing the + assistant. + 3. ``Assistant <path> pushed``. + 4. On the delegator a transport is created for the BIS, and + selected and acquired automatically, reaching + ``State: broadcasting``, i.e. it synced to the BIG, and then + ``State: active``. + +:Notes: The delegator does not scan the source: it syncs to the + periodic advertising over the ACL to the assistant, as pushing a + local stream requests PAST. When instead the assistant scans and + relays a *remote* source, it shares the stream without PAST and + the delegator has to sync by scanning itself; that topology, with + the assistant on a third host, is left to be added later. + + The broadcast code of the local stream is handed to the delegator + by the push, so its automatic transport selection does not have to + prompt for it, and the push itself is only asked for the device to + share the stream with. + + The delegator is paired first: the Broadcast Receive State + characteristic requires an encrypted link, and without it the + assistant fails to read it and the push is rejected with + ``org.bluez.Error.InvalidArguments``. + + The stream is verified on the delegator rather than through the + state of the MediaAssistant object, as an object created for a + local stream stays in the ``local`` state.
test/functional/test_bap.py +98 -17
142 lines not on this page · raw message
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH 12/12 bap: reuse the PA sync established to discover a Broadcast Source
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
A Broadcast Sink creates a short lived PA sync to read the BASE of a Broadcast Source, closes it, and creates a new one once a stream is enabled, as syncing to the BIG requires a PA sync. The second sync has to be established again before the BIG sync can be requested, which delays the start of the stream.
Keep the sync of the BIG Info report around instead, and reuse it, but only while there is nothing else to discover, as a sync holds resources that are needed to discover other Broadcast Sources: it is released as soon as another source is probed, and after a grace timeout if no stream is enabled in the meantime.
--- profiles/audio/bap.c | 115 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 107 insertions(+), 8 deletions(-)
profiles/audio/bap.c +107 -8
@@ -139,6 +139,8 @@ struct bap_data {struct queue *bcast_snks;struct queue *server_streams;GIOChannel *listen_io; +bool pa_synced; +unsigned int pa_timer;unsigned int io_id;unsigned int cig_update_id;bool services_ready;
@@ -176,6 +178,9 @@ static void bap_data_free(struct bap_data *data) {struct queue *bcast_snks = data->bcast_snks; +if (data->pa_timer) +g_source_remove (data->pa_timer); +if (data->listen_io) {g_io_channel_shutdown (data->listen_io, TRUE,NULL );g_io_channel_unref (data->listen_io);
@@ -1560,6 +1565,63 @@ static void bis_handler(uint8_t sid, uint8_t bis, uint8_t sgrp, path); } +/* Time a PA sync is kept around waiting for a stream to be enabled, +* before it is released. +*/ +#define PA_SYNC_GRACE_TIMEOUT 5 + +static void pa_sync_release (struct bap_data *data) +{ +if (!data->pa_synced) +return ; + +DBG ("Release PA sync" ); + +if (data->pa_timer) { +g_source_remove (data->pa_timer); + data->pa_timer =0 ; + } + +if (data->listen_io) { +g_io_channel_shutdown (data->listen_io, TRUE,NULL ); +g_io_channel_unref (data->listen_io); + data->listen_io =NULL ; + } + + data->pa_synced = false; +} + +static gboolean pa_sync_timeout (gpointer user_data) +{ +struct bap_data *data = user_data; + + data->pa_timer =0 ; +pa_sync_release (data); + +return FALSE; +} + +static bool pa_sync_pending (const void *data,const void *match_data) +{ +const struct bap_data *bdata = data; + +if (bdata == match_data) +return false; + +/* A session with a listener that has not synced yet is still +* discovering a Broadcast Source. +*/ +return bdata->listen_io && !bdata->pa_synced; +} + +static void pa_sync_release_session (void *data,void *user_data) +{ +struct bap_data *bdata = data; + +if (bdata != user_data) +pa_sync_release (bdata); +} +static gboolean big_info_report_cb (GIOChannel *io,GIOCondition cond,gpointer user_data) {
@@ -1591,10 +1653,21 @@ static gboolean big_info_report_cb(GIOChannel *io, GIOCondition cond,g_io_channel_unref (data->listen_io); data->listen_io =NULL ; -/* For short-lived PA, the sync is no longer needed at -* this point, so the io can be closed. -*/ -g_io_channel_shutdown (io, TRUE,NULL ); +if (queue_find (sessions, pa_sync_pending, data)) { +/* Other Broadcast Sources are still being discovered, so the +* sync is closed to not hold the resources needed for them. +*/ +g_io_channel_shutdown (io, TRUE,NULL ); + }else { +/* Nothing else to discover: keep the sync for a while, as +* syncing to the BIG requires one, so it does not have to be +* established again if a stream is enabled. +*/ + data->listen_io =g_io_channel_ref (io); + data->pa_synced = true; + data->pa_timer =g_timeout_add_seconds (PA_SYNC_GRACE_TIMEOUT , + pa_sync_timeout, data); + }/* Analyze received BASE data and create remote media endpoints for each * BIS matching our capabilities
@@ -3592,6 +3665,11 @@ static int pa_sync(struct bap_data *data)DBG ("Create PA sync with this source" ); +/* Release any sync kept by another session, as it is not needed +* to discover this source. +*/ +queue_foreach (sessions, pa_sync_release_session, data); + data->listen_io = bt_io_listen(NULL, iso_pa_sync_confirm_cb, data, NULL, &err, BT_IO_OPT_SOURCE_BDADDR,
@@ -3662,10 +3740,12 @@ static gboolean iso_do_big_sync(GIOChannel *io, GIOCondition cond,DBG ("BIG info received, do BIG sync" ); -g_io_channel_unref (data->listen_io); -g_io_channel_shutdown (data->listen_io, TRUE,NULL ); - data->listen_io = io; -g_io_channel_ref (data->listen_io); +if (data->listen_io != io) { +g_io_channel_unref (data->listen_io); +g_io_channel_shutdown (data->listen_io, TRUE,NULL ); + data->listen_io = io; +g_io_channel_ref (data->listen_io); + }/* Append each linked BIS to the BIG sync request */ append_setup (setup->stream, &iso_bc_addr);
@@ -3714,6 +3794,25 @@ static void pa_and_big_sync(struct bap_setup *setup) {GError *err =NULL ;struct bap_data *bap_data = setup->data; + +if (bap_data->pa_synced) { +DBG ("Reuse PA sync with this source" ); + +/* The sync is in use from now on, so it is not released +* while the BIG sync is being set up. +*/ + bap_data->pa_synced = false; + +if (bap_data->pa_timer) { +g_source_remove (bap_data->pa_timer); + bap_data->pa_timer =0 ; + } + + bap_data->io_id =g_io_add_watch (bap_data->listen_io,G_IO_OUT , + iso_do_big_sync, setup); +return ; + } +DBG ("Create PA sync with this source" ); bap_data->listen_io = bt_io_listen(NULL, long_pa_sync_confirm_cb, setup,
Signature · 1 line
2.55.0
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 14 lines · On Wed, 9 Sep 2026 15:22:56 -0400 you wrote:
From: Luiz Augusto von Dentz <[email protected]>
This adds functional tests for A2DP and BAP, driven through bluetoothctl, together with the endpoint registration scripts they use and the documentation describing what each of them does.
The test documentation is reworked to describe every case as setup, steps, expected outcome and notes, so a test can be reproduced and reviewed without reading its source, and the reason behind the way it is written is not lost. The setup of each case includes a topology diagram showing how many hosts are used and the role each of them takes. Tests of a profile need more context than the core ones, so they are documented separately, in doc/functional-<profile>.rst.
Quoted 1 line
[...]
Here is the summary with links:
- [BlueZ,v1,01/12] build: add doc/test-functional.rst to EXTRA_DIST
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=8df6386b97c8 - [BlueZ,v1,02/12] doc: describe the functional test cases https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=fb3457bcd1e5 - [BlueZ,v1,03/12] client: do not prompt for LE Audio settings on A2DP endpoints https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=45b123f3a9c2 - [BlueZ,v1,04/12] client: add A2DP endpoint registration scripts https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=23fac1a310c0 - [BlueZ,v1,05/12] test: functional: add A2DP tests https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a888c89ead5a - [BlueZ,v1,06/12] client: rename media endpoint scripts to include the codec https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d6d9a13775af - [BlueZ,v1,07/12] client: add BAP endpoint registration scripts https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=304e388070f5 - [BlueZ,v1,08/12] doc: bluetoothctl: document init script option and scripts https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=2fccbd5040e9 - [BlueZ,v1,09/12] test: functional: add BAP unicast tests https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a60d81439eab - [BlueZ,v1,10/12] test: functional: add BAP broadcast tests https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=8c99eaa01d53 - [BlueZ,v1,11/12] test: functional: add BAP broadcast assistant test https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=4f77841df4ac - [BlueZ,v1,12/12] bap: reuse the PA sync established to discover a Broadcast Source https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=61a2b3d93897
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html