2013-12-12 12:48:27

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 0/7] Add basic socket tests

From: Andrei Emeltchenko <[email protected]>

Initial socket test cases

Andrei Emeltchenko (7):
android/tester: Rename controller_setup to test_dummy
android/tester: Make generic_data structure const void pointer
android/tester: Add basic Socket Init test
android/tester: Add Socket data to generic test data struct
android/tester: Add Socket listen() invalid sock type
android/hal-sock: Fix returning unsupported instead of invalid
android/tester: Add Socket listen() invalid L2CAP socket type

android/android-tester.c | 114 +++++++++++++++++++++++++++++++++++++++++------
android/hal-sock.c | 2 +-
2 files changed, 102 insertions(+), 14 deletions(-)

--
1.8.3.2



2013-12-12 13:02:51

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCHv2 0/7] Add basic socket tests

Hi Andrei,

On Thu, Dec 12, 2013, Andrei Emeltchenko wrote:
> Initial socket test cases
>
> Andrei Emeltchenko (7):
> android/tester: Rename controller_setup to test_dummy
> android/tester: Make generic_data structure const void pointer
> android/tester: Add basic Socket Init test
> android/tester: Add Socket data to generic test data struct
> android/tester: Add Socket listen() invalid sock type
> android/hal-sock: Fix returning unsupported instead of invalid
> android/tester: Add Socket listen() invalid L2CAP socket type
>
> android/android-tester.c | 114 +++++++++++++++++++++++++++++++++++++++++------
> android/hal-sock.c | 2 +-
> 2 files changed, 102 insertions(+), 14 deletions(-)

All patches in this set have been applied. Thanks.

Johan

2013-12-12 12:48:31

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 4/7] android/tester: Add Socket data to generic test data struct

From: Andrei Emeltchenko <[email protected]>

Socket data will be used in generic Socket HAL tests
---
android/android-tester.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index c58b13a..11c3639 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -66,6 +66,15 @@ struct generic_data {
uint8_t expected_hal_callbacks[];
};

+struct socket_data {
+ btsock_type_t sock_type;
+ const char *service_name;
+ const uint8_t *service_uuid;
+ int channel;
+ int flags;
+ bt_status_t expected_status;
+};
+
#define WAIT_FOR_SIGNAL_TIME 2 /* in seconds */
#define EMULATOR_SIGNAL "emulator_started"

--
1.8.3.2


2013-12-12 12:48:28

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 1/7] android/tester: Rename controller_setup to test_dummy

From: Andrei Emeltchenko <[email protected]>

test_dummy is a better name for dummy function test.
---
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 a36c10a..7ecc80d 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -672,7 +672,7 @@ static void test_disable(const void *test_data)
data->if_bluetooth->disable();
}

-static void controller_setup(const void *test_data)
+static void test_dummy(const void *test_data)
{
tester_test_passed();
}
@@ -696,7 +696,7 @@ int main(int argc, char *argv[])

tester_init(&argc, &argv);

- test_bredrle("Test Init", NULL, setup_base, controller_setup, teardown);
+ test_bredrle("Test Init", NULL, setup_base, test_dummy, teardown);

test_bredrle("Test Enable - Success", &bluetooth_enable_success_test,
setup_base, test_enable, teardown);
--
1.8.3.2


2013-12-12 12:48:33

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 6/7] android/hal-sock: Fix returning unsupported instead of invalid

From: Andrei Emeltchenko <[email protected]>

