diff options
Diffstat (limited to 'test/pthread')
| -rw-r--r-- | test/pthread/Makefile | 8 | ||||
| -rw-r--r-- | test/pthread/Makefile.in | 8 | ||||
| -rw-r--r-- | test/pthread/cancellation-points.c | 10 | ||||
| -rw-r--r-- | test/pthread/ex6.c | 7 | ||||
| -rw-r--r-- | test/pthread/ex7.c | 7 | ||||
| -rw-r--r-- | test/pthread/tst-join2.c | 104 | ||||
| -rw-r--r-- | test/pthread/tst-join3.c | 123 |
7 files changed, 257 insertions, 10 deletions
diff --git a/test/pthread/Makefile b/test/pthread/Makefile index ef924ad1a..97ebee894 100644 --- a/test/pthread/Makefile +++ b/test/pthread/Makefile @@ -1,8 +1,8 @@ # uClibc pthread tests # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. +top_builddir=../../ +top_srcdir=../../ +include ../Rules.mak +-include Makefile.in include ../Test.mak - -EXTRA_LDFLAGS := -lpthread - -LDFLAGS_cancellation-points := -lrt diff --git a/test/pthread/Makefile.in b/test/pthread/Makefile.in new file mode 100644 index 000000000..c50748d69 --- /dev/null +++ b/test/pthread/Makefile.in @@ -0,0 +1,8 @@ +# uClibc pthread tests +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + +TESTS_DISABLED += cancellation-points + +EXTRA_LDFLAGS := -lpthread + +LDFLAGS_cancellation-points := -lrt diff --git a/test/pthread/cancellation-points.c b/test/pthread/cancellation-points.c index 3fe49fcaa..5453060f7 100644 --- a/test/pthread/cancellation-points.c +++ b/test/pthread/cancellation-points.c @@ -29,12 +29,12 @@ /* take care of optional things ... */ #define STUB(func, args) static void func args { sleep(0); } -#if !defined(__UCLIBC__) || defined(__UCLIBC_AIO__) +#if defined(__UCLIBC_AIO__) # include <aio.h> #else STUB(aio_suspend, (void *p, int n, const void *p2)) #endif -#if !defined(__UCLIBC__) || defined(__UCLIBC_STROPTS__) +#if defined(__UCLIBC_STROPTS__) # include <stropts.h> #else STUB(getmsg, (int f, void *p, void *p2, void *p3)) @@ -141,7 +141,9 @@ MAKE_CANCEL_THREAD_FUNC_EX(sem_wait, (&sem), help_sem_setup()) MAKE_CANCEL_THREAD_FUNC(send, (-1, NULL, 0, 0)) MAKE_CANCEL_THREAD_FUNC(sendmsg, (-1, NULL, 0)) MAKE_CANCEL_THREAD_FUNC(sendto, (-1, NULL, 0, 0, NULL, 0)) +#ifdef __UCLIBC_SUSV4_LEGACY__ MAKE_CANCEL_THREAD_FUNC(sigpause, (0)) +#endif MAKE_CANCEL_THREAD_FUNC(sigsuspend, (NULL)) MAKE_CANCEL_THREAD_FUNC(sigtimedwait, (NULL, NULL, NULL)) MAKE_CANCEL_THREAD_FUNC(sigwait, (NULL, NULL)) @@ -149,7 +151,9 @@ MAKE_CANCEL_THREAD_FUNC(sigwaitinfo, (NULL, NULL)) MAKE_CANCEL_THREAD_FUNC(sleep, (0)) MAKE_CANCEL_THREAD_FUNC(system, ("")) MAKE_CANCEL_THREAD_FUNC(tcdrain, (-1)) +#ifdef __UCLIBC_SUSV3_LEGACY__ MAKE_CANCEL_THREAD_FUNC(usleep, (0)) +#endif MAKE_CANCEL_THREAD_FUNC(wait, (NULL)) MAKE_CANCEL_THREAD_FUNC(waitid, (0, 0, NULL, 0)) MAKE_CANCEL_THREAD_FUNC(waitpid, (-1, NULL, 0)) @@ -264,7 +268,9 @@ int main(int argc, char *argv[]) ret += TEST_FUNC(sleep); ret += TEST_FUNC(system); ret += TEST_FUNC(tcdrain); +#ifdef __UCLIBC_SUSV3_LEGACY__ ret += TEST_FUNC(usleep); +#endif ret += TEST_FUNC(wait); ret += TEST_FUNC(waitid); ret += TEST_FUNC(waitpid); diff --git a/test/pthread/ex6.c b/test/pthread/ex6.c index bb96ca5fa..ffb628771 100644 --- a/test/pthread/ex6.c +++ b/test/pthread/ex6.c @@ -2,7 +2,7 @@ #include <stdio.h> #include <string.h> #include <pthread.h> -#include <unistd.h> +#include <time.h> static void * test_thread (void *v_param) @@ -14,6 +14,9 @@ int main (void) { unsigned long count; + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 10 * 1000; setvbuf (stdout, NULL, _IONBF, 0); @@ -35,7 +38,7 @@ main (void) } /* pthread_detach (thread); */ pthread_join (thread, NULL); - usleep (10); + nanosleep (&ts, NULL); } return 0; } diff --git a/test/pthread/ex7.c b/test/pthread/ex7.c index 49af18d96..8eeb9a2e5 100644 --- a/test/pthread/ex7.c +++ b/test/pthread/ex7.c @@ -8,7 +8,7 @@ #include <string.h> #include <pthread.h> #include <sys/time.h> -#include <unistd.h> +#include <time.h> /* Our event variable using a condition variable contruct. */ typedef struct { @@ -63,6 +63,9 @@ int main (void) { unsigned long count; + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 10 * 1000; setvbuf (stdout, NULL, _IONBF, 0); @@ -96,7 +99,7 @@ main (void) printf ("count = %lu\n", count); } - usleep (10); + nanosleep (&ts, NULL); } return 0; diff --git a/test/pthread/tst-join2.c b/test/pthread/tst-join2.c new file mode 100644 index 000000000..2cfab8b0e --- /dev/null +++ b/test/pthread/tst-join2.c @@ -0,0 +1,104 @@ +/* Copyright (C) 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + + +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; + + +static void * +tf (void *arg) +{ + if (pthread_mutex_lock (&lock) != 0) + { + puts ("child: mutex_lock failed"); + return NULL; + } + + return (void *) 42l; +} + + +static int +do_test (void) +{ + pthread_t th; + + if (pthread_mutex_lock (&lock) != 0) + { + puts ("mutex_lock failed"); + exit (1); + } + + if (pthread_create (&th, NULL, tf, NULL) != 0) + { + puts ("mutex_create failed"); + exit (1); + } + + void *status; + int val = pthread_tryjoin_np (th, &status); + if (val == 0) + { + puts ("1st tryjoin succeeded"); + exit (1); + } + else if (val != EBUSY) + { + puts ("1st tryjoin didn't return EBUSY"); + exit (1); + } + + if (pthread_mutex_unlock (&lock) != 0) + { + puts ("mutex_unlock failed"); + exit (1); + } + + while ((val = pthread_tryjoin_np (th, &status)) != 0) + { + if (val != EBUSY) + { + printf ("tryjoin returned %s (%d), expected only 0 or EBUSY\n", + strerror (val), val); + exit (1); + } + + /* Delay minimally. */ + struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 }; + nanosleep (&ts, NULL); + } + + if (status != (void *) 42l) + { + printf ("return value %p, expected %p\n", status, (void *) 42l); + exit (1); + } + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/test/pthread/tst-join3.c b/test/pthread/tst-join3.c new file mode 100644 index 000000000..df1135fb5 --- /dev/null +++ b/test/pthread/tst-join3.c @@ -0,0 +1,123 @@ +/* Copyright (C) 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/time.h> + + +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; + + +static void * +tf (void *arg) +{ + if (pthread_mutex_lock (&lock) != 0) + { + puts ("child: mutex_lock failed"); + return NULL; + } + + return (void *) 42l; +} + + +static int +do_test (void) +{ + pthread_t th; + + if (pthread_mutex_lock (&lock) != 0) + { + puts ("mutex_lock failed"); + exit (1); + } + + if (pthread_create (&th, NULL, tf, NULL) != 0) + { + puts ("mutex_create failed"); + exit (1); + } + + void *status; + struct timespec ts; + struct timeval tv; + (void) gettimeofday (&tv, NULL); + TIMEVAL_TO_TIMESPEC (&tv, &ts); + ts.tv_nsec += 200000000; + if (ts.tv_nsec >= 1000000000) + { + ts.tv_nsec -= 1000000000; + ++ts.tv_sec; + } + int val = pthread_timedjoin_np (th, &status, &ts); + if (val == 0) + { + puts ("1st timedjoin succeeded"); + exit (1); + } + else if (val != ETIMEDOUT) + { + puts ("1st timedjoin didn't return ETIMEDOUT"); + exit (1); + } + + if (pthread_mutex_unlock (&lock) != 0) + { + puts ("mutex_unlock failed"); + exit (1); + } + + while (1) + { + (void) gettimeofday (&tv, NULL); + TIMEVAL_TO_TIMESPEC (&tv, &ts); + ts.tv_nsec += 200000000; + if (ts.tv_nsec >= 1000000000) + { + ts.tv_nsec -= 1000000000; + ++ts.tv_sec; + } + + val = pthread_timedjoin_np (th, &status, &ts); + if (val == 0) + break; + + if (val != ETIMEDOUT) + { + printf ("timedjoin returned %s (%d), expected only 0 or ETIMEDOUT\n", + strerror (val), val); + exit (1); + } + } + + if (status != (void *) 42l) + { + printf ("return value %p, expected %p\n", status, (void *) 42l); + exit (1); + } + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |
