Mesh: Add cases in unit test 07/240807/2 accepted/tizen/unified/20200812.143920 submit/tizen/20200811.230110
authorAnupam Roy <anupam.r@samsung.com>
Tue, 11 Aug 2020 14:33:27 +0000 (20:03 +0530)
committerPyun DoHyun <dh79.pyun@samsung.com>
Tue, 11 Aug 2020 22:45:25 +0000 (22:45 +0000)
This patch adds following cases in mesh unit test
- Destroy Network
- Create & Destroy Network(s) in loop for stress test

Change-Id: I7c02e8799d93c4fa4555e5022928aa23a7d01981
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
tests/test/bt_mesh_unit_test.c
tests/test/bt_mesh_unit_test.h

index fb9221b..923d305 100644 (file)
@@ -125,6 +125,10 @@ tc_table_t tc_network[] = {
                , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS},
        {"bt_mesh_network_create"
                , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE},
+       {"bt_mesh_network_create_in_loop"
+               , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP},
+       {"bt_mesh_network_destroy"
+               , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY},
        {"bt_mesh_network_load"
                , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD},
        {"bt_mesh_network_set_name"
@@ -755,6 +759,14 @@ int test_set_params(int test_id, char *param){
                                break;
                        }
                        break;
+               case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP:
+                       param_count = 1;
+                       TC_PRT("Input param(%d) (Number of networks)\n",param_index + 1);
+                       break;
+               case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY:
+                       param_count = 1;
+                       TC_PRT("Input param(%d) (network_handle)\n",param_index + 1);
+                       break;
                case BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY:
                        param_count = 1;
                        TC_PRT("Input param(%d) (node Handle)\n",param_index + 1);
@@ -1294,6 +1306,97 @@ int test_input_callback(void *data)
                        g_free(network_name);
                        break;
                }
+               case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP: {
+                       char* network_name = "Mesh Test Network";
+
+                       if (g_test_param.param_count != 1) {
+                               TC_PRT("Enter Input parameter first.\n");
+                               break;
+                       }
+                       int num = atoi(g_test_param.params[0]);
+                       TC_PRT("Create [%d] Networks", num);
+                       for (int i = 0; i < num; i++) {
+                               /* Create Node */
+                               bt_mesh_node_h node_h;
+                               bt_mesh_node_features_s features;
+                               features.features = BT_MESH_FEATURE_RELAY;
+                               features.features |= BT_MESH_FEATURE_LOWPOWER;
+
+                               ret = bt_mesh_node_create(&features, &node_h);
+                               TC_PRT("return %s\n", __bt_get_error_message(ret));
+                               if (ret == BT_ERROR_NONE) {
+                                       print_node_handle(node_h);
+                               } else {
+                                       TC_PRT("Node Creation Failed!");
+                                       break;
+                               }
+
+                               /* Create Element */
+                               bt_mesh_element_h elem_h;
+                               ret = bt_mesh_node_create_element(node_h, &elem_h);
+                               TC_PRT("return %s\n", __bt_get_error_message(ret));
+                               if (ret == BT_ERROR_NONE) {
+                                       print_element_handle(elem_h);
+                               } else {
+                                       TC_PRT("Element Creation Failed!");
+                                       break;
+                               }
+
+                               /* Create Model */
+                               bt_mesh_model_h model_h;
+                               bt_mesh_model_id_s mod_id;
+                               memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s));
+
+                               mod_id.model_id = 0x0003;
+                               mod_id.company_id = 0xFFFF;
+                               TC_PRT("The model_id is [0x%2.2x]\n", mod_id.model_id);
+                               ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
+                               TC_PRT("return %s\n", __bt_get_error_message(ret));
+                               if (ret == BT_ERROR_NONE) {
+                                       print_model_handle(model_h);
+                               } else {
+                                       TC_PRT("Model Creation Failed!");
+                                       break;
+                               }
+
+                               /* Create Network */
+                               network_name = g_strdup_printf("TestMeshNet%d", i);
+                               bt_mesh_network_h net_h;
+                               char *token;
+                               ret = bt_mesh_network_create(node_h, (const char*)network_name, &net_h, &token);
+                               TC_PRT("return %s\n", __bt_get_error_message(ret));
+                               if (ret == BT_ERROR_NONE) {
+                                       TC_PRT("Network Created, token [%s] Network Number[%d]", token, i);
+                                       print_network_handle(network);
+                               } else {
+                                       TC_PRT("Network Creation Failed!");
+                                       break;
+                               }
+                               g_free(network_name);
+
+                               /* Destroy Network */
+                               ret = bt_mesh_network_destroy(net_h);
+                               TC_PRT("return %s\n", __bt_get_error_message(ret));
+                               if (ret == BT_ERROR_NONE) {
+                                       TC_PRT("Network Destroyed Successfully!");
+                               } else {
+                                       TC_PRT("Network Destroy Failed!!....break out");
+                                       break;
+                               }
+                       }
+                       break;
+               }
+               case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY: {
+                       bt_mesh_network_h network_h;
+                       if (g_test_param.param_count != 1) {
+                               TC_PRT("Enter parameters first!");
+                               break;
+                       }
+                       network_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
+                       ret = bt_mesh_network_destroy(network_h);
+                       TC_PRT("return %s\n", __bt_get_error_message(ret));
+                       break;
+               }
                case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD: {
                        char *token_str;
                        if (g_test_param.param_count != 1) {
index 488bb10..79be438 100644 (file)
@@ -56,6 +56,8 @@ typedef enum {
        BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS,
        BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS,
        BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE,
+       BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP,
+       BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY,
        BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD,
        BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME,
        BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_NAME,