From 2ef097640758653a0e9d63e90a4aac329cd86368 Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 22 Feb 1999 02:54:12 +0000 Subject: 1999-02-23 Ross Johnson * Makefile: Some refinement. * *.c: More exhaustive checking through assertions; clean up; add some more tests. --- tests/self2.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'tests/self2.c') diff --git a/tests/self2.c b/tests/self2.c index 461e5f9..83339f1 100644 --- a/tests/self2.c +++ b/tests/self2.c @@ -1,33 +1,46 @@ -#include -#include -#include +/* + * self2.c + * + * Test for pthread_self(). + * + * Depends on API functions: + * pthread_create() + * pthread_self() + * + * Implicitly depends on: + * pthread_getspecific() + * pthread_setspecific() + */ + +#include "test.h" +#include + +static pthread_t me; void * entry(void * arg) { - /* Like systems such as HP-UX, we can't print the value of the thread ID - because it's not an integral type. Instead, we'll poke our noses into - the pthread_t structure and dump a useful internal value. This is - ordinarily bad, m'kay? */ + me = pthread_self(); - pthread_t t = pthread_self(); - printf("my thread is %lx\n", t->threadH); return arg; } int main() { - int rc; pthread_t t; - if (pthread_create(&t, NULL, entry, NULL) != 0) - { - return 1; - } + assert(pthread_create(&t, NULL, entry, NULL) == 0); Sleep(2000); + /* + * Not much more we can do here but bytewise compare t with + * what pthread_self returned. + */ + assert(t == me); + assert(memcmp((const void *) t, (const void *) me, sizeof t) == 0); + /* Success. */ return 0; } -- cgit v1.2.3