summaryrefslogtreecommitdiff
path: root/pr/tests/foreign.c
diff options
context:
space:
mode:
Diffstat (limited to 'pr/tests/foreign.c')
-rw-r--r--pr/tests/foreign.c254
1 files changed, 128 insertions, 126 deletions
diff --git a/pr/tests/foreign.c b/pr/tests/foreign.c
index 6c682f30..a711b758 100644
--- a/pr/tests/foreign.c
+++ b/pr/tests/foreign.c
@@ -48,9 +48,9 @@ static PRFileDesc *output;
static int _debug_on = 0;
-#define DEFAULT_THREAD_COUNT 10
+#define DEFAULT_THREAD_COUNT 10
-#define DPRINTF(arg) if (_debug_on) PR_fprintf arg
+#define DPRINTF(arg) if (_debug_on) PR_fprintf arg
#if defined(_PR_PTHREADS)
#include <pthread.h>
@@ -86,16 +86,16 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg)
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_UNJOINABLE_THREAD, 0);
+ PR_USER_THREAD, start, arg,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
rv = (NULL == thread) ? PR_FAILURE : PR_SUCCESS;
}
break;
- case thread_pthread:
+ case thread_pthread:
#if defined(_PR_PTHREADS)
{
int rv;
@@ -126,11 +126,11 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg)
break;
#endif /* defined(_PR_PTHREADS) */
- 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;
@@ -141,12 +141,12 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg)
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;
}
@@ -155,9 +155,9 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg)
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;
} /* NSPRPUB_TESTS_CreateThread */
@@ -177,133 +177,135 @@ static void OneShot(void *arg)
PRFileDesc *pair[2];
PRIntn test = (PRIntn)arg;
- for (test = 0; test < 12; ++test) {
-
- switch (test)
- {
- case 0:
- lock = PR_NewLock();
- DPRINTF((output,"Thread[0x%x] called PR_NewLock\n",
- PR_GetCurrentThread()));
- PR_DestroyLock(lock);
- break;
-
- case 1:
- (void)PR_SecondsToInterval(1);
- DPRINTF((output,"Thread[0x%x] called PR_SecondsToInterval\n",
- PR_GetCurrentThread()));
- break;
-
- case 2: (void)PR_CreateThread(
- PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
- DPRINTF((output,"Thread[0x%x] called PR_CreateThread\n",
- PR_GetCurrentThread()));
- break;
-
- case 3:
- fd = PR_Open("foreign.tmp", PR_CREATE_FILE | PR_RDWR, 0666);
- DPRINTF((output,"Thread[0x%x] called PR_Open\n",
- PR_GetCurrentThread()));
- PR_Close(fd);
- break;
-
- case 4:
- fd = PR_NewUDPSocket();
- DPRINTF((output,"Thread[0x%x] called PR_NewUDPSocket\n",
- PR_GetCurrentThread()));
- PR_Close(fd);
- break;
-
- case 5:
- fd = PR_NewTCPSocket();
- DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocket\n",
- PR_GetCurrentThread()));
- PR_Close(fd);
- break;
+ for (test = 0; test < 12; ++test) {
- case 6:
+ switch (test)
+ {
+ case 0:
+ lock = PR_NewLock();
+ DPRINTF((output,"Thread[0x%x] called PR_NewLock\n",
+ PR_GetCurrentThread()));
+ PR_DestroyLock(lock);
+ break;
+
+ case 1:
+ (void)PR_SecondsToInterval(1);
+ DPRINTF((output,"Thread[0x%x] called PR_SecondsToInterval\n",
+ PR_GetCurrentThread()));
+ break;
+
+ case 2: (void)PR_CreateThread(
+ PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
+ DPRINTF((output,"Thread[0x%x] called PR_CreateThread\n",
+ PR_GetCurrentThread()));
+ break;
+
+ case 3:
+ fd = PR_Open("foreign.tmp", PR_CREATE_FILE | PR_RDWR, 0666);
+ DPRINTF((output,"Thread[0x%x] called PR_Open\n",
+ PR_GetCurrentThread()));
+ PR_Close(fd);
+ break;
+
+ case 4:
+ fd = PR_NewUDPSocket();
+ DPRINTF((output,"Thread[0x%x] called PR_NewUDPSocket\n",
+ PR_GetCurrentThread()));
+ PR_Close(fd);
+ break;
+
+ case 5:
+ fd = PR_NewTCPSocket();
+ DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocket\n",
+ PR_GetCurrentThread()));
+ PR_Close(fd);
+ break;
+
+ case 6:
#define TEMP_DIR "/tmp/"
- dir = PR_OpenDir(TEMP_DIR);
- DPRINTF((output,"Thread[0x%x] called PR_OpenDir\n",
- PR_GetCurrentThread()));
- PR_CloseDir(dir);
- break;
-
- case 7:
- (void)PR_NewThreadPrivateIndex(&pdkey, NULL);
- DPRINTF((output,"Thread[0x%x] called PR_NewThreadPrivateIndex\n",
- PR_GetCurrentThread()));
- break;
-
- case 8:
- (void)PR_GetEnv("PATH");
- DPRINTF((output,"Thread[0x%x] called PR_GetEnv\n",
- PR_GetCurrentThread()));
- break;
-
- case 9:
- (void)PR_NewTCPSocketPair(pair);
- DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocketPair\n",
- PR_GetCurrentThread()));
- PR_Close(pair[0]);
- PR_Close(pair[1]);
- break;
-
- case 10:
- PR_SetConcurrency(2);
- DPRINTF((output,"Thread[0x%x] called PR_SetConcurrency\n",
- PR_GetCurrentThread()));
- break;
-
- case 11:
- PR_SetThreadPriority(PR_GetCurrentThread(), PR_PRIORITY_HIGH);
- DPRINTF((output,"Thread[0x%x] called PR_SetThreadPriority\n",
- PR_GetCurrentThread()));
- break;
-
- default:
- break;
- } /* switch() */
- }
+ dir = PR_OpenDir(TEMP_DIR);
+ DPRINTF((output,"Thread[0x%x] called PR_OpenDir\n",
+ PR_GetCurrentThread()));
+ PR_CloseDir(dir);
+ break;
+
+ case 7:
+ (void)PR_NewThreadPrivateIndex(&pdkey, NULL);
+ DPRINTF((output,"Thread[0x%x] called PR_NewThreadPrivateIndex\n",
+ PR_GetCurrentThread()));
+ break;
+
+ case 8:
+ (void)PR_GetEnv("PATH");
+ DPRINTF((output,"Thread[0x%x] called PR_GetEnv\n",
+ PR_GetCurrentThread()));
+ break;
+
+ case 9:
+ (void)PR_NewTCPSocketPair(pair);
+ DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocketPair\n",
+ PR_GetCurrentThread()));
+ PR_Close(pair[0]);
+ PR_Close(pair[1]);
+ break;
+
+ case 10:
+ PR_SetConcurrency(2);
+ DPRINTF((output,"Thread[0x%x] called PR_SetConcurrency\n",
+ PR_GetCurrentThread()));
+ break;
+
+ case 11:
+ PR_SetThreadPriority(PR_GetCurrentThread(), PR_PRIORITY_HIGH);
+ DPRINTF((output,"Thread[0x%x] called PR_SetThreadPriority\n",
+ PR_GetCurrentThread()));
+ break;
+
+ default:
+ break;
+ } /* switch() */
+ }
} /* OneShot */
int main(int argc, char **argv)
{
PRStatus rv;
- PRInt32 thread_cnt = DEFAULT_THREAD_COUNT;
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dt:");
+ PRInt32 thread_cnt = DEFAULT_THREAD_COUNT;
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dt:");
#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
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'd': /* debug mode */
- _debug_on = 1;
- break;
- case 't': /* thread count */
- thread_cnt = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ case 't': /* thread count */
+ thread_cnt = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- PR_SetConcurrency(2);
+ PR_SetConcurrency(2);
- output = PR_GetSpecialFD(PR_StandardOutput);
+ output = PR_GetSpecialFD(PR_StandardOutput);
while (thread_cnt-- > 0)
{