summaryrefslogtreecommitdiff
path: root/pr/tests/provider.c
diff options
context:
space:
mode:
Diffstat (limited to 'pr/tests/provider.c')
-rw-r--r--pr/tests/provider.c410
1 files changed, 243 insertions, 167 deletions
diff --git a/pr/tests/provider.c b/pr/tests/provider.c
index bb5dd329..1bd15fb6 100644
--- a/pr/tests/provider.c
+++ b/pr/tests/provider.c
@@ -184,7 +184,7 @@ static void _MY_Assert(const char *s, const char *file, PRIntn ln)
static PRBool Aborted(PRStatus rv)
{
return ((PR_FAILURE == rv) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) ?
- PR_TRUE : PR_FALSE;
+ PR_TRUE : PR_FALSE;
}
static void TimeOfDayMessage(const char *msg, PRThread* me)
@@ -213,8 +213,9 @@ static void PR_CALLBACK Client(void *arg)
PRIntervalTime timeout = PR_MillisecondsToInterval(DEFAULT_CLIENT_TIMEOUT);
- for (index = 0; index < sizeof(buffer); ++index)
+ for (index = 0; index < sizeof(buffer); ++index) {
buffer[index] = (char)index;
+ }
client->started = PR_IntervalNow();
@@ -231,7 +232,7 @@ static void PR_CALLBACK Client(void *arg)
(void)PR_NetAddrToString(&client->serverAddress, buffer, sizeof(buffer));
TEST_LOG(cltsrv_log_file, TEST_LOG_INFO,
- ("\tClient(0x%p): connecting to server at %s\n", me, buffer));
+ ("\tClient(0x%p): connecting to server at %s\n", me, buffer));
fd = PR_Socket(domain, SOCK_STREAM, protocol);
TEST_ASSERT(NULL != fd);
@@ -253,10 +254,12 @@ static void PR_CALLBACK Client(void *arg)
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): sending descriptor for %u bytes\n", me, descbytes));
bytes = PR_Send(
- fd, descriptor, sizeof(*descriptor), SEND_FLAGS, timeout);
+ fd, descriptor, sizeof(*descriptor), SEND_FLAGS, timeout);
if (sizeof(CSDescriptor_t) != bytes)
{
- if (Aborted(PR_FAILURE)) goto aborted;
+ if (Aborted(PR_FAILURE)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -271,15 +274,18 @@ static void PR_CALLBACK Client(void *arg)
while (netbytes < descbytes)
{
filebytes = sizeof(buffer);
- if ((descbytes - netbytes) < filebytes)
+ if ((descbytes - netbytes) < filebytes) {
filebytes = descbytes - netbytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): sending %d bytes\n", me, filebytes));
bytes = PR_Send(fd, buffer, filebytes, SEND_FLAGS, timeout);
if (filebytes != bytes)
{
- if (Aborted(PR_FAILURE)) goto aborted;
+ if (Aborted(PR_FAILURE)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -295,8 +301,9 @@ static void PR_CALLBACK Client(void *arg)
while (filebytes < descbytes)
{
netbytes = sizeof(buffer);
- if ((descbytes - filebytes) < netbytes)
+ if ((descbytes - filebytes) < netbytes) {
netbytes = descbytes - filebytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): receiving %d bytes\n", me, netbytes));
@@ -314,26 +321,28 @@ static void PR_CALLBACK Client(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\tClient(0x%p): receive data timeout\n", me));
- else
+ else
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\tClient(0x%p): receive error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto retry;
- }
+ }
if (0 == bytes)
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tClient(0x%p): unexpected end of stream\n",
- PR_GetCurrentThread()));
+ PR_GetCurrentThread()));
break;
}
filebytes += bytes;
}
rv = PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
retry:
(void)PR_Close(fd); fd = NULL;
@@ -346,14 +355,18 @@ retry:
client->bytesTransferred += 2 * descbytes;
rv = PR_WaitCondVar(client->stateChange, rand() % clipping);
PR_Unlock(client->ml);
- if (Aborted(rv)) break;
+ if (Aborted(rv)) {
+ break;
+ }
}
aborted:
client->stopped = PR_IntervalNow();
PR_ClearInterrupt();
- if (NULL != fd) rv = PR_Close(fd);
+ if (NULL != fd) {
+ rv = PR_Close(fd);
+ }
PR_Lock(client->ml);
client->state = cs_exit;
@@ -363,7 +376,7 @@ aborted:
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("\tClient(0x%p): stopped after %u operations and %u bytes\n",
- PR_GetCurrentThread(), client->operations, client->bytesTransferred));
+ PR_GetCurrentThread(), client->operations, client->bytesTransferred));
} /* Client */
@@ -381,11 +394,13 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): receiving desciptor\n", me));
bytes = PR_Recv(
- fd, descriptor, sizeof(*descriptor), RECV_FLAGS, timeout);
+ fd, descriptor, sizeof(*descriptor), RECV_FLAGS, timeout);
if (-1 == bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto exit;
+ if (Aborted(rv)) {
+ goto exit;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -408,14 +423,16 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\t\tProcessRequest(0x%p): read descriptor {%d, %s}\n",
- me, descbytes, descriptor->filename));
+ me, descbytes, descriptor->filename));
file = PR_Open(
- descriptor->filename, (PR_CREATE_FILE | PR_WRONLY), 0666);
+ descriptor->filename, (PR_CREATE_FILE | PR_WRONLY), 0666);
if (NULL == file)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -430,8 +447,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
while (filebytes < descbytes)
{
netbytes = sizeof(buffer);
- if ((descbytes - filebytes) < netbytes)
+ if ((descbytes - filebytes) < netbytes) {
netbytes = descbytes - filebytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): receive %d bytes\n", me, netbytes));
@@ -439,7 +457,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (-1 == bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -455,7 +475,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_LOG(
cltsrv_log_file, TEST_LOG_WARNING,
("\t\tProcessRequest(0x%p): unexpected error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
if(0 == bytes)
@@ -477,7 +497,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (netbytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -495,7 +517,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
PR_Unlock(server->ml);
rv = PR_Close(file); file = NULL;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
TEST_LOG(
@@ -505,19 +529,21 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (NULL == file)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): open file timeout\n",
- PR_GetCurrentThread()));
+ PR_GetCurrentThread()));
goto aborted;
}
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): other file open error (%u, %u)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
TEST_ASSERT(NULL != file);
@@ -526,8 +552,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
while (netbytes < descbytes)
{
filebytes = sizeof(buffer);
- if ((descbytes - netbytes) < filebytes)
+ if ((descbytes - netbytes) < filebytes) {
filebytes = descbytes - netbytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): read %d bytes from file\n", me, filebytes));
@@ -535,7 +562,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (filebytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
@@ -544,7 +573,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): other file error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
TEST_ASSERT(bytes > 0);
@@ -557,7 +586,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (filebytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -567,7 +598,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
}
break;
}
- TEST_ASSERT(bytes > 0);
+ TEST_ASSERT(bytes > 0);
}
PR_Lock(server->ml);
@@ -575,15 +606,21 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
PR_Unlock(server->ml);
rv = PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
rv = PR_Close(file); file = NULL;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
aborted:
PR_ClearInterrupt();
- if (NULL != file) PR_Close(file);
+ if (NULL != file) {
+ PR_Close(file);
+ }
drv = PR_Delete(descriptor->filename);
TEST_ASSERT(PR_SUCCESS == drv);
exit:
@@ -640,22 +677,22 @@ static PRStatus JoinThread(PRThread *thread)
PRStatus rv;
switch (thread_provider)
{
- case thread_nspr:
- rv = PR_JoinThread(thread);
- break;
- case thread_pthread:
+ case thread_nspr:
+ rv = PR_JoinThread(thread);
+ break;
+ case thread_pthread:
#if defined(_PR_PTHREADS)
- rv = PR_SUCCESS;
- break;
+ rv = PR_SUCCESS;
+ break;
#endif /* defined(_PR_PTHREADS) */
- case thread_win32:
+ case thread_win32:
#if defined(WIN32)
- rv = PR_SUCCESS;
- break;
+ rv = PR_SUCCESS;
+ break;
#endif
- default:
- rv = PR_FAILURE;
- break;
+ default:
+ rv = PR_FAILURE;
+ break;
}
return rv;
} /* JoinThread */
@@ -667,16 +704,16 @@ static PRStatus NewThread(
switch (thread_provider)
{
- case thread_nspr:
+ case thread_nspr:
{
PRThread *thread = PR_CreateThread(
- PR_USER_THREAD, start, arg,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, start, arg,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD, 0);
rv = (NULL == thread) ? PR_FAILURE : PR_SUCCESS;
}
break;
- case thread_pthread:
+ case thread_pthread:
#if defined(_PR_PTHREADS)
{
int rv;
@@ -707,11 +744,11 @@ static PRStatus NewThread(
#endif /* defined(_PR_PTHREADS) */
break;
- case thread_sproc:
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- rv = PR_FAILURE;
- break;
- case thread_win32:
+ case thread_sproc:
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ rv = PR_FAILURE;
+ break;
+ case thread_win32:
#if defined(WIN32)
{
void *th;
@@ -722,12 +759,12 @@ static PRStatus NewThread(
start_object->start = start;
start_object->arg = arg;
th = (void*)_beginthreadex(
- NULL, /* LPSECURITY_ATTRIBUTES - pointer to thread security attributes */
- 0U, /* DWORD - initial thread stack size, in bytes */
- windows_start, /* LPTHREAD_START_ROUTINE - pointer to thread function */
- start_object, /* LPVOID - argument for new thread */
- STACK_SIZE_PARAM_IS_A_RESERVATION, /*DWORD dwCreationFlags - creation flags */
- &id /* LPDWORD - pointer to returned thread identifier */ );
+ NULL, /* LPSECURITY_ATTRIBUTES - pointer to thread security attributes */
+ 0U, /* DWORD - initial thread stack size, in bytes */
+ windows_start, /* LPTHREAD_START_ROUTINE - pointer to thread function */
+ start_object, /* LPVOID - argument for new thread */
+ STACK_SIZE_PARAM_IS_A_RESERVATION, /*DWORD dwCreationFlags - creation flags */
+ &id /* LPDWORD - pointer to returned thread identifier */ );
rv = (NULL == th) ? PR_FAILURE : PR_SUCCESS;
}
@@ -736,9 +773,9 @@ static PRStatus NewThread(
rv = PR_FAILURE;
#endif
break;
- default:
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- rv = PR_FAILURE;
+ default:
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ rv = PR_FAILURE;
}
return rv;
} /* NewThread */
@@ -750,12 +787,14 @@ static PRStatus CreateWorker(CSServer_t *server, CSPool_t *pool)
worker->server = server;
PR_INIT_CLIST(&worker->element);
rv = NewThread(
- Worker, worker, DEFAULT_SERVER_PRIORITY, PR_UNJOINABLE_THREAD);
- if (PR_FAILURE == rv) PR_DELETE(worker);
+ Worker, worker, DEFAULT_SERVER_PRIORITY, PR_UNJOINABLE_THREAD);
+ if (PR_FAILURE == rv) {
+ PR_DELETE(worker);
+ }
TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
- ("\tCreateWorker(0x%p): create new worker (0x%p)\n",
- PR_GetCurrentThread(), worker->thread));
+ ("\tCreateWorker(0x%p): create new worker (0x%p)\n",
+ PR_GetCurrentThread(), worker->thread));
return rv;
} /* CreateWorker */
@@ -786,14 +825,14 @@ static void PR_CALLBACK Worker(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\t\tWorker(0x%p): waiting for accept slot[%d]\n",
- me, pool->accepting));
+ me, pool->accepting));
rv = PR_WaitCondVar(pool->acceptComplete, PR_INTERVAL_NO_TIMEOUT);
if (Aborted(rv) || (cs_run != server->state))
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("\tWorker(0x%p): has been %s\n",
- me, (Aborted(rv) ? "interrupted" : "stopped")));
+ me, (Aborted(rv) ? "interrupted" : "stopped")));
goto exit;
}
}
@@ -831,13 +870,15 @@ static void PR_CALLBACK Worker(void *arg)
*/
PRBool another =
((pool->workers < server->workers.minimum) ||
- ((0 == pool->accepting)
- && (pool->workers < server->workers.maximum))) ?
- PR_TRUE : PR_FALSE;
+ ((0 == pool->accepting)
+ && (pool->workers < server->workers.maximum))) ?
+ PR_TRUE : PR_FALSE;
pool->active += 1;
PR_Unlock(server->ml);
- if (another) (void)CreateWorker(server, pool);
+ if (another) {
+ (void)CreateWorker(server, pool);
+ }
rv = ProcessRequest(fd, server);
if (PR_SUCCESS != rv)
@@ -963,7 +1004,7 @@ static void PR_CALLBACK Server(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("\tServer(0x%p): waiting for %u workers to exit\n",
- me, server->pool.workers));
+ me, server->pool.workers));
(void)PR_WaitCondVar(server->pool.exiting, PR_INTERVAL_NO_TIMEOUT);
}
@@ -974,9 +1015,11 @@ static void PR_CALLBACK Server(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("\tServer(0x%p): stopped after %u operations and %u bytes\n",
- me, server->operations, server->bytesTransferred));
+ me, server->operations, server->bytesTransferred));
- if (NULL != server->listener) PR_Close(server->listener);
+ if (NULL != server->listener) {
+ PR_Close(server->listener);
+ }
server->stopped = PR_IntervalNow();
} /* Server */
@@ -987,7 +1030,9 @@ static void WaitForCompletion(PRIntn execution)
{
PRIntn dally = (execution > 30) ? 30 : execution;
PR_Sleep(PR_SecondsToInterval(dally));
- if (pthread_stats) PT_FPrintStats(debug_out, "\nPThread Statistics\n");
+ if (pthread_stats) {
+ PT_FPrintStats(debug_out, "\nPThread Statistics\n");
+ }
execution -= dally;
}
} /* WaitForCompletion */
@@ -1025,7 +1070,7 @@ int main(int argc, char **argv)
CSClient_t *client;
PRStatus rv, joinStatus;
CSServer_t *server = NULL;
- char *thread_type;
+ char *thread_type;
PRUintn backlog = DEFAULT_BACKLOG;
PRUintn clients = DEFAULT_CLIENTS;
@@ -1052,9 +1097,9 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "GX6b:a:c:w:W:e:s:T:vdhp");
#if defined(WIN32)
- thread_provider = thread_win32;
+ thread_provider = thread_win32;
#elif defined(_PR_PTHREADS)
- thread_provider = thread_pthread;
+ thread_provider = thread_pthread;
#else
thread_provider = thread_nspr;
#endif
@@ -1063,70 +1108,95 @@ int main(int argc, char **argv)
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'G': /* use global threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'X': /* use XTP as transport */
- protocol = 36;
- break;
- case '6': /* Use IPv6 */
- domain = PR_AF_INET6;
- break;
- case 'a': /* the value for accepting */
- accepting = atoi(opt->value);
- break;
- case 'b': /* the value for backlock */
- backlog = atoi(opt->value);
- break;
- case 'T': /* the thread provider */
- if ('n' == *opt->value) thread_provider = thread_nspr;
- else if ('p' == *opt->value) thread_provider = thread_pthread;
- else if ('w' == *opt->value) thread_provider = thread_win32;
- else {Help(); return 2; }
- break;
- case 'c': /* number of client threads */
- clients = atoi(opt->value);
- break;
- case 'w': /* minimum server worker threads */
- workersMin = atoi(opt->value);
- break;
- case 'W': /* maximum server worker threads */
- workersMax = atoi(opt->value);
- break;
- case 'e': /* program execution time in seconds */
- execution = atoi(opt->value);
- break;
- case 's': /* server's address */
- serverName = opt->value;
- break;
- case 'v': /* verbosity */
- verbosity = IncrementVerbosity();
- break;
- case 'd': /* debug mode */
- debug_mode = PR_TRUE;
- break;
- case 'p': /* pthread mode */
- pthread_stats = PR_TRUE;
- break;
- case 'h':
- default:
- Help();
- return 2;
+ case 'G': /* use global threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'X': /* use XTP as transport */
+ protocol = 36;
+ break;
+ case '6': /* Use IPv6 */
+ domain = PR_AF_INET6;
+ break;
+ case 'a': /* the value for accepting */
+ accepting = atoi(opt->value);
+ break;
+ case 'b': /* the value for backlock */
+ backlog = atoi(opt->value);
+ break;
+ case 'T': /* the thread provider */
+ if ('n' == *opt->value) {
+ thread_provider = thread_nspr;
+ }
+ else if ('p' == *opt->value) {
+ thread_provider = thread_pthread;
+ }
+ else if ('w' == *opt->value) {
+ thread_provider = thread_win32;
+ }
+ else {
+ Help();
+ return 2;
+ }
+ break;
+ case 'c': /* number of client threads */
+ clients = atoi(opt->value);
+ break;
+ case 'w': /* minimum server worker threads */
+ workersMin = atoi(opt->value);
+ break;
+ case 'W': /* maximum server worker threads */
+ workersMax = atoi(opt->value);
+ break;
+ case 'e': /* program execution time in seconds */
+ execution = atoi(opt->value);
+ break;
+ case 's': /* server's address */
+ serverName = opt->value;
+ break;
+ case 'v': /* verbosity */
+ verbosity = IncrementVerbosity();
+ break;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ case 'p': /* pthread mode */
+ pthread_stats = PR_TRUE;
+ break;
+ case 'h':
+ default:
+ Help();
+ return 2;
}
}
PL_DestroyOptState(opt);
- if (0 != PL_strcmp(serverName, DEFAULT_SERVER)) serverIsLocal = PR_FALSE;
- if (0 == execution) execution = DEFAULT_EXECUTION_TIME;
- if (0 == workersMax) workersMax = DEFAULT_WORKERS_MAX;
- if (0 == workersMin) workersMin = DEFAULT_WORKERS_MIN;
- if (0 == accepting) accepting = ALLOWED_IN_ACCEPT;
- if (0 == backlog) backlog = DEFAULT_BACKLOG;
+ if (0 != PL_strcmp(serverName, DEFAULT_SERVER)) {
+ serverIsLocal = PR_FALSE;
+ }
+ if (0 == execution) {
+ execution = DEFAULT_EXECUTION_TIME;
+ }
+ if (0 == workersMax) {
+ workersMax = DEFAULT_WORKERS_MAX;
+ }
+ if (0 == workersMin) {
+ workersMin = DEFAULT_WORKERS_MIN;
+ }
+ if (0 == accepting) {
+ accepting = ALLOWED_IN_ACCEPT;
+ }
+ if (0 == backlog) {
+ backlog = DEFAULT_BACKLOG;
+ }
- if (workersMin > accepting) accepting = workersMin;
+ if (workersMin > accepting) {
+ accepting = workersMin;
+ }
PR_STDIO_INIT();
TimeOfDayMessage("Client/Server started at", PR_GetCurrentThread());
@@ -1161,7 +1231,7 @@ int main(int argc, char **argv)
("main(0x%p): creating server thread\n", PR_GetCurrentThread()));
rv = NewThread(
- Server, server, PR_PRIORITY_HIGH, PR_JOINABLE_THREAD);
+ Server, server, PR_PRIORITY_HIGH, PR_JOINABLE_THREAD);
TEST_ASSERT(PR_SUCCESS == rv);
TEST_LOG(
@@ -1169,14 +1239,15 @@ int main(int argc, char **argv)
("main(0x%p): waiting for server init\n", PR_GetCurrentThread()));
PR_Lock(server->ml);
- while (server->state == cs_init)
+ while (server->state == cs_init) {
PR_WaitCondVar(server->stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(server->ml);
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("main(0x%p): server init complete (port #%d)\n",
- PR_GetCurrentThread(), server->port));
+ PR_GetCurrentThread(), server->port));
}
if (clients != 0)
@@ -1189,7 +1260,7 @@ int main(int argc, char **argv)
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("main(0x%p): creating %d client threads\n",
- PR_GetCurrentThread(), clients));
+ PR_GetCurrentThread(), clients));
if (!serverIsLocal)
{
@@ -1221,11 +1292,12 @@ int main(int argc, char **argv)
cltsrv_log_file, TEST_LOG_INFO,
("main(0x%p): creating client threads\n", PR_GetCurrentThread()));
rv = NewThread(
- Client, &client[index], PR_PRIORITY_NORMAL, PR_JOINABLE_THREAD);
+ Client, &client[index], PR_PRIORITY_NORMAL, PR_JOINABLE_THREAD);
TEST_ASSERT(PR_SUCCESS == rv);
PR_Lock(client[index].ml);
- while (cs_init == client[index].state)
+ while (cs_init == client[index].state) {
PR_WaitCondVar(client[index].stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(client[index].ml);
}
}
@@ -1234,7 +1306,7 @@ int main(int argc, char **argv)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("main(0x%p): waiting for execution interval (%d seconds)\n",
- PR_GetCurrentThread(), execution));
+ PR_GetCurrentThread(), execution));
WaitForCompletion(execution);
@@ -1245,8 +1317,8 @@ int main(int argc, char **argv)
for (index = 0; index < clients; ++index)
{
TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
- ("main(0x%p): notifying client(0x%p) to stop\n",
- PR_GetCurrentThread(), client[index].thread));
+ ("main(0x%p): notifying client(0x%p) to stop\n",
+ PR_GetCurrentThread(), client[index].thread));
PR_Lock(client[index].ml);
if (cs_run == client[index].state)
@@ -1260,11 +1332,11 @@ int main(int argc, char **argv)
PR_Unlock(client[index].ml);
TEST_LOG(cltsrv_log_file, TEST_LOG_VERBOSE,
- ("main(0x%p): joining client(0x%p)\n",
- PR_GetCurrentThread(), client[index].thread));
+ ("main(0x%p): joining client(0x%p)\n",
+ PR_GetCurrentThread(), client[index].thread));
- joinStatus = JoinThread(client[index].thread);
- TEST_ASSERT(PR_SUCCESS == joinStatus);
+ joinStatus = JoinThread(client[index].thread);
+ TEST_ASSERT(PR_SUCCESS == joinStatus);
PR_DestroyCondVar(client[index].stateChange);
PR_DestroyLock(client[index].ml);
}
@@ -1277,19 +1349,20 @@ int main(int argc, char **argv)
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("main(0x%p): notifying server(0x%p) to stop\n",
- PR_GetCurrentThread(), server->thread));
+ PR_GetCurrentThread(), server->thread));
PR_Lock(server->ml);
server->state = cs_stop;
PR_Interrupt(server->thread);
- while (cs_exit != server->state)
+ while (cs_exit != server->state) {
PR_WaitCondVar(server->stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(server->ml);
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("main(0x%p): joining server(0x%p)\n",
- PR_GetCurrentThread(), server->thread));
+ PR_GetCurrentThread(), server->thread));
joinStatus = JoinThread(server->thread);
TEST_ASSERT(PR_SUCCESS == joinStatus);
@@ -1304,16 +1377,19 @@ int main(int argc, char **argv)
cltsrv_log_file, TEST_LOG_ALWAYS,
("main(0x%p): test complete\n", PR_GetCurrentThread()));
- if (thread_provider == thread_win32)
- thread_type = "\nWin32 Thread Statistics\n";
- else if (thread_provider == thread_pthread)
- thread_type = "\npthread Statistics\n";
- else if (thread_provider == thread_sproc)
- thread_type = "\nsproc Statistics\n";
+ if (thread_provider == thread_win32) {
+ thread_type = "\nWin32 Thread Statistics\n";
+ }
+ else if (thread_provider == thread_pthread) {
+ thread_type = "\npthread Statistics\n";
+ }
+ else if (thread_provider == thread_sproc) {
+ thread_type = "\nsproc Statistics\n";
+ }
else {
- PR_ASSERT(thread_provider == thread_nspr);
- thread_type = "\nPRThread Statistics\nn";
- }
+ PR_ASSERT(thread_provider == thread_nspr);
+ thread_type = "\nPRThread Statistics\nn";
+ }
PT_FPrintStats(debug_out, thread_type);