added some pthread tests from posixtestsuite
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17897 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,5 +2,9 @@ SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance inter
|
|||||||
|
|
||||||
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces difftime ;
|
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces difftime ;
|
||||||
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces kill ;
|
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces kill ;
|
||||||
|
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_key_create ;
|
||||||
|
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_key_delete ;
|
||||||
|
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_getspecific ;
|
||||||
|
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_setspecific ;
|
||||||
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigprocmask ;
|
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigprocmask ;
|
||||||
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigsuspend ;
|
SubInclude HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces sigsuspend ;
|
||||||
|
|||||||
+72
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
|
* This file is licensed under the GPL license. For the full content
|
||||||
|
* of this license, see the COPYING file at the top level of this
|
||||||
|
* source tree.
|
||||||
|
|
||||||
|
* Test that pthread_getspecific()
|
||||||
|
*
|
||||||
|
* shall return the value currently bound to the specified key on behalf of the calling thread.
|
||||||
|
* Calling pthread_getspecific() with a key value not obtained from pthread_key_create() or
|
||||||
|
* after key has been deleted with pthread_key_delete() is undefined.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Create NUM_OF_KEYS pthread_key_t objects
|
||||||
|
* 2. Set each key to a thread-specific value with pthread_setspecific()
|
||||||
|
* 3. Call pthread_getspecific() on each key and check that the value returned is correct.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "posixtest.h"
|
||||||
|
|
||||||
|
#define NUM_OF_KEYS 10
|
||||||
|
#define KEY_VALUE 0
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pthread_key_t keys[NUM_OF_KEYS];
|
||||||
|
int i;
|
||||||
|
void* rc;
|
||||||
|
|
||||||
|
for(i = 0;i<NUM_OF_KEYS;i++)
|
||||||
|
{
|
||||||
|
if(pthread_key_create(&keys[i], NULL) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_create() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if(pthread_setspecific(keys[i], (void *)(long)(i + KEY_VALUE)) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_setspecific() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0;i<NUM_OF_KEYS;++i)
|
||||||
|
{
|
||||||
|
rc = pthread_getspecific(keys[i]);
|
||||||
|
if(rc != (void *)(long)(i + KEY_VALUE))
|
||||||
|
{
|
||||||
|
printf("Test FAILED: Did not return correct value of thread-specific key, expected %d, but got %ld\n", (i + KEY_VALUE), (long)rc);
|
||||||
|
return PTS_FAIL;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if(pthread_key_delete(keys[i]) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_delete() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Test PASSED\n");
|
||||||
|
return PTS_PASS;
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
|
* This file is licensed under the GPL license. For the full content
|
||||||
|
* of this license, see the COPYING file at the top level of this
|
||||||
|
* source tree.
|
||||||
|
|
||||||
|
* Test that pthread_getspecific()
|
||||||
|
*
|
||||||
|
* It shall return the thread-specific data value associated with the given 'key'. If no
|
||||||
|
* thread-specific data value is associated with 'key, then the value NULL shall be returned.
|
||||||
|
* It does not return any errors.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Create pthread_key_t object and do no specify a key accociated with this key
|
||||||
|
* 2. Call pthread_getspecific() and check that the value returns NULL.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "posixtest.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pthread_key_t key;
|
||||||
|
void* rc;
|
||||||
|
|
||||||
|
if(pthread_key_create(&key, NULL) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_create() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = pthread_getspecific(key);
|
||||||
|
if(rc != NULL)
|
||||||
|
{
|
||||||
|
printf("Test FAILED: Did not return correct value, expected NULL, but got %ld\n", (long)rc);
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pthread_key_delete(key) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_delete() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Test PASSED\n");
|
||||||
|
return PTS_PASS;
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_getspecific ;
|
||||||
|
|
||||||
|
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||||
|
|
||||||
|
SimpleTest pthread_getspecific_1-1 : 1-1.c ;
|
||||||
|
SimpleTest pthread_getspecific_3-1 : 3-1.c ;
|
||||||
|
|
||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
|
* This file is licensed under the GPL license. For the full content
|
||||||
|
* of this license, see the COPYING file at the top level of this
|
||||||
|
* source tree.
|
||||||
|
|
||||||
|
* Test that pthread_key_create()
|
||||||
|
*
|
||||||
|
* shall create a thread-specific data key visible to all threaads in the process. Key values
|
||||||
|
* provided by pthread_key_create() are opaque objects used to locate thread-specific data.
|
||||||
|
* Although the same key value may be used by different threads, the values bound to the key
|
||||||
|
* by pthread_setspecific() are maintained on a per-thread basis and persist for the life of
|
||||||
|
* the calling thread.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Define an array of keys
|
||||||
|
* 2. Use pthread_key_create() and create those keys
|
||||||
|
* 3. Verify that you can set and get specific values for those keys without errors.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "posixtest.h"
|
||||||
|
|
||||||
|
#define NUM_OF_KEYS 10
|
||||||
|
#define KEY_VALUE 0
|
||||||
|
|
||||||
|
pthread_key_t keys[NUM_OF_KEYS];
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
void* rc;
|
||||||
|
|
||||||
|
for(i = 0;i<NUM_OF_KEYS;i++)
|
||||||
|
{
|
||||||
|
if(pthread_key_create(&keys[i], NULL) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_create() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if(pthread_setspecific(keys[i], (void *)(long)(i + KEY_VALUE)) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_setspecific() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0;i<NUM_OF_KEYS;++i)
|
||||||
|
{
|
||||||
|
rc = pthread_getspecific(keys[i]);
|
||||||
|
if(rc != (void *)(long)(i + KEY_VALUE))
|
||||||
|
{
|
||||||
|
printf("Test FAILED: Did not return correct value of thread-specific key, expected %ld, but got %ld\n", (long)(i + KEY_VALUE), (long)rc);
|
||||||
|
return PTS_FAIL;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if(pthread_key_delete(keys[i]) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_delete() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Test PASSED\n");
|
||||||
|
return PTS_PASS;
|
||||||
|
}
|
||||||
+88
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
|
* This file is licensed under the GPL license. For the full content
|
||||||
|
* of this license, see the COPYING file at the top level of this
|
||||||
|
* source tree.
|
||||||
|
|
||||||
|
* Test that pthread_key_create()
|
||||||
|
*
|
||||||
|
* shall create a thread-specific data key visible to all threaads in the process. Key values
|
||||||
|
* provided by pthread_key_create() are opaque objects used to locate thread-specific data.
|
||||||
|
* Although the same key value may be used by different threads, the values bound to the key
|
||||||
|
* by pthread_setspecific() are maintained on a per-thread basis and persist for the life of
|
||||||
|
* the calling thread.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Define and create a key
|
||||||
|
* 2. Verify that you can create many threads with the same key value
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "posixtest.h"
|
||||||
|
|
||||||
|
#define NUM_OF_THREADS 10
|
||||||
|
#define KEY_VALUE 1000
|
||||||
|
pthread_key_t keys[NUM_OF_THREADS];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Thread function that sets the key to KEY_VALUE */
|
||||||
|
void *a_thread_func()
|
||||||
|
{
|
||||||
|
/* Set the key to KEY_VALUE */
|
||||||
|
if(pthread_setspecific(keys[i], (void *)(KEY_VALUE)) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_setspecific() failed\n");
|
||||||
|
pthread_exit((void*)PTS_FAIL);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pthread_t new_th;
|
||||||
|
void *value_ptr;
|
||||||
|
|
||||||
|
/* Create a key */
|
||||||
|
for(i = 0;i<NUM_OF_THREADS;i++)
|
||||||
|
{
|
||||||
|
if(pthread_key_create(&keys[i], NULL) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_create() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create NUM_OF_THREADS threads and in the thread_func, it will
|
||||||
|
* use pthread_setspecific with the same KEY_VALUE */
|
||||||
|
for(i = 0;i<NUM_OF_THREADS;i++)
|
||||||
|
{
|
||||||
|
/* Create a thread */
|
||||||
|
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||||
|
{
|
||||||
|
perror("Error creating thread\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for thread to end */
|
||||||
|
if(pthread_join(new_th, &value_ptr) != 0)
|
||||||
|
{
|
||||||
|
perror("Error in pthread_join\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(value_ptr == (void*) PTS_FAIL)
|
||||||
|
{
|
||||||
|
printf("Test FAILED: Could not use a certain key value to set for many keys\n");
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Test PASSED\n");
|
||||||
|
return PTS_PASS;
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
|
* This file is licensed under the GPL license. For the full content
|
||||||
|
* of this license, see the COPYING file at the top level of this
|
||||||
|
* source tree.
|
||||||
|
|
||||||
|
* Test that pthread_key_create()
|
||||||
|
*
|
||||||
|
* Upon key creation, the value NULL shall be associated with the new key in all active threads.
|
||||||
|
* Upon thread creation, the value NULL shall be associated with all defined keys in the new
|
||||||
|
* thread.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Create a key
|
||||||
|
* 2. Verify that the default value is NULL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "posixtest.h"
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pthread_key_t key;
|
||||||
|
void* rc;
|
||||||
|
|
||||||
|
/* Verify that the value associated with "key" in a new thread is NULL */
|
||||||
|
rc = pthread_getspecific(key);
|
||||||
|
if(rc != NULL)
|
||||||
|
{
|
||||||
|
printf("Test FAILED\n");
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pthread_key_create(&key, NULL) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_create() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
/* Verify that the value associated with "key" after it is newly created is
|
||||||
|
* NULL */
|
||||||
|
rc = pthread_getspecific(key);
|
||||||
|
if(rc != NULL)
|
||||||
|
{
|
||||||
|
printf("Test FAILED\n");
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Test PASSED\n");
|
||||||
|
return PTS_PASS;
|
||||||
|
}
|
||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
|
* This file is licensed under the GPL license. For the full content
|
||||||
|
* of this license, see the COPYING file at the top level of this
|
||||||
|
* source tree.
|
||||||
|
|
||||||
|
* Test that pthread_key_create()
|
||||||
|
*
|
||||||
|
* An optional destructor function may be associated with each key value. At thread exit, if
|
||||||
|
* a key value has a non-NULL destructor pointer, and the thread has a non-NULL value associated
|
||||||
|
* with that key, the value of the key is set to NULL, and then the function pointed to is called
|
||||||
|
* with the previously associated value as its sole argument. The order of destructor calls is
|
||||||
|
* unspecified if more than one destructor exists for a thread when it exits.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Define an array of keys
|
||||||
|
* 2. Use pthread_key_create() and create those keys
|
||||||
|
* 3. Verify that you can set and get specific values for those keys without errors.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "posixtest.h"
|
||||||
|
|
||||||
|
#define KEY_VALUE 1000
|
||||||
|
|
||||||
|
pthread_key_t key;
|
||||||
|
int dest_cnt;
|
||||||
|
|
||||||
|
/* Destructor funciton */
|
||||||
|
void dest_func(void *p)
|
||||||
|
{
|
||||||
|
dest_cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Thread function */
|
||||||
|
void *a_thread_func()
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Set the value of the key to a value */
|
||||||
|
if(pthread_setspecific(key, (void *)(KEY_VALUE)) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_setspecific() failed\n");
|
||||||
|
pthread_exit((void*) PTS_UNRESOLVED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The thread ends here, the destructor for the key should now be called after this */
|
||||||
|
pthread_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pthread_t new_th;
|
||||||
|
|
||||||
|
/* Inialize the destructor flag */
|
||||||
|
dest_cnt = 0;
|
||||||
|
|
||||||
|
/* Create a key with a destructor function */
|
||||||
|
if(pthread_key_create(&key, dest_func) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_create() failed\n");
|
||||||
|
pthread_exit((void*) PTS_UNRESOLVED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create a thread */
|
||||||
|
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||||
|
{
|
||||||
|
perror("Error creating thread\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for the thread's return */
|
||||||
|
if(pthread_join(new_th, NULL) != 0)
|
||||||
|
{
|
||||||
|
perror("Error in pthread_join()\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if the destructor was called */
|
||||||
|
if(dest_cnt == 0)
|
||||||
|
{
|
||||||
|
printf("Test FAILED: Destructor not called\n");
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Test PASSED\n");
|
||||||
|
return PTS_PASS;
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_key_create ;
|
||||||
|
|
||||||
|
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||||
|
|
||||||
|
SimpleTest pthread_key_create_1-1 : 1-1.c ;
|
||||||
|
SimpleTest pthread_key_create_1-2 : 1-2.c ;
|
||||||
|
SimpleTest pthread_key_create_2-1 : 2-1.c ;
|
||||||
|
SimpleTest pthread_key_create_3-1 : 3-1.c ;
|
||||||
|
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
|
* This file is licensed under the GPL license. For the full content
|
||||||
|
* of this license, see the COPYING file at the top level of this
|
||||||
|
* source tree.
|
||||||
|
|
||||||
|
* Test that pthread_key_delete()
|
||||||
|
*
|
||||||
|
* Shall delete a thread-specific data key previously returned by pthread_key_create. The
|
||||||
|
* thread-specific data values specified data values associated with 'key' need not be NULL at
|
||||||
|
* the time pthread_key_delete is called. It is the responsibility of the application to free
|
||||||
|
* any application storage or perform any cleanup actions for data structures related to the
|
||||||
|
* deleted key or associated thread-specific data in any threads; this cleanup can be done
|
||||||
|
* either before or after pthread_key_delete is called. Any attempt to use 'key' following
|
||||||
|
* the call to pthread_key_delete results in undefined behavior.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Create many keys, and do not specify and value to them (default is NULL)
|
||||||
|
* 2. Delete the keys with pthread_key_delete
|
||||||
|
* 3. Verify that this will not result in an error
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "posixtest.h"
|
||||||
|
|
||||||
|
#define NUM_OF_KEYS 10
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pthread_key_t keys[NUM_OF_KEYS];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0;i<NUM_OF_KEYS;i++)
|
||||||
|
{
|
||||||
|
if(pthread_key_create(&keys[i], NULL) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_create() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pthread_key_delete(keys[i]) != 0)
|
||||||
|
{
|
||||||
|
printf("Test FAILED\n");
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
printf("Test PASSED\n");
|
||||||
|
return PTS_PASS;
|
||||||
|
}
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
|
* This file is licensed under the GPL license. For the full content
|
||||||
|
* of this license, see the COPYING file at the top level of this
|
||||||
|
* source tree.
|
||||||
|
|
||||||
|
* Test that pthread_key_delete()
|
||||||
|
*
|
||||||
|
* Shall delete a thread-specific data key previously returned by pthread_key_create. The
|
||||||
|
* thread-specific data values specified data values associated with 'key' need not be NULL at
|
||||||
|
* the time pthread_key_delete is called. It is the responsibility of the application to free
|
||||||
|
* any application storage or perform any cleanup actions for data structures related to the
|
||||||
|
* deleted key or associated thread-specific data in any threads; this cleanup can be done
|
||||||
|
* either before or after pthread_key_delete is called. Any attempt to use 'key' following
|
||||||
|
* the call to pthread_key_delete results in undefined behavior.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Create many keys, and specify and value to them
|
||||||
|
* 2. Delete the keys with pthread_key_delete
|
||||||
|
* 3. Verify that this will not result in an error
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "posixtest.h"
|
||||||
|
|
||||||
|
#define NUM_OF_KEYS 10
|
||||||
|
#define KEY_VALUE 100
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pthread_key_t keys[NUM_OF_KEYS];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0;i<NUM_OF_KEYS;i++)
|
||||||
|
{
|
||||||
|
if(pthread_key_create(&keys[i], NULL) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_create() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pthread_setspecific(keys[i], (void*)(long)(KEY_VALUE + i)) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_setspecific failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pthread_key_delete(keys[i]) != 0)
|
||||||
|
{
|
||||||
|
printf("Test FAILED\n");
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Test PASSED\n");
|
||||||
|
return PTS_PASS;
|
||||||
|
}
|
||||||
+103
@@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
|
* This file is licensed under the GPL license. For the full content
|
||||||
|
* of this license, see the COPYING file at the top level of this
|
||||||
|
* source tree.
|
||||||
|
|
||||||
|
* Test that pthread_key_delete()
|
||||||
|
*
|
||||||
|
pthread_key_delete function shall be callable from within destructor functions. No
|
||||||
|
destructor functions shall be invoked by pthread_key_delete. Any destructor function
|
||||||
|
that may have been associated with 'key' shall no longer be called up thread exit.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Create a key with a destructor function associated with it
|
||||||
|
* 2. In the destructor function, call pthread_key_delete
|
||||||
|
* 3. Verify that this can be done with no errors
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "posixtest.h"
|
||||||
|
|
||||||
|
#define KEY_VALUE 1000
|
||||||
|
|
||||||
|
pthread_key_t key;
|
||||||
|
int dest_cnt;
|
||||||
|
|
||||||
|
/* Destructor funciton */
|
||||||
|
void dest_func(void *p)
|
||||||
|
{
|
||||||
|
dest_cnt++;
|
||||||
|
/* Delete the key and check if an error has occured */
|
||||||
|
if(pthread_key_delete(key) != 0)
|
||||||
|
{
|
||||||
|
dest_cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Thread function */
|
||||||
|
void *a_thread_func()
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Set the value of the key to a value */
|
||||||
|
if(pthread_setspecific(key, (void *)(KEY_VALUE)) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_setspecific() failed\n");
|
||||||
|
pthread_exit((void*) PTS_UNRESOLVED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The thread ends here, the destructor for the key should now be called after this */
|
||||||
|
pthread_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pthread_t new_th;
|
||||||
|
|
||||||
|
/* Inialize the destructor flag */
|
||||||
|
dest_cnt = 0;
|
||||||
|
|
||||||
|
/* Create a key with a destructor function */
|
||||||
|
if(pthread_key_create(&key, dest_func) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_create() failed\n");
|
||||||
|
pthread_exit((void*) PTS_UNRESOLVED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create a thread */
|
||||||
|
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||||
|
{
|
||||||
|
perror("Error creating thread\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for the thread's return */
|
||||||
|
if(pthread_join(new_th, NULL) != 0)
|
||||||
|
{
|
||||||
|
perror("Error in pthread_join()\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if the destructor was called and if the pthread_key_delete function was
|
||||||
|
* called successfully */
|
||||||
|
if(dest_cnt != 1)
|
||||||
|
{
|
||||||
|
if(dest_cnt == 0)
|
||||||
|
{
|
||||||
|
printf("Error calling the key destructor function\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
printf("Test FAILED: pthread_key_delete failed to be called from the destructor function\n");
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Test PASSED\n");
|
||||||
|
return PTS_PASS;
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_key_delete ;
|
||||||
|
|
||||||
|
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||||
|
|
||||||
|
SimpleTest pthread_key_delete_1-1 : 1-1.c ;
|
||||||
|
SimpleTest pthread_key_delete_1-2 : 1-2.c ;
|
||||||
|
SimpleTest pthread_key_delete_2-1 : 2-1.c ;
|
||||||
|
|
||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
|
* This file is licensed under the GPL license. For the full content
|
||||||
|
* of this license, see the COPYING file at the top level of this
|
||||||
|
* source tree.
|
||||||
|
|
||||||
|
* Test that pthread_setspecific()
|
||||||
|
*
|
||||||
|
* shall associate a thread-specific value with a key obtained via a previouse call to
|
||||||
|
* pthread_key_create. Different threads may bind different values to the same key.
|
||||||
|
* Calling pthread_setspecific with a key value not obtiained from pthread_key_create of after
|
||||||
|
* the key has been deleted with pthread_key_delete is undefined.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Create NUM_OF_KEYS pthread_key_t objects
|
||||||
|
* 2. Set each key to a thread-specific value with pthread_setspecific()
|
||||||
|
* 3. Call pthread_getspecific() on each key and check that the value returned is correct.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "posixtest.h"
|
||||||
|
|
||||||
|
#define NUM_OF_KEYS 10
|
||||||
|
#define KEY_VALUE 0
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pthread_key_t keys[NUM_OF_KEYS];
|
||||||
|
int i;
|
||||||
|
void* rc;
|
||||||
|
|
||||||
|
for(i = 0;i<NUM_OF_KEYS;i++)
|
||||||
|
{
|
||||||
|
if(pthread_key_create(&keys[i], NULL) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_create() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if(pthread_setspecific(keys[i], (void *)(long)(i + KEY_VALUE)) != 0)
|
||||||
|
{
|
||||||
|
printf("Test FAILED: Could not set the value of the key to %d\n", (i + KEY_VALUE));
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0;i<NUM_OF_KEYS;++i)
|
||||||
|
{
|
||||||
|
rc = pthread_getspecific(keys[i]);
|
||||||
|
if(rc != (void *)(long)(i + KEY_VALUE))
|
||||||
|
{
|
||||||
|
printf("Test FAILED: Did not return correct value of thread-specific key, expected %ld, but got %ld\n", (long)(i + KEY_VALUE), (long)rc);
|
||||||
|
return PTS_FAIL;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if(pthread_key_delete(keys[i]) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_delete() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Test PASSED\n");
|
||||||
|
return PTS_PASS;
|
||||||
|
}
|
||||||
+103
@@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, Intel Corporation. All rights reserved.
|
||||||
|
* Created by: bing.wei.liu REMOVE-THIS AT intel DOT com
|
||||||
|
* This file is licensed under the GPL license. For the full content
|
||||||
|
* of this license, see the COPYING file at the top level of this
|
||||||
|
* source tree.
|
||||||
|
|
||||||
|
* Test that pthread_setspecific()
|
||||||
|
*
|
||||||
|
* shall acssociate a thread-specific value with a key obtained via a previouse call to
|
||||||
|
* pthread_key_create. Different threads may bind different values to the same key.
|
||||||
|
* Calling pthread_setspecific with a key value not obtiained from pthread_key_create of after
|
||||||
|
* the key has been deleted with pthread_key_delete is undefined.
|
||||||
|
*
|
||||||
|
* Steps:
|
||||||
|
* 1. Create a key
|
||||||
|
* 2. Bind a value from the main thread to this key
|
||||||
|
* 3. Create a thread and bind another value to this key
|
||||||
|
* 4. Compare the values bound to the key between the main thread and the newly created thread,
|
||||||
|
* they should be different and pertaining to what each thread set as the value.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "posixtest.h"
|
||||||
|
|
||||||
|
#define KEY_VALUE_1 100
|
||||||
|
#define KEY_VALUE_2 200
|
||||||
|
|
||||||
|
pthread_key_t key;
|
||||||
|
void* rc1;
|
||||||
|
void* rc2;
|
||||||
|
|
||||||
|
void *a_thread_func()
|
||||||
|
{
|
||||||
|
/* Bind a value to key for this thread (this will be different from the value
|
||||||
|
* that we bind for the main thread) */
|
||||||
|
if(pthread_setspecific(key, (void *)(KEY_VALUE_2)) != 0)
|
||||||
|
{
|
||||||
|
printf("Test FAILED: Could not set the value of the key to %d\n", (KEY_VALUE_2));
|
||||||
|
pthread_exit((void*)PTS_FAIL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the bound value of the key that we just set. */
|
||||||
|
rc2 = pthread_getspecific(key);
|
||||||
|
|
||||||
|
pthread_exit(0);
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
pthread_t new_th;
|
||||||
|
|
||||||
|
/* Create the key */
|
||||||
|
if(pthread_key_create(&key, NULL) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: pthread_key_create() failed\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bind a value for this main thread */
|
||||||
|
if(pthread_setspecific(key, (void *)(KEY_VALUE_1)) != 0)
|
||||||
|
{
|
||||||
|
printf("Test FAILED: Could not set the value of the key to %d\n", (KEY_VALUE_1));
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create another thread. This thread will also bind a value to the key */
|
||||||
|
if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
|
||||||
|
{
|
||||||
|
printf("Error: in pthread_create()\n");
|
||||||
|
return PTS_UNRESOLVED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for thread to end execution */
|
||||||
|
pthread_join(new_th, NULL);
|
||||||
|
|
||||||
|
/* Get the value associated for the key in this main thread */
|
||||||
|
rc1 = pthread_getspecific(key);
|
||||||
|
|
||||||
|
/* Compare this value with the value associated for the key in the newly created
|
||||||
|
* thread, they should be different. */
|
||||||
|
if(rc1 != (void *)(KEY_VALUE_1))
|
||||||
|
{
|
||||||
|
printf("Test FAILED: Incorrect value bound to key, expected %d, got %ld\n", KEY_VALUE_1, (long)rc1);
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(rc2 != (void *)(KEY_VALUE_2))
|
||||||
|
{
|
||||||
|
printf("Test FAILED: Incorrect value bound to key, expected %d, got %ld\n", KEY_VALUE_2, (long)rc2);
|
||||||
|
return PTS_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Test PASSED\n");
|
||||||
|
return PTS_PASS;
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
SubDir HAIKU_TOP src tests system libroot posix posixtestsuite conformance interfaces pthread_setspecific ;
|
||||||
|
|
||||||
|
SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) $(DOTDOT) include ] ;
|
||||||
|
|
||||||
|
SimpleTest pthread_setspecific_1-1 : 1-1.c ;
|
||||||
|
SimpleTest pthread_setspecific_1-2 : 1-2.c ;
|
||||||
|
|
||||||
Reference in New Issue
Block a user