public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/4] sco-tester: add timeout / close during connection tests
@ 2025-11-29 16:40 Pauli Virtanen
  2025-11-29 16:41 ` [PATCH BlueZ 2/4] btdev: implement Sync Conn Accept/Reject flow Pauli Virtanen
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Pauli Virtanen @ 2025-11-29 16:40 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pauli Virtanen

Add tests for connect timeout behavior and kernel corner cases:

eSCO CVSD - Timeout
eSCO CVSD - Close
---

Notes:
    Resend.

 tools/sco-tester.c | 77 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 70 insertions(+), 7 deletions(-)

diff --git a/tools/sco-tester.c b/tools/sco-tester.c
index d2ab51b35..660f36e07 100644
--- a/tools/sco-tester.c
+++ b/tools/sco-tester.c
@@ -56,9 +56,15 @@ struct sco_client_data {
 	const uint8_t *send_data;
 	uint16_t data_len;
 
+	/* Connect timeout */
+	unsigned int connect_timeout_us;
+
 	/* Shutdown socket after connect */
 	bool shutdown;
 
+	/* Close socket after connect */
+	bool close_after_connect;
+
 	/* Enable SO_TIMESTAMPING with these flags */
 	uint32_t so_timestamping;
 
@@ -247,7 +253,7 @@ static void test_data_free(void *test_data)
 }
 
 #define test_sco_full(name, data, setup, func, _disable_esco, _enable_codecs, \
-							_disable_sco_flowctl) \
+					_disable_sco_flowctl, _timeout) \
 	do { \
 		struct test_data *user; \
 		user = malloc(sizeof(struct test_data)); \
@@ -264,28 +270,39 @@ static void test_data_free(void *test_data)
 		user->disable_sco_flowctl = _disable_sco_flowctl; \
 		tester_add_full(name, data, \
 				test_pre_setup, setup, func, NULL, \
-				test_post_teardown, 2, user, test_data_free); \
+				test_post_teardown, _timeout, user, \
+				test_data_free); \
 	} while (0)
 
 #define test_sco(name, data, setup, func) \
-	test_sco_full(name, data, setup, func, false, false, false)
+	test_sco_full(name, data, setup, func, false, false, false, 2)
 
 #define test_sco_no_flowctl(name, data, setup, func) \
-	test_sco_full(name, data, setup, func, false, false, true)
+	test_sco_full(name, data, setup, func, false, false, true, 2)
 
 #define test_sco_11(name, data, setup, func) \
-	test_sco_full(name, data, setup, func, true, false, false)
+	test_sco_full(name, data, setup, func, true, false, false, 2)
 
 #define test_sco_11_no_flowctl(name, data, setup, func) \
-	test_sco_full(name, data, setup, func, true, false, true)
+	test_sco_full(name, data, setup, func, true, false, true, 2)
 
 #define test_offload_sco(name, data, setup, func) \
-	test_sco_full(name, data, setup, func, false, true, false)
+	test_sco_full(name, data, setup, func, false, true, false, 2)
 
 static const struct sco_client_data connect_success = {
 	.expect_err = 0
 };
 
+static const struct sco_client_data connect_timeout = {
+	.expect_err = ETIMEDOUT,
+	.connect_timeout_us = 1,
+};
+
+/* Check timeout handling if closed before connect finishes */
+static const struct sco_client_data connect_close = {
+	.close_after_connect = true,
+};
+
 static const struct sco_client_data disconnect_success = {
 	.expect_err = 0,
 	.shutdown = true,
@@ -684,6 +701,7 @@ end:
 
 static int create_sco_sock(struct test_data *data)
 {
+	const struct sco_client_data *scodata = data->test_data;
 	const uint8_t *central_bdaddr;
 	struct sockaddr_sco addr;
 	int sk, err;
@@ -697,6 +715,19 @@ static int create_sco_sock(struct test_data *data)
 		return err;
 	}
 
+	if (scodata->connect_timeout_us) {
+		struct timeval timeout = {
+			.tv_sec = scodata->connect_timeout_us / 1000000,
+			.tv_usec = scodata->connect_timeout_us % 1000000
+		};
+
+		if (setsockopt(sk, SOL_SOCKET, SO_SNDTIMEO,
+					(void *)&timeout, sizeof(timeout))) {
+			tester_warn("failed to set timeout: %m");
+			return -EINVAL;
+		}
+	}
+
 	central_bdaddr = hciemu_get_central_bdaddr(data->hciemu);
 	if (!central_bdaddr) {
 		tester_warn("No central bdaddr");
@@ -923,6 +954,7 @@ static gboolean sco_connect_cb(GIOChannel *io, GIOCondition cond,
 static void test_connect(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
+	const struct sco_client_data *scodata = data->test_data;
 	GIOChannel *io;
 	int sk;
 
@@ -938,6 +970,12 @@ static void test_connect(const void *test_data)
 		return;
 	}
 
+	if (scodata->close_after_connect) {
+		close(sk);
+		tester_test_passed();
+		return;
+	}
+
 	data->sk = sk;
 
 	io = g_io_channel_unix_new(sk);
@@ -1036,6 +1074,25 @@ end:
 	close(sk);
 }
 
+static bool hook_delay_evt(const void *msg, uint16_t len, void *user_data)
+{
+	tester_print("Delaying emulator response...");
+	g_usleep(500000);
+	tester_print("Delaying emulator response... Done.");
+	return true;
+}
+
+static void test_connect_delayed(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+
+	hciemu_add_hook(data->hciemu, HCIEMU_HOOK_POST_EVT,
+					BT_HCI_EVT_SYNC_CONN_COMPLETE,
+					hook_delay_evt, NULL);
+
+	test_connect(test_data);
+}
+
 static bool hook_setup_sync_evt(const void *buf, uint16_t len, void *user_data)
 {
 	struct test_data *data = tester_get_data();
@@ -1201,6 +1258,12 @@ int main(int argc, char *argv[])
 	test_sco("eSCO CVSD - Success", &connect_success, setup_powered,
 							test_connect);
 
+	test_sco_full("eSCO CVSD - Timeout", &connect_timeout, setup_powered,
+				test_connect_delayed, false, false, false, 8);
+
+	test_sco("eSCO CVSD - Close", &connect_close, setup_powered,
+						test_connect_delayed);
+
 	test_sco("eSCO mSBC - Success", &connect_success, setup_powered,
 							test_connect_transp);
 
-- 
2.51.1


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

end of thread, other threads:[~2025-12-02 14:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-29 16:40 [PATCH BlueZ 1/4] sco-tester: add timeout / close during connection tests Pauli Virtanen
2025-11-29 16:41 ` [PATCH BlueZ 2/4] btdev: implement Sync Conn Accept/Reject flow Pauli Virtanen
2025-11-29 16:41 ` [PATCH BlueZ 3/4] bthost: add bthost_setup_sco() and accept incoming eSCO Pauli Virtanen
2025-11-29 16:41 ` [PATCH BlueZ 4/4] sco-tester: add socket listen tests Pauli Virtanen
2025-11-29 17:36 ` [BlueZ,1/4] sco-tester: add timeout / close during connection tests bluez.test.bot
2025-12-02 14:30 ` [PATCH BlueZ 1/4] " patchwork-bot+bluetooth

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