diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile index 4cd9bf4fa1..4759581ef7 100644 --- a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/Jamfile @@ -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 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 sigsuspend ; diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_getspecific/1-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_getspecific/1-1.c new file mode 100644 index 0000000000..5ad8cfcd7c --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_getspecific/1-1.c @@ -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 +#include +#include +#include +#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 +#include +#include +#include +#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; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_getspecific/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_getspecific/Jamfile new file mode 100644 index 0000000000..2205e2b503 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_getspecific/Jamfile @@ -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 ; + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/1-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/1-1.c new file mode 100644 index 0000000000..0fff2ac3a9 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/1-1.c @@ -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 +#include +#include +#include +#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 +#include +#include +#include +#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 +#include +#include +#include +#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; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/3-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/3-1.c new file mode 100644 index 0000000000..56cb1f8cae --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/3-1.c @@ -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 +#include +#include +#include +#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; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/Jamfile new file mode 100644 index 0000000000..4d2daeb31e --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/Jamfile @@ -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 ; + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_delete/1-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_delete/1-1.c new file mode 100644 index 0000000000..bda6610fc5 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_delete/1-1.c @@ -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 +#include +#include +#include +#include "posixtest.h" + +#define NUM_OF_KEYS 10 + +int main() +{ + pthread_key_t keys[NUM_OF_KEYS]; + int i; + + for(i = 0;i +#include +#include +#include +#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 +#include +#include +#include +#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; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_delete/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_delete/Jamfile new file mode 100644 index 0000000000..7cf3dff98f --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_delete/Jamfile @@ -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 ; + diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_setspecific/1-1.c b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_setspecific/1-1.c new file mode 100644 index 0000000000..c2c22ce8ee --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_setspecific/1-1.c @@ -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 +#include +#include +#include +#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 +#include +#include +#include +#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; +} diff --git a/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_setspecific/Jamfile b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_setspecific/Jamfile new file mode 100644 index 0000000000..f310a723a0 --- /dev/null +++ b/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_setspecific/Jamfile @@ -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 ; +