Author: Armin Rigo <[email protected]>
Branch: static-callback-embedding
Changeset: r2568:083815c0ba89
Date: 2016-01-12 18:40 +0100
http://bitbucket.org/cffi/cffi/changeset/083815c0ba89/

Log:    (untested) trying to have the multithreaded tests run on windows

diff --git a/testing/embedding/test_basic.py b/testing/embedding/test_basic.py
--- a/testing/embedding/test_basic.py
+++ b/testing/embedding/test_basic.py
@@ -78,6 +78,7 @@
         path = self.get_path()
         filename = '%s.c' % name
         shutil.copy(os.path.join(local_dir, filename), path)
+        shutil.copy(os.path.join(local_dir, 'thread-test.h'), path)
         import distutils.ccompiler
         curdir = os.getcwd()
         try:
diff --git a/testing/embedding/test_performance.py 
b/testing/embedding/test_performance.py
--- a/testing/embedding/test_performance.py
+++ b/testing/embedding/test_performance.py
@@ -3,7 +3,7 @@
 
 if sys.platform == 'win32':
     import py
-    py.test.skip("written with pthreads")
+    py.test.skip("written with POSIX functions")
 
 
 class TestPerformance(EmbeddingTests):
diff --git a/testing/embedding/thread-test.h b/testing/embedding/thread-test.h
new file mode 100644
--- /dev/null
+++ b/testing/embedding/thread-test.h
@@ -0,0 +1,62 @@
+/************************************************************/
+#ifndef _MSC_VER
+/************************************************************/
+
+
+#include <pthread.h>
+#include <semaphore.h>
+
+
+/************************************************************/
+#else
+/************************************************************/
+
+
+/* Very quick and dirty, just what I need for these tests.
+   Don't use directly in any real code! 
+*/
+
+#include <Windows.h>
+#include <assert.h>
+
+typedef HANDLE sem_t;
+typedef HANDLE pthread_t;
+
+int sem_init(sem_t *sem, int pshared, unsigned int value)
+{
+    assert(pshared == 0);
+    assert(value == 0);
+    *sem = CreateSemaphore(NULL, 0, 999, NULL);
+    return *sem ? 0 : -1;
+}
+
+int sem_post(sem_t *sem)
+{
+    return ReleaseSemaphore(*res, 1, NULL) ? 0 : -1;
+}
+
+int sem_wait(sem_t *sem)
+{
+    WaitForSingleObject(*res, INFINITE);
+    return 0;
+}
+
+DWORD WINAPI myThreadProc(LPVOID lpParameter)
+{
+    void *(* start_routine)(void *) = (void *(*)(void *))lpParameter;
+    start_routine(NULL);
+    return 0;
+}
+
+int pthread_create(pthread_t *thread, void *attr,
+                   void *start_routine(void *), void *arg)
+{
+    assert(arg == NULL);
+    *thread = CreateThread(NULL, 0, myThreadProc, start_routine, 0, NULL);
+    return *thread ? 0 : -1;
+}
+
+
+/************************************************************/
+#endif
+/************************************************************/
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
@@ -1,7 +1,6 @@
 #include <stdio.h>
-#include <pthread.h>
-#include <semaphore.h>
 #include <assert.h>
+#include "thread-test.h"
 
 #define NTHREADS 10
 
diff --git a/testing/embedding/thread2-test.c b/testing/embedding/thread2-test.c
--- a/testing/embedding/thread2-test.c
+++ b/testing/embedding/thread2-test.c
@@ -1,7 +1,6 @@
 #include <stdio.h>
-#include <pthread.h>
-#include <semaphore.h>
 #include <assert.h>
+#include "thread-test.h"
 
 extern int add1(int, int);
 extern int add2(int, int, int);
diff --git a/testing/embedding/thread3-test.c b/testing/embedding/thread3-test.c
--- a/testing/embedding/thread3-test.c
+++ b/testing/embedding/thread3-test.c
@@ -1,7 +1,6 @@
 #include <stdio.h>
-#include <pthread.h>
-#include <semaphore.h>
 #include <assert.h>
+#include "thread-test.h"
 
 extern int add2(int, int, int);
 extern int add3(int, int, int, int);
diff --git a/testing/embedding/tlocal-test.c b/testing/embedding/tlocal-test.c
--- a/testing/embedding/tlocal-test.c
+++ b/testing/embedding/tlocal-test.c
@@ -1,7 +1,6 @@
 #include <stdio.h>
-#include <pthread.h>
-#include <semaphore.h>
 #include <assert.h>
+#include "thread-test.h"
 
 #define NTHREADS 10
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to