From: hyunuktak Date: Wed, 20 Mar 2019 08:37:56 +0000 (+0900) Subject: Add multi handle test X-Git-Tag: submit/tizen/20190322.054530^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ce2bf9a105242f1b3dd7413f479a66ed56302f89;p=platform%2Fcore%2Fapi%2Fsmart-traffic-control.git Add multi handle test Change-Id: Ia86695c47f8b278a400b5ccd4f126dedbceb0dc8 Signed-off-by: hyunuktak --- diff --git a/src/internal/stc-private.c b/src/internal/stc-private.c index c885879..da3899f 100755 --- a/src/internal/stc-private.c +++ b/src/internal/stc-private.c @@ -676,7 +676,6 @@ void _stc_handle_remove(stc_h stc) g_stc_handle_list = g_slist_remove(g_stc_handle_list, stc); g_free(stc); - stc = NULL; } bool _stc_handle_check_validity(stc_h stc) diff --git a/src/stc.c b/src/stc.c index a0fbef3..a8f4dcf 100755 --- a/src/stc.c +++ b/src/stc.c @@ -108,10 +108,10 @@ EXPORT_API int stc_deinitialize(stc_h stc) } STC_LOGI("Destroy handle [%p]", stc); - _stc_handle_remove(stc); - _stc_deinitialize(stc); + _stc_handle_remove(stc); + STC_LOGI("STC successfully de-initialized"); STC_UNLOCK; diff --git a/test/restriction.c b/test/restriction.c index 0b8ec5e..1ca96a0 100755 --- a/test/restriction.c +++ b/test/restriction.c @@ -58,6 +58,7 @@ static char g_rstn_type[MENU_DATA_SIZE] = "1"; static char g_rstn_rule_index[MENU_DATA_SIZE] = "0"; extern stc_h g_stc; +extern stc_h g_stc_sub; static stc_restriction_rule_h g_restriction_rule_h = NULL; static stc_restriction_list_h g_restriction_list_h = NULL; static int g_restriction_rule_index = 0; @@ -172,12 +173,13 @@ static void __test_stc_warn_threshold_crossed_cb(stc_restriction_rule_h rule, { int ret = STC_ERROR_NONE; char *app_id = NULL; + stc_h stc = (stc_h)user_data; msg(HR_SINGLE); ret = stc_restriction_rule_get_app_id(rule, &app_id); if (ret == STC_ERROR_NONE) - msg("Warn threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, app_id); + msg("[%p] Warn threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, stc, app_id); g_free(app_id); msg(HR_SINGLE); @@ -188,12 +190,13 @@ static void __test_stc_restriction_threshold_crossed_cb(stc_restriction_rule_h r { int ret = STC_ERROR_NONE; char *app_id = NULL; + stc_h stc = (stc_h)user_data; msg(HR_SINGLE); ret = stc_restriction_rule_get_app_id(rule, &app_id); if (ret == STC_ERROR_NONE) - msg("Restriction threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, app_id); + msg("[%p] Restriction threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, stc, app_id); g_free(app_id); msg(HR_SINGLE); @@ -571,19 +574,37 @@ int test_stc_restriction_list_destroy(void) int test_stc_restriction_register_cb(void) { int ret = stc_set_warn_threshold_crossed_cb(g_stc, - __test_stc_warn_threshold_crossed_cb, NULL); + __test_stc_warn_threshold_crossed_cb, g_stc); if (ret == STC_ERROR_NONE) - msg(LOG_GREEN "Success to register warn threshold crossed cb" LOG_END); + msg(LOG_GREEN "Success to register warn threshold crossed cb [%p]" LOG_END, g_stc); + else + msg("Fail to register warn threshold crossed cb " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + + ret = stc_set_warn_threshold_crossed_cb(g_stc_sub, + __test_stc_warn_threshold_crossed_cb, g_stc_sub); + + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to register warn threshold crossed cb [%p]" LOG_END, g_stc_sub); else msg("Fail to register warn threshold crossed cb " LOG_RED "[%s]" LOG_END, test_stc_convert_error_type_to_string(ret)); ret = stc_set_restriction_threshold_crossed_cb(g_stc, - __test_stc_restriction_threshold_crossed_cb, NULL); + __test_stc_restriction_threshold_crossed_cb, g_stc); + + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to register restriction threshold crossed cb [%p]" LOG_END, g_stc); + else + msg("Fail to register restriction threshold crossed cb " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + + ret = stc_set_restriction_threshold_crossed_cb(g_stc_sub, + __test_stc_restriction_threshold_crossed_cb, g_stc_sub); if (ret == STC_ERROR_NONE) - msg(LOG_GREEN "Success to register restriction threshold crossed cb" LOG_END); + msg(LOG_GREEN "Success to register restriction threshold crossed cb [%p]" LOG_END, g_stc_sub); else msg("Fail to register restriction threshold crossed cb " LOG_RED "[%s]" LOG_END, test_stc_convert_error_type_to_string(ret)); @@ -596,19 +617,35 @@ int test_stc_restriction_unregister_cb(void) int ret = stc_unset_warn_threshold_crossed_cb(g_stc); if (ret == STC_ERROR_NONE) - msg(LOG_GREEN "Success to unregister warn threshold crossed cb" LOG_END); + msg(LOG_GREEN "Success to unregister warn threshold crossed cb [%p]" LOG_END, g_stc); else msg("Fail to unregister warn threshold crossed cb " LOG_RED "[%s]" LOG_END, test_stc_convert_error_type_to_string(ret)); - ret = stc_unset_restriction_threshold_crossed_cb(g_stc); + ret = stc_unset_warn_threshold_crossed_cb(g_stc_sub); if (ret == STC_ERROR_NONE) - msg(LOG_GREEN "Success to unregister warn threshold crossed cb" LOG_END); + msg(LOG_GREEN "Success to unregister warn threshold crossed cb [%p]" LOG_END, g_stc_sub); else msg("Fail to unregister warn threshold crossed cb " LOG_RED "[%s]" LOG_END, test_stc_convert_error_type_to_string(ret)); + ret = stc_unset_restriction_threshold_crossed_cb(g_stc); + + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to unregister restriction threshold crossed cb [%p]" LOG_END, g_stc); + else + msg("Fail to unregister restriction threshold crossed cb " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + + ret = stc_unset_restriction_threshold_crossed_cb(g_stc_sub); + + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to unregister restriction threshold crossed cb [%p]" LOG_END, g_stc_sub); + else + msg("Fail to unregister restriction threshold crossed cb " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; } diff --git a/test/stc_test.c b/test/stc_test.c index 71d1694..558f713 100755 --- a/test/stc_test.c +++ b/test/stc_test.c @@ -55,6 +55,7 @@ extern struct menu_data menu_pcap[]; extern struct menu_data menu_iptables[]; stc_h g_stc = NULL; +stc_h g_stc_sub = NULL; const char *test_stc_convert_error_type_to_string(stc_error_e err) { @@ -359,9 +360,23 @@ static int __test_stc_initialize(MManager *mm, struct menu_data *menu) g_stc = NULL; } + if (g_stc_sub) { + stc_deinitialize(g_stc_sub); + g_stc_sub = NULL; + } + ret = stc_initialize(&g_stc); if (ret == STC_ERROR_NONE) - msg(LOG_GREEN "Success to initialize STC" LOG_END); + msg(LOG_GREEN "Success to initialize STC [%p]" LOG_END, g_stc); + else { + msg("Fail to initialize STC " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + + ret = stc_initialize(&g_stc_sub); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to initialize STC [%p]" LOG_END, g_stc_sub); else { msg("Fail to initialize STC " LOG_RED "[%s]" LOG_END, test_stc_convert_error_type_to_string(ret)); @@ -400,7 +415,15 @@ static int __test_stc_deinitialize(void) test_stc_convert_error_type_to_string(ret)); } - g_stc = NULL; + if (g_stc_sub) { + ret = stc_deinitialize(g_stc_sub); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to deinitialize STC" LOG_END); + else + msg("Fail to deinitialize STC " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + } + return ret; }