diff options
-rw-r--r-- | src/bluetooth-common.c | 4 | ||||
-rw-r--r-- | src/bluetooth-mesh.c | 2 | ||||
-rw-r--r-- | tests/test/bt_mesh_unit_test.c | 143 | ||||
-rw-r--r-- | tests/unittest/utc_bluetooth_mesh_network_positive.c | 5 |
4 files changed, 119 insertions, 35 deletions
diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c index 44f06fe..80fdeb9 100644 --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -4152,8 +4152,8 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us element_s = _bt_mesh_get_node_get_element_from_index(res->net_uuid, res->primary_unicast, res->elem_index); if (!element_s) { - BT_ERR("Mesh: Element not found in Network!! Unexpected!!"); - break; + /* In case of group message, element may not be found */ + BT_INFO("Mesh: Element not found in Network!!"); } /* Get appkey info */ diff --git a/src/bluetooth-mesh.c b/src/bluetooth-mesh.c index ba000bc..1e68b3b 100644 --- a/src/bluetooth-mesh.c +++ b/src/bluetooth-mesh.c @@ -796,7 +796,7 @@ int bt_mesh_node_reset(bt_mesh_node_h node_handle) BT_INFO("Mesh: Reset the node [0x%2.2x]", node_s->unicast); /* Fill node */ - memset(&node, 0x00, sizeof(bluetooth_mesh_node_t)); + memset(&node, 0x00, sizeof(bluetooth_mesh_node_info_t)); g_strlcpy(node.net_uuid, network_s->uuid, 33); node.primary_unicast = node_s->unicast; node.num_elements = g_slist_length(node_s->elements); diff --git a/tests/test/bt_mesh_unit_test.c b/tests/test/bt_mesh_unit_test.c index ea13f91..e274ec8 100644 --- a/tests/test/bt_mesh_unit_test.c +++ b/tests/test/bt_mesh_unit_test.c @@ -52,7 +52,10 @@ static GSList *unprov_dev_list; static GSList *prov_dev_list; static GSList *srv_model_list; static char *g_device_uuid; -static bool node_discovered = false; +static bool call_success = false; + +static int try = 0; +static int max_try = 10; static bt_mesh_netkey_h g_netkey; static bt_mesh_appkey_h g_appkey; @@ -71,6 +74,7 @@ static void wait_for_async_over() } static void wait_for_async() { + TC_PRT("Wait for operation...\n"); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); } @@ -471,7 +475,7 @@ void __bt_mesh_node_discover_status_cb(int result, bt_mesh_network_h network, bt print_node_handle(node_param); if (result == BT_ERROR_NONE) { g_node = node_param; - node_discovered = true; + call_success = true; } wait_for_async_over(); } @@ -558,6 +562,7 @@ static void __bt_mesh_node_configure_appkey_cb(int result, bt_mesh_node_key_conf { TC_PRT("result: %s", __bt_get_error_message(result)); if (result == BT_ERROR_NONE) { + call_success = true; //print_node_handle(node); if (op == BT_MESH_NODE_KEY_ADD) TC_PRT("AppKey Added!"); @@ -642,6 +647,7 @@ void __bt_mesh_model_bind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h { TC_PRT("result: %s", __bt_get_error_message(result)); if (result == BT_ERROR_NONE) { + call_success = true; print_model_handle(model); print_appkey_handle(appkey); } @@ -653,11 +659,13 @@ void __bt_mesh_model_msg_cb(int result, bt_mesh_element_h element, bt_mesh_appke { TC_PRT("result: %s", __bt_get_error_message(result)); if (result == BT_ERROR_NONE) { + call_success = true; TC_PRT("opcode: 0X%2.2X", msg->opcode); TC_PRT("msg: %s", msg->data); print_element_handle(element); print_appkey_handle(appkey); } + wait_for_async_over(); } void __bt_mesh_model_unbind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey, @@ -692,6 +700,7 @@ void __bt_mesh_model_subscription_op_cb(int result, bt_mesh_model_subscription_o { TC_PRT("result: %s", __bt_get_error_message(result)); if (result == BT_ERROR_NONE) { + call_success = true; switch(op) { case 0: TC_PRT("Model Subscription Operation is ADD"); @@ -712,6 +721,7 @@ void __bt_mesh_model_subscription_op_cb(int result, bt_mesh_model_subscription_o print_model_handle(model); print_group_handle(group); } + wait_for_async_over(); } bool __bt_mesh_model_subscription_list_cb(int result, bt_mesh_model_h model, int total, const GSList *sub_addr, @@ -803,6 +813,7 @@ void __bt_mesh_network_scan_unprovisioned_device_result_cb(int result, bt_mesh_n else if (state == BT_MESH_SCANNING_FINISHED) { TC_PRT("The scanning state is: STOPPED"); print_network_handle(network); + wait_for_async_over(); } else { GSList *l; @@ -846,6 +857,46 @@ void __bt_mesh_authentication_request_cb(int result, bt_mesh_authentication_type request_type = auth_type; } +int __bt_mesh_model_send_msg(bt_mesh_model_h model, + bt_mesh_appkey_h appkey, bt_mesh_model_msg_params_s *msg_params, + bt_mesh_model_msg_cb callback, void *user_data) +{ + int ret = BT_ERROR_NONE; + call_success = false; + try = 0; + + while (!call_success && try < max_try) { + try++; + ret = bt_mesh_model_send_msg(model, appkey, msg_params, + callback, user_data); + if (ret != BT_ERROR_NONE) + TC_PRT("return %s\n", __bt_get_error_message(ret)); + else + wait_for_async(); + } + return ret; +} + +int __bt_mesh_group_send_msg(bt_mesh_group_h group, + bt_mesh_appkey_h appkey, bt_mesh_model_msg_params_s *msg_params, + bt_mesh_model_msg_cb callback, void *user_data) +{ + int ret = BT_ERROR_NONE; + call_success = false; + try = 0; + + while (!call_success && try < max_try) { + try++; + ret = bt_mesh_group_send_msg(group, appkey, msg_params, + callback, user_data); + if (ret != BT_ERROR_NONE) + TC_PRT("return %s\n", __bt_get_error_message(ret)); + else + wait_for_async(); + } + return ret; +} + int test_set_params(int test_id, char *param){ static int param_index = 0; int param_count = 0; @@ -2528,8 +2579,8 @@ int test_input_callback(void *data) /* Stop any ongoing scan */ ret = bt_mesh_stop_unprovisioned_device_scan(network); - if (ret != BT_ERROR_NONE) - TC_PRT("return %s\n", __bt_get_error_message(ret)); + if (ret == BT_ERROR_NONE) + wait_for_async(); /* Start scan */ TC_PRT("The scan is set for [%u] seconds", scan_params.seconds); @@ -2549,28 +2600,29 @@ int test_input_callback(void *data) /* Stop any ongoing scan */ ret = bt_mesh_stop_unprovisioned_device_scan(network); - if (ret != BT_ERROR_NONE) - TC_PRT("return %s\n", __bt_get_error_message(ret)); + if (ret == BT_ERROR_NONE) + wait_for_async(); /* Provision device */ ret = bt_mesh_network_provision_device(network, g_device_uuid, __bt_mesh_network_device_provision_cb, NULL); if (ret != BT_ERROR_NONE) TC_PRT("return %s\n", __bt_get_error_message(ret)); - wait_for_async(); + else + wait_for_async(); /* Try to discover provisioned device */ - node_discovered = false; - int try = 0; - int max_try = 10; if (ret == BT_ERROR_NONE) { - while (!node_discovered && try < max_try) { + call_success = false; + try = 0; + while (!call_success && try < max_try) { try++; ret = bt_mesh_network_discover_node(network, (const char*)g_device_uuid, __bt_mesh_node_discover_status_cb, NULL); if (ret != BT_ERROR_NONE) TC_PRT("return %s\n", __bt_get_error_message(ret)); - wait_for_async(); + else + wait_for_async(); } } break; @@ -2608,24 +2660,55 @@ int test_input_callback(void *data) TC_PRT("return %s\n", __bt_get_error_message(ret)); /* Add appkey in remote node*/ - ret = bt_mesh_node_configure_appkey(node_h, config, appkey_h, - __bt_mesh_node_configure_appkey_cb, NULL); - if (ret != BT_ERROR_NONE) - TC_PRT("return %s\n", __bt_get_error_message(ret)); - wait_for_async(); + call_success = false; + try = 0; + if (ret == BT_ERROR_NONE) { + while (!call_success && try < max_try) { + try++; + ret = bt_mesh_node_configure_appkey(node_h, config, appkey_h, + __bt_mesh_node_configure_appkey_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("return %s\n", __bt_get_error_message(ret)); + else + wait_for_async(); + } + } /* Bind appkey in on-off server*/ + call_success = false; + try = 0; model_h = g_model_onoff_srv; - ret = bt_mesh_model_bind_appkey(model_h, appkey_h, __bt_mesh_model_bind_cb, NULL); - if (ret != BT_ERROR_NONE) - TC_PRT("return %s\n", __bt_get_error_message(ret)); - wait_for_async(); + if (ret == BT_ERROR_NONE) { + while (!call_success && try < max_try) { + try++; + ret = bt_mesh_model_bind_appkey(model_h, appkey_h, + __bt_mesh_model_bind_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("return %s\n", __bt_get_error_message(ret)); + else + wait_for_async(); + } + } + /* + * Configure group subscription + * Subscribe remote OnOff server model to Group with address c000 + */ group_h = g_group; - ret = bt_mesh_model_configure_group_subscription(op, model_h, group_h, - __bt_mesh_model_subscription_op_cb, NULL); - if (ret != BT_ERROR_NONE) - TC_PRT("return %s\n", __bt_get_error_message(ret)); + call_success = false; + try = 0; + model_h = g_model_onoff_srv; + if (ret == BT_ERROR_NONE) { + while (!call_success && try < max_try) { + try++; + ret = bt_mesh_model_configure_group_subscription(op, model_h, + group_h, __bt_mesh_model_subscription_op_cb, NULL); + if (ret != BT_ERROR_NONE) + TC_PRT("return %s\n", __bt_get_error_message(ret)); + else + wait_for_async(); + } + } break; } @@ -2641,8 +2724,8 @@ int test_input_callback(void *data) const char *msg_s = "0101"; msg_params.opcode = 0x8202; msg_params.data = g_strdup(msg_s); - ret = bt_mesh_model_send_msg(model_h, appkey_h, &msg_params, - __bt_mesh_model_msg_cb, NULL); + ret = __bt_mesh_model_send_msg(model_h, appkey_h, &msg_params, + __bt_mesh_model_msg_cb, NULL); if (ret != BT_ERROR_NONE) TC_PRT("return %s\n", __bt_get_error_message(ret)); break; @@ -2659,7 +2742,7 @@ int test_input_callback(void *data) const char *msg_s = "0001"; msg_params.opcode = 0x8202; msg_params.data = g_strdup(msg_s); - ret = bt_mesh_model_send_msg(model_h, appkey_h, &msg_params, + ret = __bt_mesh_model_send_msg(model_h, appkey_h, &msg_params, __bt_mesh_model_msg_cb, NULL); if (ret != BT_ERROR_NONE) TC_PRT("return %s\n", __bt_get_error_message(ret)); @@ -2677,7 +2760,7 @@ int test_input_callback(void *data) const char *msg_s = "0101"; msg_params.opcode = 0x8202; msg_params.data = g_strdup(msg_s); - ret = bt_mesh_group_send_msg(group_h, appkey_h, &msg_params, + ret = __bt_mesh_group_send_msg(group_h, appkey_h, &msg_params, __bt_mesh_model_msg_cb, NULL); if (ret != BT_ERROR_NONE) TC_PRT("return %s\n", __bt_get_error_message(ret)); @@ -2695,7 +2778,7 @@ int test_input_callback(void *data) const char *msg_s = "0001"; msg_params.opcode = 0x8202; msg_params.data = g_strdup(msg_s); - ret = bt_mesh_group_send_msg(group_h, appkey_h, &msg_params, + ret = __bt_mesh_group_send_msg(group_h, appkey_h, &msg_params, __bt_mesh_model_msg_cb, NULL); if (ret != BT_ERROR_NONE) TC_PRT("return %s\n", __bt_get_error_message(ret)); diff --git a/tests/unittest/utc_bluetooth_mesh_network_positive.c b/tests/unittest/utc_bluetooth_mesh_network_positive.c index b4bdd73..41a2d4c 100644 --- a/tests/unittest/utc_bluetooth_mesh_network_positive.c +++ b/tests/unittest/utc_bluetooth_mesh_network_positive.c @@ -633,14 +633,15 @@ int utc_bluetooth_bt_mesh_network_create_p(void) int utc_bluetooth_bt_mesh_network_load_p(void) { int ret = BT_ERROR_NONE; + bt_mesh_network_h network_local = NULL; if (mesh_supported) { assert_eq(startup_flag, BT_ERROR_NONE); - ret = bt_mesh_network_load(token, &network); + ret = bt_mesh_network_load(token, &network_local); assert_eq(ret, BT_ERROR_NONE); } else { - ret = bt_mesh_network_load(token, &network); + ret = bt_mesh_network_load(token, &network_local); assert_eq(ret, BT_ERROR_NOT_SUPPORTED); } |