2014-10-03 13:08:39

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 1/5] android/tester: Rename and expose callback verification function

This is needed to verify action result on remotes side by using hciemu
hooks for example. As hooks are test specific, we need this to be
exposed to other testers.
---
android/tester-main.c | 78 +++++++++++++++++++++++++--------------------------
android/tester-main.h | 1 +
2 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/android/tester-main.c b/android/tester-main.c
index ddae668..5d66fe1 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -880,7 +880,7 @@ static gboolean verify_callback(gpointer user_data)
return FALSE;
}

-static void schedule_callback_call(struct step *step)
+void schedule_callback_verification(struct step *step)
{
g_atomic_int_inc(&scheduled_cbacks_num);
g_idle_add(verify_callback, step);
@@ -898,7 +898,7 @@ static void adapter_state_changed_cb(bt_state_t state)
step->callback_result.state = state;
step->callback = CB_BT_ADAPTER_STATE_CHANGED;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static bt_property_t *copy_properties(int num_properties,
@@ -954,7 +954,7 @@ static void adapter_properties_cb(bt_status_t status, int num_properties,
properties);
step->callback = CB_BT_ADAPTER_PROPERTIES;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void discovery_state_changed_cb(bt_discovery_state_t state)
@@ -964,7 +964,7 @@ static void discovery_state_changed_cb(bt_discovery_state_t state)
step->callback = CB_BT_DISCOVERY_STATE_CHANGED;
step->callback_result.state = state;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void device_found_cb(int num_properties, bt_property_t *properties)
@@ -977,7 +977,7 @@ static void device_found_cb(int num_properties, bt_property_t *properties)

step->callback = CB_BT_DEVICE_FOUND;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void remote_device_properties_cb(bt_status_t status,
@@ -992,7 +992,7 @@ static void remote_device_properties_cb(bt_status_t status,

step->callback = CB_BT_REMOTE_DEVICE_PROPERTIES;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void bond_state_changed_cb(bt_status_t status,
@@ -1012,7 +1012,7 @@ static void bond_state_changed_cb(bt_status_t status,

step->callback = CB_BT_BOND_STATE_CHANGED;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void pin_request_cb(bt_bdaddr_t *remote_bd_addr,
@@ -1041,7 +1041,7 @@ static void pin_request_cb(bt_bdaddr_t *remote_bd_addr,
g_free(props[2]->val);
g_free(props[2]);

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr,
@@ -1072,7 +1072,7 @@ static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr,
g_free(props[2]->val);
g_free(props[2]);

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void acl_state_changed_cb(bt_status_t status,
@@ -1085,7 +1085,7 @@ static void acl_state_changed_cb(bt_status_t status,
step->callback_result.status = status;
step->callback_result.state = state;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static bt_callbacks_t bt_callbacks = {
@@ -1112,7 +1112,7 @@ static void hidhost_connection_state_cb(bt_bdaddr_t *bd_addr,
step->callback = CB_HH_CONNECTION_STATE;
step->callback_result.state = state;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void hidhost_virual_unplug_cb(bt_bdaddr_t *bd_addr, bthh_status_t status)
@@ -1122,7 +1122,7 @@ static void hidhost_virual_unplug_cb(bt_bdaddr_t *bd_addr, bthh_status_t status)
step->callback = CB_HH_VIRTUAL_UNPLUG;
step->callback_result.status = status;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void hidhost_protocol_mode_cb(bt_bdaddr_t *bd_addr,
@@ -1137,7 +1137,7 @@ static void hidhost_protocol_mode_cb(bt_bdaddr_t *bd_addr,

/* TODO: add bdaddr to verify? */

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void hidhost_hid_info_cb(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid)
@@ -1146,7 +1146,7 @@ static void hidhost_hid_info_cb(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid)

step->callback = CB_HH_HID_INFO;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void hidhost_get_report_cb(bt_bdaddr_t *bd_addr, bthh_status_t status,
@@ -1159,7 +1159,7 @@ static void hidhost_get_report_cb(bt_bdaddr_t *bd_addr, bthh_status_t status,
step->callback_result.status = status;
step->callback_result.report_size = size;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static bthh_callbacks_t bthh_callbacks = {
@@ -1181,7 +1181,7 @@ static void gattc_register_client_cb(int status, int client_if,

step->callback_result.status = status;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_scan_result_cb(bt_bdaddr_t *bda, int rssi, uint8_t *adv_data)
@@ -1205,7 +1205,7 @@ static void gattc_scan_result_cb(bt_bdaddr_t *bda, int rssi, uint8_t *adv_data)
g_free(props[1]->val);
g_free(props[1]);

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_connect_cb(int conn_id, int status, int client_if,
@@ -1228,7 +1228,7 @@ static void gattc_connect_cb(int conn_id, int status, int client_if,
g_free(props[0]->val);
g_free(props[0]);

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_disconnect_cb(int conn_id, int status, int client_if,
@@ -1251,7 +1251,7 @@ static void gattc_disconnect_cb(int conn_id, int status, int client_if,
g_free(props[0]->val);
g_free(props[0]);

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_listen_cb(int status, int server_if)
@@ -1261,7 +1261,7 @@ static void gattc_listen_cb(int status, int server_if)
step->callback = CB_GATTC_LISTEN;
step->callback_result.status = status;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_search_result_cb(int conn_id, btgatt_srvc_id_t *srvc_id)
@@ -1272,7 +1272,7 @@ static void gattc_search_result_cb(int conn_id, btgatt_srvc_id_t *srvc_id)
step->callback_result.conn_id = conn_id;
step->callback_result.service = g_memdup(srvc_id, sizeof(*srvc_id));

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_search_complete_cb(int conn_id, int status)
@@ -1282,7 +1282,7 @@ static void gattc_search_complete_cb(int conn_id, int status)
step->callback = CB_GATTC_SEARCH_COMPLETE;
step->callback_result.conn_id = conn_id;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_get_characteristic_cb(int conn_id, int status,
@@ -1299,7 +1299,7 @@ static void gattc_get_characteristic_cb(int conn_id, int status,
sizeof(*char_id));
step->callback_result.char_prop = char_prop;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_get_descriptor_cb(int conn_id, int status,
@@ -1317,7 +1317,7 @@ static void gattc_get_descriptor_cb(int conn_id, int status,
step->callback_result.descriptor = g_memdup(descr_id,
sizeof(*descr_id));

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_get_included_service_cb(int conn_id, int status,
@@ -1332,7 +1332,7 @@ static void gattc_get_included_service_cb(int conn_id, int status,
step->callback_result.included = g_memdup(incl_srvc_id,
sizeof(*srvc_id));

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_read_characteristic_cb(int conn_id, int status,
@@ -1345,7 +1345,7 @@ static void gattc_read_characteristic_cb(int conn_id, int status,
step->callback_result.conn_id = conn_id;
step->callback_result.read_params = g_memdup(p_data, sizeof(*p_data));

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_read_descriptor_cb(int conn_id, int status,
@@ -1358,7 +1358,7 @@ static void gattc_read_descriptor_cb(int conn_id, int status,
step->callback_result.conn_id = conn_id;
step->callback_result.read_params = g_memdup(p_data, sizeof(*p_data));

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_write_characteristic_cb(int conn_id, int status,
@@ -1371,7 +1371,7 @@ static void gattc_write_characteristic_cb(int conn_id, int status,
step->callback_result.conn_id = conn_id;
step->callback_result.write_params = g_memdup(p_data, sizeof(*p_data));

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_write_descriptor_cb(int conn_id, int status,
@@ -1384,7 +1384,7 @@ static void gattc_write_descriptor_cb(int conn_id, int status,
step->callback_result.conn_id = conn_id;
step->callback_result.write_params = g_memdup(p_data, sizeof(*p_data));

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_register_for_notification_cb(int conn_id, int registered,
@@ -1402,7 +1402,7 @@ static void gattc_register_for_notification_cb(int conn_id, int registered,
sizeof(*char_id));
step->callback_result.notification_registered = registered;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gattc_notif_cb(int conn_id, btgatt_notify_params_t *p_data)
@@ -1413,7 +1413,7 @@ static void gattc_notif_cb(int conn_id, btgatt_notify_params_t *p_data)
step->callback_result.conn_id = conn_id;
step->callback_result.notify_params = g_memdup(p_data, sizeof(*p_data));

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gatts_register_server_cb(int status, int server_if,
@@ -1425,7 +1425,7 @@ static void gatts_register_server_cb(int status, int server_if,

step->callback_result.status = status;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void gatts_connection_cb(int conn_id, int server_if, int connected,
@@ -1448,7 +1448,7 @@ static void gatts_connection_cb(int conn_id, int server_if, int connected,
g_free(props[0]->val);
g_free(props[0]);

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void pan_control_state_cb(btpan_control_state_t state,
@@ -1462,7 +1462,7 @@ static void pan_control_state_cb(btpan_control_state_t state,
step->callback_result.ctrl_state = error;
step->callback_result.local_role = state;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void pan_connection_state_cb(btpan_connection_state_t state,
@@ -1478,7 +1478,7 @@ static void pan_connection_state_cb(btpan_connection_state_t state,
step->callback_result.local_role = local_role;
step->callback_result.remote_role = remote_role;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static btpan_callbacks_t btpan_callbacks = {
@@ -1495,7 +1495,7 @@ static void hdp_app_reg_state_cb(int app_id, bthl_app_reg_state_t state)
step->callback_result.app_id = app_id;
step->callback_result.app_state = state;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void hdp_channel_state_cb(int app_id, bt_bdaddr_t *bd_addr,
@@ -1510,7 +1510,7 @@ static void hdp_channel_state_cb(int app_id, bt_bdaddr_t *bd_addr,
step->callback_result.mdep_cfg_index = mdep_cfg_index;
step->callback_result.channel_state = state;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static bthl_callbacks_t bthl_callbacks = {
@@ -1527,7 +1527,7 @@ static void a2dp_connection_state_cb(btav_connection_state_t state,
step->callback = CB_A2DP_CONN_STATE;
step->callback_result.state = state;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static void a2dp_audio_state_cb(btav_audio_state_t state, bt_bdaddr_t *bd_addr)
@@ -1537,7 +1537,7 @@ static void a2dp_audio_state_cb(btav_audio_state_t state, bt_bdaddr_t *bd_addr)
step->callback = CB_A2DP_AUDIO_STATE;
step->callback_result.state = state;

- schedule_callback_call(step);
+ schedule_callback_verification(step);
}

static btav_callbacks_t bta2dp_callbacks = {
diff --git a/android/tester-main.h b/android/tester-main.h
index a343589..3e5c27d 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -561,6 +561,7 @@ void remove_gatt_tests(void);

/* Generic tester API */
void schedule_action_verification(struct step *step);
+void schedule_callback_verification(struct step *step);

/* Emulator actions */
void emu_setup_powered_remote_action(void);
--
1.9.1



2014-10-06 11:35:56

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH 1/5] android/tester: Rename and expose callback verification function

Hi Jakub,

On Friday 03 of October 2014 15:08:39 Jakub Tyszkowski wrote:
> This is needed to verify action result on remotes side by using hciemu
> hooks for example. As hooks are test specific, we need this to be
> exposed to other testers.
> ---
> android/tester-main.c | 78 +++++++++++++++++++++++++--------------------------
> android/tester-main.h | 1 +
> 2 files changed, 40 insertions(+), 39 deletions(-)
>
> diff --git a/android/tester-main.c b/android/tester-main.c
> index ddae668..5d66fe1 100644
> --- a/android/tester-main.c
> +++ b/android/tester-main.c
> @@ -880,7 +880,7 @@ static gboolean verify_callback(gpointer user_data)
> return FALSE;
> }
>
> -static void schedule_callback_call(struct step *step)
> +void schedule_callback_verification(struct step *step)
> {
> g_atomic_int_inc(&scheduled_cbacks_num);
> g_idle_add(verify_callback, step);
> @@ -898,7 +898,7 @@ static void adapter_state_changed_cb(bt_state_t state)
> step->callback_result.state = state;
> step->callback = CB_BT_ADAPTER_STATE_CHANGED;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static bt_property_t *copy_properties(int num_properties,
> @@ -954,7 +954,7 @@ static void adapter_properties_cb(bt_status_t status, int num_properties,
> properties);
> step->callback = CB_BT_ADAPTER_PROPERTIES;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void discovery_state_changed_cb(bt_discovery_state_t state)
> @@ -964,7 +964,7 @@ static void discovery_state_changed_cb(bt_discovery_state_t state)
> step->callback = CB_BT_DISCOVERY_STATE_CHANGED;
> step->callback_result.state = state;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void device_found_cb(int num_properties, bt_property_t *properties)
> @@ -977,7 +977,7 @@ static void device_found_cb(int num_properties, bt_property_t *properties)
>
> step->callback = CB_BT_DEVICE_FOUND;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void remote_device_properties_cb(bt_status_t status,
> @@ -992,7 +992,7 @@ static void remote_device_properties_cb(bt_status_t status,
>
> step->callback = CB_BT_REMOTE_DEVICE_PROPERTIES;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void bond_state_changed_cb(bt_status_t status,
> @@ -1012,7 +1012,7 @@ static void bond_state_changed_cb(bt_status_t status,
>
> step->callback = CB_BT_BOND_STATE_CHANGED;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void pin_request_cb(bt_bdaddr_t *remote_bd_addr,
> @@ -1041,7 +1041,7 @@ static void pin_request_cb(bt_bdaddr_t *remote_bd_addr,
> g_free(props[2]->val);
> g_free(props[2]);
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr,
> @@ -1072,7 +1072,7 @@ static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr,
> g_free(props[2]->val);
> g_free(props[2]);
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void acl_state_changed_cb(bt_status_t status,
> @@ -1085,7 +1085,7 @@ static void acl_state_changed_cb(bt_status_t status,
> step->callback_result.status = status;
> step->callback_result.state = state;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static bt_callbacks_t bt_callbacks = {
> @@ -1112,7 +1112,7 @@ static void hidhost_connection_state_cb(bt_bdaddr_t *bd_addr,
> step->callback = CB_HH_CONNECTION_STATE;
> step->callback_result.state = state;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void hidhost_virual_unplug_cb(bt_bdaddr_t *bd_addr, bthh_status_t status)
> @@ -1122,7 +1122,7 @@ static void hidhost_virual_unplug_cb(bt_bdaddr_t *bd_addr, bthh_status_t status)
> step->callback = CB_HH_VIRTUAL_UNPLUG;
> step->callback_result.status = status;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void hidhost_protocol_mode_cb(bt_bdaddr_t *bd_addr,
> @@ -1137,7 +1137,7 @@ static void hidhost_protocol_mode_cb(bt_bdaddr_t *bd_addr,
>
> /* TODO: add bdaddr to verify? */
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void hidhost_hid_info_cb(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid)
> @@ -1146,7 +1146,7 @@ static void hidhost_hid_info_cb(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid)
>
> step->callback = CB_HH_HID_INFO;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void hidhost_get_report_cb(bt_bdaddr_t *bd_addr, bthh_status_t status,
> @@ -1159,7 +1159,7 @@ static void hidhost_get_report_cb(bt_bdaddr_t *bd_addr, bthh_status_t status,
> step->callback_result.status = status;
> step->callback_result.report_size = size;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static bthh_callbacks_t bthh_callbacks = {
> @@ -1181,7 +1181,7 @@ static void gattc_register_client_cb(int status, int client_if,
>
> step->callback_result.status = status;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_scan_result_cb(bt_bdaddr_t *bda, int rssi, uint8_t *adv_data)
> @@ -1205,7 +1205,7 @@ static void gattc_scan_result_cb(bt_bdaddr_t *bda, int rssi, uint8_t *adv_data)
> g_free(props[1]->val);
> g_free(props[1]);
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_connect_cb(int conn_id, int status, int client_if,
> @@ -1228,7 +1228,7 @@ static void gattc_connect_cb(int conn_id, int status, int client_if,
> g_free(props[0]->val);
> g_free(props[0]);
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_disconnect_cb(int conn_id, int status, int client_if,
> @@ -1251,7 +1251,7 @@ static void gattc_disconnect_cb(int conn_id, int status, int client_if,
> g_free(props[0]->val);
> g_free(props[0]);
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_listen_cb(int status, int server_if)
> @@ -1261,7 +1261,7 @@ static void gattc_listen_cb(int status, int server_if)
> step->callback = CB_GATTC_LISTEN;
> step->callback_result.status = status;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_search_result_cb(int conn_id, btgatt_srvc_id_t *srvc_id)
> @@ -1272,7 +1272,7 @@ static void gattc_search_result_cb(int conn_id, btgatt_srvc_id_t *srvc_id)
> step->callback_result.conn_id = conn_id;
> step->callback_result.service = g_memdup(srvc_id, sizeof(*srvc_id));
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_search_complete_cb(int conn_id, int status)
> @@ -1282,7 +1282,7 @@ static void gattc_search_complete_cb(int conn_id, int status)
> step->callback = CB_GATTC_SEARCH_COMPLETE;
> step->callback_result.conn_id = conn_id;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_get_characteristic_cb(int conn_id, int status,
> @@ -1299,7 +1299,7 @@ static void gattc_get_characteristic_cb(int conn_id, int status,
> sizeof(*char_id));
> step->callback_result.char_prop = char_prop;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_get_descriptor_cb(int conn_id, int status,
> @@ -1317,7 +1317,7 @@ static void gattc_get_descriptor_cb(int conn_id, int status,
> step->callback_result.descriptor = g_memdup(descr_id,
> sizeof(*descr_id));
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_get_included_service_cb(int conn_id, int status,
> @@ -1332,7 +1332,7 @@ static void gattc_get_included_service_cb(int conn_id, int status,
> step->callback_result.included = g_memdup(incl_srvc_id,
> sizeof(*srvc_id));
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_read_characteristic_cb(int conn_id, int status,
> @@ -1345,7 +1345,7 @@ static void gattc_read_characteristic_cb(int conn_id, int status,
> step->callback_result.conn_id = conn_id;
> step->callback_result.read_params = g_memdup(p_data, sizeof(*p_data));
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_read_descriptor_cb(int conn_id, int status,
> @@ -1358,7 +1358,7 @@ static void gattc_read_descriptor_cb(int conn_id, int status,
> step->callback_result.conn_id = conn_id;
> step->callback_result.read_params = g_memdup(p_data, sizeof(*p_data));
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_write_characteristic_cb(int conn_id, int status,
> @@ -1371,7 +1371,7 @@ static void gattc_write_characteristic_cb(int conn_id, int status,
> step->callback_result.conn_id = conn_id;
> step->callback_result.write_params = g_memdup(p_data, sizeof(*p_data));
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_write_descriptor_cb(int conn_id, int status,
> @@ -1384,7 +1384,7 @@ static void gattc_write_descriptor_cb(int conn_id, int status,
> step->callback_result.conn_id = conn_id;
> step->callback_result.write_params = g_memdup(p_data, sizeof(*p_data));
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_register_for_notification_cb(int conn_id, int registered,
> @@ -1402,7 +1402,7 @@ static void gattc_register_for_notification_cb(int conn_id, int registered,
> sizeof(*char_id));
> step->callback_result.notification_registered = registered;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gattc_notif_cb(int conn_id, btgatt_notify_params_t *p_data)
> @@ -1413,7 +1413,7 @@ static void gattc_notif_cb(int conn_id, btgatt_notify_params_t *p_data)
> step->callback_result.conn_id = conn_id;
> step->callback_result.notify_params = g_memdup(p_data, sizeof(*p_data));
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gatts_register_server_cb(int status, int server_if,
> @@ -1425,7 +1425,7 @@ static void gatts_register_server_cb(int status, int server_if,
>
> step->callback_result.status = status;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void gatts_connection_cb(int conn_id, int server_if, int connected,
> @@ -1448,7 +1448,7 @@ static void gatts_connection_cb(int conn_id, int server_if, int connected,
> g_free(props[0]->val);
> g_free(props[0]);
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void pan_control_state_cb(btpan_control_state_t state,
> @@ -1462,7 +1462,7 @@ static void pan_control_state_cb(btpan_control_state_t state,
> step->callback_result.ctrl_state = error;
> step->callback_result.local_role = state;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void pan_connection_state_cb(btpan_connection_state_t state,
> @@ -1478,7 +1478,7 @@ static void pan_connection_state_cb(btpan_connection_state_t state,
> step->callback_result.local_role = local_role;
> step->callback_result.remote_role = remote_role;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static btpan_callbacks_t btpan_callbacks = {
> @@ -1495,7 +1495,7 @@ static void hdp_app_reg_state_cb(int app_id, bthl_app_reg_state_t state)
> step->callback_result.app_id = app_id;
> step->callback_result.app_state = state;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void hdp_channel_state_cb(int app_id, bt_bdaddr_t *bd_addr,
> @@ -1510,7 +1510,7 @@ static void hdp_channel_state_cb(int app_id, bt_bdaddr_t *bd_addr,
> step->callback_result.mdep_cfg_index = mdep_cfg_index;
> step->callback_result.channel_state = state;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static bthl_callbacks_t bthl_callbacks = {
> @@ -1527,7 +1527,7 @@ static void a2dp_connection_state_cb(btav_connection_state_t state,
> step->callback = CB_A2DP_CONN_STATE;
> step->callback_result.state = state;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static void a2dp_audio_state_cb(btav_audio_state_t state, bt_bdaddr_t *bd_addr)
> @@ -1537,7 +1537,7 @@ static void a2dp_audio_state_cb(btav_audio_state_t state, bt_bdaddr_t *bd_addr)
> step->callback = CB_A2DP_AUDIO_STATE;
> step->callback_result.state = state;
>
> - schedule_callback_call(step);
> + schedule_callback_verification(step);
> }
>
> static btav_callbacks_t bta2dp_callbacks = {
> diff --git a/android/tester-main.h b/android/tester-main.h
> index a343589..3e5c27d 100644
> --- a/android/tester-main.h
> +++ b/android/tester-main.h
> @@ -561,6 +561,7 @@ void remove_gatt_tests(void);
>
> /* Generic tester API */
> void schedule_action_verification(struct step *step);
> +void schedule_callback_verification(struct step *step);
>
> /* Emulator actions */
> void emu_setup_powered_remote_action(void);
>

All patches applied (with changes we discussed offline). Thanks.

--
Best regards,
Szymon Janc

2014-10-03 13:08:43

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 5/5] android/tester: Add case for reconnecting HID keyboard device

This test case checks if we correctly raise security level for
reconnecting keyboard devices when previously paired.
---
android/tester-hidhost.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++
android/tester-main.c | 1 +
android/tester-main.h | 1 +
3 files changed, 94 insertions(+)

diff --git a/android/tester-hidhost.c b/android/tester-hidhost.c
index 24036ce..af340ea 100644
--- a/android/tester-hidhost.c
+++ b/android/tester-hidhost.c
@@ -43,6 +43,9 @@

#define HID_EXPECTED_REPORT_SIZE 0x02

+#define HID_MSG_CONTROL 0x10
+#define HID_VIRTUAL_CABLE_UNPLUG 0x05
+
static struct queue *list; /* List of hidhost test cases */

#define did_req_pdu 0x06, \
@@ -261,6 +264,13 @@ static void hid_ctrl_cid_hook_cb(const void *data, uint16_t len,

schedule_callback_verification(step);
break;
+ case HID_MSG_CONTROL | HID_VIRTUAL_CABLE_UNPLUG:
+ step = g_new0(struct step, 1);
+
+ step->callback = CB_EMU_CONNECTION_REJECTED;
+
+ schedule_callback_verification(step);
+ break;
}
}
static void hid_ctrl_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
@@ -306,6 +316,14 @@ static void hid_intr_connect_cb(uint16_t handle, uint16_t cid, void *user_data)
cid_data);
}

+static bt_scan_mode_t setprop_scan_mode_conn_val = BT_SCAN_MODE_CONNECTABLE;
+
+static bt_property_t prop_test_scan_mode_conn = {
+ .type = BT_PROPERTY_ADAPTER_SCAN_MODE,
+ .val = &setprop_scan_mode_conn_val,
+ .len = sizeof(setprop_scan_mode_conn_val),
+};
+
/* Emulate SDP (PSM = 1) */
static struct emu_set_l2cap_data l2cap_setup_sdp_data = {
.psm = 1,
@@ -450,6 +468,62 @@ static void hidhost_send_data_action(void)
schedule_action_verification(step);
}

+static void client_l2cap_rsp(uint8_t code, const void *data, uint16_t len,
+ void *user_data)
+{
+ struct test_data *t_data = tester_get_data();
+ struct bthost *bthost = hciemu_client_get_host(t_data->hciemu);
+ struct emu_l2cap_cid_data *cid_data = user_data;
+ const uint16_t *psm = data;
+ const struct iovec con_req = raw_pdu(0x13, 0x00, /* PSM */
+ 0x41, 0x00); /* Source CID */
+
+ if (len < sizeof(*psm)) {
+ tester_warn("Invalid l2cap response.");
+ return;
+ }
+
+ switch (*psm) {
+ case 0x40:
+ bthost_add_cid_hook(bthost, cid_data->handle, 0x40,
+ hid_ctrl_cid_hook_cb, cid_data);
+
+ bthost_l2cap_req(bthost, cid_data->handle, 0x02,
+ con_req.iov_base, con_req.iov_len,
+ client_l2cap_rsp, cid_data);
+ break;
+ case 0x41:
+ bthost_add_cid_hook(bthost, cid_data->handle, 0x41,
+ hid_intr_cid_hook_cb, cid_data);
+ break;
+ default:
+ break;
+ }
+}
+
+static void hidhost_conn_cb(uint16_t handle, void *user_data)
+{
+ const struct iovec con_req = raw_pdu(0x11, 0x00, /* PSM */
+ 0x40, 0x00); /* Source CID */
+
+ struct test_data *data = tester_get_data();
+ struct bthost *bthost = hciemu_client_get_host(data->hciemu);
+
+ if (data->hciemu_type == HCIEMU_TYPE_BREDR) {
+ tester_warn("Not handled device type.");
+ return;
+ }
+
+ ctrl_cid_data.cid = 0x40;
+ ctrl_cid_data.handle = handle;
+
+ tester_print("Sending L2CAP Request from remote");
+
+ bthost_l2cap_req(bthost, handle, 0x02, con_req.iov_base,
+ con_req.iov_len, client_l2cap_rsp,
+ &ctrl_cid_data);
+}
+
static struct test_case test_cases[] = {
TEST_CASE_BREDRLE("HidHost Init",
ACTION_SUCCESS(dummy_action, NULL),
@@ -619,6 +693,24 @@ static struct test_case test_cases[] = {
BTHH_CONN_STATE_DISCONNECTED),
CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
),
+ TEST_CASE_BREDRLE("HidHost Reject Unknown Remote Connection",
+ ACTION_SUCCESS(bluetooth_enable_action, NULL),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+ ACTION_SUCCESS(bt_set_property_action,
+ &prop_test_scan_mode_conn),
+ CALLBACK_ADAPTER_PROPS(&prop_test_scan_mode_conn, 1),
+ ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
+ ACTION_SUCCESS(emu_add_l2cap_server_action,
+ &l2cap_setup_kb_sdp_data),
+ ACTION_SUCCESS(emu_add_l2cap_server_action,
+ &l2cap_setup_cc_data),
+ ACTION_SUCCESS(emu_add_l2cap_server_action,
+ &l2cap_setup_ic_data),
+ /* Trigger incoming connection */
+ ACTION_SUCCESS(emu_set_connect_cb_action, hidhost_conn_cb),
+ ACTION_SUCCESS(emu_remote_connect_hci_action, NULL),
+ CALLBACK(CB_EMU_CONNECTION_REJECTED),
+ ),
};

struct queue *get_hidhost_tests(void)
diff --git a/android/tester-main.c b/android/tester-main.c
index d5ebe16..bb064b7 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -106,6 +106,7 @@ static struct {
DBG_CB(CB_EMU_CONFIRM_SEND_DATA),
DBG_CB(CB_EMU_ENCRYPTION_ENABLED),
DBG_CB(CB_EMU_ENCRYPTION_DISABLED),
+ DBG_CB(CB_EMU_CONNECTION_REJECTED),
};

static gboolean check_callbacks_called(gpointer user_data)
diff --git a/android/tester-main.h b/android/tester-main.h
index e96ad24..922f1cf 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -402,6 +402,7 @@ typedef enum {
CB_EMU_CONFIRM_SEND_DATA,
CB_EMU_ENCRYPTION_ENABLED,
CB_EMU_ENCRYPTION_DISABLED,
+ CB_EMU_CONNECTION_REJECTED,
} expected_bt_callback_t;

struct test_data {
--
1.9.1


2014-10-03 13:08:41

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 3/5] android/tester: Add encryption change callback

This is needed for encryption verification.
---
android/tester-main.c | 25 +++++++++++++++++++++++++
android/tester-main.h | 2 ++
2 files changed, 27 insertions(+)

diff --git a/android/tester-main.c b/android/tester-main.c
index c637fd5..d5ebe16 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -104,6 +104,8 @@ static struct {

/* Emulator callbacks */
DBG_CB(CB_EMU_CONFIRM_SEND_DATA),
+ DBG_CB(CB_EMU_ENCRYPTION_ENABLED),
+ DBG_CB(CB_EMU_ENCRYPTION_DISABLED),
};

static gboolean check_callbacks_called(gpointer user_data)
@@ -291,6 +293,25 @@ static void mgmt_debug(const char *str, void *user_data)
tester_print("%s%s", prefix, str);
}

+static bool hciemu_post_encr_hook(const void *data, uint16_t len,
+ void *user_data)
+{
+ struct step *step = g_new0(struct step, 1);
+
+ /*
+ * Expected data: status (1 octet) + conn. handle (2 octets) +
+ * encryption flag (1 octet)
+ */
+ if (len < 4)
+ return true;
+
+ step->callback = ((uint8_t *)data)[3] ? CB_EMU_ENCRYPTION_ENABLED :
+ CB_EMU_ENCRYPTION_DISABLED;
+
+ schedule_callback_verification(step);
+ return true;
+}
+
static void read_info_callback(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
@@ -328,6 +349,10 @@ static void read_info_callback(uint8_t status, uint16_t length,
return;
}

+ /* set hook for encryption change */
+ hciemu_add_hook(data->hciemu, HCIEMU_HOOK_POST_EVT, 0x08,
+ hciemu_post_encr_hook, NULL);
+
tester_pre_setup_complete();
}

diff --git a/android/tester-main.h b/android/tester-main.h
index 6245381..e96ad24 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -400,6 +400,8 @@ typedef enum {

/* Emulator callbacks */
CB_EMU_CONFIRM_SEND_DATA,
+ CB_EMU_ENCRYPTION_ENABLED,
+ CB_EMU_ENCRYPTION_DISABLED,
} expected_bt_callback_t;

struct test_data {
--
1.9.1


2014-10-03 13:08:42

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 4/5] android/tester: Add case verifying encryption on HIDHost

This case verifies if encryption is enabled when connecting to
HID Keyboard device.
---
android/tester-hidhost.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)

diff --git a/android/tester-hidhost.c b/android/tester-hidhost.c
index be840b0..24036ce 100644
--- a/android/tester-hidhost.c
+++ b/android/tester-hidhost.c
@@ -132,6 +132,80 @@ static struct emu_l2cap_cid_data sdp_cid_data = {
.is_sdp = TRUE,
};

+#define hid_keyboard_rsp_pdu 0x07, \
+ 0x00, 0x01, \
+ 0x02, 0x04, \
+ 0x02, 0x01, \
+ 0x36, 0x01, 0xfe, 0x36, 0x01, 0x93, 0x09, 0x00, 0x00, \
+ 0x0a, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35, \
+ 0x03, 0x19, 0x11, 0x24, 0x09, 0x00, 0x04, 0x35, 0x0d, \
+ 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x11, 0x35, \
+ 0x03, 0x19, 0x00, 0x11, 0x09, 0x00, 0x06, 0x35, 0x09, \
+ 0x09, 0x65, 0x6e, 0x09, 0x00, 0x6a, 0x09, 0x01, 0x00, \
+ 0x09, 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, 0x11, \
+ 0x24, 0x09, 0x01, 0x00, 0x09, 0x00, 0x0d, 0x35, 0x0f, \
+ 0x35, 0x0d, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, \
+ 0x13, 0x35, 0x03, 0x19, 0x00, 0x11, 0x09, 0x01, 0x00, \
+ 0x25, 0x10, 0x53, 0x41, 0x4d, 0x53, 0x55, 0x4e, 0x47, \
+ 0x20, 0x4b, 0x65, 0x79, 0x62, 0x6f, 0x61, 0x72, 0x64, \
+ 0x09, 0x01, 0x01, 0x25, 0x08, 0x4b, 0x65, 0x79, 0x62, \
+ 0x6f, 0x61, 0x72, 0x64, 0x09, 0x01, 0x02, 0x25, 0x0d, \
+ 0x43, 0x53, 0x52, 0x20, 0x48, 0x49, 0x44, 0x45, 0x6e, \
+ 0x67, 0x69, 0x6e, 0x65, 0x09, 0x02, 0x00, 0x09, 0x01, \
+ 0x00, 0x09, 0x02, 0x01, 0x09, 0x01, 0x11, 0x09, 0x02, \
+ 0x02, 0x08, 0x40, 0x09, 0x02, 0x03, 0x08, 0x23, 0x09, \
+ 0x02, 0x04, 0x28, 0x01, 0x09, 0x02, 0x05, 0x28, 0x01, \
+ 0x09, 0x02, 0x06, 0x35, 0xb7, 0x35, 0xb5, 0x08, 0x22, \
+ 0x25, 0xb1, 0x05, 0x01, 0x09, 0x06, 0xa1, 0x01, 0x05, \
+ 0x07, 0x85, 0x01, 0x19, 0xe0, 0x29, 0xe7, 0x15, 0x00, \
+ 0x25, 0x01, 0x75, 0x01, 0x95, 0x08, 0x81, 0x02, 0x95, \
+ 0x01, 0x75, 0x08, 0x81, 0x01, 0x95, 0x05, 0x75, 0x01, \
+ 0x05, 0x08, 0x85, 0x01, 0x19, 0x01, 0x29, 0x05, 0x91, \
+ 0x02, 0x95, 0x01, 0x75, 0x03, 0x91, 0x03, 0x95, 0x06, \
+ 0x75, 0x08, 0x15, 0x00, 0x25, 0x65, 0x05, 0x07, 0x19, \
+ 0x00, 0x29, 0x6f, 0x81, 0x00, 0xc0, 0x05, 0x0c, 0x09, \
+ 0x01, 0xa1, 0x01, 0x85, 0x02, 0x05, 0x0c, 0x15, 0x00, \
+ 0x25, 0x01, 0x75, 0x01, 0x95, 0x18, 0x09, 0xe2, 0x09, \
+ 0xea, 0x09, 0xe9, 0x09, 0xb7, 0x09, 0xcd, 0x0a, 0x23, \
+ 0x02, 0x0a, 0x8a, 0x01, 0x0a, 0x21, 0x02, 0x75, 0x01, \
+ 0x95, 0x03, 0x81, 0x02, 0x75, 0x01, 0x95, 0x05, 0x81, \
+ 0x01, 0x05, 0x08, 0x85, 0xff, 0x95, 0x01, 0x75, 0x02, \
+ 0x09, 0x24, 0x09, 0x26, 0x81, 0x02, 0x75, 0x06, 0x81, \
+ 0x01, 0xc0, 0x06, 0x7f, 0xff, 0x09, 0x01, 0xa1, 0x01, \
+ 0x85, 0x03, 0x15, 0x00, 0x25, 0x01, 0x09, 0xb9, 0x09, \
+ 0xb5, 0x09, 0xba, 0x09, 0xbb, 0x09, 0xbc, 0x09, 0xbd, \
+ 0x09, 0xb6, 0x09, 0xb7, 0x75, 0x01, 0x95, 0x06, 0x81, \
+ 0x02, 0x75, 0x01, 0x95, 0x02, 0x81, 0x01, 0xc0, 0x09, \
+ 0x02, 0x07, 0x35, 0x08, 0x35, 0x06, 0x09, 0x04, 0x09, \
+ 0x09, 0x01, 0x00, 0x09, 0x02, 0x08, 0x28, 0x00, 0x09, \
+ 0x02, 0x09, 0x28, 0x01, 0x09, 0x02, 0x0a, 0x28, 0x01, \
+ 0x09, 0x02, 0x0b, 0x09, 0x01, 0x00, 0x09, 0x02, 0x0c, \
+ 0x09, 0x1f, 0x40, 0x09, 0x02, 0x0d, 0x28, 0x00, 0x09, \
+ 0x02, 0x0e, 0x28, 0x01, 0x36, 0x00, 0x65, 0x09, 0x00, \
+ 0x00, 0x0a, 0x00, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, \
+ 0x35, 0x03, 0x19, 0x12, 0x00, 0x09, 0x00, 0x04, 0x35, \
+ 0x0d, 0x35, 0x06, 0x19, 0x01, 0x00, 0x09, 0x00, 0x01, \
+ 0x35, 0x03, 0x19, 0x00, 0x01, 0x09, 0x00, 0x06, 0x35, \
+ 0x09, 0x09, 0x65, 0x6e, 0x09, 0x00, 0x6a, 0x09, 0x01, \
+ 0x00, 0x09, 0x00, 0x09, 0x35, 0x08, 0x35, 0x06, 0x19, \
+ 0x12, 0x00, 0x09, 0x01, 0x00, 0x09, 0x01, 0x01, 0x25, \
+ 0x00, 0x09, 0x02, 0x00, 0x09, 0x01, 0x00, 0x09, 0x02, \
+ 0x01, 0x09, 0x23, 0x3d, 0x09, 0x02, 0x02, 0x09, 0x01, \
+ 0x3d, 0x09, 0x02, 0x03, 0x09, 0x00, 0x00, 0x09, 0x02, \
+ 0x04, 0x28, 0x01, 0x09, 0x02, 0x05, 0x09, 0x00, 0x02, \
+ 0x00
+
+static const struct pdu_set sdp_kb_pdus[] = {
+ { raw_pdu(did_req_pdu), raw_pdu(did_rsp_pdu) },
+ { raw_pdu(hid_req_pdu), raw_pdu(hid_keyboard_rsp_pdu) },
+ { end_pdu, end_pdu },
+};
+
+static struct emu_l2cap_cid_data sdp_kb_cid_data = {
+ .pdu = sdp_kb_pdus,
+ .is_sdp = TRUE,
+};
+
static struct emu_l2cap_cid_data ctrl_cid_data;
static struct emu_l2cap_cid_data intr_cid_data;

@@ -239,6 +313,12 @@ static struct emu_set_l2cap_data l2cap_setup_sdp_data = {
.user_data = &sdp_cid_data,
};

+static struct emu_set_l2cap_data l2cap_setup_kb_sdp_data = {
+ .psm = 1,
+ .func = tester_generic_connect_cb,
+ .user_data = &sdp_kb_cid_data,
+};
+
/* Emulate Control Channel (PSM = 17) */
static struct emu_set_l2cap_data l2cap_setup_cc_data = {
.psm = 17,
@@ -517,6 +597,28 @@ static struct test_case test_cases[] = {
ACTION_SUCCESS(hidhost_send_data_action, NULL),
CALLBACK(CB_EMU_CONFIRM_SEND_DATA),
),
+ TEST_CASE_BREDRLE("HidHost Connect Encrypted Success",
+ 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(set_default_ssp_request_handler, NULL),
+ ACTION_SUCCESS(emu_add_l2cap_server_action,
+ &l2cap_setup_kb_sdp_data),
+ ACTION_SUCCESS(emu_add_l2cap_server_action,
+ &l2cap_setup_cc_data),
+ ACTION_SUCCESS(emu_add_l2cap_server_action,
+ &l2cap_setup_ic_data),
+ ACTION_SUCCESS(hidhost_connect_action, NULL),
+ CALLBACK(CB_EMU_ENCRYPTION_ENABLED),
+ CALLBACK_STATE(CB_HH_CONNECTION_STATE,
+ BTHH_CONN_STATE_CONNECTED),
+ ACTION_SUCCESS(hidhost_send_data_action, NULL),
+ ACTION_SUCCESS(bluetooth_disable_action, NULL),
+ CALLBACK_STATE(CB_HH_CONNECTION_STATE,
+ BTHH_CONN_STATE_DISCONNECTED),
+ CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+ ),
};

struct queue *get_hidhost_tests(void)
--
1.9.1


2014-10-03 13:08:40

by Jakub Tyszkowski

[permalink] [raw]
Subject: [PATCH 2/5] android/tester: Improve HIDHost data sending verification

Hciemu hooks may be called in different test stage than we expect
and we shouldn't blindly verifying the step with success every time
when data is send, as we really dont know the step we are currently in.

This patch fixes this issue by splitting the action in two steps: action
step that triggers data sending and callback step that verifies on
remotes sid that data was send.
---
android/tester-hidhost.c | 35 +++++++++++++----------------------
android/tester-main.c | 3 +++
android/tester-main.h | 3 +++
3 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/android/tester-hidhost.c b/android/tester-hidhost.c
index 8da5d32..be840b0 100644
--- a/android/tester-hidhost.c
+++ b/android/tester-hidhost.c
@@ -183,9 +183,9 @@ static void hid_ctrl_cid_hook_cb(const void *data, uint16_t len,
/* Successfully verify sending data step */
step = g_new0(struct step, 1);

- step->action_status = BT_STATUS_SUCCESS;
+ step->callback = CB_EMU_CONFIRM_SEND_DATA;

- schedule_action_verification(step);
+ schedule_callback_verification(step);
break;
}
}
@@ -213,9 +213,9 @@ static void hid_intr_cid_hook_cb(const void *data, uint16_t len,
/* Successfully verify sending data step */
step = g_new0(struct step, 1);

- step->action_status = BT_STATUS_SUCCESS;
+ step->callback = CB_EMU_CONFIRM_SEND_DATA;

- schedule_action_verification(step);
+ schedule_callback_verification(step);
break;
}
}
@@ -345,40 +345,29 @@ static void hidhost_set_report_action(void)
{
struct test_data *data = tester_get_data();
const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
+ struct step *step = g_new0(struct step, 1);
char *buf = "fe0201";
bt_bdaddr_t bdaddr;
- int status;

bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);

- /* Successfull result should be verified on the other end (hook) */
- status = data->if_hid->send_data(&bdaddr, buf);
- if (status) {
- struct step *step = g_new0(struct step, 1);
-
- step->action_status = status;
- schedule_action_verification(step);
- }
+ step->action_status = data->if_hid->send_data(&bdaddr, buf);
+ schedule_action_verification(step);
}

static void hidhost_send_data_action(void)
{
struct test_data *data = tester_get_data();
const uint8_t *hid_addr = hciemu_get_client_bdaddr(data->hciemu);
+ struct step *step = g_new0(struct step, 1);
char *buf = "010101";
bt_bdaddr_t bdaddr;
- int status;

bdaddr2android((const bdaddr_t *) hid_addr, &bdaddr);

- /* Successfull result should be verified on the other end (hook) */
- status = data->if_hid->set_report(&bdaddr, BTHH_INPUT_REPORT, buf);
- if (status) {
- struct step *step = g_new0(struct step, 1);
-
- step->action_status = status;
- schedule_action_verification(step);
- }
+ step->action_status = data->if_hid->set_report(&bdaddr,
+ BTHH_INPUT_REPORT, buf);
+ schedule_action_verification(step);
}

static struct test_case test_cases[] = {
@@ -509,6 +498,7 @@ static struct test_case test_cases[] = {
CALLBACK_STATE(CB_HH_CONNECTION_STATE,
BTHH_CONN_STATE_CONNECTED),
ACTION_SUCCESS(hidhost_set_report_action, NULL),
+ CALLBACK(CB_EMU_CONFIRM_SEND_DATA),
),
TEST_CASE_BREDRLE("HidHost SendData Success",
ACTION_SUCCESS(bluetooth_enable_action, NULL),
@@ -525,6 +515,7 @@ static struct test_case test_cases[] = {
CALLBACK_STATE(CB_HH_CONNECTION_STATE,
BTHH_CONN_STATE_CONNECTED),
ACTION_SUCCESS(hidhost_send_data_action, NULL),
+ CALLBACK(CB_EMU_CONFIRM_SEND_DATA),
),
};

diff --git a/android/tester-main.c b/android/tester-main.c
index 5d66fe1..c637fd5 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -101,6 +101,9 @@ static struct {
DBG_CB(CB_GATTS_REQUEST_WRITE),
DBG_CB(CB_GATTS_REQUEST_EXEC_WRITE),
DBG_CB(CB_GATTS_RESPONSE_CONFIRMATION),
+
+ /* Emulator callbacks */
+ DBG_CB(CB_EMU_CONFIRM_SEND_DATA),
};

static gboolean check_callbacks_called(gpointer user_data)
diff --git a/android/tester-main.h b/android/tester-main.h
index 3e5c27d..6245381 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -397,6 +397,9 @@ typedef enum {
CB_GATTS_REQUEST_WRITE,
CB_GATTS_REQUEST_EXEC_WRITE,
CB_GATTS_RESPONSE_CONFIRMATION,
+
+ /* Emulator callbacks */
+ CB_EMU_CONFIRM_SEND_DATA,
} expected_bt_callback_t;

struct test_data {
--
1.9.1