These were already ported to the new testing framework. --- android/android-tester.c | 416 ----------------------------------------------- 1 file changed, 416 deletions(-) diff --git a/android/android-tester.c b/android/android-tester.c index ae86b87..7f384ce 100644 --- a/android/android-tester.c +++ b/android/android-tester.c @@ -2053,39 +2053,6 @@ static void test_dummy(const void *test_data) tester_test_passed(); } -/* Test Socket HAL */ - -static gboolean adapter_socket_state_changed(gpointer user_data) -{ - struct bt_cb_data *cb_data = user_data; - - switch (cb_data->state) { - case BT_STATE_ON: - setup_powered_emulated_remote(); - break; - case BT_STATE_OFF: - tester_setup_failed(); - break; - default: - break; - } - - g_free(cb_data); - - g_atomic_int_dec_and_test(&scheduled_cbacks_num); - return FALSE; -} - -static void adapter_socket_state_changed_cb(bt_state_t state) -{ - struct bt_cb_data *cb_data = g_new0(struct bt_cb_data, 1); - - cb_data->state = state; - - g_atomic_int_inc(&scheduled_cbacks_num); - g_idle_add(adapter_socket_state_changed, cb_data); -} - const bt_bdaddr_t bdaddr_dummy = { .address = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55} }; @@ -2162,333 +2129,6 @@ static const struct socket_data btsock_inv_listen_listen = { .test_channel = true, }; -static bt_callbacks_t bt_socket_callbacks = { - .size = sizeof(bt_callbacks), - .adapter_state_changed_cb = adapter_socket_state_changed_cb, - .adapter_properties_cb = NULL, - .remote_device_properties_cb = NULL, - .device_found_cb = NULL, - .discovery_state_changed_cb = NULL, - .pin_request_cb = NULL, - .ssp_request_cb = NULL, - .bond_state_changed_cb = NULL, - .acl_state_changed_cb = NULL, - .thread_evt_cb = NULL, - .dut_mode_recv_cb = NULL, - .le_test_mode_cb = NULL -}; - -static void setup_socket_interface(const void *test_data) -{ - struct test_data *data = tester_get_data(); - bt_status_t status; - const void *sock; - - if (!setup(data)) { - tester_setup_failed(); - return; - } - - status = data->if_bluetooth->init(&bt_socket_callbacks); - if (status != BT_STATUS_SUCCESS) { - data->if_bluetooth = NULL; - tester_setup_failed(); - return; - } - - sock = data->if_bluetooth->get_profile_interface(BT_PROFILE_SOCKETS_ID); - if (!sock) { - tester_setup_failed(); - return; - } - - data->if_sock = sock; - - tester_setup_complete(); -} - -static void setup_socket_interface_enabled(const void *test_data) -{ - struct test_data *data = tester_get_data(); - bt_status_t status; - const void *sock; - - if (!setup(data)) { - tester_setup_failed(); - return; - } - - status = data->if_bluetooth->init(&bt_socket_callbacks); - if (status != BT_STATUS_SUCCESS) { - data->if_bluetooth = NULL; - tester_setup_failed(); - return; - } - - sock = data->if_bluetooth->get_profile_interface(BT_PROFILE_SOCKETS_ID); - if (!sock) { - tester_setup_failed(); - return; - } - - data->if_sock = sock; - - status = data->if_bluetooth->enable(); - if (status != BT_STATUS_SUCCESS) - tester_setup_failed(); -} - -static void test_generic_listen(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->listen(test->sock_type, - test->service_name, 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) < 0) { - tester_test_failed(); - return; - } - - if (status == BT_STATUS_SUCCESS && test->test_channel) { - int channel, len; - - len = read(sock_fd, &channel, sizeof(channel)); - if (len != sizeof(channel) || channel != test->channel) { - tester_test_failed(); - goto clean; - } - - tester_print("read correct channel: %d", channel); - } - - tester_test_passed(); - -clean: - if (sock_fd >= 0) - close(sock_fd); -} - -static void test_listen_close(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->listen(test->sock_type, - test->service_name, test->service_uuid, - test->channel, &sock_fd, test->flags); - if (status != test->expected_status) { - tester_warn("sock->listen() failed"); - tester_test_failed(); - goto clean; - } - - /* Check that file descriptor is valid */ - if (status == BT_STATUS_SUCCESS && fcntl(sock_fd, F_GETFD) < 0) { - tester_warn("sock_fd %d is not valid", sock_fd); - tester_test_failed(); - return; - } - - tester_print("Got valid sock_fd: %d", sock_fd); - - /* Now close sock_fd */ - close(sock_fd); - sock_fd = -1; - - /* Try to listen again */ - status = data->if_sock->listen(test->sock_type, - test->service_name, test->service_uuid, - test->channel, &sock_fd, test->flags); - if (status != test->expected_status) { - tester_warn("sock->listen() failed"); - tester_test_failed(); - goto clean; - } - - /* Check that file descriptor is valid */ - if (status == BT_STATUS_SUCCESS && fcntl(sock_fd, F_GETFD) < 0) { - tester_warn("sock_fd %d is not valid", sock_fd); - tester_test_failed(); - return; - } - - tester_print("Got valid sock_fd: %d", sock_fd); - - tester_test_passed(); - -clean: - if (sock_fd >= 0) - close(sock_fd); -} - -static void test_listen_listen(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_fd1 = -1, sock_fd2 = -1; - - status = data->if_sock->listen(test->sock_type, - test->service_name, test->service_uuid, - test->channel, &sock_fd1, test->flags); - if (status != BT_STATUS_SUCCESS) { - tester_warn("sock->listen() failed"); - tester_test_failed(); - goto clean; - } - - status = data->if_sock->listen(test->sock_type, - test->service_name, test->service_uuid, - test->channel, &sock_fd2, test->flags); - if (status != test->expected_status) { - tester_warn("sock->listen() failed, status %d", status); - tester_test_failed(); - goto clean; - } - - tester_print("status after second listen(): %d", status); - - tester_test_passed(); - -clean: - if (sock_fd1 >= 0) - close(sock_fd1); - - if (sock_fd2 >= 0) - close(sock_fd2); -} - -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) < 0) { - tester_test_failed(); - return; - } - - tester_test_passed(); - -clean: - if (sock_fd >= 0) - close(sock_fd); -} - -static gboolean socket_chan_cb(GIOChannel *io, GIOCondition cond, - gpointer user_data) -{ - int sock_fd = g_io_channel_unix_get_fd(io); - struct test_data *data = tester_get_data(); - const struct socket_data *test = data->test_data; - int channel, len; - - tester_print("%s", __func__); - - if (cond & G_IO_HUP) { - tester_warn("Socket %d hang up", sock_fd); - goto failed; - } - - if (cond & (G_IO_ERR | G_IO_NVAL)) { - tester_warn("Socket error: sock %d cond %d", sock_fd, cond); - goto failed; - } - - if (test->test_channel) { - len = read(sock_fd, &channel, sizeof(channel)); - if (len != sizeof(channel) || channel != test->channel) - goto failed; - - tester_print("read correct channel: %d", channel); - tester_test_passed(); - return FALSE; - } - -failed: - tester_test_failed(); - return FALSE; -} - -static void test_socket_real_connect(const void *test_data) -{ - struct test_data *data = tester_get_data(); - const struct socket_data *test = data->test_data; - struct bthost *bthost = hciemu_client_get_host(data->hciemu); - const uint8_t *client_bdaddr; - bt_bdaddr_t emu_bdaddr; - bt_status_t status; - int sock_fd = -1; - - client_bdaddr = hciemu_get_client_bdaddr(data->hciemu); - if (!client_bdaddr) { - tester_warn("No client bdaddr"); - tester_test_failed(); - return; - } - - bdaddr2android((bdaddr_t *) client_bdaddr, &emu_bdaddr); - - bthost_add_l2cap_server(bthost, 0x0003, NULL, NULL); - - status = data->if_sock->connect(&emu_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) < 0) { - tester_test_failed(); - return; - } - - tester_print("status %d sock_fd %d", status, sock_fd); - - if (status == BT_STATUS_SUCCESS) { - GIOChannel *io; - - io = g_io_channel_unix_new(sock_fd); - g_io_channel_set_close_on_unref(io, TRUE); - - g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, - socket_chan_cb, NULL); - - g_io_channel_unref(io); - } - - return; - -clean: - if (sock_fd >= 0) - close(sock_fd); -} - static gboolean hidhost_connection_state(gpointer user_data) { struct test_data *data = tester_get_data(); @@ -3134,62 +2774,6 @@ int main(int argc, char *argv[]) tester_init(&argc, &argv); - test_bredrle("Socket Init", NULL, setup_socket_interface, - test_dummy, teardown); - - test_bredrle("Socket Listen - Invalid: sock_type 0", - &btsock_inv_param_socktype, setup_socket_interface, - test_generic_listen, teardown); - - test_bredrle("Socket Listen - Invalid: sock_type L2CAP", - &btsock_inv_param_socktype_l2cap, - setup_socket_interface, test_generic_listen, teardown); - - test_bredrle("Socket Listen - Invalid: chan, uuid", - &btsock_inv_params_chan_uuid, - setup_socket_interface, test_generic_listen, teardown); - - test_bredrle("Socket Listen - Check returned fd valid", - &btsock_success, - setup_socket_interface, test_generic_listen, teardown); - - test_bredrle("Socket Listen - Check returned channel", - &btsock_success_check_chan, - setup_socket_interface, test_generic_listen, teardown); - - test_bredrle("Socket Listen - Close and Listen again", - &btsock_success_check_chan, - setup_socket_interface, test_listen_close, teardown); - - test_bredrle("Socket Listen - Invalid: double Listen", - &btsock_inv_listen_listen, - setup_socket_interface, test_listen_listen, teardown); - - test_bredrle("Socket Connect - Check returned fd valid", - &btsock_success, setup_socket_interface, - test_generic_connect, teardown); - - test_bredrle("Socket Connect - Invalid: sock_type 0", - &btsock_inv_param_socktype, setup_socket_interface, - test_generic_connect, teardown); - - test_bredrle("Socket Connect - Invalid: sock_type L2CAP", - &btsock_inv_param_socktype_l2cap, - setup_socket_interface, test_generic_connect, teardown); - - test_bredrle("Socket Connect - Invalid: chan, uuid", - &btsock_inv_params_chan_uuid, - setup_socket_interface, test_generic_connect, teardown); - - test_bredrle("Socket Connect - Invalid: bdaddr", - &btsock_inv_param_bdaddr, - setup_socket_interface, test_generic_connect, teardown); - - test_bredrle("Socket Connect - Check returned chan", - &btsock_success_check_chan, - setup_socket_interface_enabled, - test_socket_real_connect, teardown); - test_bredrle("HIDHost Init", NULL, setup_hidhost_interface, test_dummy, teardown); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html