summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-09-13 16:32:38 -0700
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-09-13 16:32:38 -0700
commitb632ec3f3240aef4b68360085f330b6e50c9ec3b (patch)
treed13b9362257999d15eb7f64f94e2df73ced33ee8 /tools
parent877b88c5f2e92dd8a6a2f98ee4a25c4c30ddd887 (diff)
downloadbluez-b632ec3f3240aef4b68360085f330b6e50c9ec3b.tar.gz
rfcomm-tester: Add test to close socket while connecting
This adds Basic RFCOMM Socket Client - Close test which attempt to close socket while connecting.
Diffstat (limited to 'tools')
-rw-r--r--tools/rfcomm-tester.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/tools/rfcomm-tester.c b/tools/rfcomm-tester.c
index d594ebf34..a9adf7f0f 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);
+ 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);
-
- tester_print("Connect in progress %d", sk);
}
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",