aboutsummaryrefslogtreecommitdiff
path: root/tests/pthread
diff options
context:
space:
mode:
authorYu Kobayashi <yukoba@accelart.jp>2013-08-16 04:12:17 +0900
committerYu Kobayashi <yukoba@accelart.jp>2013-08-16 04:12:17 +0900
commit83504a9c7f58b365b1d580620fe42f6b90191f56 (patch)
treeeb3e02563775177b11d442a4989904eff168c9d1 /tests/pthread
parent0f76b5793a07987f17e95410af843eaa7f4eb823 (diff)
Bug fixes of the pthread specific and a test added.
Diffstat (limited to 'tests/pthread')
-rw-r--r--tests/pthread/specific.c60
-rw-r--r--tests/pthread/specific.c.txt8
2 files changed, 68 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;
+}
diff --git a/tests/pthread/specific.c.txt b/tests/pthread/specific.c.txt
new file mode 100644
index 00000000..ad122b3d
--- /dev/null
+++ b/tests/pthread/specific.c.txt
@@ -0,0 +1,8 @@
+pthread_key_create = 0
+pthread_setspecific = 0
+pthread_getspecific = 123
+pthread_getspecific after key recreate = (nil)
+pthread_key_delete = 0
+pthread_key_delete repeated = 22
+pthread_setspecific for value NULL = 22
+pthread_key_delete just after created = 0