[PATCH BlueZ] rfcomm-tester: Add test to close socket while connecting

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

 



From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>

This adds Basic RFCOMM Socket Client - Close test which attempt to close
socket while connecting.
---
 tools/rfcomm-tester.c | 43 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/tools/rfcomm-tester.c b/tools/rfcomm-tester.c
index d594ebf345ce..a9adf7f0f52d 100644
--- a/tools/rfcomm-tester.c
+++ b/tools/rfcomm-tester.c
@@ -47,6 +47,7 @@ struct test_data {
 struct rfcomm_client_data {
 	uint8_t server_channel;
 	uint8_t client_channel;
+	bool close;
 	int expected_connect_err;
 	const uint8_t *send_data;
 	const uint8_t *read_data;
@@ -297,6 +298,12 @@ const struct rfcomm_client_data connect_success = {
 	.client_channel = 0x0c
 };
 
+const struct rfcomm_client_data connect_close = {
+	.server_channel = 0x0c,
+	.client_channel = 0x0c,
+	.close = true
+};
+
 const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
 
 const struct rfcomm_client_data connect_send_success = {
@@ -519,6 +526,8 @@ static gboolean rc_connect_cb(GIOChannel *io, GIOCondition cond,
 		return false;
 	}
 
+	data->io = NULL;
+
 	if (err < 0)
 		tester_test_failed();
 	else
@@ -527,6 +536,20 @@ static gboolean rc_connect_cb(GIOChannel *io, GIOCondition cond,
 	return false;
 }
 
+static gboolean rc_close_cb(GIOChannel *io, GIOCondition cond,
+							gpointer user_data)
+{
+	struct test_data *data = tester_get_data();
+
+	data->io_id = 0;
+
+	tester_print("Closed");
+
+	tester_test_passed();
+
+	return false;
+}
+
 static void client_hook_func(const void *data, uint16_t len,
 							void *user_data)
 {
@@ -627,13 +650,20 @@ static void test_connect(const void *test_data)
 	}
 
 	io = g_io_channel_unix_new(sk);
-	g_io_channel_set_close_on_unref(io, TRUE);
-
-	data->io_id = g_io_add_watch(io, G_IO_OUT, rc_connect_cb, NULL);
-
-	g_io_channel_unref(io);
 
 	tester_print("Connect in progress %d", sk);
+
+	if (cli->close) {
+		data->io_id = g_io_add_watch(io, G_IO_NVAL, rc_close_cb, NULL);
+		close(sk);
+		tester_print("Close socket %d", sk);
+	} else {
+		g_io_channel_set_close_on_unref(io, TRUE);
+		data->io_id = g_io_add_watch(io, G_IO_OUT, rc_connect_cb,
+						NULL);
+	}
+
+	g_io_channel_unref(io);
 }
 
 static gboolean server_received_data(GIOChannel *io, GIOCondition cond,
@@ -815,6 +845,9 @@ int main(int argc, char *argv[])
 				test_connect);
 	test_rfcomm("Basic RFCOMM Socket Client - Conn Refused",
 			&connect_nval, setup_powered_client, test_connect);
+	test_rfcomm("Basic RFCOMM Socket Client - Close",
+				&connect_close, setup_powered_client,
+				test_connect);
 	test_rfcomm("Basic RFCOMM Socket Server - Success", &listen_success,
 					setup_powered_server, test_server);
 	test_rfcomm("Basic RFCOMM Socket Server - Write Success",
-- 
2.37.3




[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