* [PATCH v2 1/2] l2cap-tester: Add tests for closing socket before connection completes
@ 2023-09-14 21:10 Luiz Augusto von Dentz
2023-09-14 21:10 ` [PATCH v2 2/2] l2cap-tester: Add tests for connection timeout Luiz Augusto von Dentz
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2023-09-14 21:10 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds the following tests which attempts to close/shutdown the
socket before the connection completes:
L2CAP BR/EDR Client - Close
L2CAP LE Client - Close
L2CAP Ext-Flowctl Client - Close
---
tools/l2cap-tester.c | 74 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c
index 141dd570c3f6..f4810e3eacea 100644
--- a/tools/l2cap-tester.c
+++ b/tools/l2cap-tester.c
@@ -271,6 +271,10 @@ static const struct l2cap_data client_connect_success_test = {
.server_psm = 0x1001,
};
+static const struct l2cap_data client_connect_close_test = {
+ .client_psm = 0x1001,
+};
+
static const struct l2cap_data client_connect_ssp_success_test_1 = {
.client_psm = 0x1001,
.server_psm = 0x1001,
@@ -438,6 +442,10 @@ static const struct l2cap_data le_client_connect_success_test_1 = {
.server_psm = 0x0080,
};
+static const struct l2cap_data le_client_connect_close_test_1 = {
+ .client_psm = 0x0080,
+};
+
static const struct l2cap_data le_client_connect_adv_success_test_1 = {
.client_psm = 0x0080,
.server_psm = 0x0080,
@@ -678,6 +686,11 @@ static const struct l2cap_data ext_flowctl_client_connect_success_test_1 = {
.mode = BT_MODE_EXT_FLOWCTL,
};
+static const struct l2cap_data ext_flowctl_client_connect_close_test_1 = {
+ .client_psm = 0x0080,
+ .mode = BT_MODE_EXT_FLOWCTL,
+};
+
static const struct l2cap_data ext_flowctl_client_connect_adv_success_test_1 = {
.client_psm = 0x0080,
.server_psm = 0x0080,
@@ -1094,6 +1107,10 @@ static gboolean socket_closed_cb(GIOChannel *io, GIOCondition cond,
{
struct test_data *data = tester_get_data();
const struct l2cap_data *l2data = data->test_data;
+ int err, sk_err, sk;
+ socklen_t len = sizeof(sk_err);
+
+ tester_print("Disconnected");
if (l2data->shut_sock_wr) {
/* if socket is closed using SHUT_WR, L2CAP disconnection
@@ -1107,6 +1124,20 @@ static gboolean socket_closed_cb(GIOChannel *io, GIOCondition cond,
}
}
+ data->io_id = 0;
+
+ sk = g_io_channel_unix_get_fd(io);
+
+ if (getsockopt(sk, SOL_SOCKET, SO_ERROR, &sk_err, &len) < 0)
+ err = -errno;
+ else
+ err = -sk_err;
+
+ if (-err != l2data->expect_err)
+ tester_test_failed();
+ else
+ tester_test_passed();
+
return FALSE;
}
@@ -1454,6 +1485,38 @@ static void test_connect(const void *test_data)
tester_print("Connect in progress");
}
+static void test_connect_close(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+ const struct l2cap_data *l2data = data->test_data;
+ GIOChannel *io;
+ int sk;
+
+ sk = create_l2cap_sock(data, 0, l2data->cid, l2data->sec_level,
+ l2data->mode);
+ if (sk < 0) {
+ if (sk == -ENOPROTOOPT)
+ tester_test_abort();
+ else
+ tester_test_failed();
+ return;
+ }
+
+ if (connect_l2cap_sock(data, sk, l2data->client_psm,
+ l2data->cid) < 0) {
+ close(sk);
+ tester_test_failed();
+ return;
+ }
+
+ 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_HUP, socket_closed_cb, NULL);
+ g_io_channel_unref(io);
+
+ shutdown(sk, SHUT_RDWR);
+}
+
static void test_connect_reject(const void *test_data)
{
struct test_data *data = tester_get_data();
@@ -2122,6 +2185,11 @@ int main(int argc, char *argv[])
&client_connect_success_test,
setup_powered_client, test_connect);
+ test_l2cap_bredr("L2CAP BR/EDR Client - Close",
+ &client_connect_close_test,
+ setup_powered_client,
+ test_connect_close);
+
test_l2cap_bredr("L2CAP BR/EDR Client SSP - Success 1",
&client_connect_ssp_success_test_1,
setup_powered_client, test_connect);
@@ -2188,6 +2256,9 @@ int main(int argc, char *argv[])
test_l2cap_le("L2CAP LE Client - Success",
&le_client_connect_success_test_1,
setup_powered_client, test_connect);
+ test_l2cap_le("L2CAP LE Client - Close",
+ &le_client_connect_close_test_1,
+ setup_powered_client, test_connect_close);
test_l2cap_le("L2CAP LE Client, Direct Advertising - Success",
&le_client_connect_adv_success_test_1,
setup_powered_client, test_connect);
@@ -2233,6 +2304,9 @@ int main(int argc, char *argv[])
test_l2cap_le("L2CAP Ext-Flowctl Client - Success",
&ext_flowctl_client_connect_success_test_1,
setup_powered_client, test_connect);
+ test_l2cap_le("L2CAP Ext-Flowctl Client - Close",
+ &ext_flowctl_client_connect_close_test_1,
+ setup_powered_client, test_connect_close);
test_l2cap_le("L2CAP Ext-Flowctl Client, Direct Advertising - Success",
&ext_flowctl_client_connect_adv_success_test_1,
setup_powered_client, test_connect);
--
2.41.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] l2cap-tester: Add tests for connection timeout
2023-09-14 21:10 [PATCH v2 1/2] l2cap-tester: Add tests for closing socket before connection completes Luiz Augusto von Dentz
@ 2023-09-14 21:10 ` Luiz Augusto von Dentz
2023-09-14 22:57 ` [v2,1/2] l2cap-tester: Add tests for closing socket before connection completes bluez.test.bot
2023-09-15 19:50 ` [PATCH v2 1/2] " patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2023-09-14 21:10 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds the following tests which attempts to use SO_SNDTIMEO so the
socket times out before the connection completes:
L2CAP BR/EDR Client - Timeout
L2CAP LE Client - Timeout
L2CAP Ext-Flowctl Client - Timeout
---
tools/l2cap-tester.c | 82 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 80 insertions(+), 2 deletions(-)
diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c
index f4810e3eacea..461f2c27c456 100644
--- a/tools/l2cap-tester.c
+++ b/tools/l2cap-tester.c
@@ -52,6 +52,7 @@ struct l2cap_data {
uint16_t cid;
uint8_t mode;
int expect_err;
+ int timeout;
uint8_t send_cmd_code;
const void *send_cmd;
@@ -275,6 +276,11 @@ static const struct l2cap_data client_connect_close_test = {
.client_psm = 0x1001,
};
+static const struct l2cap_data client_connect_timeout_test = {
+ .client_psm = 0x1001,
+ .timeout = 1
+};
+
static const struct l2cap_data client_connect_ssp_success_test_1 = {
.client_psm = 0x1001,
.server_psm = 0x1001,
@@ -446,6 +452,11 @@ static const struct l2cap_data le_client_connect_close_test_1 = {
.client_psm = 0x0080,
};
+static const struct l2cap_data le_client_connect_timeout_test_1 = {
+ .client_psm = 0x0080,
+ .timeout = 1,
+};
+
static const struct l2cap_data le_client_connect_adv_success_test_1 = {
.client_psm = 0x0080,
.server_psm = 0x0080,
@@ -691,6 +702,12 @@ static const struct l2cap_data ext_flowctl_client_connect_close_test_1 = {
.mode = BT_MODE_EXT_FLOWCTL,
};
+static const struct l2cap_data ext_flowctl_client_connect_timeout_test_1 = {
+ .client_psm = 0x0080,
+ .mode = BT_MODE_EXT_FLOWCTL,
+ .timeout = 1,
+};
+
static const struct l2cap_data ext_flowctl_client_connect_adv_success_test_1 = {
.client_psm = 0x0080,
.server_psm = 0x0080,
@@ -793,6 +810,11 @@ static void setup_powered_client_callback(uint8_t status, uint16_t length,
tester_print("Controller powered on");
+ if (l2data && l2data->timeout) {
+ tester_setup_complete();
+ return;
+ }
+
bthost = hciemu_client_get_host(data->hciemu);
bthost_set_cmd_complete_cb(bthost, client_cmd_complete, user_data);
@@ -1133,9 +1155,11 @@ static gboolean socket_closed_cb(GIOChannel *io, GIOCondition cond,
else
err = -sk_err;
- if (-err != l2data->expect_err)
+ if (!l2data->timeout && -err != l2data->expect_err) {
+ tester_print("err %d != %d expected_err", -err,
+ l2data->expect_err);
tester_test_failed();
- else
+ } else
tester_test_passed();
return FALSE;
@@ -1517,6 +1541,50 @@ static void test_connect_close(const void *test_data)
shutdown(sk, SHUT_RDWR);
}
+static void test_connect_timeout(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+ const struct l2cap_data *l2data = data->test_data;
+ GIOChannel *io;
+ int sk;
+ struct timeval sndto;
+ socklen_t len;
+
+ sk = create_l2cap_sock(data, 0, l2data->cid, l2data->sec_level,
+ l2data->mode);
+ if (sk < 0) {
+ if (sk == -ENOPROTOOPT)
+ tester_test_abort();
+ else
+ tester_test_failed();
+ return;
+ }
+
+ memset(&sndto, 0, sizeof(sndto));
+
+ sndto.tv_sec = l2data->timeout;
+ len = sizeof(sndto);
+ if (setsockopt(sk, SOL_SOCKET, SO_SNDTIMEO, &sndto, len) < 0) {
+ tester_print("Can't set SO_SNDTIMEO: %s (%d)", strerror(errno),
+ errno);
+ close(sk);
+ tester_test_failed();
+ return;
+ }
+
+ if (connect_l2cap_sock(data, sk, l2data->client_psm,
+ l2data->cid) < 0) {
+ close(sk);
+ tester_test_failed();
+ return;
+ }
+
+ 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_HUP, socket_closed_cb, NULL);
+ g_io_channel_unref(io);
+}
+
static void test_connect_reject(const void *test_data)
{
struct test_data *data = tester_get_data();
@@ -2189,6 +2257,10 @@ int main(int argc, char *argv[])
&client_connect_close_test,
setup_powered_client,
test_connect_close);
+ test_l2cap_bredr("L2CAP BR/EDR Client - Timeout",
+ &client_connect_timeout_test,
+ setup_powered_client,
+ test_connect_timeout);
test_l2cap_bredr("L2CAP BR/EDR Client SSP - Success 1",
&client_connect_ssp_success_test_1,
@@ -2259,6 +2331,9 @@ int main(int argc, char *argv[])
test_l2cap_le("L2CAP LE Client - Close",
&le_client_connect_close_test_1,
setup_powered_client, test_connect_close);
+ test_l2cap_le("L2CAP LE Client - Timeout",
+ &le_client_connect_timeout_test_1,
+ setup_powered_client, test_connect_timeout);
test_l2cap_le("L2CAP LE Client, Direct Advertising - Success",
&le_client_connect_adv_success_test_1,
setup_powered_client, test_connect);
@@ -2307,6 +2382,9 @@ int main(int argc, char *argv[])
test_l2cap_le("L2CAP Ext-Flowctl Client - Close",
&ext_flowctl_client_connect_close_test_1,
setup_powered_client, test_connect_close);
+ test_l2cap_le("L2CAP Ext-Flowctl Client - Timeout",
+ &ext_flowctl_client_connect_timeout_test_1,
+ setup_powered_client, test_connect_timeout);
test_l2cap_le("L2CAP Ext-Flowctl Client, Direct Advertising - Success",
&ext_flowctl_client_connect_adv_success_test_1,
setup_powered_client, test_connect);
--
2.41.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [v2,1/2] l2cap-tester: Add tests for closing socket before connection completes
2023-09-14 21:10 [PATCH v2 1/2] l2cap-tester: Add tests for closing socket before connection completes Luiz Augusto von Dentz
2023-09-14 21:10 ` [PATCH v2 2/2] l2cap-tester: Add tests for connection timeout Luiz Augusto von Dentz
@ 2023-09-14 22:57 ` bluez.test.bot
2023-09-15 19:50 ` [PATCH v2 1/2] " patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2023-09-14 22:57 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
[-- Attachment #1: Type: text/plain, Size: 948 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=784343
---Test result---
Test Summary:
CheckPatch PASS 1.01 seconds
GitLint PASS 0.59 seconds
BuildEll PASS 29.02 seconds
BluezMake PASS 990.55 seconds
MakeCheck PASS 12.45 seconds
MakeDistcheck PASS 163.39 seconds
CheckValgrind PASS 261.03 seconds
CheckSmatch PASS 369.51 seconds
bluezmakeextell PASS 109.74 seconds
IncrementalBuild PASS 1706.63 seconds
ScanBuild PASS 1133.44 seconds
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] l2cap-tester: Add tests for closing socket before connection completes
2023-09-14 21:10 [PATCH v2 1/2] l2cap-tester: Add tests for closing socket before connection completes Luiz Augusto von Dentz
2023-09-14 21:10 ` [PATCH v2 2/2] l2cap-tester: Add tests for connection timeout Luiz Augusto von Dentz
2023-09-14 22:57 ` [v2,1/2] l2cap-tester: Add tests for closing socket before connection completes bluez.test.bot
@ 2023-09-15 19:50 ` patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+bluetooth @ 2023-09-15 19:50 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hello:
This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Thu, 14 Sep 2023 14:10:02 -0700 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> This adds the following tests which attempts to close/shutdown the
> socket before the connection completes:
>
> L2CAP BR/EDR Client - Close
> L2CAP LE Client - Close
> L2CAP Ext-Flowctl Client - Close
>
> [...]
Here is the summary with links:
- [v2,1/2] l2cap-tester: Add tests for closing socket before connection completes
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d46f91c5be57
- [v2,2/2] l2cap-tester: Add tests for connection timeout
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7b9d2f3c7634
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-15 19:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-14 21:10 [PATCH v2 1/2] l2cap-tester: Add tests for closing socket before connection completes Luiz Augusto von Dentz
2023-09-14 21:10 ` [PATCH v2 2/2] l2cap-tester: Add tests for connection timeout Luiz Augusto von Dentz
2023-09-14 22:57 ` [v2,1/2] l2cap-tester: Add tests for closing socket before connection completes bluez.test.bot
2023-09-15 19:50 ` [PATCH v2 1/2] " patchwork-bot+bluetooth
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.