Hi Marcin, Grzegorz, On Tue, Dec 10, 2013 at 12:45 PM, Marcin Kraglak <marcin.kraglak@xxxxxxxxx> wrote: > From: Grzegorz Kolodziejczyk <grzegorz.kolodziejczyk@xxxxxxxxx> > > This adds basic tests for bluetooth hal interface, enable and controller > setup. > > --- > android/android-tester.c | 247 +++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 240 insertions(+), 7 deletions(-) > > diff --git a/android/android-tester.c b/android/android-tester.c > index 2df5bdb..6cde3cf 100644 > --- a/android/android-tester.c > +++ b/android/android-tester.c > @@ -37,16 +37,129 @@ > #define WAIT_FOR_SIGNAL_TIME 2 /* in seconds */ > #define EMULATOR_SIGNAL "emulator_started" > > +#define adapter_props adapter_prop_bdaddr, adapter_prop_bdname, \ > + adapter_prop_uuids, adapter_prop_cod, \ > + adapter_prop_scan_mode, adapter_prop_disc_timeout > + > +/* > + * those are assigned to HAL methods and callbacks, we use ID later > + * on mapped in switch-case due to different functions prototypes. > + */ > + > +enum hal_bluetooth_callbacks_id { > + adapter_test_end, > + adapter_state_changed_on, > + adapter_state_changed_off, > + adapter_prop_bdaddr, > + adapter_prop_bdname, > + adapter_prop_uuids, > + adapter_prop_cod, > + adapter_prop_scan_mode, > + adapter_prop_disc_timeout, > + adapter_prop_service_record, > + adapter_prop_bonded_devices > +}; > + > +struct generic_data { > + uint32_t expect_settings_set; > + uint8_t expected_hal_callbacks[]; > +}; > + > struct test_data { > struct mgmt *mgmt; > uint16_t mgmt_index; > + unsigned int mgmt_settings_id; > struct hciemu *hciemu; > enum hciemu_type hciemu_type; > - void *test_data; > + const struct generic_data *test_data; > pid_t bluetoothd_pid; > const bt_interface_t *if_bluetooth; > + > + bool mgmt_settings_set; > + bool hal_cb_called; > + > + GSList *expected_callbacks; > }; > > +static void test_update_state(void) > +{ > + struct test_data *data = tester_get_data(); > + > + if (data->mgmt_settings_set && data->hal_cb_called) > + tester_test_passed(); > +} > + > +static void test_mgmt_settings_set(struct test_data *data) > +{ > + data->mgmt_settings_set = true; > + > + test_update_state(); > +} > + > +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(); > + uint32_t settings; > + > + if (length != 4) { > + tester_warn("Invalid parameter size for new settings event"); > + tester_test_failed(); > + return; > + } > + > + settings = bt_get_le32(param); > + > + if ((settings & data->test_data->expect_settings_set) != > + data->test_data->expect_settings_set) > + return; > + > + test_mgmt_settings_set(data); > + mgmt_unregister(data->mgmt, data->mgmt_settings_id); > +} > + > +static void hal_cb_init(struct test_data *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])); > + i++; > + } > +} > + > +static void mgmt_cb_init(struct test_data *data) > +{ > + if (!data->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, > + command_generic_new_settings, NULL, NULL); > +} > + > +static int get_expected_hal_cb(void) > +{ > + struct test_data *data = tester_get_data(); > + > + return GPOINTER_TO_INT(data->expected_callbacks->data); > +} > + > +static void remove_expected_hal_cb(void) > +{ > + struct test_data *data = tester_get_data(); > + > + data->expected_callbacks = g_slist_remove(data->expected_callbacks, > + data->expected_callbacks->data); > + > + if (!data->expected_callbacks) > + data->hal_cb_called = true; > + > + test_update_state(); > +} > + > static void read_info_callback(uint8_t status, uint16_t length, > const void *param, void *user_data) > { > @@ -241,10 +354,107 @@ failed: > close(fd); > } > > +static void adapter_state_changed_cb(bt_state_t state) > +{ > + switch (get_expected_hal_cb()) { > + case adapter_state_changed_on: > + if (state == BT_STATE_ON) > + remove_expected_hal_cb(); > + else > + tester_test_failed(); > + break; > + default: > + break; > + } > +} > + > +static void adapter_properties_cb(bt_status_t status, int num_properties, > + bt_property_t *properties) > +{ > + enum hal_bluetooth_callbacks_id hal_cb; > + int i; > + > + for (i = 0; i < num_properties; i++) { > + hal_cb = get_expected_hal_cb(); > + switch (properties[i].type) { > + case BT_PROPERTY_BDADDR: > + if (hal_cb != adapter_prop_bdaddr) { > + tester_test_failed(); > + return; > + } > + remove_expected_hal_cb(); > + break; > + case BT_PROPERTY_BDNAME: > + if (hal_cb != adapter_prop_bdname) { > + tester_test_failed(); > + return; > + } > + remove_expected_hal_cb(); > + break; > + case BT_PROPERTY_UUIDS: > + if (hal_cb != adapter_prop_uuids) { > + tester_test_failed(); > + return; > + } > + remove_expected_hal_cb(); > + break; > + case BT_PROPERTY_CLASS_OF_DEVICE: > + if (hal_cb != adapter_prop_cod) { > + tester_test_failed(); > + return; > + } > + remove_expected_hal_cb(); > + break; > + case BT_PROPERTY_TYPE_OF_DEVICE: > + if (hal_cb != adapter_prop_bdaddr) { > + tester_test_failed(); > + return; > + } > + remove_expected_hal_cb(); > + break; > + case BT_PROPERTY_SERVICE_RECORD: > + if (hal_cb != adapter_prop_service_record) { > + tester_test_failed(); > + return; > + } > + remove_expected_hal_cb(); > + break; > + case BT_PROPERTY_ADAPTER_SCAN_MODE: > + if (hal_cb != adapter_prop_scan_mode) { > + tester_test_failed(); > + return; > + } > + remove_expected_hal_cb(); > + break; > + case BT_PROPERTY_ADAPTER_BONDED_DEVICES: > + if (hal_cb != adapter_prop_bonded_devices) { > + tester_test_failed(); > + return; > + } > + remove_expected_hal_cb(); > + break; > + case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: > + if (hal_cb != adapter_prop_disc_timeout) { > + tester_test_failed(); > + return; > + } > + remove_expected_hal_cb(); > + break; > + default: > + break; > + } > + } > +} > + > +static const struct generic_data bluetooth_enable_success_test = { > + .expected_hal_callbacks = {adapter_props, adapter_state_changed_on, > + adapter_test_end} > +}; > + > static bt_callbacks_t bt_callbacks = { > .size = sizeof(bt_callbacks), > - .adapter_state_changed_cb = NULL, > - .adapter_properties_cb = NULL, > + .adapter_state_changed_cb = adapter_state_changed_cb, > + .adapter_properties_cb = adapter_properties_cb, > .remote_device_properties_cb = NULL, > .device_found_cb = NULL, > .discovery_state_changed_cb = NULL, > @@ -257,9 +467,8 @@ static bt_callbacks_t bt_callbacks = { > .le_test_mode_cb = NULL > }; > > -static void setup(const void *test_data) > +static void setup(struct test_data *data) > { > - struct test_data *data = tester_get_data(); > const hw_module_t *module; > hw_device_t *device; > bt_status_t status; > @@ -328,6 +537,13 @@ static void setup(const void *test_data) > data->if_bluetooth = NULL; > tester_setup_failed(); > } > +} > + > +static void setup_base(const void *test_data) > +{ > + struct test_data *data = tester_get_data(); > + > + setup(data); > > tester_setup_complete(); > } > @@ -344,10 +560,23 @@ static void teardown(const void *test_data) > if (data->bluetoothd_pid) > waitpid(data->bluetoothd_pid, NULL, 0); > > + if (data->expected_callbacks) > + g_slist_free(data->expected_callbacks); > + > tester_teardown_complete(); > } > > -static void pass_test(const void *test_data) > +static void test_enable(const void *test_data) > +{ > + struct test_data *data = tester_get_data(); > + > + hal_cb_init(data); > + mgmt_cb_init(data); > + > + data->if_bluetooth->enable(); > +} > + > +static void controller_setup(const void *test_data) > { > tester_test_passed(); > } > @@ -369,7 +598,11 @@ int main(int argc, char *argv[]) > { > tester_init(&argc, &argv); > > - test_bredrle("test", NULL, setup, pass_test, teardown); > + test_bredrle("Controller setup", NULL, setup_base, controller_setup, > + teardown); > + > + test_bredrle("Test Enable - Success", &bluetooth_enable_success_test, > + setup_base, test_enable, teardown); Could you please split this in 2, one for each test, also I don't like that we are adding a generic test then replacing it, make sure each patch introduces code that are actually used by the test to make it easier to review without having to look in other patches. -- Luiz Augusto von Dentz -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html