From a6ab2ff2d65de77f7953aaab59f9d47c3de52e7a Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 22 Mar 2006 19:08:19 +0000 Subject: Added a little more threading test and put more info in ioqueue test log git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@351 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pjlib-test/ioq_perf.c | 75 +++++++++++++++++++++++++++++++++-------- pjlib/src/pjlib-test/thread.c | 16 +++++++++ 2 files changed, 77 insertions(+), 14 deletions(-) (limited to 'pjlib') diff --git a/pjlib/src/pjlib-test/ioq_perf.c b/pjlib/src/pjlib-test/ioq_perf.c index 6ab38b73..e5453f27 100644 --- a/pjlib/src/pjlib-test/ioq_perf.c +++ b/pjlib/src/pjlib-test/ioq_perf.c @@ -84,12 +84,12 @@ static void on_read_complete(pj_ioqueue_key_t *key, if (bytes_read < 0) { pj_status_t rc = -bytes_read; - char errmsg[128]; + char errmsg[PJ_ERR_MSG_SIZE]; if (rc != last_error) { //last_error = rc; pj_strerror(rc, errmsg, sizeof(errmsg)); - PJ_LOG(3,(THIS_FILE, "...error: read error, bytes_read=%d (%s)", + PJ_LOG(3,(THIS_FILE,"...error: read error, bytes_read=%d (%s)", bytes_read, errmsg)); PJ_LOG(3,(THIS_FILE, ".....additional info: total read=%u, total sent=%u", @@ -178,19 +178,33 @@ static void on_write_complete(pj_ioqueue_key_t *key, } } +struct thread_arg +{ + int id; + pj_ioqueue_t *ioqueue; + unsigned counter; +}; + /* The worker thread. */ -static int worker_thread(void *arg) +static int worker_thread(void *p) { - pj_ioqueue_t *ioqueue = arg; + struct thread_arg *arg = p; const pj_time_val timeout = {0, 100}; int rc; while (!thread_quit_flag) { - rc = pj_ioqueue_poll(ioqueue, &timeout); + + ++arg->counter; + rc = pj_ioqueue_poll(arg->ioqueue, &timeout); //TRACE_((THIS_FILE, " thread: poll returned rc=%d", rc)); if (rc < 0) { - app_perror("...error in pj_ioqueue_poll()", pj_get_netos_error()); - return -1; + char errmsg[PJ_ERR_MSG_SIZE]; + pj_strerror(-rc, errmsg, sizeof(errmsg)); + PJ_LOG(3, (THIS_FILE, + "...error in pj_ioqueue_poll() in thread %d " + "after %d loop: %s [pj_status_t=%d]", + arg->id, arg->counter, errmsg, -rc)); + //return -1; } } return 0; @@ -315,9 +329,16 @@ static int perform_test(int sock_type, const char *type_name, /* Create the threads. */ for (i=0; iid = i; + arg->ioqueue = ioqueue; + arg->counter = 0; + rc = pj_thread_create( pool, NULL, &worker_thread, - ioqueue, + arg, PJ_THREAD_DEFAULT_STACK_SIZE, PJ_THREAD_SUSPENDED, &thread[i] ); if (rc != PJ_SUCCESS) { @@ -382,6 +403,11 @@ static int perform_test(int sock_type, const char *type_name, pj_sock_close(items[i].client_fd); } + /* Destroy threads */ + for (i=0; i best_bandwidth) best_bandwidth = bandwidth, best_index = i; - /* Give it a rest before next test. */ + /* Give it a rest before next test, to allow system to close the + * sockets properly. + */ pj_thread_sleep(500); } diff --git a/pjlib/src/pjlib-test/thread.c b/pjlib/src/pjlib-test/thread.c index 2c7c41f7..72cb2ecd 100644 --- a/pjlib/src/pjlib-test/thread.c +++ b/pjlib/src/pjlib-test/thread.c @@ -125,7 +125,16 @@ static int simple_thread(const char *title, unsigned flags) return -1010; } + pj_thread_sleep(500); + if (flags & PJ_THREAD_SUSPENDED) { + + /* Check that counter is still zero */ + if (counter != 0) { + 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); @@ -135,11 +144,18 @@ static int simple_thread(const char *title, unsigned flags) PJ_LOG(3,(THIS_FILE, "..waiting for thread to quit..")); + pj_thread_sleep(500); + quit_flag = 1; pj_thread_join(thread); pj_pool_release(pool); + if (counter == 0) { + PJ_LOG(3,(THIS_FILE, "...error: thread is not running")); + return -1025; + } + PJ_LOG(3,(THIS_FILE, "...%s success", title)); return PJ_SUCCESS; } -- cgit v1.2.3