mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-04 02:18:37 +00:00
Add a regression test, courtesy of Bart Van Assche.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6379
This commit is contained in:
parent
34a8fb5292
commit
59cdea4c78
@ -95,6 +95,8 @@ 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 \
|
||||
@ -146,6 +148,7 @@ 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 \
|
||||
@ -175,6 +178,7 @@ pth_mutexspeed_LDADD = -lpthread
|
||||
pth_once_LDADD = -lpthread
|
||||
pth_rwlock_LDADD = -lpthread
|
||||
pth_stackalign_LDADD = -lpthread
|
||||
pth_detached_LDADD = -lpthread
|
||||
if VGP_PPC32_AIX5
|
||||
res_search_LDADD = -lpthread
|
||||
else
|
||||
|
||||
68
none/tests/pth_detached.c
Normal file
68
none/tests/pth_detached.c
Normal file
@ -0,0 +1,68 @@
|
||||
/* Test whether detached threads are handled properly.
|
||||
Contributed by Bart Van Assche (bart.vanassche@gmail.com).
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int s_finished_count;
|
||||
|
||||
static void* thread_func1(void* arg)
|
||||
{
|
||||
write(STDOUT_FILENO, ".", 1);
|
||||
s_finished_count++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void* thread_func2(void* arg)
|
||||
{
|
||||
pthread_detach(pthread_self());
|
||||
write(STDOUT_FILENO, "*", 1);
|
||||
s_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_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 (s_finished_count < count1 + count2)
|
||||
{
|
||||
struct timespec delay = { 0, 1 * 1000 * 1000 };
|
||||
nanosleep(&delay, 0);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
2
none/tests/pth_detached.stderr.exp
Normal file
2
none/tests/pth_detached.stderr.exp
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
1
none/tests/pth_detached.stdout.exp
Normal file
1
none/tests/pth_detached.stdout.exp
Normal file
@ -0,0 +1 @@
|
||||
....................................................................................................****************************************************************************************************
|
||||
1
none/tests/pth_detached.vgtest
Normal file
1
none/tests/pth_detached.vgtest
Normal file
@ -0,0 +1 @@
|
||||
prog: pth_detached
|
||||
Loading…
x
Reference in New Issue
Block a user