From: Andrei Emeltchenko <[email protected]>
For the socket listen() call parameters channel and uuid cannot be both
zeroes.
---
android/android-tester.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/android/android-tester.c b/android/android-tester.c
index a50ed7b..3f763d8 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -716,6 +716,16 @@ static const struct socket_data btsock_inv_param_socktype_l2cap = {
.expected_status = BT_STATUS_UNSUPPORTED,
};
+/* Test invalid: channel & uuid are both zeroes */
+static const struct socket_data btsock_inv_params_chan_uuid = {
+ .sock_type = BTSOCK_RFCOMM,
+ .channel = 0,
+ .service_uuid = NULL,
+ .service_name = "Test service",
+ .flags = 0,
+ .expected_status = BT_STATUS_PARM_INVALID,
+};
+
static void setup_socket_interface(const void *test_data)
{
struct test_data *data = tester_get_data();
@@ -795,5 +805,9 @@ int main(int argc, char *argv[])
&btsock_inv_param_socktype_l2cap,
setup_socket_interface, test_generic_listen, teardown);
+ test_bredrle("Test Socket Listen - Invalid: chan, uuid",
+ &btsock_inv_params_chan_uuid,
+ setup_socket_interface, test_generic_listen, teardown);
+
return tester_run();
}
--
1.8.3.2
Hi Andrei,
On Thu, Dec 12, 2013, Andrei Emeltchenko wrote:
> For the socket listen() call parameters channel and uuid cannot be both
> zeroes.
> ---
> android/android-tester.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
All patches in this set have been applied. Thanks.
Johan
Hi Andrei,
On Thu, Dec 12, 2013, Andrei Emeltchenko wrote:
> We close file descriptors in cleanup_rfsock() and leaving the default
> value gives us glib warnings if we close fd already and got G_IO_NVAL in
> server_cb from bt_io.
> ---
> android/socket.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/android/socket.c b/android/socket.c
> index 5e8f8e5..9d759be 100644
> --- a/android/socket.c
> +++ b/android/socket.c
> @@ -736,6 +736,7 @@ static void handle_listen(const void *buf, uint16_t len)
> rfsock->real_sock = g_io_channel_unix_get_fd(io);
>
> g_io_channel_unref(io);
> + g_io_channel_set_close_on_unref(io, FALSE);
Strictly speaking this function is not allowed to touch "io" after it
drops its own reference to it, i.e. these calls should be in the
opposite order. I fixed it up myself this time.
Johan
From: Andrei Emeltchenko <[email protected]>
---
android/android-tester.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/android/android-tester.c b/android/android-tester.c
index 4a96fb8..a6fbcb5 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -71,6 +71,7 @@ struct socket_data {
btsock_type_t sock_type;
const char *service_name;
const uint8_t *service_uuid;
+ const bt_bdaddr_t *bdaddr;
int channel;
int flags;
bt_status_t expected_status;
@@ -699,7 +700,12 @@ static void test_dummy(const void *test_data)
/* Test Socket HAL */
+const bt_bdaddr_t bdaddr_dummy = {
+ .address = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55}
+};
+
static const struct socket_data btsock_inv_param_socktype = {
+ .bdaddr = &bdaddr_dummy,
.sock_type = 0,
.channel = 1,
.service_uuid = NULL,
@@ -780,6 +786,34 @@ clean:
close(sock_fd);
}
+static void test_generic_connect(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+ const struct socket_data *test = data->test_data;
+ bt_status_t status;
+ int sock_fd = -1;
+
+ status = data->if_sock->connect(test->bdaddr, test->sock_type,
+ test->service_uuid, test->channel,
+ &sock_fd, test->flags);
+ if (status != test->expected_status) {
+ tester_test_failed();
+ goto clean;
+ }
+
+ /* Check that file descriptor is valid */
+ if (status == BT_STATUS_SUCCESS && fcntl(sock_fd, F_GETFD) == -1) {
+ tester_test_failed();
+ return;
+ }
+
+ tester_test_passed();
+
+clean:
+ if (sock_fd >= 0)
+ close(sock_fd);
+}
+
#define test_bredrle(name, data, test_setup, test, test_teardown) \
do { \
struct test_data *user; \
@@ -829,5 +863,9 @@ int main(int argc, char *argv[])
&btsock_sucess,
setup_socket_interface, test_generic_listen, teardown);
+ test_bredrle("Test Socket Connect - Invalid: sock_type 0",
+ &btsock_inv_param_socktype, setup_socket_interface,
+ test_generic_connect, teardown);
+
return tester_run();
}
--
1.8.3.2
From: Andrei Emeltchenko <[email protected]>
For the successful test case check that file descriptor is valid through
fcntl which is cheap way.
---
android/android-tester.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/android/android-tester.c b/android/android-tester.c
index 3f763d8..2bb7d73 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <unistd.h>
+#include <fcntl.h>
#include <glib.h>
#include <sys/socket.h>
@@ -757,6 +758,12 @@ static void test_generic_listen(const void *test_data)
goto clean;
}
+ /* Check that file descriptor is valid */
+ if (status == BT_STATUS_SUCCESS && fcntl(sock_fd, F_GETFD) == -1) {
+ tester_test_failed();
+ return;
+ }
+
tester_test_passed();
clean:
--
1.8.3.2
From: Andrei Emeltchenko <[email protected]>
We close file descriptors in cleanup_rfsock() and leaving the default
value gives us glib warnings if we close fd already and got G_IO_NVAL in
server_cb from bt_io.
---
android/socket.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/android/socket.c b/android/socket.c
index 5e8f8e5..9d759be 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -736,6 +736,7 @@ static void handle_listen(const void *buf, uint16_t len)
rfsock->real_sock = g_io_channel_unix_get_fd(io);
g_io_channel_unref(io);
+ g_io_channel_set_close_on_unref(io, FALSE);
DBG("real_sock %d fd %d hal_fd %d", rfsock->real_sock, rfsock->fd,
hal_fd);
--
1.8.3.2
From: Andrei Emeltchenko <[email protected]>
Check that Socket listen() returns valid file descriptor
---
android/android-tester.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/android/android-tester.c b/android/android-tester.c
index bb3f883..4a96fb8 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -727,6 +727,15 @@ static const struct socket_data btsock_inv_params_chan_uuid = {
.expected_status = BT_STATUS_PARM_INVALID,
};
+static const struct socket_data btsock_sucess = {
+ .sock_type = BTSOCK_RFCOMM,
+ .channel = 1,
+ .service_uuid = NULL,
+ .service_name = "Test service",
+ .flags = 0,
+ .expected_status = BT_STATUS_SUCCESS,
+};
+
static void setup_socket_interface(const void *test_data)
{
struct test_data *data = tester_get_data();
@@ -816,5 +825,9 @@ int main(int argc, char *argv[])
&btsock_inv_params_chan_uuid,
setup_socket_interface, test_generic_listen, teardown);
+ test_bredrle("Test Socket Listen - Check returned fd valid",
+ &btsock_sucess,
+ setup_socket_interface, test_generic_listen, teardown);
+
return tester_run();
}
--
1.8.3.2
From: Andrei Emeltchenko <[email protected]>
---
android/android-tester.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/android/android-tester.c b/android/android-tester.c
index a6fbcb5..7518f98 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -715,6 +715,7 @@ static const struct socket_data btsock_inv_param_socktype = {
};
static const struct socket_data btsock_inv_param_socktype_l2cap = {
+ .bdaddr = &bdaddr_dummy,
.sock_type = BTSOCK_L2CAP,
.channel = 1,
.service_uuid = NULL,
@@ -867,5 +868,9 @@ int main(int argc, char *argv[])
&btsock_inv_param_socktype, setup_socket_interface,
test_generic_connect, teardown);
+ test_bredrle("Test Socket Connect - Invalid: sock_type L2CAP",
+ &btsock_inv_param_socktype_l2cap,
+ setup_socket_interface, test_generic_connect, teardown);
+
return tester_run();
}
--
1.8.3.2
From: Andrei Emeltchenko <[email protected]>
---
android/android-tester.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/android/android-tester.c b/android/android-tester.c
index 2bb7d73..bb3f883 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -804,11 +804,11 @@ int main(int argc, char *argv[])
test_bredrle("Test Socket Init", NULL, setup_socket_interface,
test_dummy, teardown);
- test_bredrle("Test Socket Listen - Invalid sock type",
+ test_bredrle("Test Socket Listen - Invalid: sock_type 0",
&btsock_inv_param_socktype, setup_socket_interface,
test_generic_listen, teardown);
- test_bredrle("Test Socket Listen - Invalid: L2CAP",
+ test_bredrle("Test Socket Listen - Invalid: sock_type L2CAP",
&btsock_inv_param_socktype_l2cap,
setup_socket_interface, test_generic_listen, teardown);
--
1.8.3.2
From: Andrei Emeltchenko <[email protected]>
For socket type 0 we shall return BT_STATUS_PARM_INVALID.
---
android/hal-sock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/android/hal-sock.c b/android/hal-sock.c
index 301c77f..c39ca6a 100644
--- a/android/hal-sock.c
+++ b/android/hal-sock.c
@@ -81,7 +81,7 @@ static bt_status_t sock_connect(const bt_bdaddr_t *bdaddr, btsock_type_t type,
{
struct hal_cmd_sock_connect cmd;
- if ((!uuid && chan <= 0) || !bdaddr || !sock) {
+ if ((!uuid && chan <= 0) || !bdaddr || !sock || !type) {
error("Invalid params: bd_addr %s, uuid %s, chan %d, sock %p",
bdaddr2str(bdaddr), btuuid2str(uuid), chan, sock);
return BT_STATUS_PARM_INVALID;
--
1.8.3.2