One test case was not ported to new tester framework as it was
considered invalid.
---
doc/test-coverage.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/doc/test-coverage.txt b/doc/test-coverage.txt
index 0da8321..6b274b3 100644
--- a/doc/test-coverage.txt
+++ b/doc/test-coverage.txt
@@ -53,10 +53,10 @@ Android end-to-end testing
Application Count Description
-------------------------------------------
-android-tester 86 Android HAL interface testing
+android-tester 85 Android HAL interface testing
ipc-tester 94 Android IPC resistance testing
-----
- 180
+ 179
Android automated unit testing
--
1.9.1
Hi Jakub,
On Thu, Jul 24, 2014, Jakub Tyszkowski wrote:
> One test case was not ported to new tester framework as it was
> considered invalid.
> ---
> doc/test-coverage.txt | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
All patches in this set have been applied. Thanks.
Johan
Adding socket connect cases requires to set up the the l2cap and
rfcomm servers on the emulated device. For this, the bthost_l2cap_connect_cb
type had to exposed in tester-main.h and pulled some bthost dependencies
along.
---
android/tester-bluetooth.c | 2 +
android/tester-gatt.c | 3 +
android/tester-hidhost.c | 3 +
android/tester-main.c | 62 ++++++++++++++++-
android/tester-main.h | 9 +++
android/tester-socket.c | 168 ++++++++++++++++++++++++++++++++++++++++++++-
6 files changed, 244 insertions(+), 3 deletions(-)
diff --git a/android/tester-bluetooth.c b/android/tester-bluetooth.c
index 11d9039..018d712 100644
--- a/android/tester-bluetooth.c
+++ b/android/tester-bluetooth.c
@@ -14,7 +14,9 @@
* limitations under the License.
*
*/
+#include <stdbool.h>
+#include "emulator/bthost.h"
#include "tester-main.h"
static struct queue *list; /* List of bluetooth test cases */
diff --git a/android/tester-gatt.c b/android/tester-gatt.c
index b85cfc8..bdfbd8b 100644
--- a/android/tester-gatt.c
+++ b/android/tester-gatt.c
@@ -15,6 +15,9 @@
*
*/
+#include <stdbool.h>
+
+#include "emulator/bthost.h"
#include "tester-main.h"
static struct queue *list; /* List of gatt test cases */
diff --git a/android/tester-hidhost.c b/android/tester-hidhost.c
index a32b0df..59ff01c 100644
--- a/android/tester-hidhost.c
+++ b/android/tester-hidhost.c
@@ -15,6 +15,9 @@
*
*/
+#include <stdbool.h>
+
+#include "emulator/bthost.h"
#include "tester-main.h"
static struct queue *list; /* List of hidhost test cases */
diff --git a/android/tester-main.c b/android/tester-main.c
index c868943..3206a54 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -14,10 +14,11 @@
* limitations under the License.
*
*/
+#include <stdbool.h>
+#include "emulator/bthost.h"
#include "tester-main.h"
-#include "emulator/bthost.h"
#include "monitor/bt.h"
static char exec_dir[PATH_MAX + 1];
@@ -1119,6 +1120,65 @@ void emu_set_ssp_mode_action(void)
schedule_action_verification(step);
}
+void emu_add_l2cap_server_action(void)
+{
+ struct test_data *data = tester_get_data();
+ struct step *current_data_step = queue_peek_head(data->steps);
+ struct emu_set_l2cap_data *l2cap_data = current_data_step->set_data;
+ struct bthost *bthost;
+ struct step *step = g_new0(struct step, 1);
+
+ if (!l2cap_data) {
+ tester_warn("Invalid l2cap_data params");
+ return;
+ }
+
+ bthost = hciemu_client_get_host(data->hciemu);
+
+ bthost_add_l2cap_server(bthost, l2cap_data->psm, l2cap_data->func,
+ l2cap_data->user_data);
+
+ step->action_status = BT_STATUS_SUCCESS;
+
+ schedule_action_verification(step);
+}
+
+static void rfcomm_connect_cb(uint16_t handle, uint16_t cid, void *user_data,
+ bool status)
+{
+ struct step *step = g_new0(struct step, 1);
+
+ tester_print("Connect handle %d, cid %d cb status: %d", handle, cid,
+ status);
+
+ step->action_status = BT_STATUS_SUCCESS;
+
+ schedule_action_verification(step);
+}
+
+void emu_add_rfcomm_server_action(void)
+{
+ struct test_data *data = tester_get_data();
+ struct step *current_data_step = queue_peek_head(data->steps);
+ struct bt_action_data *rfcomm_data = current_data_step->set_data;
+ struct bthost *bthost;
+ struct step *step = g_new0(struct step, 1);
+
+ if (!rfcomm_data) {
+ tester_warn("Invalid l2cap_data params");
+ return;
+ }
+
+ bthost = hciemu_client_get_host(data->hciemu);
+
+ bthost_add_rfcomm_server(bthost, rfcomm_data->channel,
+ rfcomm_connect_cb, data);
+
+ step->action_status = BT_STATUS_SUCCESS;
+
+ schedule_action_verification(step);
+}
+
void dummy_action(void)
{
struct step *step = g_new0(struct step, 1);
diff --git a/android/tester-main.h b/android/tester-main.h
index 4c4afce..1bff9b3 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -234,6 +234,13 @@ struct bt_action_data {
int *fd;
};
+/* bthost's l2cap server setup parameters */
+struct emu_set_l2cap_data {
+ uint16_t psm;
+ bthost_l2cap_connect_cb func;
+ void *user_data;
+};
+
/*
* Callback data structure should be enhanced with data
* returned by callbacks. It's used for test case step
@@ -287,6 +294,8 @@ void schedule_action_verification(struct step *step);
void emu_setup_powered_remote_action(void);
void emu_set_pin_code_action(void);
void emu_set_ssp_mode_action(void);
+void emu_add_l2cap_server_action(void);
+void emu_add_rfcomm_server_action(void);
/* Actions */
void dummy_action(void);
diff --git a/android/tester-socket.c b/android/tester-socket.c
index b49f230..bd067ea 100644
--- a/android/tester-socket.c
+++ b/android/tester-socket.c
@@ -16,7 +16,9 @@
*/
#include <fcntl.h>
+#include <stdbool.h>
+#include "emulator/bthost.h"
#include "tester-main.h"
#include "src/shared/util.h"
@@ -79,6 +81,52 @@ static struct bt_action_data btsock_param_inv_bdaddr = {
.fd = &got_fd_result,
};
+static bt_bdaddr_t emu_remote_bdaddr_val = {
+ .address = { 0x00, 0xaa, 0x01, 0x01, 0x00, 0x00 },
+};
+static bt_property_t prop_emu_remote_bdadr = {
+ .type = BT_PROPERTY_BDADDR,
+ .val = &emu_remote_bdaddr_val,
+ .len = sizeof(emu_remote_bdaddr_val),
+};
+static bt_property_t prop_emu_remotes_default_set[] = {
+ { BT_PROPERTY_BDADDR, sizeof(emu_remote_bdaddr_val),
+ &emu_remote_bdaddr_val },
+};
+
+static struct bt_action_data btsock_param_emu_bdaddr = {
+ .addr = &emu_remote_bdaddr_val,
+ .sock_type = BTSOCK_RFCOMM,
+ .channel = 1,
+ .service_uuid = NULL,
+ .service_name = "Test service",
+ .flags = 0,
+ .fd = &got_fd_result,
+};
+
+static struct emu_set_l2cap_data l2cap_setup_data = {
+ .psm = 0x0003,
+ .func = NULL,
+ .user_data = NULL,
+};
+
+static struct bt_action_data prop_emu_remote_bdaddr_req = {
+ .addr = &emu_remote_bdaddr_val,
+ .prop_type = BT_PROPERTY_BDADDR,
+ .prop = &prop_emu_remote_bdadr,
+};
+
+static bt_property_t prop_emu_remotes_pin_req_set[] = {
+ { BT_PROPERTY_BDADDR, sizeof(emu_remote_bdaddr_val),
+ &emu_remote_bdaddr_val },
+};
+
+static struct bt_action_data ssp_confirm_accept_reply = {
+ .addr = &emu_remote_bdaddr_val,
+ .ssp_variant = BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
+ .accept = TRUE,
+};
+
static void socket_listen_action(void)
{
struct test_data *data = tester_get_data();
@@ -103,18 +151,83 @@ static void socket_connect_action(void)
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *action_data = current_data_step->set_data;
- struct step *step = g_new0(struct step, 1);
+ struct step *step;
+ int status;
*action_data->fd = -1;
- step->action_status = data->if_sock->connect(action_data->addr,
+ status = data->if_sock->connect(action_data->addr,
action_data->sock_type,
action_data->service_uuid,
action_data->channel,
action_data->fd,
action_data->flags);
+ tester_print("status %d sock_fd %d", status, *action_data->fd);
+
+ if (!status)
+ return;
+
+ step = g_new0(struct step, 1);
+ step->action_status = status;
+
+ schedule_action_verification(step);
+}
+
+static gboolean socket_chan_cb(GIOChannel *io, GIOCondition cond,
+ gpointer user_data)
+{
+ int sock_fd = g_io_channel_unix_get_fd(io);
+ struct step *step = g_new0(struct step, 1);
+ int channel, len;
+
+ tester_print("%s", __func__);
+
+ if (cond & G_IO_HUP) {
+ tester_warn("Socket %d hang up", sock_fd);
+
+ step->action_status = BT_STATUS_FAIL;
+ goto done;
+ }
+
+ if (cond & (G_IO_ERR | G_IO_NVAL)) {
+ tester_warn("Socket error: sock %d cond %d", sock_fd, cond);
+
+ step->action_status = BT_STATUS_FAIL;
+ goto done;
+ }
+
+ len = read(sock_fd, &channel, sizeof(channel));
+ if (len != sizeof(channel)) {
+ tester_warn("Socket read failed");
+
+ step->action_status = BT_STATUS_FAIL;
+ goto done;
+ }
+
+ tester_print("read correct channel: %d", channel);
+
+ step->action_status = BT_STATUS_SUCCESS;
+
+done:
schedule_action_verification(step);
+ return FALSE;
+}
+
+static void socket_read_fd_action(void)
+{
+ struct test_data *data = tester_get_data();
+ struct step *current_data_step = queue_peek_head(data->steps);
+ struct bt_action_data *action_data = current_data_step->set_data;
+ GIOChannel *io;
+
+ io = g_io_channel_unix_new(*action_data->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);
}
static void socket_verify_fd_action(void)
@@ -288,6 +401,57 @@ static struct test_case test_cases[] = {
ACTION_SUCCESS(bluetooth_disable_action, NULL),
CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
),
+ TEST_CASE_BREDRLE("Socket Connect - Check returned fd valid",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
+ ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
+ ACTION_SUCCESS(bt_create_bond_action,
+ &prop_emu_remote_bdaddr_req),
+ CALLBACK_BOND_STATE(BT_BOND_STATE_BONDING,
+ &prop_emu_remote_bdadr, 1),
+ CALLBACK_DEVICE_FOUND(prop_emu_remotes_default_set, 1),
+ CALLBACK_SSP_REQ(BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
+ prop_emu_remotes_pin_req_set, 1),
+ ACTION_SUCCESS(bt_ssp_reply_accept_action,
+ &ssp_confirm_accept_reply),
+ CALLBACK_DEVICE_PROPS(NULL, 0),
+ ACTION_SUCCESS(emu_add_l2cap_server_action, &l2cap_setup_data),
+ ACTION_SUCCESS(emu_add_rfcomm_server_action,
+ &btsock_param_emu_bdaddr),
+ ACTION_SUCCESS(socket_connect_action, &btsock_param_emu_bdaddr),
+ ACTION_SUCCESS(socket_verify_fd_action,
+ &btsock_param_emu_bdaddr),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
+ TEST_CASE_BREDRLE("Socket Connect - Check returned chann",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
+ ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
+ ACTION_SUCCESS(bt_create_bond_action,
+ &prop_emu_remote_bdaddr_req),
+ CALLBACK_BOND_STATE(BT_BOND_STATE_BONDING,
+ &prop_emu_remote_bdadr, 1),
+ CALLBACK_DEVICE_FOUND(prop_emu_remotes_default_set, 1),
+ CALLBACK_SSP_REQ(BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
+ prop_emu_remotes_pin_req_set, 1),
+ ACTION_SUCCESS(bt_ssp_reply_accept_action,
+ &ssp_confirm_accept_reply),
+ CALLBACK_DEVICE_PROPS(NULL, 0),
+ ACTION_SUCCESS(emu_add_l2cap_server_action, &l2cap_setup_data),
+ ACTION_SUCCESS(emu_add_rfcomm_server_action,
+ &btsock_param_emu_bdaddr),
+ ACTION_SUCCESS(socket_connect_action, &btsock_param_emu_bdaddr),
+ ACTION_SUCCESS(socket_verify_fd_action,
+ &btsock_param_emu_bdaddr),
+ ACTION_SUCCESS(socket_verify_channel_action,
+ &btsock_param_emu_bdaddr),
+ ACTION_SUCCESS(socket_read_fd_action, &btsock_param_emu_bdaddr),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
};
struct queue *get_socket_tests(void)
--
1.9.1
---
android/tester-socket.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/android/tester-socket.c b/android/tester-socket.c
index 7f39200..e01e0b9 100644
--- a/android/tester-socket.c
+++ b/android/tester-socket.c
@@ -59,6 +59,16 @@ static struct bt_action_data btsock_param_channel_0 = {
.fd = &got_fd_result,
};
+static struct bt_action_data btsock_param = {
+ .addr = &bdaddr_dummy,
+ .sock_type = BTSOCK_RFCOMM,
+ .channel = 1,
+ .service_uuid = NULL,
+ .service_name = "Test service",
+ .flags = 0,
+ .fd = &got_fd_result,
+};
+
static void socket_listen_action(void)
{
struct test_data *data = tester_get_data();
@@ -78,6 +88,25 @@ static void socket_listen_action(void)
schedule_action_verification(step);
}
+static void socket_verify_fd_action(void)
+{
+ struct test_data *data = tester_get_data();
+ struct step *current_data_step = queue_peek_head(data->steps);
+ struct bt_action_data *action_data = current_data_step->set_data;
+ struct step *step = g_new0(struct step, 1);
+
+ if (!*action_data->fd) {
+ step->action_status = BT_STATUS_FAIL;
+ goto done;
+ }
+
+ step->action_status = (fcntl(*action_data->fd, F_GETFD) < 0) ?
+ BT_STATUS_FAIL : BT_STATUS_SUCCESS;
+
+done:
+ schedule_action_verification(step);
+}
+
static struct test_case test_cases[] = {
TEST_CASE_BREDRLE("Socket Init",
ACTION_SUCCESS(dummy_action, NULL),
@@ -106,6 +135,14 @@ static struct test_case test_cases[] = {
ACTION_SUCCESS(bluetooth_disable_action, NULL),
CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
),
+ TEST_CASE_BREDRLE("Socket Listen - Check returned fd valid",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION_SUCCESS(socket_listen_action, &btsock_param),
+ ACTION_SUCCESS(socket_verify_fd_action, &btsock_param),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
};
struct queue *get_socket_tests(void)
--
1.9.1
Thiose test verifies socket porofile behaviour in case of invalid
parameters passed to 'connect' command.
---
android/tester-socket.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/android/tester-socket.c b/android/tester-socket.c
index 1ccd29b..b49f230 100644
--- a/android/tester-socket.c
+++ b/android/tester-socket.c
@@ -69,6 +69,16 @@ static struct bt_action_data btsock_param = {
.fd = &got_fd_result,
};
+static struct bt_action_data btsock_param_inv_bdaddr = {
+ .addr = NULL,
+ .sock_type = BTSOCK_RFCOMM,
+ .channel = 1,
+ .service_uuid = NULL,
+ .service_name = "Test service",
+ .flags = 0,
+ .fd = &got_fd_result,
+};
+
static void socket_listen_action(void)
{
struct test_data *data = tester_get_data();
@@ -88,6 +98,25 @@ static void socket_listen_action(void)
schedule_action_verification(step);
}
+static void socket_connect_action(void)
+{
+ struct test_data *data = tester_get_data();
+ struct step *current_data_step = queue_peek_head(data->steps);
+ struct bt_action_data *action_data = current_data_step->set_data;
+ struct step *step = g_new0(struct step, 1);
+
+ *action_data->fd = -1;
+
+ step->action_status = data->if_sock->connect(action_data->addr,
+ action_data->sock_type,
+ action_data->service_uuid,
+ action_data->channel,
+ action_data->fd,
+ action_data->flags);
+
+ schedule_action_verification(step);
+}
+
static void socket_verify_fd_action(void)
{
struct test_data *data = tester_get_data();
@@ -227,6 +256,38 @@ static struct test_case test_cases[] = {
ACTION_SUCCESS(bluetooth_disable_action, NULL),
CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
),
+ TEST_CASE_BREDRLE("Socket Connect - Invalid: sock_type 0",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION(BT_STATUS_PARM_INVALID, socket_connect_action,
+ &btsock_param_socktype_0),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
+ TEST_CASE_BREDRLE("Socket Connect - Invalid: sock_type L2CAP",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION(BT_STATUS_UNSUPPORTED, socket_connect_action,
+ &btsock_param_socktype_l2cap),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
+ TEST_CASE_BREDRLE("Socket Connect - Invalid: chan, uuid",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION(BT_STATUS_PARM_INVALID, socket_connect_action,
+ &btsock_param_channel_0),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
+ TEST_CASE_BREDRLE("Socket Connect - Invalid: bdaddr",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION(BT_STATUS_PARM_INVALID, socket_connect_action,
+ &btsock_param_inv_bdaddr),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
};
struct queue *get_socket_tests(void)
--
1.9.1
Dont even try to verify late callbacks when test case already ended.
This was triggering confusing message about verifying step N+1 when we
have only N steps in current case.
---
android/tester-main.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/android/tester-main.c b/android/tester-main.c
index 40416d7..c868943 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -543,8 +543,15 @@ static gboolean verify_action(gpointer user_data)
static gboolean verify_callback(gpointer user_data)
{
+ struct test_data *data = tester_get_data();
struct step *step = user_data;
+ /* Return if callback came when all steps are already verified */
+ if (queue_isempty(data->steps)) {
+ destroy_callback_step(step);
+ return FALSE;
+ }
+
/*
* TODO: This may call action from next step before callback data
* from previous step was freed.
--
1.9.1
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
This is needed for socket HAL connect test cases.
---
android/tester-main.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/android/tester-main.c b/android/tester-main.c
index bbb3375..40416d7 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -1029,16 +1029,27 @@ static void emu_connectable_complete(uint16_t opcode, uint8_t status,
const void *param, uint8_t len,
void *user_data)
{
- struct step *step = g_new0(struct step, 1);
+ struct step *step;
+ struct test_data *data = user_data;
switch (opcode) {
case BT_HCI_CMD_WRITE_SCAN_ENABLE:
+ break;
case BT_HCI_CMD_LE_SET_ADV_ENABLE:
+ /*
+ * For BREDRLE emulator we want to verify step after scan
+ * enable and not after le_set_adv_enable
+ */
+ if (data->hciemu_type == HCIEMU_TYPE_BREDRLE)
+ return;
+
break;
default:
return;
}
+ step = g_new0(struct step, 1);
+
if (status) {
tester_warn("Emulated remote setup failed.");
step->action_status = BT_STATUS_FAIL;
@@ -1061,7 +1072,8 @@ void emu_setup_powered_remote_action(void)
if ((data->hciemu_type == HCIEMU_TYPE_LE) ||
(data->hciemu_type == HCIEMU_TYPE_BREDRLE))
bthost_set_adv_enable(bthost, 0x01, 0x02);
- else
+
+ if (data->hciemu_type != HCIEMU_TYPE_LE)
bthost_write_scan_enable(bthost, 0x03);
}
--
1.9.1
---
android/tester-socket.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/android/tester-socket.c b/android/tester-socket.c
index e01e0b9..337e117 100644
--- a/android/tester-socket.c
+++ b/android/tester-socket.c
@@ -107,6 +107,35 @@ done:
schedule_action_verification(step);
}
+static void socket_verify_channel_action(void)
+{
+ struct test_data *data = tester_get_data();
+ struct step *current_data_step = queue_peek_head(data->steps);
+ struct bt_action_data *action_data = current_data_step->set_data;
+ int channel, len;
+ struct step *step = g_new(struct step, 1);
+
+ if (!*action_data->fd) {
+ tester_warn("Ups no action_data->fd");
+
+ step->action_status = BT_STATUS_FAIL;
+ goto done;
+ }
+
+ len = read(*action_data->fd, &channel, sizeof(channel));
+ if (len != sizeof(channel) || channel != action_data->channel) {
+ tester_warn("Ups bad channel");
+
+ step->action_status = BT_STATUS_FAIL;
+ goto done;
+ }
+
+ step->action_status = BT_STATUS_SUCCESS;
+
+done:
+ schedule_action_verification(step);
+}
+
static struct test_case test_cases[] = {
TEST_CASE_BREDRLE("Socket Init",
ACTION_SUCCESS(dummy_action, NULL),
@@ -143,6 +172,15 @@ static struct test_case test_cases[] = {
ACTION_SUCCESS(bluetooth_disable_action, NULL),
CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
),
+ TEST_CASE_BREDRLE("Socket Listen - Check returned channel",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION_SUCCESS(socket_listen_action, &btsock_param),
+ ACTION_SUCCESS(socket_verify_fd_action, &btsock_param),
+ ACTION_SUCCESS(socket_verify_channel_action, &btsock_param),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
};
struct queue *get_socket_tests(void)
--
1.9.1
---
android/tester-socket.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/android/tester-socket.c b/android/tester-socket.c
index 5994a3d..1ccd29b 100644
--- a/android/tester-socket.c
+++ b/android/tester-socket.c
@@ -217,6 +217,16 @@ static struct test_case test_cases[] = {
ACTION_SUCCESS(bluetooth_disable_action, NULL),
CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
),
+ TEST_CASE_BREDRLE("Socket Listen - Invalid: double Listen",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION_SUCCESS(socket_listen_action, &btsock_param),
+ ACTION_SUCCESS(socket_verify_fd_action, &btsock_param),
+ ACTION_SUCCESS(socket_verify_channel_action, &btsock_param),
+ ACTION(BT_STATUS_BUSY, socket_listen_action, &btsock_param),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
};
struct queue *get_socket_tests(void)
--
1.9.1
This checks for another successfull listen after closing previous fd.
---
android/tester-socket.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/android/tester-socket.c b/android/tester-socket.c
index 337e117..5994a3d 100644
--- a/android/tester-socket.c
+++ b/android/tester-socket.c
@@ -136,6 +136,29 @@ done:
schedule_action_verification(step);
}
+static void socket_close_channel_action(void)
+{
+ struct test_data *data = tester_get_data();
+ struct step *current_data_step = queue_peek_head(data->steps);
+ struct bt_action_data *action_data = current_data_step->set_data;
+ struct step *step = g_new0(struct step, 1);
+
+ if (!*action_data->fd) {
+ tester_warn("Ups no action_data->fd");
+
+ step->action_status = BT_STATUS_FAIL;
+ goto done;
+ }
+
+ close(*action_data->fd);
+ *action_data->fd = -1;
+
+ step->action_status = BT_STATUS_SUCCESS;
+
+done:
+ schedule_action_verification(step);
+}
+
static struct test_case test_cases[] = {
TEST_CASE_BREDRLE("Socket Init",
ACTION_SUCCESS(dummy_action, NULL),
@@ -181,6 +204,19 @@ static struct test_case test_cases[] = {
ACTION_SUCCESS(bluetooth_disable_action, NULL),
CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
),
+ TEST_CASE_BREDRLE("Socket Listen - Close and Listen again",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION_SUCCESS(socket_listen_action, &btsock_param),
+ ACTION_SUCCESS(socket_verify_fd_action, &btsock_param),
+ ACTION_SUCCESS(socket_verify_channel_action, &btsock_param),
+ ACTION_SUCCESS(socket_close_channel_action, &btsock_param),
+ ACTION_SUCCESS(socket_listen_action, &btsock_param),
+ ACTION_SUCCESS(socket_verify_fd_action, &btsock_param),
+ ACTION_SUCCESS(socket_verify_channel_action, &btsock_param),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
};
struct queue *get_socket_tests(void)
--
1.9.1
This is needed for profile specific testers to define step actions
(and verify their results) in their own file and not in tester-main.c
where only core actions, needed by all other testers should be defined.
---
android/tester-main.c | 2 +-
android/tester-main.h | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/android/tester-main.c b/android/tester-main.c
index e7b1e1b..bbb3375 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -560,7 +560,7 @@ static void schedule_callback_call(struct step *step)
g_idle_add(verify_callback, step);
}
-static void schedule_action_verification(struct step *step)
+void schedule_action_verification(struct step *step)
{
g_idle_add_full(G_PRIORITY_HIGH_IDLE, verify_action, step, NULL);
}
diff --git a/android/tester-main.h b/android/tester-main.h
index a239ae1..0f3f165 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -266,6 +266,9 @@ void remove_hidhost_tests(void);
struct queue *get_gatt_tests(void);
void remove_gatt_tests(void);
+/* Generic tester API */
+void schedule_action_verification(struct step *step);
+
/* Emulator actions */
void emu_setup_powered_remote_action(void);
void emu_set_pin_code_action(void);
--
1.9.1
---
android/tester-main.h | 14 +++++++++++
android/tester-socket.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+)
diff --git a/android/tester-main.h b/android/tester-main.h
index 0f3f165..4c4afce 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -76,6 +76,12 @@
.set_data = data_set, \
}
+#define ACTION(status, act_fun, data_set) { \
+ .action_status = status, \
+ .action = act_fun, \
+ .set_data = data_set, \
+ }
+
#define CALLBACK_STATE(cb, cb_res) { \
.callback = cb, \
.callback_result.state = cb_res, \
@@ -218,6 +224,14 @@ struct bt_action_data {
uint8_t pin_len;
uint8_t ssp_variant;
bool accept;
+
+ /* Socket HAL specific params */
+ btsock_type_t sock_type;
+ int channel;
+ const uint8_t *service_uuid;
+ const char *service_name;
+ int flags;
+ int *fd;
};
/*
diff --git a/android/tester-socket.c b/android/tester-socket.c
index fd0f035..4ab8d7e 100644
--- a/android/tester-socket.c
+++ b/android/tester-socket.c
@@ -15,14 +15,79 @@
*
*/
+#include <fcntl.h>
+
#include "tester-main.h"
+#include "src/shared/util.h"
+
static struct queue *list; /* List of socket test cases */
+static bt_bdaddr_t bdaddr_dummy = {
+ .address = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55}
+};
+
+static int got_fd_result = -1;
+
+static struct bt_action_data btsock_param_socktype_0 = {
+ .addr = &bdaddr_dummy,
+ .sock_type = 0,
+ .channel = 1,
+ .service_uuid = NULL,
+ .service_name = "Test service",
+ .flags = 0,
+ .fd = &got_fd_result,
+};
+
+static struct bt_action_data btsock_param_socktype_l2cap = {
+ .addr = &bdaddr_dummy,
+ .sock_type = BTSOCK_L2CAP,
+ .channel = 1,
+ .service_uuid = NULL,
+ .service_name = "Test service",
+ .flags = 0,
+ .fd = &got_fd_result,
+};
+
+static void socket_listen_action(void)
+{
+ struct test_data *data = tester_get_data();
+ struct step *current_data_step = queue_peek_head(data->steps);
+ struct bt_action_data *action_data = current_data_step->set_data;
+ struct step *step = g_new0(struct step, 1);
+
+ *action_data->fd = -1;
+
+ step->action_status = data->if_sock->listen(action_data->sock_type,
+ action_data->service_name,
+ action_data->service_uuid,
+ action_data->channel,
+ action_data->fd,
+ action_data->flags);
+
+ schedule_action_verification(step);
+}
+
static struct test_case test_cases[] = {
TEST_CASE_BREDRLE("Socket Init",
ACTION_SUCCESS(dummy_action, NULL),
),
+ TEST_CASE_BREDRLE("Socket Listen - Invalid: sock_type 0",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION(BT_STATUS_PARM_INVALID, socket_listen_action,
+ &btsock_param_socktype_0),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
+ TEST_CASE_BREDRLE("Socket Listen - Invalid: sock_type L2CAP",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION(BT_STATUS_UNSUPPORTED, socket_listen_action,
+ &btsock_param_socktype_l2cap),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
};
struct queue *get_socket_tests(void)
--
1.9.1
---
android/tester-socket.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/android/tester-socket.c b/android/tester-socket.c
index 4ab8d7e..7f39200 100644
--- a/android/tester-socket.c
+++ b/android/tester-socket.c
@@ -49,6 +49,16 @@ static struct bt_action_data btsock_param_socktype_l2cap = {
.fd = &got_fd_result,
};
+static struct bt_action_data btsock_param_channel_0 = {
+ .addr = &bdaddr_dummy,
+ .sock_type = BTSOCK_RFCOMM,
+ .channel = 0,
+ .service_uuid = NULL,
+ .service_name = "Test service",
+ .flags = 0,
+ .fd = &got_fd_result,
+};
+
static void socket_listen_action(void)
{
struct test_data *data = tester_get_data();
@@ -88,6 +98,14 @@ static struct test_case test_cases[] = {
ACTION_SUCCESS(bluetooth_disable_action, NULL),
CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
),
+ TEST_CASE_BREDRLE("Socket Listen - Invalid: chan, uuid",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION(BT_STATUS_PARM_INVALID, socket_listen_action,
+ &btsock_param_channel_0),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
};
struct queue *get_socket_tests(void)
--
1.9.1
All action steps steps were called recurently if not interleaved with
callbacks steps in test case definition. This could block any potential
callback that was not expected to come, as mainloop was stuck. This could
raise potential stability issues and timeouts when working with file
descriptors and io channels handled in the main loop.
---
android/tester-main.c | 143 ++++++++++++++++++++++++--------------------------
1 file changed, 70 insertions(+), 73 deletions(-)
diff --git a/android/tester-main.c b/android/tester-main.c
index 5496d2e..e7b1e1b 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -532,6 +532,15 @@ static void destroy_callback_step(void *data)
g_atomic_int_dec_and_test(&scheduled_cbacks_num);
}
+static gboolean verify_action(gpointer user_data)
+{
+ struct step *step = user_data;
+
+ verify_step(step, g_free);
+
+ return FALSE;
+}
+
static gboolean verify_callback(gpointer user_data)
{
struct step *step = user_data;
@@ -551,6 +560,11 @@ static void schedule_callback_call(struct step *step)
g_idle_add(verify_callback, step);
}
+static void schedule_action_verification(struct step *step)
+{
+ g_idle_add_full(G_PRIORITY_HIGH_IDLE, verify_action, step, NULL);
+}
+
static void adapter_state_changed_cb(bt_state_t state)
{
struct step *step = g_new0(struct step, 1);
@@ -1015,7 +1029,7 @@ static void emu_connectable_complete(uint16_t opcode, uint8_t status,
const void *param, uint8_t len,
void *user_data)
{
- struct step step;
+ struct step *step = g_new0(struct step, 1);
switch (opcode) {
case BT_HCI_CMD_WRITE_SCAN_ENABLE:
@@ -1025,17 +1039,15 @@ static void emu_connectable_complete(uint16_t opcode, uint8_t status,
return;
}
- memset(&step, 0, sizeof(step));
-
if (status) {
tester_warn("Emulated remote setup failed.");
- step.action_status = BT_STATUS_FAIL;
+ step->action_status = BT_STATUS_FAIL;
} else {
tester_warn("Emulated remote setup done.");
- step.action_status = BT_STATUS_SUCCESS;
+ step->action_status = BT_STATUS_SUCCESS;
}
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void emu_setup_powered_remote_action(void)
@@ -1059,73 +1071,68 @@ void emu_set_pin_code_action(void)
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *action_data = current_data_step->set_data;
struct bthost *bthost;
- struct step step;
+ struct step *step = g_new0(struct step, 1);
bthost = hciemu_client_get_host(data->hciemu);
bthost_set_pin_code(bthost, action_data->pin->pin,
action_data->pin_len);
- memset(&step, 0, sizeof(step));
- step.action_status = BT_STATUS_SUCCESS;
+ step->action_status = BT_STATUS_SUCCESS;
tester_print("Setting emu pin done.");
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void emu_set_ssp_mode_action(void)
{
struct test_data *data = tester_get_data();
struct bthost *bthost;
- struct step step;
+ struct step *step = g_new0(struct step, 1);
bthost = hciemu_client_get_host(data->hciemu);
bthost_write_ssp_mode(bthost, 0x01);
- memset(&step, 0, sizeof(step));
- step.action_status = BT_STATUS_SUCCESS;
+ step->action_status = BT_STATUS_SUCCESS;
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void dummy_action(void)
{
- struct step step;
+ struct step *step = g_new0(struct step, 1);
- memset(&step, 0, sizeof(step));
- step.action = dummy_action;
+ step->action = dummy_action;
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bluetooth_enable_action(void)
{
struct test_data *data = tester_get_data();
- struct step step;
+ struct step *step = g_new0(struct step, 1);
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->enable();
+ step->action_status = data->if_bluetooth->enable();
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bluetooth_disable_action(void)
{
struct test_data *data = tester_get_data();
- struct step step;
+ struct step *step = g_new0(struct step, 1);
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->disable();
+ step->action_status = data->if_bluetooth->disable();
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_set_property_action(void)
{
struct test_data *data = tester_get_data();
- struct step step;
+ struct step *step = g_new0(struct step, 1);
struct step *current_data_step = queue_peek_head(data->steps);
bt_property_t *prop;
@@ -1137,17 +1144,16 @@ void bt_set_property_action(void)
prop = (bt_property_t *)current_data_step->set_data;
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->set_adapter_property(
+ step->action_status = data->if_bluetooth->set_adapter_property(
prop);
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_get_property_action(void)
{
struct test_data *data = tester_get_data();
- struct step step;
+ struct step *step = g_new0(struct step, 1);
struct step *current_data_step = queue_peek_head(data->steps);
bt_property_t *prop;
@@ -1159,39 +1165,37 @@ void bt_get_property_action(void)
prop = (bt_property_t *)current_data_step->set_data;
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->get_adapter_property(
+ step->action_status = data->if_bluetooth->get_adapter_property(
prop->type);
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_start_discovery_action(void)
{
struct test_data *data = tester_get_data();
- struct step step;
+ struct step *step = g_new0(struct step, 1);
- step.action_status = data->if_bluetooth->start_discovery();
+ step->action_status = data->if_bluetooth->start_discovery();
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_cancel_discovery_action(void)
{
struct test_data *data = tester_get_data();
- struct step step;
+ struct step *step = g_new0(struct step, 1);
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->cancel_discovery();
+ step->action_status = data->if_bluetooth->cancel_discovery();
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_get_device_props_action(void)
{
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
- struct step step;
+ struct step *step = g_new0(struct step, 1);
if (!current_data_step->set_data) {
tester_debug("bdaddr not defined");
@@ -1199,12 +1203,11 @@ void bt_get_device_props_action(void)
return;
}
- memset(&step, 0, sizeof(step));
- step.action_status =
+ step->action_status =
data->if_bluetooth->get_remote_device_properties(
current_data_step->set_data);
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_get_device_prop_action(void)
@@ -1212,7 +1215,7 @@ void bt_get_device_prop_action(void)
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *action_data = current_data_step->set_data;
- struct step step;
+ struct step *step = g_new0(struct step, 1);
if (!action_data) {
tester_warn("No arguments for 'get remote device prop' req.");
@@ -1220,12 +1223,11 @@ void bt_get_device_prop_action(void)
return;
}
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->get_remote_device_property(
+ step->action_status = data->if_bluetooth->get_remote_device_property(
action_data->addr,
action_data->prop_type);
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_set_device_prop_action(void)
@@ -1233,7 +1235,7 @@ void bt_set_device_prop_action(void)
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *action_data = current_data_step->set_data;
- struct step step;
+ struct step *step = g_new0(struct step, 1);
if (!action_data) {
tester_warn("No arguments for 'set remote device prop' req.");
@@ -1241,12 +1243,11 @@ void bt_set_device_prop_action(void)
return;
}
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->set_remote_device_property(
+ step->action_status = data->if_bluetooth->set_remote_device_property(
action_data->addr,
action_data->prop);
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_create_bond_action(void)
@@ -1254,7 +1255,7 @@ void bt_create_bond_action(void)
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *action_data = current_data_step->set_data;
- struct step step;
+ struct step *step = g_new0(struct step, 1);
if (!action_data || !action_data->addr) {
tester_warn("Bad arguments for 'create bond' req.");
@@ -1262,10 +1263,10 @@ void bt_create_bond_action(void)
return;
}
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->create_bond(action_data->addr);
+ step->action_status =
+ data->if_bluetooth->create_bond(action_data->addr);
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_pin_reply_accept_action(void)
@@ -1273,7 +1274,7 @@ void bt_pin_reply_accept_action(void)
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *action_data = current_data_step->set_data;
- struct step step;
+ struct step *step = g_new0(struct step, 1);
if (!action_data || !action_data->addr || !action_data->pin) {
tester_warn("Bad arguments for 'pin reply' req.");
@@ -1281,13 +1282,12 @@ void bt_pin_reply_accept_action(void)
return;
}
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->pin_reply(action_data->addr,
+ step->action_status = data->if_bluetooth->pin_reply(action_data->addr,
TRUE,
action_data->pin_len,
action_data->pin);
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_ssp_reply_accept_action(void)
@@ -1295,14 +1295,13 @@ void bt_ssp_reply_accept_action(void)
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
struct bt_action_data *action_data = current_data_step->set_data;
- struct step step;
+ struct step *step = g_new0(struct step, 1);
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->ssp_reply(action_data->addr,
+ step->action_status = data->if_bluetooth->ssp_reply(action_data->addr,
action_data->ssp_variant,
action_data->accept, 0);
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_cancel_bond_action(void)
@@ -1310,12 +1309,11 @@ void bt_cancel_bond_action(void)
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
bt_bdaddr_t *addr = current_data_step->set_data;
- struct step step;
+ struct step *step = g_new0(struct step, 1);
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->cancel_bond(addr);
+ step->action_status = data->if_bluetooth->cancel_bond(addr);
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
void bt_remove_bond_action(void)
@@ -1323,12 +1321,11 @@ void bt_remove_bond_action(void)
struct test_data *data = tester_get_data();
struct step *current_data_step = queue_peek_head(data->steps);
bt_bdaddr_t *addr = current_data_step->set_data;
- struct step step;
+ struct step *step = g_new0(struct step, 1);
- memset(&step, 0, sizeof(step));
- step.action_status = data->if_bluetooth->remove_bond(addr);
+ step->action_status = data->if_bluetooth->remove_bond(addr);
- verify_step(&step, NULL);
+ schedule_action_verification(step);
}
static void generic_test_function(const void *test_data)
--
1.9.1