Mesh: Add robustness verification scenarios 52/242152/2
authorAnupam <anupam.r@samsung.com>
Mon, 24 Aug 2020 13:21:08 +0000 (18:51 +0530)
committerAnupam <anupam.r@samsung.com>
Mon, 24 Aug 2020 13:25:41 +0000 (18:55 +0530)
This patch adds following scenarios in mesh unit test
- Provision to create 'n' number of networks
- Provision to destroy all networks created by above step
- Provision to create & destroy 'n' number of networks
- Provision to init & deinit 'n' number of times

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

index 33edb70..7384c36 100644 (file)
@@ -36,6 +36,8 @@
 
 static bt_mesh_unit_test_table_e current_tc_table;
 
+static GSList *networks;
+
 static bool need_to_set_params = false;
 static int g_test_id = -1;
 static tc_params_t g_test_param = {0,};
@@ -125,10 +127,16 @@ 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_create_in_loop"
+               , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP},
+       {"bt_mesh_network_destroy_all_networks"
+               , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY_ALL_NETWORKS},
+       {"bt_mesh_network_create_and_destroy_in_loop"
+               , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_AND_DESTROY_IN_LOOP},
+       {"bt_mesh_network_init_deinit_in_loop"
+               , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_INIT_AND_DEINIT_IN_LOOP},
        {"bt_mesh_network_load"
                , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD},
        {"bt_mesh_network_set_name"
@@ -759,13 +767,21 @@ int test_set_params(int test_id, char *param){
                                break;
                        }
                        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_NETWORK_CREATE_AND_DESTROY_IN_LOOP:
+                       param_count = 1;
+                       TC_PRT("Input param(%d) (Num networks to create & destroy)\n",param_index + 1);
+                       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:
+               case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_INIT_AND_DEINIT_IN_LOOP:
                        param_count = 1;
-                       TC_PRT("Input param(%d) (network_handle)\n",param_index + 1);
+                       TC_PRT("Input param(%d) (Number of networks)\n",param_index + 1);
                        break;
                case BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY:
                        param_count = 1;
@@ -1310,6 +1326,17 @@ int test_input_callback(void *data)
                        g_free(network_name);
                        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_CREATE_IN_LOOP: {
                        char* network_name = "Mesh Test Network";
 
@@ -1320,6 +1347,7 @@ int test_input_callback(void *data)
                        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;
@@ -1329,7 +1357,6 @@ int test_input_callback(void *data)
                                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;
@@ -1340,7 +1367,6 @@ int test_input_callback(void *data)
                                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;
@@ -1353,11 +1379,9 @@ int test_input_callback(void *data)
 
                                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;
@@ -1371,7 +1395,96 @@ int test_input_callback(void *data)
                                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);
+                                       networks = g_slist_append(networks, net_h);
+                               } else {
+                                       TC_PRT("Network Creation Failed!");
+                                       break;
+                               }
+                               g_free(network_name);
+
+                       }
+                       break;
+               }
+               case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY_ALL_NETWORKS: {
+                       bt_mesh_network_h net_h;
+                       GSList *l;
+                       TC_PRT("Mesh: Destroy ALL networks : total [%d]",
+                                       g_slist_length(networks));
+
+                       /* Destroy Network */
+                       for (l = networks; l != NULL;) {
+                               net_h = l->data;
+                               l = g_slist_next(l);
+                               networks = g_slist_remove(networks, net_h);
+
+                               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_CREATE_AND_DESTROY_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) {
+                               } 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) {
+                               } 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;
+                               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) {
+                               } 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);
                                } else {
                                        TC_PRT("Network Creation Failed!");
                                        break;
@@ -1390,15 +1503,87 @@ int test_input_callback(void *data)
                        }
                        break;
                }
-               case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY: {
-                       bt_mesh_network_h network_h;
+               case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_INIT_AND_DEINIT_IN_LOOP: {
+                       char* network_name = "Mesh Test Network";
+
                        if (g_test_param.param_count != 1) {
-                               TC_PRT("Enter parameters first!");
+                               TC_PRT("Enter Input parameter first.\n");
                                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));
+                       int num = atoi(g_test_param.params[0]);
+                       TC_PRT("Create [%d] Networks", num);
+                       for (int i = 0; i < num; i++) {
+
+                               /* Mesh Init */
+                               ret = bt_mesh_initialize();
+                               if (ret == BT_ERROR_NONE) {
+                                       TC_PRT("Mesh init Passed!");
+                               } else {
+                                       TC_PRT("Mesh init failed!");
+                                       continue;
+                               }
+                               /* 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) {
+                               } 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) {
+                               } 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;
+                               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) {
+                               } else {
+                                       TC_PRT("Model Creation Failed!");
+                                       break;
+                               }
+                               /* Sleep for 100 msec to allow network Proxy attach */
+                               usleep(100000);
+                               /* 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);
+                               } else {
+                                       TC_PRT("Network Creation Failed!");
+                                       break;
+                               }
+                               g_free(network_name);
+
+                               /* Mesh De-Init */
+                               ret = bt_mesh_deinitialize();
+                               if (ret == BT_ERROR_NONE) {
+                                       TC_PRT("Mesh De-init Passed!");
+                               } else {
+                                       TC_PRT("Mesh De-init failed!");
+                               }
+                       }
                        break;
                }
                case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD: {
index 79be438..31ff8b9 100644 (file)
@@ -55,9 +55,19 @@ typedef enum {
        BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE,
        BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS,
        BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS,
+       /* Below two cases are for single
+        network create and then destroy*/
        BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE,
-       BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP,
        BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY,
+       /* below two cases are for creating given number
+        of networks & then destroying all of them */
+       BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP,
+       BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY_ALL_NETWORKS,
+       /* below case is for create & destroy given number of networks in loop */
+       BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_AND_DESTROY_IN_LOOP,
+       /* below case is for create & destroy given number of networks
+        in loop, followed by deinit of mesh */
+       BT_MESH_UNIT_TEST_FUNCTION_NETWORK_INIT_AND_DEINIT_IN_LOOP,
        BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD,
        BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME,
        BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_NAME,