Mesh: unit test: Add control menu 93/241293/1
authorAbhay Agarwal <ay.agarwal@samsung.com>
Tue, 18 Aug 2020 09:53:20 +0000 (15:23 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Tue, 18 Aug 2020 09:53:20 +0000 (15:23 +0530)
Change-Id: I78ca5a3f0ef32108b0f91d238ab7fbfcb3027f78
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
tests/test/bt_mesh_unit_test.c
tests/test/bt_mesh_unit_test.h

index 62501d2..1e87bd6 100644 (file)
@@ -50,6 +50,18 @@ static bt_mesh_authentication_type_e request_type = BT_MESH_AUTH_ALPHANUMERIC_DI
 
 GMainLoop *main_loop = NULL;
 
+tc_table_t tc_control[] = {
+       {"Back"
+               , BT_MESH_UNIT_TEST_FUNCTION_BACK},
+       {"bt_mesh_model_send_msg"
+               , BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG},
+       {"bt_mesh_group_send_msg"
+               , BT_MESH_UNIT_TEST_FUNCTION_GROUP_SEND_MSG},
+       {"select this menu to set parameters and then select the function again"
+               , BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS},
+       {NULL                                           , 0X0000},
+};
+
 tc_table_t tc_configuration[] = {
        {"Back"
                , BT_MESH_UNIT_TEST_FUNCTION_BACK},
@@ -87,8 +99,6 @@ tc_table_t tc_configuration[] = {
                , BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION},
        {"bt_mesh_model_get_publication"
                , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION},
-       {"bt_mesh_model_send_msg"
-               , BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG},
        {"bt_mesh_appkey_get_netkey"
                , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY},
        {"select this menu to set parameters and then select the function again"
@@ -193,6 +203,8 @@ tc_table_t tc_main[] = {
                , BT_MESH_UNIT_TEST_TABLE_NETWORK},
        {"Configuration"
                , BT_MESH_UNIT_TEST_TABLE_CONFIGURATION},
+       {"Control"
+               , BT_MESH_UNIT_TEST_TABLE_CONTROL},
        {"Finish"
                , BT_MESH_UNIT_TEST_TABLE_FINISH},
        {NULL                                           , 0x0000},
@@ -219,6 +231,9 @@ void tc_usage_print(void){
        case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION:
                tc_table = tc_configuration;
                break;
+       case BT_MESH_UNIT_TEST_TABLE_CONTROL:
+               tc_table = tc_control;
+               break;
        default:
                tc_table = tc_main;
                break;
@@ -957,23 +972,6 @@ int test_set_params(int test_id, char *param){
                        param_count = 1;
                        TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
                        break;
-               case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG:
-                       param_count = 4;
-                       switch(param_index) {
-                       case 0:
-                               TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
-                               break;
-                       case 1:
-                               TC_PRT("Input param(%d) (Appkey Handle)\n", param_index + 1);
-                               break;
-                       case 2:
-                               TC_PRT("Input param(%d) (opcode)\n", param_index + 1);
-                               break;
-                       case 3:
-                               TC_PRT("Input param(%d) (Message)\n", param_index + 1);
-                               break;
-                       }
-                       break;
                case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION:
                        param_count = 3;
                        switch(param_index) {
@@ -1066,6 +1064,48 @@ int test_set_params(int test_id, char *param){
                }
                break;
        }
+       case BT_MESH_UNIT_TEST_TABLE_CONTROL: {
+               switch(test_id) {
+               case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG:
+                       param_count = 4;
+                       switch(param_index) {
+                       case 0:
+                               TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
+                               break;
+                       case 1:
+                               TC_PRT("Input param(%d) (Appkey Handle)\n", param_index + 1);
+                               break;
+                       case 2:
+                               TC_PRT("Input param(%d) (opcode)\n", param_index + 1);
+                               break;
+                       case 3:
+                               TC_PRT("Input param(%d) (Message)\n", param_index + 1);
+                               break;
+                       }
+                       break;
+               case BT_MESH_UNIT_TEST_FUNCTION_GROUP_SEND_MSG:
+                       param_count = 4;
+                       switch(param_index) {
+                       case 0:
+                               TC_PRT("Input param(%d) (Group Handle)\n", param_index + 1);
+                               break;
+                       case 1:
+                               TC_PRT("Input param(%d) (Appkey Handle)\n", param_index + 1);
+                               break;
+                       case 2:
+                               TC_PRT("Input param(%d) (opcode)\n", param_index + 1);
+                               break;
+                       case 3:
+                               TC_PRT("Input param(%d) (Message)\n", param_index + 1);
+                               break;
+                       }
+                       break;
+               default:
+                       TC_PRT("There is no parameter to set\n");
+                       break;
+               }
+               break;
+       }
        default:
                TC_PRT("There is no parameter to set\n");
                need_to_set_params = false;
@@ -1956,44 +1996,96 @@ int test_input_callback(void *data)
                        TC_PRT("return %s\n", __bt_get_error_message(ret));
                        break;
                }
+               case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY: {
+                       bt_mesh_appkey_h appkey_h = 0;
+                       bt_mesh_netkey_h netkey_h;
+
+                       if (g_test_param.param_count != 1) {
+                               TC_PRT("Set Input parameter first!");
+                               break;
+                       }
+                       appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
+
+                       ret = bt_mesh_appkey_get_netkey(appkey_h, &netkey_h);
+                       TC_PRT("return %s\n", __bt_get_error_message(ret));
+                       if (ret == BT_ERROR_NONE)
+                               print_netkey_handle(netkey_h);
+                       break;
+               }
+               case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
+                       need_to_set_params = true;
+                       TC_PRT("Select the function again");
+                       break;
+               }
+               default:
+                       break;
+               }
+                       __bt_free_test_param(&g_test_param);
+               break;
+       }
+       case BT_MESH_UNIT_TEST_TABLE_CONTROL: {
+               switch (test_id) {
                case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG: {
                        bt_mesh_model_h model_h = NULL;
                        bt_mesh_appkey_h appkey_h = NULL;
                        bt_mesh_model_msg_params_s *msg_params = NULL;
+
                        if (g_test_param.param_count != 4) {
                                TC_PRT("Set Input parameter first!");
                                break;
                        }
+
+                       /* Get input parameter */
                        model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
                        appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
+
                        msg_params = g_malloc0(sizeof(bt_mesh_model_msg_params_s));
                        msg_params->opcode = strtoul(g_test_param.params[2], NULL, 16);
                        msg_params->data = "0101010101010101010101010100101010";
                        msg_params->data = g_strdup(g_test_param.params[3]);
+
                        TC_PRT("Input parameters");
                        print_model_handle(model_h);
                        print_appkey_handle(appkey_h);
                        TC_PRT("opcode 0X%4.4X", msg_params->opcode);
                        TC_PRT("Message to be sent %s", msg_params->data);
+
                        ret = bt_mesh_model_send_msg(model_h, appkey_h, msg_params,
                                __bt_mesh_model_msg_cb, NULL);
                        TC_PRT("return %s\n", __bt_get_error_message(ret));
+
                        break;
                }
-               case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY: {
-                       bt_mesh_appkey_h appkey_h = 0;
-                       bt_mesh_netkey_h netkey_h;
+               case BT_MESH_UNIT_TEST_FUNCTION_GROUP_SEND_MSG: {
+                       bt_mesh_group_h group_h = NULL;
+                       bt_mesh_appkey_h appkey_h = NULL;
+                       bt_mesh_model_msg_params_s *msg_params = NULL;
 
-                       if (g_test_param.param_count != 1) {
+                       if (g_test_param.param_count != 4) {
                                TC_PRT("Set Input parameter first!");
                                break;
                        }
-                       appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
 
-                       ret = bt_mesh_appkey_get_netkey(appkey_h, &netkey_h);
+                       /* Get input parameter */
+                       group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
+                       appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
+
+                       msg_params = g_malloc0(sizeof(bt_mesh_model_msg_params_s));
+                       msg_params->data = "0101010101010101010101010100101010";
+
+                       msg_params->opcode = strtoul(g_test_param.params[2], NULL, 16);
+                       msg_params->data = g_strdup(g_test_param.params[3]);
+
+                       TC_PRT("Input parameters");
+                       print_group_handle(group_h);
+                       print_appkey_handle(appkey_h);
+                       TC_PRT("opcode 0X%4.4X", msg_params->opcode);
+                       TC_PRT("Message to be sent %s", msg_params->data);
+
+                       ret = bt_mesh_group_send_msg(group_h, appkey_h, msg_params,
+                               __bt_mesh_model_msg_cb, NULL);
                        TC_PRT("return %s\n", __bt_get_error_message(ret));
-                       if (ret == BT_ERROR_NONE)
-                               print_netkey_handle(netkey_h);
+
                        break;
                }
                case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
@@ -2055,9 +2147,9 @@ static gboolean key_event_cb(GIOChannel *chan,
                if (test_id == 0)
                        current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
                else if(test_id >= BT_MESH_UNIT_TEST_TABLE_NETWORK
-                       && test_id <= BT_MESH_UNIT_TEST_TABLE_CONFIGURATION) {
+                       && test_id <= BT_MESH_UNIT_TEST_TABLE_CONTROL) {
                        current_tc_table = test_id;
-               } else if (test_id > BT_MESH_UNIT_TEST_TABLE_CONFIGURATION
+               } else if (test_id > BT_MESH_UNIT_TEST_TABLE_CONTROL
                        && test_id < BT_MESH_UNIT_TEST_TABLE_FINISH) {
                        current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
                } else {
index 79be438..a6ce346 100644 (file)
@@ -36,6 +36,7 @@ typedef enum {
        BT_MESH_UNIT_TEST_TABLE_MAIN = 1,
        BT_MESH_UNIT_TEST_TABLE_NETWORK = 3,
        BT_MESH_UNIT_TEST_TABLE_CONFIGURATION,
+       BT_MESH_UNIT_TEST_TABLE_CONTROL,
        BT_MESH_UNIT_TEST_TABLE_FINISH = 0XFF,
 } bt_mesh_unit_test_table_e;
 
@@ -100,8 +101,9 @@ typedef enum {
        BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST,
        BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION,
        BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION,
-       BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG,
        BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY,
+       BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG=1,
+       BT_MESH_UNIT_TEST_FUNCTION_GROUP_SEND_MSG,
        BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS = 0XFF,
 } bt_mesh_unit_test_function_e;