android/tester: Add Socket test invalid params: chan and uuid
PATCH 1/8 android/tester: Add Socket test invalid params: chan and uuid
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(+)
android/android-tester.c +14 -0
@@ -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 (); }
Signature · 1 line
1.8.3.2
PATCH 2/8 android/tester: Check that fd is valid for Success case
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(+)
android/android-tester.c +7 -0
@@ -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:
Signature · 1 line
1.8.3.2
PATCH 3/8 android/tester: trivial: Make test cases prints look nice
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
--- android/android-tester.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
android/android-tester.c +2 -2
@@ -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);
Signature · 1 line
1.8.3.2
PATCH 4/8 android/tester: Add Socket test success with valid fd
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
Check that Socket listen() returns valid file descriptor
--- android/android-tester.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
android/android-tester.c +13 -0
@@ -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 (); }
Signature · 1 line
1.8.3.2
PATCH 5/8 android/socket: Do not close fd on unref
In reply to Andrei EmeltchenkoFrom: 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(+)
android/socket.c +1 -0
@@ -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);
Signature · 1 line
1.8.3.2
Re: [PATCH 5/8] android/socket: Do not close fd on unref
Hi Andrei,
Quoted 12 lines · Andrei Emeltchenko
We close file descriptors in
cleanup_rfsock()and leaving the default value gives us glib warnings if we close fd already and gotG_IO_NVALinserver_cbfrombt_io.--- android/socket.c | 1 + 1 file changed, 1 insertion(+)android/socket.c +0
-0
android/socket.c static void handle_listen(const void *buf, uint16_t len) · line 739
Quoted 4 lines
android/socket.c +1
-0@@ -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
PATCH 6/8 android/tester: Add Socket test connect() invalid sock_type
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
--- android/android-tester.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
android/android-tester.c +38 -0
@@ -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 (); }
Signature · 1 line
1.8.3.2
PATCH 7/8 android/tester: Add Socket test connect invalid sock_type L2CAP
In reply to Andrei EmeltchenkoFrom: Andrei Emeltchenko <[email protected]>
--- android/android-tester.c | 5 +++++ 1 file changed, 5 insertions(+)
android/android-tester.c +5 -0
@@ -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 (); }
Signature · 1 line
1.8.3.2
PATCH 8/8 android/hal-sock: Fix returning incorrect error code
In reply to Andrei EmeltchenkoFrom: 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(-)
android/hal-sock.c +1 -1
@@ -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 ;
Signature · 1 line
1.8.3.2
Hi Andrei,
Quoted 5 lines · Andrei Emeltchenko
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