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

This commit is contained in:
thorpej 2003-02-26 22:05:02 +00:00
parent b33971b9c3
commit 4edae6c16a
3 changed files with 83 additions and 2 deletions

View File

@ -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 @@ ARCHSUBDIR= ${MACHINE_CPU}
.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

View File

@ -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>

View File

@ -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;
}