From ea28bc766c7c3c20635c158a518da8dfc0d74758 Mon Sep 17 00:00:00 2001 From: borine <32966433+borine@users.noreply.github.com> Date: Sun, 15 Sep 2024 21:21:21 +0200 Subject: [PATCH] Fix bluealsactl monitor after changes in 0d488c7 Closes #729 Co-authored-by: Arkadiusz Bokowy --- src/bluealsactl/cmd-monitor.c | 18 ++++++++++++++---- test/mock/mock-bluez.c | 13 +++++++++++++ test/test-alsa-ctl.c | 5 ++++- test/test-utils-ctl.c | 6 +++++- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/bluealsactl/cmd-monitor.c b/src/bluealsactl/cmd-monitor.c index 1cdeb3419..8800d58ac 100644 --- a/src/bluealsactl/cmd-monitor.c +++ b/src/bluealsactl/cmd-monitor.c @@ -95,11 +95,21 @@ static dbus_bool_t monitor_dbus_message_iter_get_pcm_props_cb(const char *key, } else if (monitor_properties_set[PROPERTY_VOLUME].enabled && strcmp(key, monitor_properties_set[PROPERTY_VOLUME].name) == 0) { - if (type != (type_expected = DBUS_TYPE_UINT16)) + if (type != (type_expected = DBUS_TYPE_ARRAY)) goto fail; - dbus_uint16_t volume; - dbus_message_iter_get_basic(&variant, &volume); - printf("PropertyChanged %s Volume 0x%.4X\n", path, volume); + + DBusMessageIter iter; + uint8_t *data; + int len; + + dbus_message_iter_recurse(&variant, &iter); + dbus_message_iter_get_fixed_array(&iter, &data, &len); + + printf("PropertyChanged %s Volume", path); + for (size_t i = 0; i < (size_t)len; i++) + printf(" %u%s", data[i] & 0x7f, data[i] & 0x80 ? "(M)" : ""); + printf("\n"); + } return TRUE; diff --git a/test/mock/mock-bluez.c b/test/mock/mock-bluez.c index d8a17be3c..0c63db041 100644 --- a/test/mock/mock-bluez.c +++ b/test/mock/mock-bluez.c @@ -297,6 +297,15 @@ int mock_bluez_device_profile_new_connection(const char *device_path, return 0; } +static gboolean mock_bluez_media_transport_fuzz(void *userdata) { + MockBluezMediaTransport1 *transport = userdata; + /* Pseudo-random hash based on the device path to simulate different values. */ + unsigned int hash = g_str_hash(mock_bluez_media_transport1_get_device(transport)); + mock_bluez_media_transport1_set_delay(transport, hash % 2777); + mock_bluez_media_transport1_set_volume(transport, hash % 101); + return G_SOURCE_REMOVE; +} + static void mock_bluez_media_endpoint_set_configuration_finish(GObject *source, GAsyncResult *result, G_GNUC_UNUSED void *userdata) { MockBluezMediaEndpoint1 *endpoint = MOCK_BLUEZ_MEDIA_ENDPOINT1(source); @@ -343,6 +352,10 @@ int mock_bluez_device_media_set_configuration(const char *device_path, if (strcmp(uuid, BT_UUID_A2DP_SINK) == 0) mock_bluez_media_transport1_set_state(transport, "pending"); + /* If fuzzing is enabled, update some properties after slight delay. */ + if (mock_fuzzing_ms) + g_timeout_add(mock_fuzzing_ms, mock_bluez_media_transport_fuzz, transport); + rv = 0; break; } diff --git a/test/test-alsa-ctl.c b/test/test-alsa-ctl.c index 0aadb5b3f..5ef1c1bd4 100644 --- a/test/test-alsa-ctl.c +++ b/test/test-alsa-ctl.c @@ -535,12 +535,15 @@ CK_START_TEST(test_notifications) { /* Processed events: * - 0 removes; 2 new elems (12:34:... A2DP) + * - 4 updates per new A2DP (updated delay and volume) * - 2 removes; 4 new elems (12:34:... A2DP, 23:45:... A2DP) + * - 4 updates per new A2DP (updated delay and volume) * - 4 removes; 7 new elems (2x A2DP, SCO playback, battery) * - 7 removes; 9 new elems (2x A2DP, SCO playback/capture, battery) * - 4 updates per codec (SCO codec updates if codec selection is supported) */ - size_t expected_events = (0 + 2) + (2 + 4) + (4 + 7) + (7 + 9) + events_update_codec; + size_t expected_events = + (0 + 2) + 4 + (2 + 4) + 4 + (4 + 7) + (7 + 9) + events_update_codec; /* XXX: It is possible that the battery element (RFCOMM D-Bus path) will not * be exported in time. In such case, the number of events will be less diff --git a/test/test-utils-ctl.c b/test/test-utils-ctl.c index b81429141..f57733bd1 100644 --- a/test/test-utils-ctl.c +++ b/test/test-utils-ctl.c @@ -408,8 +408,12 @@ CK_START_TEST(test_monitor) { ck_assert_ptr_ne(strstr(output, "Device: /org/bluez/hci11/dev_23_45_67_89_AB_CD"), NULL); -#if ENABLE_MSBC /* notifications for property changed */ + ck_assert_ptr_ne(strstr(output, + "PropertyChanged /org/bluealsa/hci11/dev_12_34_56_78_9A_BC/a2dpsrc/sink Volume 54 54"), NULL); + ck_assert_ptr_ne(strstr(output, + "PropertyChanged /org/bluealsa/hci11/dev_23_45_67_89_AB_CD/a2dpsrc/sink Volume 84 84"), NULL); +#if ENABLE_MSBC ck_assert_ptr_ne(strstr(output, "PropertyChanged /org/bluealsa/hci11/dev_12_34_56_78_9A_BC/hfpag/sink Codec CVSD"), NULL); ck_assert_ptr_ne(strstr(output,