Re: [PATCH BlueZ 2/2] test-vcp: free server-side bt_vcp on test teardown

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Kirill,

On Thu, Jun 19, 2025 at 11:34 AM Kirill Samburskiy <k.samburskiy@xxxxxx> wrote:
>
> Shutdown tester IO before freeing bt_att instance to trigger its IO
> disconnection callbacks. This detaches bt_vcp instance created by
> vcp_get_session function, and executes detach callback registered
> through bt_vcp_register that frees memory used by this bt_vcp instance.
> This prevents the test from failing in some environments.

I guess this should close the following issues:

https://github.com/bluez/bluez/issues/726
https://github.com/bluez/bluez/issues/683

> ---
>  unit/test-vcp.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/unit/test-vcp.c b/unit/test-vcp.c
> index 6a61ea2c4..04254700b 100644
> --- a/unit/test-vcp.c
> +++ b/unit/test-vcp.c
> @@ -38,6 +38,7 @@ struct test_data {
>         struct queue *ccc_states;
>         size_t iovcnt;
>         struct iovec *iov;
> +       unsigned int vcp_id;
>  };
>
>  struct notify {
> @@ -78,9 +79,9 @@ static void print_debug(const char *str, void *user_data)
>                 tester_debug("%s%s", prefix, str);
>  }
>
> -static void test_teardown(const void *user_data)
> +static gboolean test_teardown_finish(gpointer user_data)
>  {
> -       struct test_data *data = (void *)user_data;
> +       struct test_data *data = user_data;
>
>         bt_vcp_unref(data->vcp);
>         bt_gatt_server_unref(data->server);
> @@ -90,7 +91,16 @@ static void test_teardown(const void *user_data)
>
>         queue_destroy(data->ccc_states, free);
>
> +       bt_vcp_unregister(data->vcp_id);
>         tester_teardown_complete();
> +
> +       return FALSE;
> +}
> +
> +static void test_teardown(const void *user_data)
> +{
> +       tester_shutdown_io();
> +       g_idle_add(test_teardown_finish, (void *) user_data);
>  }
>
>  static bool ccc_state_match(const void *a, const void *b)
> @@ -163,6 +173,15 @@ done:
>                                                         sizeof(value));
>  }
>
> +static void vcp_client_attached(struct bt_vcp *vcp, void *user_data)
> +{
> +}
> +
> +static void vcp_client_detached(struct bt_vcp *vcp, void *user_data)
> +{
> +       bt_vcp_unref(vcp);

Hmm, are the multiple references to vcp that makes
test_teardown_finish not to free on bt_vcp_unref?

> +}
> +
>  static void test_server(const void *user_data)
>  {
>         struct test_data *data = (void *)user_data;
> @@ -188,6 +207,9 @@ static void test_server(const void *user_data)
>         data->vcp = bt_vcp_new(data->db, NULL);
>         g_assert(data->vcp);
>
> +       data->vcp_id = bt_vcp_register(vcp_client_attached,
> +                                               vcp_client_detached, NULL);
> +
>         data->server = bt_gatt_server_new(data->db, att, 64, 0);
>         g_assert(data->server);
>
> --
> 2.34.1
>
>


-- 
Luiz Augusto von Dentz





[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux