From c930d4cf75ac11324b2035f6517dedabe26962ed Mon Sep 17 00:00:00 2001 From: bennylp Date: Tue, 16 Jul 2024 16:05:53 +0700 Subject: [PATCH] Split exclusive part of transport_loop_test --- pjsip/src/test/test.c | 12 ++-- pjsip/src/test/test.h | 1 + pjsip/src/test/transport_loop_test.c | 83 +++++++++++++++++----------- 3 files changed, 59 insertions(+), 37 deletions(-) diff --git a/pjsip/src/test/test.c b/pjsip/src/test/test.c index f8d54cc21..e1f332065 100644 --- a/pjsip/src/test/test.c +++ b/pjsip/src/test/test.c @@ -356,8 +356,10 @@ int test_main(int argc, char *argv[]) } #endif - /* Note: put exclusive tests last */ - +#if INCLUDE_LOOP_TEST + UT_ADD_TEST(&test_app.ut_app, transport_loop_test, 0); +#endif + #if INCLUDE_UDP_TEST /* Transport tests share same testing codes which are not reentrant */ UT_ADD_TEST(&test_app.ut_app, transport_udp_test, 0); @@ -367,12 +369,14 @@ int test_main(int argc, char *argv[]) UT_ADD_TEST(&test_app.ut_app, transport_tcp_test, 0); #endif - /* Loop test needs to be exclusive, because there must NOT be any other + /* Note: put exclusive tests last */ + + /* This needs to be exclusive, because there must NOT be any other * loop transport otherwise some test will fail (e.g. sending will * fallback to that transport) */ #if INCLUDE_LOOP_TEST - UT_ADD_TEST(&test_app.ut_app, transport_loop_test, + UT_ADD_TEST(&test_app.ut_app, transport_loop_resolve_error_test, PJ_TEST_EXCLUSIVE | PJ_TEST_KEEP_LAST); #endif diff --git a/pjsip/src/test/test.h b/pjsip/src/test/test.h index 51526a112..7fac3e3c6 100644 --- a/pjsip/src/test/test.h +++ b/pjsip/src/test/test.h @@ -86,6 +86,7 @@ int tsx_destroy_test(void); int transport_udp_test(void); int transport_loop_test(void); int transport_loop_multi_test(void); +int transport_loop_resolve_error_test(void); int transport_tcp_test(void); int resolve_test(void); int regc_test(void); diff --git a/pjsip/src/test/transport_loop_test.c b/pjsip/src/test/transport_loop_test.c index 4434f0a6e..0d13230db 100644 --- a/pjsip/src/test/transport_loop_test.c +++ b/pjsip/src/test/transport_loop_test.c @@ -273,40 +273,14 @@ int transport_loop_test() enum { LOOP = 8 }; pjsip_transport *loop = NULL; char host_port_transport[64]; - pj_bool_t disable_no_selector = PJ_FALSE; int i, pkt_lost; int status; long ref_cnt; int rtt[LOOP], min_rtt; - PJ_LOG(3,(THIS_FILE, " Loop transport count: %d", - pjsip_tpmgr_get_transport_count_by_type( - pjsip_endpt_get_tpmgr(endpt), - PJSIP_TRANSPORT_LOOP_DGRAM))); - - /* if there is another transport, wait sometime until it's gone */ - loop = wait_loop_transport_clear(10); - - if (loop) { - /* We are not supposed to have another instance of loop transport, but - * we found one. If there are more than one, test will fail. Otherwise - * test should succeed - */ - PJ_LOG(2,(THIS_FILE, - "Warning: found %d loop transport instances", - pjsip_tpmgr_get_transport_count_by_type( - pjsip_endpt_get_tpmgr(endpt), - PJSIP_TRANSPORT_LOOP_DGRAM))); - disable_no_selector = PJ_TRUE; - pjsip_loop_set_discard(loop, 0, NULL); - pjsip_loop_set_failure(loop, 0, NULL); - pjsip_loop_set_delay(loop, 0); - } else { - PJ_TEST_EQ(loop, NULL, NULL, return -2); - PJ_TEST_SUCCESS(pjsip_loop_start(endpt, &loop), NULL, return -3); - pjsip_transport_add_ref(loop); - } + PJ_TEST_SUCCESS(pjsip_loop_start(endpt, &loop), NULL, return -3); + pjsip_transport_add_ref(loop); pj_ansi_snprintf(host_port_transport, sizeof(host_port_transport), "%.*s:%d;transport=loop-dgram", @@ -317,11 +291,6 @@ int transport_loop_test() /* Get initial reference counter */ ref_cnt = pj_atomic_get(loop->ref_cnt); - /* Resolve error */ - status = loop_resolve_error(disable_no_selector); - if (status) - goto on_return; - /* Test basic transport attributes */ status = generic_transport_test(loop); if (status != PJ_SUCCESS) @@ -387,3 +356,51 @@ int transport_loop_test() pjsip_transport_dec_ref(loop); return status; } + + +/* tgus needs to be exclusive, because there must NOT be any other + * loop transport otherwise some test will fail (e.g. sending will + * fallback to that transport) + */ +int transport_loop_resolve_error_test() +{ + pjsip_transport *loop; + pj_bool_t disable_no_selector = PJ_FALSE; + int status; + + PJ_LOG(3,(THIS_FILE, " Loop transport count: %d", + pjsip_tpmgr_get_transport_count_by_type( + pjsip_endpt_get_tpmgr(endpt), + PJSIP_TRANSPORT_LOOP_DGRAM))); + + /* if there is another transport, wait sometime until it's gone */ + loop = wait_loop_transport_clear(10); + + if (loop) { + /* We are not supposed to have another instance of loop transport, but + * we found one. If there are more than one, test will fail. Otherwise + * test should succeed + */ + PJ_LOG(2,(THIS_FILE, + "Warning: found %d loop transport instances", + pjsip_tpmgr_get_transport_count_by_type( + pjsip_endpt_get_tpmgr(endpt), + PJSIP_TRANSPORT_LOOP_DGRAM))); + disable_no_selector = PJ_TRUE; + pjsip_loop_set_discard(loop, 0, NULL); + pjsip_loop_set_failure(loop, 0, NULL); + pjsip_loop_set_delay(loop, 0); + } else { + PJ_TEST_EQ(loop, NULL, NULL, return -2); + PJ_TEST_SUCCESS(pjsip_loop_start(endpt, &loop), NULL, return -3); + pjsip_transport_add_ref(loop); + } + + /* Resolve error */ + status = loop_resolve_error(disable_no_selector); + +on_return: + /* Decrement reference. */ + pjsip_transport_dec_ref(loop); + return status; +}