diff options
author | rpj <rpj> | 1999-02-22 02:54:12 +0000 |
---|---|---|
committer | rpj <rpj> | 1999-02-22 02:54:12 +0000 |
commit | 2ef097640758653a0e9d63e90a4aac329cd86368 (patch) | |
tree | 71751f699b0aedba3227446ac228d30f2a127173 /tests/self2.c | |
parent | 943bc9bb02212649a83ec32152299d50d34226e6 (diff) |
1999-02-23 Ross Johnson <rpj@ise.canberra.edu.au>
* Makefile: Some refinement.
* *.c: More exhaustive checking through assertions; clean up;
add some more tests.
Diffstat (limited to 'tests/self2.c')
-rw-r--r-- | tests/self2.c | 41 |
1 files changed, 27 insertions, 14 deletions
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 <pthread.h> -#include <assert.h> -#include <stdio.h> +/* + * 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 <string.h> + +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; } |