Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/regress/lib/libpthread Add a regression test for the pthread...



details:   https://anonhg.NetBSD.org/src/rev/3dccb175a25f
branches:  trunk
changeset: 543517:3dccb175a25f
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Feb 26 22:05:02 2003 +0000

description:
Add a regression test for the pthread_{,attr}_{get,set}name_np() API.

diffstat:

 regress/lib/libpthread/Makefile      |   4 +-
 regress/lib/libpthread/name/Makefile |  15 ++++++++
 regress/lib/libpthread/name/name.c   |  66 ++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 2 deletions(-)

diffs (107 lines):

diff -r f7dffed1422c -r 3dccb175a25f regress/lib/libpthread/Makefile
--- a/regress/lib/libpthread/Makefile   Wed Feb 26 22:02:48 2003 +0000
+++ b/regress/lib/libpthread/Makefile   Wed Feb 26 22:05:02 2003 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.9 2003/02/20 21:09:40 uwe Exp $
+#      $NetBSD: Makefile,v 1.10 2003/02/26 22:05:02 thorpej Exp $
 
 .include <bsd.own.mk>
 
@@ -16,7 +16,7 @@
 .if defined(ARCHSUBDIR)
 
 SUBDIR+= barrier1 cond1 cond2 cond3 cond4 cond5 \
-        mutex1 mutex2 mutex3 mutex4 once1 once2 sem
+        mutex1 mutex2 mutex3 mutex4 name once1 once2 sem
 
 .endif
 
diff -r f7dffed1422c -r 3dccb175a25f regress/lib/libpthread/name/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libpthread/name/Makefile      Wed Feb 26 22:05:02 2003 +0000
@@ -0,0 +1,15 @@
+#      $NetBSD: Makefile,v 1.1 2003/02/26 22:05:03 thorpej Exp $
+
+WARNS=1
+
+PROG=  name
+SRCS=  name.c
+
+LDADD= -lpthread
+
+NOMAN=
+
+regress:
+       ./name
+
+.include <bsd.prog.mk>
diff -r f7dffed1422c -r 3dccb175a25f regress/lib/libpthread/name/name.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libpthread/name/name.c        Wed Feb 26 22:05:02 2003 +0000
@@ -0,0 +1,66 @@
+/*     $NetBSD: name.c,v 1.1 2003/02/26 22:05:03 thorpej Exp $ */
+
+#include <assert.h>
+#include <err.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+void *threadfunc(void *arg);
+
+#define        NAME_TOO_LONG   "12345678901234567890123456789012"      /* 32 chars */
+#define        NAME_JUST_RIGHT "1234567890123456789012345678901"       /* 31 chars */
+
+#define        CONST_NAME      "xyzzy"
+char non_const_name[] = CONST_NAME;
+
+int
+main(int argc, char *argv[])
+{
+       pthread_t thr, self = pthread_self();
+       pthread_attr_t attr;
+       char retname[32];
+       int ret;
+
+       pthread_attr_init(&attr);
+       assert(0 == pthread_attr_getname_np(&attr, retname, sizeof(retname),
+           NULL));
+       assert(retname[0] == '\0');
+       assert(EINVAL == pthread_attr_setname_np(&attr, NAME_TOO_LONG, NULL));
+       assert(0 == pthread_attr_setname_np(&attr, "%s", NAME_JUST_RIGHT));
+
+       strcpy(retname, "foo");
+       assert(0 == pthread_getname_np(self, retname, sizeof(retname)));
+       assert(retname[0] == '\0');
+
+       ret = pthread_create(&thr, &attr, threadfunc, NULL);
+       if (ret != 0)
+               err(1, "pthread_create");
+
+       ret = pthread_join(thr, NULL);
+       if (ret != 0)
+               err(1, "pthread_join");
+
+       assert(ESRCH == pthread_getname_np(thr, retname, sizeof(retname)));
+
+       return 0;
+}
+
+void *
+threadfunc(void *arg)
+{
+       pthread_t self = pthread_self();
+       char retname[32];
+
+       assert(0 == pthread_getname_np(self, retname, sizeof(retname)));
+       assert(0 == strcmp(retname, NAME_JUST_RIGHT));
+
+       assert(0 == pthread_setname_np(self, non_const_name, NULL));
+       memset(non_const_name, 0, sizeof(non_const_name));
+       assert(0 == pthread_getname_np(self, retname, sizeof(retname)));
+       assert(0 == strcmp(retname, CONST_NAME));
+
+       return NULL;
+}



Home | Main Index | Thread Index | Old Index