Author: Armin Rigo <[email protected]>
Branch: static-callback-embedding
Changeset: r2508:d7d65b08d388
Date: 2016-01-01 12:10 +0100
http://bitbucket.org/cffi/cffi/changeset/d7d65b08d388/
Log: A test of loading different cffi embedded modules in different
threads. Test fails.
diff --git a/testing/embedding/test_thread.py b/testing/embedding/test_thread.py
--- a/testing/embedding/test_thread.py
+++ b/testing/embedding/test_thread.py
@@ -11,3 +11,10 @@
"preparing...\n" +
"adding 40 and 2\n" * 10 +
"done\n")
+
+ def test_init_different_modules_in_different_threads(self):
+ self.prepare_module('add1')
+ self.prepare_module('add2')
+ self.compile('thread2-test', ['_add1_cffi', '_add2_cffi'],
['-pthread'])
+ output = self.execute('thread2-test')
+ assert output == XXX
diff --git a/testing/embedding/thread1-test.c b/testing/embedding/thread1-test.c
--- a/testing/embedding/thread1-test.c
+++ b/testing/embedding/thread1-test.c
@@ -34,7 +34,7 @@
status = pthread_create(&th, NULL, start_routine, NULL);
assert(status == 0);
}
- for (i = 1; i <= NTHREADS; i++) {
+ for (i = 0; i < NTHREADS; i++) {
status = sem_wait(&done);
assert(status == 0);
}
diff --git a/testing/embedding/thread2-test.c b/testing/embedding/thread2-test.c
new file mode 100644
--- /dev/null
+++ b/testing/embedding/thread2-test.c
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <pthread.h>
+#include <semaphore.h>
+#include <assert.h>
+
+extern int add1(int, int);
+extern int add2(int, int, int);
+
+static sem_t done;
+
+
+static void *start_routine_1(void *arg)
+{
+ int x, status;
+ x = add1(40, 2);
+ assert(x == 42);
+
+ status = sem_post(&done);
+ assert(status == 0);
+
+ return arg;
+}
+
+static void *start_routine_2(void *arg)
+{
+ int x, status;
+ x = add2(1000, 200, 30);
+ assert(x == 1230);
+
+ status = sem_post(&done);
+ assert(status == 0);
+
+ return arg;
+}
+
+int main(void)
+{
+ pthread_t th;
+ int i, status = sem_init(&done, 0, 0);
+ assert(status == 0);
+
+ printf("starting\n");
+ status = pthread_create(&th, NULL, start_routine_1, NULL);
+ assert(status == 0);
+ status = pthread_create(&th, NULL, start_routine_2, NULL);
+ assert(status == 0);
+
+ for (i = 0; i < 2; i++) {
+ status = sem_wait(&done);
+ assert(status == 0);
+ }
+ printf("done\n");
+ return 0;
+}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit