public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/2] test-vcp: Fix test failing in some environments
@ 2025-06-19 15:31 Kirill Samburskiy
  2025-06-19 15:31 ` [PATCH BlueZ 1/2] shared/tester: add ability to shutdown tester IO Kirill Samburskiy
  2025-06-19 15:31 ` [PATCH BlueZ 2/2] test-vcp: free server-side bt_vcp on test teardown Kirill Samburskiy
  0 siblings, 2 replies; 8+ messages in thread
From: Kirill Samburskiy @ 2025-06-19 15:31 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Kirill Samburskiy

This patch fixes test-vcp failing on some environments. It is done by
manually shutting down tester IO as a part of test teardown, as well as
freeing server-side bt_vcp instances.

---
After updating our bluez source code from v5.72 to v5.83 we noticed
that one of the tests (test-vcp) no longer passes on all environments
(specifically when building for x86_64 or arm64 architectures). This
patch resolves the problem, enabling all tests to pass. Here is a
short extract from test logs:

```
AICS/SR/CP/BV-01-C - init
AICS/SR/CP/BV-01-C - setup
AICS/SR/CP/BV-01-C - setup complete
AICS/SR/CP/BV-01-C - run
gatt_notify_cb: Failed to send notification
ERROR:src/shared/tester.c:981:test_io_recv: assertion failed (len == iov->iov_len): (5 == 6)
```

The reason this test was failing is incomplete test teardown.
Specifically, bt_vcp instances created by vcp_get_session function
are not freed and, more importantly, not removed from sessions queue
(both function and queue are found in shared/vcp.c file).

When a new test case is started, vcp_get_session function may be called
at some point. This function looks up session object using current
bt_att object as key. Each test case creates its own bt_att instance,
however in our case bt_att is always allocated at the same memory
address. This leads to vcp_get_session function looking up session
object belonging to the previous test case instead of creating a new
bt_vcp instance (since both current and previous test cases allocated
memory for bt_att object at the same address).

Getting the wrong session object leads to using wrong gatt_db, which
then uses the wrong user_data for CCC callbacks, ultimately leading
to gatt_notify_cb function from test-vcp.c getting incorrect test_data
pointer. Finally gatt_notify_cb attempts to send a notification using
an already freed bt_gatt_server instance, which unsurprisingly fails,
causing expected data to not be written into tester IO channel.

This patch fixes the issue by doing two things. First, it shuts down
tester IO as a part of test teardown, triggering disconnection
callbacks in bt_att object. One of these callbacks is registered in
vcp_get_session function, specifically vcp_disconnected function.
This function detaches bt_vcp instance (removes from sessions queue)
and triggers *_remote_client_detached callbacks. The second part of the
fix is registering vcp remote client callbacks using bt_vcp_register
function, with vcp_client_detached function responsible for unrefing
(and freeing) the detached bt_vcp instance. Since the instance is now
removed from sessions queue, vcp_get_session function can no longer
look up a wrong object during the test, allowing it to pass.

The test teardown is now split in two functions. The reason for that is
that IO disonnection callbacks are executed by main loop, thus after
io_shutdown functions were executed, we need to return to main loop
to let them execute before proceeding with teardown and freeing bt_att.
If bt_att is freed too early, its disconnection callbacks are not going
to be executed.

Kirill Samburskiy (2):
  shared/tester: add ability to shutdown tester IO
  test-vcp: free server-side bt_vcp on test teardown

 src/shared/tester.c |  6 ++++++
 src/shared/tester.h |  1 +
 unit/test-vcp.c     | 26 ++++++++++++++++++++++++--
 3 files changed, 31 insertions(+), 2 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread
* [PATCH BlueZ v2 1/4] shared/bap: ignore NULL attach/detach callbacks
@ 2025-06-20 13:51 Kirill Samburskiy
  2025-06-20 15:12 ` test-vcp: Fix test failing in some environments bluez.test.bot
  0 siblings, 1 reply; 8+ messages in thread
From: Kirill Samburskiy @ 2025-06-20 13:51 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Kirill Samburskiy

Allow registering NULL attach/detach callbacks with bt_bap_register
for cases when one of callbacks is not needed, e.g. in tests.
---
 src/shared/bap.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index f0c6f6485..76340d565 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -4415,6 +4415,9 @@ static void bap_detached(void *data, void *user_data)
 	struct bt_bap_cb *cb = data;
 	struct bt_bap *bap = user_data;
 
+	if (!cb->detached)
+		return;
+
 	cb->detached(bap, cb->user_data);
 }
 
@@ -4499,6 +4502,9 @@ static void bap_attached(void *data, void *user_data)
 	struct bt_bap_cb *cb = data;
 	struct bt_bap *bap = user_data;
 
+	if (!cb->attached)
+		return;
+
 	cb->attached(bap, cb->user_data);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-06-20 15:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-19 15:31 [PATCH BlueZ 0/2] test-vcp: Fix test failing in some environments Kirill Samburskiy
2025-06-19 15:31 ` [PATCH BlueZ 1/2] shared/tester: add ability to shutdown tester IO Kirill Samburskiy
2025-06-19 16:59   ` test-vcp: Fix test failing in some environments bluez.test.bot
2025-06-19 17:45   ` [PATCH BlueZ 1/2] shared/tester: add ability to shutdown tester IO Luiz Augusto von Dentz
2025-06-19 15:31 ` [PATCH BlueZ 2/2] test-vcp: free server-side bt_vcp on test teardown Kirill Samburskiy
2025-06-19 17:16   ` Luiz Augusto von Dentz
2025-06-19 17:54     ` Luiz Augusto von Dentz
  -- strict thread matches above, loose matches on Subject: below --
2025-06-20 13:51 [PATCH BlueZ v2 1/4] shared/bap: ignore NULL attach/detach callbacks Kirill Samburskiy
2025-06-20 15:12 ` test-vcp: Fix test failing in some environments bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox