aboutsummaryrefslogtreecommitdiff
path: root/tests/pthread/specific.c
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-08-26 10:53:21 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-08-26 10:53:21 -0700
commit70d3a36274858ce8ed071036fb1903e02d606663 (patch)
treea30d0cc44a06f2b2e2548df1ac7187ce21ded173 /tests/pthread/specific.c
parentfc56aa8d28bbc5ef66a0a5f21c12892f320098b7 (diff)
parent83504a9c7f58b365b1d580620fe42f6b90191f56 (diff)
Merge pull request #1525 from yukoba/pthread-specific
Bug fixes of pthread specific
Diffstat (limited to 'tests/pthread/specific.c')
-rw-r--r--tests/pthread/specific.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/pthread/specific.c b/tests/pthread/specific.c
new file mode 100644
index 00000000..914884e7
--- /dev/null
+++ b/tests/pthread/specific.c
@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+
+static void destr_function(void *arg)
+{
+ // Not implemented yet in Emscripten
+}
+
+int main(void)
+{
+ pthread_key_t key = 0;
+ int rv;
+ int data = 123;
+ int *data2;
+
+ assert(pthread_key_delete(key) != 0);
+ assert(pthread_getspecific(key) == NULL);
+
+ rv = pthread_key_create(&key, &destr_function);
+ printf("pthread_key_create = %d\n", rv);
+ assert(rv == 0);
+
+ assert(pthread_getspecific(key) == NULL);
+
+ rv = pthread_setspecific(key, (void*) &data);
+ printf("pthread_setspecific = %d\n", rv);
+ assert(rv == 0);
+
+ data2 = pthread_getspecific(key);
+ assert(data2 != NULL);
+ printf("pthread_getspecific = %d\n", *data2);
+ assert(*data2 == 123);
+
+ rv = pthread_key_create(&key, &destr_function);
+ data2 = pthread_getspecific(key);
+ printf("pthread_getspecific after key recreate = %p\n", data2);
+ assert(data2 == NULL);
+
+ rv = pthread_key_delete(key);
+ printf("pthread_key_delete = %d\n", rv);
+ assert(rv == 0);
+
+ rv = pthread_key_delete(key);
+ printf("pthread_key_delete repeated = %d\n", rv);
+ assert(rv == EINVAL);
+
+ rv = pthread_setspecific(key, NULL);
+ printf("pthread_setspecific for value NULL = %d\n", rv);
+ assert(rv == EINVAL);
+
+ rv = pthread_key_create(&key, &destr_function);
+ assert(rv == 0);
+ rv = pthread_key_delete(key);
+ printf("pthread_key_delete just after created = %d\n", rv);
+ assert(rv == 0);
+
+ return 0;
+}