Repository: lucy-clownfish
Updated Branches:
  refs/heads/master 13688813c -> 49782425c


Use new helpers in threaded C error tests


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/130abe7d
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/130abe7d
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/130abe7d

Branch: refs/heads/master
Commit: 130abe7d19bbf5b5554d461e0ed52455296c8c85
Parents: 0627cd4
Author: Nick Wellnhofer <[email protected]>
Authored: Sun May 10 00:12:28 2015 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Tue May 12 20:15:24 2015 +0200

----------------------------------------------------------------------
 runtime/c/src/Clownfish/Test/TestThreads.c | 68 +++----------------------
 1 file changed, 8 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/130abe7d/runtime/c/src/Clownfish/Test/TestThreads.c
----------------------------------------------------------------------
diff --git a/runtime/c/src/Clownfish/Test/TestThreads.c 
b/runtime/c/src/Clownfish/Test/TestThreads.c
index bf4a203..f75c097 100644
--- a/runtime/c/src/Clownfish/Test/TestThreads.c
+++ b/runtime/c/src/Clownfish/Test/TestThreads.c
@@ -24,21 +24,9 @@
 #include "Clownfish/Err.h"
 #include "Clownfish/String.h"
 #include "Clownfish/TestHarness/TestBatchRunner.h"
-
-/**************************** No thread support ****************************/
-#ifdef CFISH_NOTHREADS
+#include "Clownfish/TestHarness/TestUtils.h"
 
 static void
-test_threads(TestBatchRunner *runner) {
-    SKIP(runner, 4, "no thread support");
-}
-
-/********************************** Windows ********************************/
-#elif defined(CHY_HAS_WINDOWS_H)
-
-#include <windows.h>
-
-static DWORD
 S_err_thread(void *arg) {
     TestBatchRunner *runner = (TestBatchRunner*)arg;
 
@@ -46,68 +34,28 @@ S_err_thread(void *arg) {
               "global error in thread initialized to null");
 
     Err_set_error(Err_new(Str_newf("thread")));
-
-    return 0;
 }
 
 static void
 test_threads(TestBatchRunner *runner) {
-    Err_set_error(Err_new(Str_newf("main")));
-
-    HANDLE thread = CreateThread(NULL, 0, S_err_thread, runner, 0, NULL);
-    TEST_TRUE(runner, thread != NULL, "CreateThread succeeds");
-    DWORD event = WaitForSingleObject(thread, INFINITE);
-    TEST_INT_EQ(runner, event, WAIT_OBJECT_0, "WaitForSingleObject succeeds");
-    CloseHandle(thread);
-
-    String *mess = Err_Get_Mess(Err_get_error());
-    TEST_TRUE(runner, Str_Equals_Utf8(mess, "main", 4),
-              "thread doesn't clobber global error");
-}
-
-/******************************** pthreads *********************************/
-#elif defined(CHY_HAS_PTHREAD_H)
-
-#include <pthread.h>
+    if (!TestUtils_has_threads) {
+        SKIP(runner, 2, "no thread support");
+        return;
+    }
 
-static void*
-S_err_thread(void *arg) {
-    TestBatchRunner *runner = (TestBatchRunner*)arg;
-
-    TEST_TRUE(runner, Err_get_error() == NULL,
-              "global error in thread initialized to null");
-
-    Err_set_error(Err_new(Str_newf("thread")));
-
-    return NULL;
-}
-
-static void
-test_threads(TestBatchRunner *runner) {
     Err_set_error(Err_new(Str_newf("main")));
 
-    int err;
-    pthread_t thread;
-    err = pthread_create(&thread, NULL, S_err_thread, runner);
-    TEST_INT_EQ(runner, err, 0, "pthread_create succeeds");
-    err = pthread_join(thread, NULL);
-    TEST_INT_EQ(runner, err, 0, "pthread_join succeeds");
+    Thread *thread = TestUtils_thread_create(S_err_thread, runner);
+    TestUtils_thread_join(thread);
 
     String *mess = Err_Get_Mess(Err_get_error());
     TEST_TRUE(runner, Str_Equals_Utf8(mess, "main", 4),
               "thread doesn't clobber global error");
 }
 
-/****************** No support for thread-local storage ********************/
-#else
-
-#error "No support for thread-local storage."
-
-#endif
-
 void
 TestThreads_Run_IMP(TestThreads *self, TestBatchRunner *runner) {
-    TestBatchRunner_Plan(runner, (TestBatch*)self, 4);
+    TestBatchRunner_Plan(runner, (TestBatch*)self, 2);
     test_threads(runner);
 }
 

Reply via email to