summaryrefslogtreecommitdiff
path: root/testing/embedding
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2016-01-12 18:40:29 +0100
committerArmin Rigo <arigo@tunes.org>2016-01-12 18:40:29 +0100
commit06231613300fd6e6f0db0aec616efc4b19af7f91 (patch)
treed9a542aa6f7e59d99353a02355f18cd055483895 /testing/embedding
parent3d61fb1c89b5899acbba2ff9eb35a1a0fb0cac3f (diff)
downloadcffi-06231613300fd6e6f0db0aec616efc4b19af7f91.tar.gz
(untested) trying to have the multithreaded tests run on windows
Diffstat (limited to 'testing/embedding')
-rw-r--r--testing/embedding/test_basic.py1
-rw-r--r--testing/embedding/test_performance.py2
-rw-r--r--testing/embedding/thread-test.h62
-rw-r--r--testing/embedding/thread1-test.c3
-rw-r--r--testing/embedding/thread2-test.c3
-rw-r--r--testing/embedding/thread3-test.c3
-rw-r--r--testing/embedding/tlocal-test.c3
7 files changed, 68 insertions, 9 deletions
diff --git a/testing/embedding/test_basic.py b/testing/embedding/test_basic.py
index ee99330..683777a 100644
--- a/testing/embedding/test_basic.py
+++ b/testing/embedding/test_basic.py
@@ -78,6 +78,7 @@ class EmbeddingTests:
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
index 9b9d130..f9f2605 100644
--- a/testing/embedding/test_performance.py
+++ b/testing/embedding/test_performance.py
@@ -3,7 +3,7 @@ from testing.embedding.test_basic import EmbeddingTests
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
index 0000000..d56bd92
--- /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
index 6030e41..70bb861 100644
--- 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
index 2348d37..62f5ec8 100644
--- 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
index 04cfc47..fa549af 100644
--- 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
index 09e2bc1..a769a50 100644
--- 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