summaryrefslogtreecommitdiff
path: root/pjlib/src/pjlib-test
diff options
context:
space:
mode:
Diffstat (limited to 'pjlib/src/pjlib-test')
-rw-r--r--pjlib/src/pjlib-test/test.c26
-rw-r--r--pjlib/src/pjlib-test/thread.c43
2 files changed, 34 insertions, 35 deletions
diff --git a/pjlib/src/pjlib-test/test.c b/pjlib/src/pjlib-test/test.c
index 94d77bfb..2015b18b 100644
--- a/pjlib/src/pjlib-test/test.c
+++ b/pjlib/src/pjlib-test/test.c
@@ -1,5 +1,5 @@
/* $Id$ */
-/*
+/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
*
@@ -15,7 +15,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "test.h"
#include <pjlib.h>
@@ -38,7 +38,7 @@ pj_pool_factory *mem;
int param_echo_sock_type;
const char *param_echo_server = ECHO_SERVER_ADDRESS;
int param_echo_port = ECHO_SERVER_START_PORT;
-int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
+int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
PJ_LOG_HAS_MICRO_SEC;
int null_func()
@@ -63,7 +63,7 @@ int test_inner(void)
app_perror("pj_init() error!!", rc);
return rc;
}
-
+
//pj_dump_config();
pj_caching_pool_init( &caching_pool, NULL, 0 );
@@ -98,7 +98,7 @@ int test_inner(void)
#if INCLUDE_STRING_TEST
DO_TEST( string_test() );
#endif
-
+
#if INCLUDE_FIFOBUF_TEST
DO_TEST( fifobuf_test() );
#endif
@@ -184,8 +184,8 @@ int test_inner(void)
if (param_echo_sock_type == 0)
param_echo_sock_type = pj_SOCK_DGRAM();
- echo_client( param_echo_sock_type,
- param_echo_server,
+ echo_client( param_echo_sock_type,
+ param_echo_server,
param_echo_port);
#endif
@@ -196,18 +196,18 @@ on_return:
pj_caching_pool_destroy( &caching_pool );
PJ_LOG(3,("test", ""));
-
+
pj_thread_get_stack_info(pj_thread_this(), &filename, &line);
- PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u",
+ PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u",
pj_thread_get_stack_max_usage(pj_thread_this()),
filename, line));
if (rc == 0)
PJ_LOG(3,("test", "Looks like everything is okay!.."));
else
PJ_LOG(3,("test", "Test completed with error(s)"));
-
+
pj_shutdown();
-
+
return 0;
}
@@ -217,14 +217,12 @@ int test_main(void)
{
PJ_USE_EXCEPTION;
- pj_AF_INET();
-
PJ_TRY {
return test_inner();
}
PJ_CATCH_ANY {
int id = PJ_GET_EXCEPTION();
- PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
+ PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
id, pj_exception_id_name(id)));
}
PJ_END;
diff --git a/pjlib/src/pjlib-test/thread.c b/pjlib/src/pjlib-test/thread.c
index 0c62b85c..f2ae976c 100644
--- a/pjlib/src/pjlib-test/thread.c
+++ b/pjlib/src/pjlib-test/thread.c
@@ -1,5 +1,5 @@
/* $Id$ */
-/*
+/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
*
@@ -15,7 +15,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "test.h"
@@ -30,7 +30,7 @@
* - whether multithreading works.
* - whether thread timeslicing works, and threads have equal
* time-slice proportion.
- *
+ *
* APIs tested:
* - pj_thread_create()
* - pj_thread_register()
@@ -77,6 +77,7 @@ static void* thread_proc(pj_uint32_t *pcounter)
pj_status_t rc;
id = *pcounter;
+ PJ_UNUSED_ARG(id); /* Warning about unused var if TRACE__ is disabled */
TRACE__((THIS_FILE, " thread %d running..", id));
pj_bzero(desc, sizeof(desc));
@@ -120,9 +121,9 @@ static int simple_thread(const char *title, unsigned flags)
pj_thread_t *thread;
pj_status_t rc;
pj_uint32_t counter = 0;
-
+
PJ_LOG(3,(THIS_FILE, "..%s", title));
-
+
pool = pj_pool_create(mem, NULL, 4000, 4000, NULL);
if (!pool)
return -1000;
@@ -152,14 +153,14 @@ static int simple_thread(const char *title, unsigned flags)
PJ_LOG(3,(THIS_FILE, "...error: thread is not suspended"));
return -1015;
}
-
+
rc = pj_thread_resume(thread);
if (rc != PJ_SUCCESS) {
app_perror("...error: resume thread error", rc);
return -1020;
}
}
-
+
PJ_LOG(3,(THIS_FILE, "..waiting for thread to quit.."));
pj_thread_sleep(1500);
@@ -173,7 +174,7 @@ static int simple_thread(const char *title, unsigned flags)
PJ_LOG(3,(THIS_FILE, "...error: thread is not running"));
return -1025;
}
-
+
PJ_LOG(3,(THIS_FILE, "...%s success", title));
return PJ_SUCCESS;
}
@@ -202,10 +203,10 @@ static int timeslice_test(void)
/* Create all threads in suspended mode. */
for (i=0; i<NUM_THREADS; ++i) {
counter[i] = i;
- rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc,
- &counter[i],
- PJ_THREAD_DEFAULT_STACK_SIZE,
- PJ_THREAD_SUSPENDED,
+ rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc,
+ &counter[i],
+ PJ_THREAD_DEFAULT_STACK_SIZE,
+ PJ_THREAD_SUSPENDED,
&thread[i]);
if (rc!=PJ_SUCCESS) {
app_perror("...ERROR in pj_thread_create()", rc);
@@ -223,7 +224,7 @@ static int timeslice_test(void)
/* Check that all counters are still zero. */
for (i=0; i<NUM_THREADS; ++i) {
if (counter[i] > i) {
- PJ_LOG(3,(THIS_FILE, "....ERROR! Thread %d-th is not suspended!",
+ PJ_LOG(3,(THIS_FILE, "....ERROR! Thread %d-th is not suspended!",
i));
return -30;
}
@@ -239,7 +240,7 @@ static int timeslice_test(void)
}
}
- /* Main thread sleeps for some time to allow threads to run.
+ /* Main thread sleeps for some time to allow threads to run.
* The longer we sleep, the more accurate the calculation will be,
* but it'll make user waits for longer for the test to finish.
*/
@@ -252,7 +253,7 @@ static int timeslice_test(void)
/* Wait until all threads quit, then destroy. */
for (i=0; i<NUM_THREADS; ++i) {
- TRACE__((THIS_FILE, " Main thread joining thread %d [%p]..",
+ TRACE__((THIS_FILE, " Main thread joining thread %d [%p]..",
i, thread[i]));
rc = pj_thread_join(thread[i]);
if (rc != PJ_SUCCESS) {
@@ -291,14 +292,14 @@ static int timeslice_test(void)
*/
diff = (highest-lowest)*100 / ((highest+lowest)/2);
if ( diff >= 50) {
- PJ_LOG(3,(THIS_FILE,
+ PJ_LOG(3,(THIS_FILE,
"...ERROR: thread didn't have equal timeslice!"));
- PJ_LOG(3,(THIS_FILE,
+ PJ_LOG(3,(THIS_FILE,
".....lowest counter=%u, highest counter=%u, diff=%u%%",
lowest, highest, diff));
return -80;
} else {
- PJ_LOG(3,(THIS_FILE,
+ PJ_LOG(3,(THIS_FILE,
"...info: timeslice diff between lowest & highest=%u%%",
diff));
}
@@ -314,11 +315,11 @@ int thread_test(void)
rc = simple_thread("simple thread test", 0);
if (rc != PJ_SUCCESS)
return rc;
-
+
rc = simple_thread("suspended thread test", PJ_THREAD_SUSPENDED);
if (rc != PJ_SUCCESS)
return rc;
-
+
rc = timeslice_test();
if (rc != PJ_SUCCESS)
return rc;
@@ -328,7 +329,7 @@ int thread_test(void)
#else
/* To prevent warning about "translation unit is empty"
- * when this test is disabled.
+ * when this test is disabled.
*/
int dummy_thread_test;
#endif /* INCLUDE_THREAD_TEST */