[UTC][ITC][cion][Non-ACR] Fix timing issue 26/268026/2
authorjusung <jusung07.son@samsung.com>
Wed, 15 Dec 2021 02:07:04 +0000 (11:07 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 15 Dec 2021 06:27:22 +0000 (15:27 +0900)
 - check connection result
 - adjust wait time

Change-Id: Ie6c2e9adac4aab927b91fbce9d2503cacd8f09c0
Signed-off-by: jusung <jusung07.son@samsung.com>
src/itc/cion/ITs-cion-client.c
src/itc/cion/ITs-cion-common.h
src/itc/cion/ITs-cion-payload.c
src/itc/cion/ITs-cion-server.c
src/utc/cion/utc-cion-client.c
src/utc/cion/utc-cion-connection_result.c
src/utc/cion/utc-cion-payload.c
src/utc/cion/utc-cion-payload_async_result.c
src/utc/cion/utc-cion-peer_info.c
src/utc/cion/utc-cion-server.c

index a942e04239a60f2df09cf3abb146f2909f49cd46..4011814c87f53b62dce02e6d58241ff5aef47a9b 100755 (executable)
@@ -22,6 +22,8 @@
 *  @{
 */
 bool g_bCallbackCalledDiscover;
+bool g_bCallbackCalledResult;
+
 struct cbdata {
        cion_client_h client;
        bool connected;
@@ -36,7 +38,7 @@ static gboolean __timeout_cb(gpointer data)
 
 static void RunPollingLoop(void) {
        main_loop = g_main_loop_new(NULL, FALSE);
-       source_id = g_timeout_add(10000, __timeout_cb, NULL);\
+       source_id = g_timeout_add(60000, __timeout_cb, NULL);\
        g_main_loop_run(main_loop);\
        g_source_remove(source_id);
        main_loop = NULL;
@@ -73,7 +75,7 @@ static gpointer SendDataThread(gpointer data)
 * @parameter           const char *service_name,const cion_peer_info_h peer_info, const unsigned char *data,unsigned int data_size, unsigned char **return_data,unsigned int *return_data_size, void *user_data
 * @return                      NA
 */
-void ServerDataReceivedCB(const char *service_name,const cion_peer_info_h peer_info, const unsigned char *data,unsigned int data_size, unsigned char **return_data,unsigned int *return_data_size, void *user_data) 
+void ServerDataReceivedCB(const char *service_name,const cion_peer_info_h peer_info, const unsigned char *data,unsigned int data_size, unsigned char **return_data,unsigned int *return_data_size, void *user_data)
 {
        FPRINTF("[Line : %d][%s] Callback ServerDataReceivedCB called\\n", __LINE__, API_NAMESPACE);
        char pszStr[] ="data_result";
@@ -151,6 +153,8 @@ static void ClientServerDiscoveredCB3(const char *service_name,const cion_peer_i
        nRetVal =  cion_client_connect(cbdata->client, peer_info);
        if (nRetVal != CION_ERROR_NONE)
                FPRINTF("[Line : %d][%s] Failed cion_client_connect\\n", __LINE__, API_NAMESPACE);
+
+       StopPollingLoop();
 }
 
 /**
@@ -209,8 +213,17 @@ static void ClientPayloadReceivedCB(const char *service_name,const cion_peer_inf
 */
 static void ClientConnectionResultCB(const char *service_name,const cion_peer_info_h peer_info,const cion_connection_result_h result, void *user_data)
 {
-       FPRINTF("[Line : %d][%s] Callback ClientConnectionResultCB called\\n", __LINE__, API_NAMESPACE);
+       cion_connection_status_e status;
+       int nRetVal;
+
+       nRetVal = cion_connection_result_get_status(result, &status);
+
+       FPRINTF("[Line : %d][%s] Callback ClientConnectionResultCB called[%d][%d]\\n", __LINE__, API_NAMESPACE, nRetVal, status);
        sleep(2);
+
+       if (status == CION_CONNECTION_STATUS_OK)
+               g_bCallbackCalledResult = true;
+
        StopPollingLoop();
 }
 
@@ -454,6 +467,7 @@ int ITc_cion_client_send_data_p(void)
        cion_server_h hServer;
        g_bCallbackCalled = false;
        g_bCallbackCalledDiscover = false;
+       g_bCallbackCalledResult = false;
        int nTimeoutId = -1;
 
        GThread *thread;
@@ -474,7 +488,7 @@ int ITc_cion_client_send_data_p(void)
        nRetVal = cion_server_listen(hServer, ServerConnectionRequestCB,hServer);
        PRINT_RESULT(CION_ERROR_NONE, nRetVal, "cion_server_listen", CionGetError(nRetVal));
 
-       nRetVal = cion_client_add_connection_result_cb(hClient,ClientConnectionResultCB, NULL);
+       nRetVal = cion_client_add_connection_result_cb(hClient, ClientConnectionResultCB, NULL);
        PRINT_RESULT(CION_ERROR_NONE, nRetVal, "cion_client_add_connection_result_cb", CionGetError(nRetVal));
 
        cbdata.client = hClient;
@@ -487,11 +501,19 @@ int ITc_cion_client_send_data_p(void)
                FPRINTF("[Line : %d][%s] Callback ClientServerDiscoveredCB4 not invoked\\n", __LINE__, API_NAMESPACE);
                return 1;
        }
+
+       RunPollingLoop();
+       if(g_bCallbackCalledResult != true)
+       {
+               FPRINTF("[Line : %d][%s] Callback ClientConnectionResultCB not invoked\\n", __LINE__, API_NAMESPACE);
+               return 1;
+       }
+
        send_data.client = hClient;
        thread = g_thread_new("send_data", SendDataThread, &send_data);
 
        RunPollingLoop();
-       PRINT_RESULT(CION_ERROR_NONE, send_data.ret, "cion_client_try_discovery", CionGetError(send_data.ret));
+       PRINT_RESULT(CION_ERROR_NONE, send_data.ret, "cion_client_send_data", CionGetError(send_data.ret));
        if(strncmp((const char *)send_data.return_data, "data_result",send_data.return_data_size) != 0)
        {
                FPRINTF("[Line : %d][%s] data is not correct\\n", __LINE__, API_NAMESPACE);
@@ -536,6 +558,7 @@ int ITc_cion_client_send_payload_async_p(void)
        unsigned char pszData[] = "ITc_cion_client_send_payload_async_p";
        struct cbdata cbdata;
        g_bCallbackCalled = false;
+       g_bCallbackCalledResult = false;
        int nTimeoutId = -1;
 
        nRetVal = cion_server_create(&hServer,"ITc_cion_client_send_payload_async_p","ITc_cion_client_send_payload_async_p", NULL);
@@ -555,6 +578,9 @@ int ITc_cion_client_send_payload_async_p(void)
        nRetVal = cion_client_try_discovery(hClient, ClientServerDiscoveredCB3,&cbdata);
        PRINT_RESULT_CLEANUP(CION_ERROR_NONE, nRetVal, "cion_client_try_discovery", CionGetError(nRetVal),cion_server_destroy(hServer);cion_client_destroy(hClient));
 
+       nRetVal = cion_client_add_connection_result_cb(hClient,ClientConnectionResultCB, NULL);
+       PRINT_RESULT(CION_ERROR_NONE, nRetVal, "cion_client_add_connection_result_cb", CionGetError(nRetVal));
+
        RunPollingLoop();
        if(g_bCallbackCalled != true)
        {
@@ -564,6 +590,13 @@ int ITc_cion_client_send_payload_async_p(void)
                return 1;
        }
 
+       RunPollingLoop();
+       if(g_bCallbackCalledResult != true)
+       {
+               FPRINTF("[Line : %d][%s] Callback ClientConnectionResultCB not invoked\\n", __LINE__, API_NAMESPACE);
+               return 1;
+       }
+
        nRetVal = cion_payload_create(&hPayload, CION_PAYLOAD_TYPE_DATA);
        PRINT_RESULT_CLEANUP(CION_ERROR_NONE, nRetVal, "cion_payload_create", CionGetError(nRetVal),cion_server_destroy(hServer);cion_client_destroy(hClient));
        CHECK_HANDLE(hPayload,"cion_payload_create");
index d65961d8da73d2eb706fa3f0ba15cbbba1f18934..7ae8c174672d88fcccb3e154d3fcd2a7319519e3 100755 (executable)
@@ -26,8 +26,8 @@
 #include <app.h>
 
 #define API_NAMESPACE                          "CION_ITC"
-#define TIMEOUT_CB                             10000
-#define TIMEOUT_CB1                            5000
+#define TIMEOUT_CB                             60000
+#define TIMEOUT_CB1                            60000
 /** @addtogroup itc-%{MODULE_NAME}
 *  @ingroup itc
 *  @{
index 83c2ca88954eb73ed8fd2ed58debb5465a3a51cd..8cf8bb9cba11e76f3e7e72750b3d806eca04fb0b 100755 (executable)
@@ -32,7 +32,7 @@ static gboolean __timeout_cb(gpointer data)
 
 static void RunPollingLoop(void) {
        main_loop = g_main_loop_new(NULL, FALSE);
-       source_id = g_timeout_add(5000, __timeout_cb, NULL);\
+       source_id = g_timeout_add(60000, __timeout_cb, NULL);\
        g_main_loop_run(main_loop);\
        g_source_remove(source_id);
        main_loop = NULL;
@@ -745,4 +745,4 @@ int ITc_cion_payload_get_total_bytes_p(void)
 
 
 /** @} */
-/** @} */
\ No newline at end of file
+/** @} */
index f12391ba9ed56979fd2a321f4b25321edc21748b..57dfe8783795f725dcca212673f5c14201cd5cfd 100755 (executable)
@@ -37,7 +37,7 @@ static gboolean __timeout_cb(gpointer data)
 
 static void RunPollingLoop(void) {
        main_loop = g_main_loop_new(NULL, FALSE);
-       source_id = g_timeout_add(10000, __timeout_cb, NULL);\
+       source_id = g_timeout_add(60000, __timeout_cb, NULL);\
        g_main_loop_run(main_loop);\
        g_source_remove(source_id);
        main_loop = NULL;
@@ -119,6 +119,8 @@ static void ServerConnectionRequestCB3(const char *service_name,const cion_peer_
        ret = cion_peer_info_clone(peer_info, peer);
        if (ret != CION_ERROR_NONE)
                FPRINTF("[Line : %d][%s] failed cion_peer_info_clone\\n", __LINE__, API_NAMESPACE);
+
+       StopPollingLoop();
 }
 
 /**
index 329625bf5487bc56fd07452828ee29849e7ba193..b57da50dc5e257c35ddfa8808c4907b1083631e2 100644 (file)
@@ -47,7 +47,7 @@ static gboolean __timeout_cb(gpointer data)
 
 static void __run_polling_loop(void) {
        main_loop = g_main_loop_new(NULL, FALSE);
-       source_id = g_timeout_add(10000, __timeout_cb, NULL);\
+       source_id = g_timeout_add(60000, __timeout_cb, NULL);\
        g_main_loop_run(main_loop);\
        g_source_remove(source_id);
        main_loop = NULL;
@@ -248,6 +248,12 @@ int utc_cion_client_stop_discovery_n(void)
 static void __server_connection_request_cb(const char *service_name,
                const cion_peer_info_h peer_info, void *user_data)
 {
+       int ret;
+       cion_server_h server = (cion_server_h)user_data;
+
+       ret = cion_server_accept(server, peer_info);
+       if (ret != CION_ERROR_NONE)
+               dlog_print(DLOG_ERROR, LOG_TAG, "[%s] Failed to accept client", __func__);
 }
 
 static void __client_server_discovered_cb2(const char *service_name,
@@ -288,7 +294,7 @@ int utc_cion_client_connect_p(void)
                        __client_connection_result_cb1, NULL);
        assert_eq(ret, CION_ERROR_NONE);
 
-       ret = cion_server_listen(server, __server_connection_request_cb, NULL);
+       ret = cion_server_listen(server, __server_connection_request_cb, server);
        assert_eq(ret, CION_ERROR_NONE);
 
        ret = cion_client_try_discovery(client, __client_server_discovered_cb2,
@@ -332,17 +338,6 @@ int utc_cion_client_connect_n(void)
        return 0;
 }
 
-static void __server_connection_request_cb2(const char *service_name,
-               const cion_peer_info_h peer_info, void *user_data)
-{
-       int ret;
-       cion_server_h server = (cion_server_h)user_data;
-
-       ret = cion_server_accept(server, peer_info);
-       if (ret != CION_ERROR_NONE)
-               dlog_print(DLOG_ERROR, LOG_TAG, "[%s] Failed to accept client", __func__);
-}
-
 static void __client_server_discovered_cb3(const char *service_name,
                const cion_peer_info_h peer_info, void *user_data)
 {
@@ -416,7 +411,11 @@ int utc_cion_client_disconnect_p(void)
                        NULL);
        assert_eq(ret, CION_ERROR_NONE);
 
-       ret = cion_server_listen(server, __server_connection_request_cb2, server);
+       ret = cion_client_add_connection_result_cb(cbdata.client,
+                       __client_connection_result_cb1, NULL);
+       assert_eq(ret, CION_ERROR_NONE);
+
+       ret = cion_server_listen(server, __server_connection_request_cb, server);
        assert_eq(ret, CION_ERROR_NONE);
 
        ret = cion_client_try_discovery(cbdata.client, __client_server_discovered_cb3,
@@ -424,7 +423,11 @@ int utc_cion_client_disconnect_p(void)
        assert_eq(ret, CION_ERROR_NONE);
 
        dlog_print(DLOG_INFO, LOG_TAG,
-                       "[%s] Wait for discovering & connecting to server", __func__);
+                       "[%s] Wait for discovering to server", __func__);
+       __run_polling_loop();
+
+       dlog_print(DLOG_INFO, LOG_TAG,
+                       "[%s] Wait for connecting to server", __func__);
        __run_polling_loop();
 
        assert_eq(cbdata.connected, true);
@@ -479,7 +482,7 @@ int utc_cion_client_send_data_p(void)
        ret = cion_server_set_data_received_cb(server, __server_data_received_cb, NULL);
        assert_eq(ret, CION_ERROR_NONE);
 
-       ret = cion_server_listen(server, __server_connection_request_cb2, server);
+       ret = cion_server_listen(server, __server_connection_request_cb, server);
        assert_eq(ret, CION_ERROR_NONE);
 
        ret = cion_client_add_connection_result_cb(client,
@@ -576,7 +579,11 @@ int utc_cion_client_send_payload_async_p(void)
                        "utc_cion_client_send_payload_async_p", NULL);
        assert_eq(ret, CION_ERROR_NONE);
 
-       ret = cion_server_listen(server, __server_connection_request_cb2, server);
+       ret = cion_client_add_connection_result_cb(client,
+                       __client_connection_result_cb1, NULL);
+       assert_eq(ret, CION_ERROR_NONE);
+
+       ret = cion_server_listen(server, __server_connection_request_cb, server);
        assert_eq(ret, CION_ERROR_NONE);
 
        cbdata.client = client;
@@ -587,7 +594,11 @@ int utc_cion_client_send_payload_async_p(void)
        assert_eq(ret, CION_ERROR_NONE);
 
        dlog_print(DLOG_INFO, LOG_TAG,
-                       "[%s] Wait for discovering & connecting to server", __func__);
+                       "[%s] Wait for discovering to server", __func__);
+       __run_polling_loop();
+
+       dlog_print(DLOG_INFO, LOG_TAG,
+                       "[%s] Wait for connecting to server", __func__);
        __run_polling_loop();
 
        ret = cion_payload_create(&payload, CION_PAYLOAD_TYPE_DATA);
index de85cf84a45534dd9b784c649ee2b2634c54d40f..54e34036cd2449067f27412ca07517e4252e13fc 100644 (file)
@@ -34,7 +34,7 @@ static gboolean __timeout_cb(gpointer data)
 
 static void __run_polling_loop(void) {
        main_loop = g_main_loop_new(NULL, FALSE);
-       source_id = g_timeout_add(10000, __timeout_cb, NULL);\
+       source_id = g_timeout_add(60000, __timeout_cb, NULL);\
        g_main_loop_run(main_loop);\
        g_source_remove(source_id);
        main_loop = NULL;
index 4dc5fdc886028a7438d36301bf7165295e4935dc..e9730ff8821fab56aa934ae16a214542661d21ab 100644 (file)
@@ -35,7 +35,7 @@ static gboolean __timeout_cb(gpointer data)
 
 static void __run_polling_loop(void) {
        main_loop = g_main_loop_new(NULL, FALSE);
-       source_id = g_timeout_add(5000, __timeout_cb, NULL);\
+       source_id = g_timeout_add(60000, __timeout_cb, NULL);\
        g_main_loop_run(main_loop);\
        g_source_remove(source_id);
        main_loop = NULL;
index 8e1252413e20bcfae6e080af0a93d51755da353b..060c604143fa1ed3b26ae556f6153c29aa796000 100644 (file)
@@ -34,7 +34,7 @@ static gboolean __timeout_cb(gpointer data)
 
 static void __run_polling_loop(void) {
        main_loop = g_main_loop_new(NULL, FALSE);
-       source_id = g_timeout_add(5000, __timeout_cb, NULL);\
+       source_id = g_timeout_add(60000, __timeout_cb, NULL);\
        g_main_loop_run(main_loop);\
        g_source_remove(source_id);
        main_loop = NULL;
index 1083da03ed85b44a64d6b8d1cd39faef7d020334..eb1cdbbe106e3776b6388103adff318213ff21b2 100644 (file)
@@ -34,7 +34,7 @@ static gboolean __timeout_cb(gpointer data)
 
 static void __run_polling_loop(void) {
        main_loop = g_main_loop_new(NULL, FALSE);
-       source_id = g_timeout_add(5000, __timeout_cb, NULL);\
+       source_id = g_timeout_add(60000, __timeout_cb, NULL);\
        g_main_loop_run(main_loop);\
        g_source_remove(source_id);
        main_loop = NULL;
index 349bca5253b61fc412c6415658e5789b346dde2a..9e790b440a12fa389b5417b8e63ea64c73183bbb 100644 (file)
@@ -34,7 +34,7 @@ static gboolean __timeout_cb(gpointer data)
 
 static void __run_polling_loop(void) {
        main_loop = g_main_loop_new(NULL, FALSE);
-       source_id = g_timeout_add(10000, __timeout_cb, NULL);\
+       source_id = g_timeout_add(60000, __timeout_cb, NULL);\
        g_main_loop_run(main_loop);\
        g_source_remove(source_id);
        main_loop = NULL;