From: Nicholas Nethercote Date: Sun, 10 Feb 2008 22:36:55 +0000 (+0000) Subject: From Bart van Assche: X-Git-Tag: svn/VALGRIND_3_4_0~1077 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8d9deb93d5d35ff2307dda8fb4b7d52480f41e03;p=thirdparty%2Fvalgrind.git From Bart van Assche: A long time ago pthreads-functions were instrumented in the drd-patch via modifications of coregrind/vg_preloaded.c. A.o. detached threads were recognized by intercepting pthread_create(). This intercept was active for all tools, so it made sense to add a unit test for it (none/tests/pth_detached.c). This intercept has been moved from coregrind/vg_preloaded.c to exp-drd/drd_preloaded.c, so this unit test does no longer make sense for nulgrind. This test may be removed. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7391 --- diff --git a/none/tests/Makefile.am b/none/tests/Makefile.am index 197a2d1260..2577e7c03d 100644 --- a/none/tests/Makefile.am +++ b/none/tests/Makefile.am @@ -95,8 +95,6 @@ EXTRA_DIST = $(noinst_SCRIPTS) \ pth_rwlock.stderr.exp pth_rwlock.vgtest \ pth_stackalign.stderr.exp \ pth_stackalign.stdout.exp pth_stackalign.vgtest \ - pth_detached.stderr.exp \ - pth_detached.stdout.exp pth_detached.vgtest \ rcrl.stderr.exp rcrl.stdout.exp rcrl.vgtest \ readline1.stderr.exp readline1.stdout.exp \ readline1.vgtest \ @@ -148,7 +146,6 @@ check_PROGRAMS = \ pth_atfork1 pth_blockedsig pth_cancel1 pth_cancel2 pth_cvsimple \ pth_empty pth_exit pth_exit2 pth_mutexspeed pth_once pth_rwlock \ pth_stackalign \ - pth_detached \ rcrl readline1 res_search resolv \ rlimit_nofile selfrun sem semlimit sha1_test \ shortpush shorts stackgrowth sigstackgrowth susphello \ @@ -178,7 +175,6 @@ pth_mutexspeed_LDADD = -lpthread pth_once_LDADD = -lpthread pth_rwlock_LDADD = -lpthread pth_stackalign_LDADD = -lpthread -pth_detached_LDADD = -lpthread if VGO_AIX5 res_search_LDADD = -lpthread else diff --git a/none/tests/pth_detached.c b/none/tests/pth_detached.c deleted file mode 100644 index 5a94622793..0000000000 --- a/none/tests/pth_detached.c +++ /dev/null @@ -1,90 +0,0 @@ -/* Test whether detached threads are handled properly. - Contributed by Bart Van Assche (bart.vanassche@gmail.com). -*/ - -#include -#include -#include -#include -#include - -static int s_finished_count = 0; -static pthread_mutex_t s_mutex; - -void increment_finished_count() -{ - pthread_mutex_lock(&s_mutex); - s_finished_count++; - pthread_mutex_unlock(&s_mutex); -} - -int get_finished_count() -{ - int result; - pthread_mutex_lock(&s_mutex); - result = s_finished_count; - pthread_mutex_unlock(&s_mutex); - return result; -} - -static void* thread_func1(void* arg) -{ - write(STDOUT_FILENO, ".", 1); - increment_finished_count(); - return 0; -} - -static void* thread_func2(void* arg) -{ - pthread_detach(pthread_self()); - write(STDOUT_FILENO, ".", 1); - increment_finished_count(); - return 0; -} - -int main(int argc, char** argv) -{ - const int count1 = argc > 1 ? atoi(argv[1]) : 100; - const int count2 = argc > 2 ? atoi(argv[2]) : 100; - int i; - int detachstate; - pthread_attr_t attr; - - pthread_mutex_init(&s_mutex, 0); - - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - assert(pthread_attr_getdetachstate(&attr, &detachstate) == 0); - assert(detachstate == PTHREAD_CREATE_DETACHED); - pthread_attr_setstacksize(&attr, 16384); - // Create count1 detached threads by setting the "detached" property via - // thread attributes. - for (i = 0; i < count1; i++) - { - pthread_t thread; - pthread_create(&thread, &attr, thread_func1, 0); - } - // Create count2 detached threads by letting the threads detach themselves. - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - assert(pthread_attr_getdetachstate(&attr, &detachstate) == 0); - assert(detachstate == PTHREAD_CREATE_JOINABLE); - for (i = 0; i < count2; i++) - { - pthread_t thread; - pthread_create(&thread, &attr, thread_func2, 0); - } - pthread_attr_destroy(&attr); - - // Wait until all detached threads have written their output to stdout. - while (get_finished_count() < count1 + count2) - { - struct timespec delay = { 0, 1 * 1000 * 1000 }; - nanosleep(&delay, 0); - } - - printf("\n"); - - pthread_mutex_destroy(&s_mutex); - - return 0; -} diff --git a/none/tests/pth_detached.stderr.exp b/none/tests/pth_detached.stderr.exp deleted file mode 100644 index 139597f9cb..0000000000 --- a/none/tests/pth_detached.stderr.exp +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/none/tests/pth_detached.stdout.exp b/none/tests/pth_detached.stdout.exp deleted file mode 100644 index 0ced6c1a8b..0000000000 --- a/none/tests/pth_detached.stdout.exp +++ /dev/null @@ -1 +0,0 @@ -........................................................................................................................................................................................................ diff --git a/none/tests/pth_detached.vgtest b/none/tests/pth_detached.vgtest deleted file mode 100644 index eba5b8741d..0000000000 --- a/none/tests/pth_detached.vgtest +++ /dev/null @@ -1 +0,0 @@ -prog: pth_detached