Skip to content

Commit

Permalink
Split exclusive part of transport_loop_test
Browse files Browse the repository at this point in the history
  • Loading branch information
bennylp committed Jul 16, 2024
1 parent bd96226 commit c930d4c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 37 deletions.
12 changes: 8 additions & 4 deletions pjsip/src/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions pjsip/src/test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
83 changes: 50 additions & 33 deletions pjsip/src/test/transport_loop_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}

0 comments on commit c930d4c

Please sign in to comment.