Mesh: unit test: Modify scenario configuration 56/242356/2 accepted/tizen/unified/20200827.105821 submit/tizen/20200825.221936
authorAbhay Agarwal <ay.agarwal@samsung.com>
Tue, 25 Aug 2020 12:56:21 +0000 (18:26 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Tue, 25 Aug 2020 15:51:51 +0000 (21:21 +0530)
This patch adds logic to try mesh configuration API calls
multiple times till received success.
This patch also adds 'wait' for scan cancel response.

Change-Id: Iaaa7f488c35ee9514178630999fcb95b28473bae
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
src/bluetooth-common.c
tests/test/bt_mesh_unit_test.c

index 44f06fe..80fdeb9 100644 (file)
@@ -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 */
index ea13f91..5dfb990 100644 (file)
@@ -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;
@@ -471,7 +474,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 +561,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 +646,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 +658,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 +699,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 +720,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 +812,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 +856,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;
@@ -2530,6 +2580,8 @@ int test_input_callback(void *data)
                        ret = bt_mesh_stop_unprovisioned_device_scan(network);
                        if (ret != BT_ERROR_NONE)
                                TC_PRT("return %s\n", __bt_get_error_message(ret));
+                       else
+                               wait_for_async();
 
                        /* Start scan */
                        TC_PRT("The scan is set for [%u] seconds", scan_params.seconds);
@@ -2551,26 +2603,29 @@ int test_input_callback(void *data)
                        ret = bt_mesh_stop_unprovisioned_device_scan(network);
                        if (ret != BT_ERROR_NONE)
                                TC_PRT("return %s\n", __bt_get_error_message(ret));
+                       else
+                               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 +2663,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 +2727,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 +2745,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 +2763,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 +2781,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));