linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid
@ 2013-12-12 15:17 Andrei Emeltchenko
  2013-12-12 15:17 ` [PATCH 2/8] android/tester: Check that fd is valid for Success case Andrei Emeltchenko
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Andrei Emeltchenko @ 2013-12-12 15:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


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

* [PATCH 2/8] android/tester: Check that fd is valid for Success case
  2013-12-12 15:17 [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Andrei Emeltchenko
@ 2013-12-12 15:17 ` Andrei Emeltchenko
  2013-12-12 15:17 ` [PATCH 3/8] android/tester: trivial: Make test cases prints look nice Andrei Emeltchenko
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrei Emeltchenko @ 2013-12-12 15:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


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

* [PATCH 3/8] android/tester: trivial: Make test cases prints look nice
  2013-12-12 15:17 [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Andrei Emeltchenko
  2013-12-12 15:17 ` [PATCH 2/8] android/tester: Check that fd is valid for Success case Andrei Emeltchenko
@ 2013-12-12 15:17 ` Andrei Emeltchenko
  2013-12-12 15:17 ` [PATCH 4/8] android/tester: Add Socket test success with valid fd Andrei Emeltchenko
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrei Emeltchenko @ 2013-12-12 15:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

---
 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


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

* [PATCH 4/8] android/tester: Add Socket test success with valid fd
  2013-12-12 15:17 [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Andrei Emeltchenko
  2013-12-12 15:17 ` [PATCH 2/8] android/tester: Check that fd is valid for Success case Andrei Emeltchenko
  2013-12-12 15:17 ` [PATCH 3/8] android/tester: trivial: Make test cases prints look nice Andrei Emeltchenko
@ 2013-12-12 15:17 ` Andrei Emeltchenko
  2013-12-12 15:17 ` [PATCH 5/8] android/socket: Do not close fd on unref Andrei Emeltchenko
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrei Emeltchenko @ 2013-12-12 15:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


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

* [PATCH 5/8] android/socket: Do not close fd on unref
  2013-12-12 15:17 [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Andrei Emeltchenko
                   ` (2 preceding siblings ...)
  2013-12-12 15:17 ` [PATCH 4/8] android/tester: Add Socket test success with valid fd Andrei Emeltchenko
@ 2013-12-12 15:17 ` Andrei Emeltchenko
  2013-12-13 14:39   ` Johan Hedberg
  2013-12-12 15:17 ` [PATCH 6/8] android/tester: Add Socket test connect() invalid sock_type Andrei Emeltchenko
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 10+ messages in thread
From: Andrei Emeltchenko @ 2013-12-12 15:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


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

* [PATCH 6/8] android/tester: Add Socket test connect() invalid sock_type
  2013-12-12 15:17 [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Andrei Emeltchenko
                   ` (3 preceding siblings ...)
  2013-12-12 15:17 ` [PATCH 5/8] android/socket: Do not close fd on unref Andrei Emeltchenko
@ 2013-12-12 15:17 ` Andrei Emeltchenko
  2013-12-12 15:17 ` [PATCH 7/8] android/tester: Add Socket test connect invalid sock_type L2CAP Andrei Emeltchenko
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrei Emeltchenko @ 2013-12-12 15:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

---
 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


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

* [PATCH 7/8] android/tester: Add Socket test connect invalid sock_type L2CAP
  2013-12-12 15:17 [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Andrei Emeltchenko
                   ` (4 preceding siblings ...)
  2013-12-12 15:17 ` [PATCH 6/8] android/tester: Add Socket test connect() invalid sock_type Andrei Emeltchenko
@ 2013-12-12 15:17 ` Andrei Emeltchenko
  2013-12-12 15:17 ` [PATCH 8/8] android/hal-sock: Fix returning incorrect error code Andrei Emeltchenko
  2013-12-13 14:45 ` [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Johan Hedberg
  7 siblings, 0 replies; 10+ messages in thread
From: Andrei Emeltchenko @ 2013-12-12 15:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

---
 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


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

* [PATCH 8/8] android/hal-sock: Fix returning incorrect error code
  2013-12-12 15:17 [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Andrei Emeltchenko
                   ` (5 preceding siblings ...)
  2013-12-12 15:17 ` [PATCH 7/8] android/tester: Add Socket test connect invalid sock_type L2CAP Andrei Emeltchenko
@ 2013-12-12 15:17 ` Andrei Emeltchenko
  2013-12-13 14:45 ` [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Johan Hedberg
  7 siblings, 0 replies; 10+ messages in thread
From: Andrei Emeltchenko @ 2013-12-12 15:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


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

* Re: [PATCH 5/8] android/socket: Do not close fd on unref
  2013-12-12 15:17 ` [PATCH 5/8] android/socket: Do not close fd on unref Andrei Emeltchenko
@ 2013-12-13 14:39   ` Johan Hedberg
  0 siblings, 0 replies; 10+ messages in thread
From: Johan Hedberg @ 2013-12-13 14:39 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth

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

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

* Re: [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid
  2013-12-12 15:17 [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Andrei Emeltchenko
                   ` (6 preceding siblings ...)
  2013-12-12 15:17 ` [PATCH 8/8] android/hal-sock: Fix returning incorrect error code Andrei Emeltchenko
@ 2013-12-13 14:45 ` Johan Hedberg
  7 siblings, 0 replies; 10+ messages in thread
From: Johan Hedberg @ 2013-12-13 14:45 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth

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

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

end of thread, other threads:[~2013-12-13 14:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-12 15:17 [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Andrei Emeltchenko
2013-12-12 15:17 ` [PATCH 2/8] android/tester: Check that fd is valid for Success case Andrei Emeltchenko
2013-12-12 15:17 ` [PATCH 3/8] android/tester: trivial: Make test cases prints look nice Andrei Emeltchenko
2013-12-12 15:17 ` [PATCH 4/8] android/tester: Add Socket test success with valid fd Andrei Emeltchenko
2013-12-12 15:17 ` [PATCH 5/8] android/socket: Do not close fd on unref Andrei Emeltchenko
2013-12-13 14:39   ` Johan Hedberg
2013-12-12 15:17 ` [PATCH 6/8] android/tester: Add Socket test connect() invalid sock_type Andrei Emeltchenko
2013-12-12 15:17 ` [PATCH 7/8] android/tester: Add Socket test connect invalid sock_type L2CAP Andrei Emeltchenko
2013-12-12 15:17 ` [PATCH 8/8] android/hal-sock: Fix returning incorrect error code Andrei Emeltchenko
2013-12-13 14:45 ` [PATCH 1/8] android/tester: Add Socket test invalid params: chan and uuid Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).