For socket type 0 we shall return BT_STATUS_PARM_INVALID,
BT_STATUS_UNSUPPORTED shall be returned for unsupported socket types
like L2CAP.
---
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 f45be30..301c77f 100644
--- a/android/hal-sock.c
+++ b/android/hal-sock.c
@@ -54,7 +54,7 @@ static bt_status_t sock_listen(btsock_type_t type, const char *service_name,
const uint8_t *uuid, int chan,
int *sock, int flags)
{
- if ((!uuid && chan <= 0) || !sock) {
+ if ((!uuid && chan <= 0) || !sock || !type) {
error("Invalid params: uuid %s, chan %d, sock %p",
btuuid2str(uuid), chan, sock);
return BT_STATUS_PARM_INVALID;
--
1.8.3.2


2013-12-12 12:48:29

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 2/7] android/tester: Make generic_data structure const void pointer

From: Andrei Emeltchenko <[email protected]>

This allows us to have different types of generic data, like socket
data, bluetooth data, etc.
---
android/android-tester.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index 7ecc80d..800c14d 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -74,7 +74,7 @@ struct test_data {
unsigned int mgmt_settings_id;
struct hciemu *hciemu;
enum hciemu_type hciemu_type;
- const struct generic_data *test_data;
+ const void *test_data;
pid_t bluetoothd_pid;
const bt_interface_t *if_bluetooth;

@@ -111,6 +111,7 @@ static void command_generic_new_settings(uint16_t index, uint16_t length,
const void *param, void *user_data)
{
struct test_data *data = tester_get_data();
+ const struct generic_data *test_data = data->test_data;
uint32_t settings;

if (length != 4) {
@@ -121,8 +122,8 @@ static void command_generic_new_settings(uint16_t index, uint16_t length,

settings = bt_get_le32(param);

- if ((settings & data->test_data->expect_settings_set) !=
- data->test_data->expect_settings_set)
+ if ((settings & test_data->expect_settings_set) !=
+ test_data->expect_settings_set)
return;

test_mgmt_settings_set(data);
@@ -131,29 +132,34 @@ static void command_generic_new_settings(uint16_t index, uint16_t length,

static void hal_cb_init(struct test_data *data)
{
+ const struct generic_data *test_data = data->test_data;
unsigned int i = 0;

- while (data->test_data->expected_hal_callbacks[i]) {
- data->expected_callbacks =
- g_slist_append(data->expected_callbacks,
- GINT_TO_POINTER(data->test_data->expected_hal_callbacks[i]));
+ while (test_data->expected_hal_callbacks[i]) {
+ data->expected_callbacks =
+ g_slist_append(data->expected_callbacks,
+ GINT_TO_POINTER(test_data->expected_hal_callbacks[i]));
i++;
}
}

static void mgmt_cb_init(struct test_data *data)
{
- if (!data->test_data->expect_settings_set)
+ const struct generic_data *test_data = data->test_data;
+
+ if (!test_data->expect_settings_set)
test_mgmt_settings_set(data);
else
data->mgmt_settings_id = mgmt_register(data->mgmt,
- MGMT_EV_NEW_SETTINGS, data->mgmt_index,
+ MGMT_EV_NEW_SETTINGS, data->mgmt_index,
command_generic_new_settings, NULL, NULL);
}

static void expected_status_init(struct test_data *data)
{
- if (!(data->test_data->expected_adapter_status))
+ const struct generic_data *test_data = data->test_data;
+
+ if (!(test_data->expected_adapter_status))
data->status_checked = true;
}

@@ -167,8 +173,9 @@ static void init_test_conditions(struct test_data *data)
static void check_expected_status(uint8_t status)
{
struct test_data *data = tester_get_data();
+ const struct generic_data *test_data = data->test_data;

- if (data->test_data->expected_adapter_status == status)
+ if (test_data->expected_adapter_status == status)
data->status_checked = true;
else
tester_test_failed();
--
1.8.3.2


2013-12-12 12:48:32

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 5/7] android/tester: Add Socket listen() invalid sock type

From: Andrei Emeltchenko <[email protected]>

Test invalid socket type during listen()
---
android/android-tester.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index 11c3639..f5df0df 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -698,6 +698,15 @@ static void test_dummy(const void *test_data)

/* Test Socket HAL */

+static const struct socket_data btsock_inv_param_socktype = {
+ .sock_type = 0,
+ .channel = 1,
+ .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();
@@ -714,6 +723,28 @@ static void setup_socket_interface(const void *test_data)
tester_setup_complete();
}

+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;
+ }
+
+ 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; \
@@ -747,5 +778,9 @@ 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",
+ &btsock_inv_param_socktype, setup_socket_interface,
+ test_generic_listen, teardown);
+
return tester_run();
}
--
1.8.3.2


2013-12-12 12:48:34

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 7/7] android/tester: Add Socket listen() invalid L2CAP socket type

From: Andrei Emeltchenko <[email protected]>

Check that we get BT_STATUS_UNSUPPORTED for socket type BTSOCK_L2CAP.
---
android/android-tester.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index f5df0df..a50ed7b 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -707,6 +707,15 @@ static const struct socket_data btsock_inv_param_socktype = {
.expected_status = BT_STATUS_PARM_INVALID,
};

+static const struct socket_data btsock_inv_param_socktype_l2cap = {
+ .sock_type = BTSOCK_L2CAP,
+ .channel = 1,
+ .service_uuid = NULL,
+ .service_name = "Test service",
+ .flags = 0,
+ .expected_status = BT_STATUS_UNSUPPORTED,
+};
+
static void setup_socket_interface(const void *test_data)
{
struct test_data *data = tester_get_data();
@@ -782,5 +791,9 @@ int main(int argc, char *argv[])
&btsock_inv_param_socktype, setup_socket_interface,
test_generic_listen, teardown);

+ test_bredrle("Test Socket Listen - Invalid: L2CAP",
+ &btsock_inv_param_socktype_l2cap,
+ setup_socket_interface, test_generic_listen, teardown);
+
return tester_run();
}
--
1.8.3.2


2013-12-12 12:48:30

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCHv2 3/7] android/tester: Add basic Socket Init test

From: Andrei Emeltchenko <[email protected]>

Test get_socket_interface() and basic setup
---
android/android-tester.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

diff --git a/android/android-tester.c b/android/android-tester.c
index 800c14d..c58b13a 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -34,6 +34,7 @@

#include <hardware/hardware.h>
#include <hardware/bluetooth.h>
+#include <hardware/bt_sock.h>

#define adapter_props adapter_prop_bdaddr, adapter_prop_bdname, \
adapter_prop_uuids, adapter_prop_cod, \
@@ -76,7 +77,9 @@ struct test_data {
enum hciemu_type hciemu_type;
const void *test_data;
pid_t bluetoothd_pid;
+
const bt_interface_t *if_bluetooth;
+ const btsock_interface_t *if_sock;

bool mgmt_settings_set;
bool hal_cb_called;
@@ -684,6 +687,24 @@ static void test_dummy(const void *test_data)
tester_test_passed();
}

+/* Test Socket HAL */
+
+static void setup_socket_interface(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+ const void *sock;
+
+ setup(data);
+
+ sock = data->if_bluetooth->get_profile_interface(BT_PROFILE_SOCKETS_ID);
+ if (!sock)
+ tester_setup_failed();
+
+ data->if_sock = sock;
+
+ tester_setup_complete();
+}
+
#define test_bredrle(name, data, test_setup, test, test_teardown) \
do { \
struct test_data *user; \
@@ -714,5 +735,8 @@ int main(int argc, char *argv[])
test_bredrle("Test Disable - Success", &bluetooth_disable_success_test,
setup_enabled_adapter, test_disable, teardown);

+ test_bredrle("Test Socket Init", NULL, setup_socket_interface,
+ test_dummy, teardown);
+
return tester_run();
}
--
1.8.3.2