From c94735ecdde19c4de652efd144faeec1a729b1e0 Mon Sep 17 00:00:00 2001 From: rpj Date: Thu, 28 Dec 2000 05:32:07 +0000 Subject: ./ChangeLog: 2000-12-28 Ross Johnson * private.c (ptw32_threadStart): Unhandled exceptions are now passed through to the system to deal with. This is consistent with normal Windows behaviour. C++ applications may use set_terminate() to override the default behaviour which is to call ptw32_terminate(). Ptw32_terminate() cleans up some POSIX thread stuff before calling the system default function which calls abort(). The users termination function should conform to standard C++ semantics which is to not return. It should exit the thread (call pthread_exit()) or exit the application. * private.c (ptw32_terminate): Added as the default set_terminate() function. It calls the system default function after cleaning up some POSIX thread stuff. * implement.h (ptw32_try_enter_critical_section): Move declaration. * global.c (ptw32_try_enter_critical_section): Moved from dll.c. * dll.c: Move process and thread attach/detach code into functions in nonportable.c. * nonportable.c (pthread_win32_process_attach_np): Process attach code from dll.c is now available to static linked applications. * nonportable.c (pthread_win32_process_detach_np): Likewise. * nonportable.c (pthread_win32_thread_attach_np): Likewise. * nonportable.c (pthread_win32_thread_detach_np): Likewise. * pthread.h: Add new non-portable prototypes for static linked applications. * GNUmakefile (OPT): Increase optimisation flag and remove debug info flag. * pthread.def: Add new non-portable exports for static linked applications. 2000-12-11 Ross Johnson * FAQ: Update Answer 6 re getting a fully working Mingw32 built library. 2000-09-09 Ross Johnson * pthread.h (ctime_r): Fix arg. ./tests/ChangeLog: 2000-12-28 Ross Johnson * eyal1.c: Increase thread work loads. * exception2.c: New test. * exception3.c: New test. * Makefile: Add new tests exception2.c and exception3.c. * GNUmakefile: Likewise. 2000-12-11 Ross Johnson * cleanup3.c: Remove unused variable. * cleanup2.c: Likewise. * exception1.c: Throw an exception rather than use a deliberate zero divide so that catch(...) will handle it under Mingw32. Mingw32 now builds the library correctly to pass all tests - see Thomas Pfaff's detailed instructions re needed changes to Mingw32 in the Pthreads-Win32 FAQ. --- tests/ChangeLog | 19 +++ tests/GNUmakefile | 9 +- tests/Makefile | 4 +- tests/cleanup2.c | 2 - tests/cleanup3.c | 2 - tests/exception1.c | 453 +++++++++++++++++++++++++++-------------------------- tests/exception2.c | 120 ++++++++++++++ tests/exception3.c | 164 +++++++++++++++++++ tests/eyal1.c | 4 +- 9 files changed, 544 insertions(+), 233 deletions(-) create mode 100644 tests/exception2.c create mode 100644 tests/exception3.c (limited to 'tests') diff --git a/tests/ChangeLog b/tests/ChangeLog index a809dca..db66602 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,22 @@ +2000-12-28 Ross Johnson + + * eyal1.c: Increase thread work loads. + * exception2.c: New test. + * exception3.c: New test. + * Makefile: Add new tests exception2.c and exception3.c. + * GNUmakefile: Likewise. + +2000-12-11 Ross Johnson + + * cleanup3.c: Remove unused variable. + * cleanup2.c: Likewise. + * exception1.c: Throw an exception rather than use + a deliberate zero divide so that catch(...) will + handle it under Mingw32. Mingw32 now builds the + library correctly to pass all tests - see Thomas + Pfaff's detailed instructions re needed changes + to Mingw32 in the Pthreads-Win32 FAQ. + 2000-09-08 Ross Johnson * cancel5.c: New; tests calling pthread_cancel() diff --git a/tests/GNUmakefile b/tests/GNUmakefile index a775e10..7b4fd64 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -3,6 +3,7 @@ CP = copy +MV = rename RM = erase MKDIR = mkdir TOUCH = echo Passed > @@ -13,7 +14,8 @@ ECHO = @echo # GLANG = c++ CC = gcc -CFLAGS = -g -O0 -mthreads -UNDEBUG -Wall -x $(GLANG) +#CFLAGS = -g -O0 -mthreads -UNDEBUG -Wall -x $(GLANG) +CFLAGS = -O3 -mthreads -UNDEBUG -Wall -x $(GLANG) BUILD_DIR = .. INCLUDES = -I. LIBS = -L. -lpthreadw32 @@ -37,7 +39,7 @@ TESTS = loadfree \ rwlock1 rwlock2 rwlock3 rwlock4 rwlock5 rwlock6 \ context1 cancel3 cancel4 cancel5 \ cleanup0 cleanup1 cleanup2 cleanup3 \ - exception1 + exception1 exception2 exception3 PASSES = $(TESTS:%=%.pass) @@ -89,7 +91,10 @@ cleanup1.pass: cleanup0.pass cleanup2.pass: cleanup1.pass cleanup3.pass: cleanup2.pass exception1.pass: cancel4.pass +exception2.pass: exception1.pass +exception3.pass: exception2.pass +#%.pass: %.exe $(HDR) %.pass: %.exe $(LIB) $(DLL) $(HDR) $* @ $(ECHO) Passed diff --git a/tests/Makefile b/tests/Makefile index 41e202c..208b438 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -49,7 +49,7 @@ PASSES= loadfree.pass \ context1.pass \ cancel3.pass cancel4.pass cancel5.pass \ cleanup0.pass cleanup1.pass cleanup2.pass cleanup3.pass \ - exception1.pass + exception1.pass exception2.pass exception3.pass all: @ $(ECHO) Run one of the following command lines: @@ -146,3 +146,5 @@ cleanup1.pass: cleanup0.pass cleanup2.pass: cleanup1.pass cleanup3.pass: cleanup2.pass exception1.pass: cancel4.pass +exception2.pass: exception1.pass +exception3.pass: exception2.pass diff --git a/tests/cleanup2.c b/tests/cleanup2.c index 6d07d53..3c5e039 100644 --- a/tests/cleanup2.c +++ b/tests/cleanup2.c @@ -60,8 +60,6 @@ struct bag_t_ { static bag_t threadbag[NUMTHREADS + 1]; -static pthread_mutex_t waitLock = PTHREAD_MUTEX_INITIALIZER; - static int pop_count = 0; static void diff --git a/tests/cleanup3.c b/tests/cleanup3.c index 56b1a8f..1e24acf 100644 --- a/tests/cleanup3.c +++ b/tests/cleanup3.c @@ -61,8 +61,6 @@ struct bag_t_ { static bag_t threadbag[NUMTHREADS + 1]; -static pthread_mutex_t waitLock = PTHREAD_MUTEX_INITIALIZER; - static int pop_count = 0; static void diff --git a/tests/exception1.c b/tests/exception1.c index 609e5ed..1452d1a 100644 --- a/tests/exception1.c +++ b/tests/exception1.c @@ -1,224 +1,229 @@ -/* - * File: exception1.c - * - * Test Synopsis: Test passing of exceptions back to the application. - * - * Test Method (Validation or Falsification): - * - - * - * Requirements Tested: - * - - * - * Features Tested: - * - - * - * Cases Tested: - * - - * - * Description: - * - - * - * Environment: - * - - * - * Input: - * - None. - * - * Output: - * - File name, Line number, and failed expression on failure. - * - No output on success. - * - * Assumptions: - * - have working pthread_create, pthread_self, pthread_mutex_lock/unlock - * pthread_testcancel, pthread_cancel, pthread_join - * - * Pass Criteria: - * - Process returns zero exit status. - * - * Fail Criteria: - * - Process returns non-zero exit status. - */ - -#if defined(_MSC_VER) || defined(__cplusplus) - -#include "test.h" - -/* - * Create NUMTHREADS threads in addition to the Main thread. - */ -enum { - NUMTHREADS = 4 -}; - -void * -exceptionedThread(void * arg) -{ - int result = ((int)PTHREAD_CANCELED + 1); - int one = 1; - int zero = 0; - int dummy = 0; - - /* Set to async cancelable */ - - assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0); - - assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0); - - Sleep(100); - -#if defined(_MSC_VER) && !defined(__cplusplus) - __try - { - /* Avoid being optimised out */ - if (dummy == one/zero) - Sleep(0); - } - __except (EXCEPTION_EXECUTE_HANDLER) - { - /* Should get into here. */ - result = ((int)PTHREAD_CANCELED + 2); - } -#elif defined(__cplusplus) - try - { - /* Avoid being optimised out */ - if (dummy == one/zero) - Sleep(0); - } -#if defined(PtW32CatchAll) - PtW32CatchAll -#else - catch (...) -#endif - { - /* Should get into here. */ - result = ((int)PTHREAD_CANCELED + 2); - } -#endif - - return (void *) result; -} - -void * -canceledThread(void * arg) -{ - int result = ((int)PTHREAD_CANCELED + 1); - int count; - - /* Set to async cancelable */ - - assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0); - - assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0); - -#if defined(_MSC_VER) && !defined(__cplusplus) - __try - { - /* - * We wait up to 10 seconds, waking every 0.1 seconds, - * for a cancelation to be applied to us. - */ - for (count = 0; count < 100; count++) - Sleep(100); - } - __except (EXCEPTION_EXECUTE_HANDLER) - { - /* Should NOT get into here. */ - result = ((int)PTHREAD_CANCELED + 2); - } -#elif defined(__cplusplus) - try - { - /* - * We wait up to 10 seconds, waking every 0.1 seconds, - * for a cancelation to be applied to us. - */ - for (count = 0; count < 100; count++) - Sleep(100); - } -#if defined(PtW32CatchAll) - PtW32CatchAll -#else - catch (...) -#endif - { - /* Should NOT get into here. */ - result = ((int)PTHREAD_CANCELED + 2); - } -#endif - - return (void *) result; -} - -int -main() -{ - int failed = 0; - int i; - pthread_t mt; - pthread_t et[NUMTHREADS]; - pthread_t ct[NUMTHREADS]; - - assert((mt = pthread_self()) != NULL); - - for (i = 0; i < NUMTHREADS; i++) - { - assert(pthread_create(&et[i], NULL, exceptionedThread, NULL) == 0); - assert(pthread_create(&ct[i], NULL, canceledThread, NULL) == 0); - } - - /* - * Code to control or munipulate child threads should probably go here. - */ - Sleep(500); - - for (i = 0; i < NUMTHREADS; i++) - { - assert(pthread_cancel(ct[i]) == 0); - } - - /* - * Give threads time to run. - */ - Sleep(NUMTHREADS * 100); - - /* - * Check any results here. Set "failed" and only print output on failure. - */ - failed = 0; - for (i = 0; i < NUMTHREADS; i++) - { - int fail = 0; - int result = 0; - - /* Canceled thread */ - assert(pthread_join(ct[i], (void **) &result) == 0); - fail = (result != (int) PTHREAD_CANCELED); - - failed = (failed || fail); - - /* Exception thread */ - assert(pthread_join(et[i], (void **) &result) == 0); - fail = (result != ((int) PTHREAD_CANCELED + 2)); - - failed = (failed || fail); - } - - assert(!failed); - - /* - * Success. - */ - return 0; -} - -#else /* defined(_MSC_VER) || defined(__cplusplus) */ - -int -main() -{ - fprintf(stderr, "Test N/A for this compiler environment.\n"); - return 0; -} - -#endif /* defined(_MSC_VER) || defined(__cplusplus) */ +/* + * File: exception1.c + * + * Test Synopsis: Test passing of exceptions back to the application. + * + * Test Method (Validation or Falsification): + * - + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - have working pthread_create, pthread_self, pthread_mutex_lock/unlock + * pthread_testcancel, pthread_cancel, pthread_join + * + * Pass Criteria: + * - Process returns zero exit status. + * + * Fail Criteria: + * - Process returns non-zero exit status. + */ + +#if defined(_MSC_VER) || defined(__cplusplus) + +#include "test.h" + +/* + * Create NUMTHREADS threads in addition to the Main thread. + */ +enum { + NUMTHREADS = 4 +}; + +void * +exceptionedThread(void * arg) +{ + int dummy = 0; + int result = ((int)PTHREAD_CANCELED + 1); + /* Set to async cancelable */ + + assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0); + + assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0); + + Sleep(100); + +#if defined(_MSC_VER) && !defined(__cplusplus) + __try + { + int zero = 0; + int one = 1; + /* + * The deliberate exception condition (zero devide) is + * in an "if" to avoid being optimised out. + */ + if (dummy == one/zero) + Sleep(0); + } + __except (EXCEPTION_EXECUTE_HANDLER) + { + /* Should get into here. */ + result = ((int)PTHREAD_CANCELED + 2); + } +#elif defined(__cplusplus) + try + { + /* + * I had a zero divide exception here but it + * wasn't being caught by the catch(...) + * below under Mingw32. That could be a problem. + */ + throw dummy; + } +#if defined(PtW32CatchAll) + PtW32CatchAll +#else + catch (...) +#endif + { + /* Should get into here. */ + result = ((int)PTHREAD_CANCELED + 2); + } +#endif + + return (void *) result; +} + +void * +canceledThread(void * arg) +{ + int result = ((int)PTHREAD_CANCELED + 1); + int count; + + /* Set to async cancelable */ + + assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0); + + assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0); + +#if defined(_MSC_VER) && !defined(__cplusplus) + __try + { + /* + * We wait up to 10 seconds, waking every 0.1 seconds, + * for a cancelation to be applied to us. + */ + for (count = 0; count < 100; count++) + Sleep(100); + } + __except (EXCEPTION_EXECUTE_HANDLER) + { + /* Should NOT get into here. */ + result = ((int)PTHREAD_CANCELED + 2); + } +#elif defined(__cplusplus) + try + { + /* + * We wait up to 10 seconds, waking every 0.1 seconds, + * for a cancelation to be applied to us. + */ + for (count = 0; count < 100; count++) + Sleep(100); + } +#if defined(PtW32CatchAll) + PtW32CatchAll +#else + catch (...) +#endif + { + /* Should NOT get into here. */ + result = ((int)PTHREAD_CANCELED + 2); + } +#endif + + return (void *) result; +} + +int +main() +{ + int failed = 0; + int i; + pthread_t mt; + pthread_t et[NUMTHREADS]; + pthread_t ct[NUMTHREADS]; + + assert((mt = pthread_self()) != NULL); + + for (i = 0; i < NUMTHREADS; i++) + { + assert(pthread_create(&et[i], NULL, exceptionedThread, NULL) == 0); + assert(pthread_create(&ct[i], NULL, canceledThread, NULL) == 0); + } + + /* + * Code to control or munipulate child threads should probably go here. + */ + Sleep(1000); + + for (i = 0; i < NUMTHREADS; i++) + { + assert(pthread_cancel(ct[i]) == 0); + } + + /* + * Give threads time to run. + */ + Sleep(NUMTHREADS * 1000); + + /* + * Check any results here. Set "failed" and only print output on failure. + */ + failed = 0; + for (i = 0; i < NUMTHREADS; i++) + { + int fail = 0; + int result = 0; + + /* Canceled thread */ + assert(pthread_join(ct[i], (void **) &result) == 0); + assert(!(fail = (result != (int) PTHREAD_CANCELED))); + + failed = (failed || fail); + + /* Exceptioned thread */ + assert(pthread_join(et[i], (void **) &result) == 0); + assert(!(fail = (result != ((int) PTHREAD_CANCELED + 2)))); + + failed = (failed || fail); + } + + assert(!failed); + + /* + * Success. + */ + return 0; +} + +#else /* defined(_MSC_VER) || defined(__cplusplus) */ + +int +main() +{ + fprintf(stderr, "Test N/A for this compiler environment.\n"); + return 0; +} + +#endif /* defined(_MSC_VER) || defined(__cplusplus) */ diff --git a/tests/exception2.c b/tests/exception2.c new file mode 100644 index 0000000..da3d3b4 --- /dev/null +++ b/tests/exception2.c @@ -0,0 +1,120 @@ +/* + * File: exception2.c + * + * Test Synopsis: Test passing of exceptions out of thread scope. + * + * Test Method (Validation or Falsification): + * - + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - have working pthread_create, pthread_self, pthread_mutex_lock/unlock + * pthread_testcancel, pthread_cancel, pthread_join + * + * Pass Criteria: + * - Process returns zero exit status. + * + * Fail Criteria: + * - Process returns non-zero exit status. + */ + + +#if defined(_MSC_VER) && defined(__cplusplus) +#include +#else +#include +#endif + +#if defined(_MSC_VER) || defined(__cplusplus) + +#include "test.h" + +/* + * Create NUMTHREADS threads in addition to the Main thread. + */ +enum { + NUMTHREADS = 1 +}; + + +void * +exceptionedThread(void * arg) +{ + int dummy = 0x1; + +#if defined(_MSC_VER) && !defined(__cplusplus) + + RaiseException(dummy, 0, 0, NULL); + +#elif defined(__cplusplus) + + throw dummy; + +#endif + + return (void *) 100; +} + +int +main(int argc, char argv[]) +{ + int i; + pthread_t mt; + pthread_t et[NUMTHREADS]; + + if (argc <= 1) + { + int result; + + printf("You should see an \"abnormal termination\" message\n"); + fflush(stdout); + result = system("exception2.exe die"); + exit(0); + } + + assert((mt = pthread_self()) != NULL); + + for (i = 0; i < NUMTHREADS; i++) + { + assert(pthread_create(&et[i], NULL, exceptionedThread, NULL) == 0); + } + + Sleep(1000); + + /* + * Success. + */ + return 0; +} + +#else /* defined(_MSC_VER) || defined(__cplusplus) */ + +int +main() +{ + fprintf(stderr, "Test N/A for this compiler environment.\n"); + return 0; +} + +#endif /* defined(_MSC_VER) || defined(__cplusplus) */ diff --git a/tests/exception3.c b/tests/exception3.c new file mode 100644 index 0000000..b820b4b --- /dev/null +++ b/tests/exception3.c @@ -0,0 +1,164 @@ +/* + * File: exception3.c + * + * Test Synopsis: Test running of user supplied teerminate() function. + * + * Test Method (Validation or Falsification): + * - + * + * Requirements Tested: + * - + * + * Features Tested: + * - + * + * Cases Tested: + * - + * + * Description: + * - + * + * Environment: + * - + * + * Input: + * - None. + * + * Output: + * - File name, Line number, and failed expression on failure. + * - No output on success. + * + * Assumptions: + * - have working pthread_create, pthread_self, pthread_mutex_lock/unlock + * pthread_testcancel, pthread_cancel, pthread_join + * + * Pass Criteria: + * - Process returns zero exit status. + * + * Fail Criteria: + * - Process returns non-zero exit status. + */ + + +#if defined(_MSC_VER) && defined(__cplusplus) +#include +#else +#include +#endif + +#if defined(_MSC_VER) || defined(__cplusplus) + +#include "test.h" + +/* + * Create NUMTHREADS threads in addition to the Main thread. + */ +enum { + NUMTHREADS = 20 +}; + +int caught = 0; +pthread_mutex_t caughtLock = PTHREAD_MUTEX_INITIALIZER; + +#if defined(_MSC_VER) && !defined(__cplusplus) + +LONG unhandledExceptionFilter (EXCEPTION_POINTERS *ep) +{ + if (ep->ExceptionRecord->ExceptionCode == 0x1) + { + pthread_mutex_lock(&caughtLock); + caught++; + pthread_mutex_unlock(&caughtLock); + } + + return EXCEPTION_CONTINUE_EXECUTION; +} + +#elif defined(__cplusplus) + +void +terminateFunction () +{ + pthread_mutex_lock(&caughtLock); + caught++; +#if 1 + { + FILE * fp = fopen("pthread.log", "a"); + fprintf(fp, "Caught = %d\n", caught); + fclose(fp); + } +#endif + pthread_mutex_unlock(&caughtLock); + pthread_exit((void *) 0); +} + +#endif + +void * +exceptionedThread(void * arg) +{ + int dummy = 0x1; + + { +#if defined(_MSC_VER) && !defined(__cplusplus) + + RaiseException(dummy, 0, 0, NULL); + +#elif defined(__cplusplus) + + (void) set_terminate(&terminateFunction); + + throw dummy; + +#endif + } + + return (void *) 100; +} + +int +main() +{ + int i; + pthread_t mt; + pthread_t et[NUMTHREADS]; + + assert((mt = pthread_self()) != NULL); + + { +#if defined(_MSC_VER) && !defined(__cplusplus) + LPTOP_LEVEL_EXCEPTION_FILTER oldHandler; + oldHandler = SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) unhandledExceptionFilter); +#endif + + for (i = 0; i < NUMTHREADS; i++) + { + assert(pthread_create(&et[i], NULL, exceptionedThread, NULL) == 0); + } + +#if defined(_MSC_VER) && !defined(__cplusplus) + (void) SetUnhandledExceptionFilter(oldHandler); +#endif + + Sleep(30000); + } + + printf("Caught = %d\n", caught); + assert(caught == NUMTHREADS); + + /* + * Success. + */ + return 0; +} + +#else /* defined(_MSC_VER) || defined(__cplusplus) */ + +int +main() +{ + fprintf(stderr, "Test N/A for this compiler environment.\n"); + return 0; +} + +#endif /* defined(_MSC_VER) || defined(__cplusplus) */ diff --git a/tests/eyal1.c b/tests/eyal1.c index 843cb33..a9ba909 100644 --- a/tests/eyal1.c +++ b/tests/eyal1.c @@ -62,8 +62,8 @@ struct thread_control { typedef struct thread_control TC; static TC *tcs = NULL; -static int nthreads = 14; -static int nwork = 100; +static int nthreads = 10; +static int nwork = 1000; static int quiet = 0; static int todo = -1; -- cgit v1.2.3