Repository: lucy-clownfish
Updated Branches:
  refs/heads/thread_safe_errors c5e90d666 -> c9a86b0dc


Move threads tests to host language dirs


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

Branch: refs/heads/thread_safe_errors
Commit: 98ef222d05f62849039a889112aac5a939bee969
Parents: c5e90d6
Author: Nick Wellnhofer <[email protected]>
Authored: Sat Dec 27 13:52:07 2014 +0100
Committer: Nick Wellnhofer <[email protected]>
Committed: Sat Dec 27 14:05:37 2014 +0100

----------------------------------------------------------------------
 runtime/c/src/Clownfish/Test/TestThreads.c  | 89 ++++++++++++++++++++++++
 runtime/core/Clownfish/Test.c               |  2 +
 runtime/core/Clownfish/Test/TestErr.c       | 61 +---------------
 runtime/core/Clownfish/Test/TestThreads.c   | 28 ++++++++
 runtime/core/Clownfish/Test/TestThreads.cfh | 28 ++++++++
 runtime/perl/t/core/050-threads.t           | 23 ++++++
 runtime/perl/xs/XSBind.c                    | 10 +++
 7 files changed, 181 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/98ef222d/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
new file mode 100644
index 0000000..f64f30a
--- /dev/null
+++ b/runtime/c/src/Clownfish/Test/TestThreads.c
@@ -0,0 +1,89 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define CFISH_USE_SHORT_NAMES
+#define TESTCFISH_USE_SHORT_NAMES
+
+#include "charmony.h"
+
+#include "Clownfish/Test/TestThreads.h"
+
+#include "Clownfish/Err.h"
+#include "Clownfish/String.h"
+#include "Clownfish/TestHarness/TestBatchRunner.h"
+
+/**************************** No thread support ****************************/
+#ifdef CFISH_NOTHREADS
+
+static void
+test_threads(TestBatchRunner *runner) {
+    SKIP(runner, 4, "no thread support");
+}
+
+/********************************** Windows ********************************/
+#elif defined(CHY_HAS_WINDOWS_H)
+
+static void
+test_threads(TestBatchRunner *runner) {
+    SKIP(runner, 4, "TODO: test threads on Windows");
+}
+
+/******************************** pthreads *********************************/
+#elif defined(CHY_HAS_PTHREAD_H)
+
+#include <pthread.h>
+
+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");
+
+    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);
+    test_threads(runner);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/98ef222d/runtime/core/Clownfish/Test.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test.c b/runtime/core/Clownfish/Test.c
index 2a1e445..606e8fe 100644
--- a/runtime/core/Clownfish/Test.c
+++ b/runtime/core/Clownfish/Test.c
@@ -31,6 +31,7 @@
 #include "Clownfish/Test/TestLockFreeRegistry.h"
 #include "Clownfish/Test/TestNum.h"
 #include "Clownfish/Test/TestObj.h"
+#include "Clownfish/Test/TestThreads.h"
 #include "Clownfish/Test/TestVArray.h"
 #include "Clownfish/Test/Util/TestAtomic.h"
 #include "Clownfish/Test/Util/TestMemory.h"
@@ -55,6 +56,7 @@ Test_create_test_suite() {
     TestSuite_Add_Batch(suite, (TestBatch*)TestAtomic_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestLFReg_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestMemory_new());
+    TestSuite_Add_Batch(suite, (TestBatch*)TestThreads_new());
 
     return suite;
 }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/98ef222d/runtime/core/Clownfish/Test/TestErr.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestErr.c 
b/runtime/core/Clownfish/Test/TestErr.c
index 2cb54dd..b31313d 100644
--- a/runtime/core/Clownfish/Test/TestErr.c
+++ b/runtime/core/Clownfish/Test/TestErr.c
@@ -17,8 +17,6 @@
 #define CFISH_USE_SHORT_NAMES
 #define TESTCFISH_USE_SHORT_NAMES
 
-#include "charmony.h"
-
 #include "Clownfish/Test/TestErr.h"
 
 #include "Clownfish/String.h"
@@ -43,67 +41,10 @@ test_To_String(TestBatchRunner *runner) {
     DECREF(error);
 }
 
-/**************************** No thread support ****************************/
-#ifdef CFISH_NOTHREADS
-
-static void
-test_threads(TestBatchRunner *runner) {
-    SKIP(runner, 4, "no thread support");
-}
-
-/********************************** Windows ********************************/
-#elif defined(CHY_HAS_WINDOWS_H)
-
-static void
-test_threads(TestBatchRunner *runner) {
-    SKIP(runner, 4, "TODO: test threads on Windows");
-}
-
-/******************************** pthreads *********************************/
-#elif defined(CHY_HAS_PTHREAD_H)
-
-#include <pthread.h>
-
-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");
-
-    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
 TestErr_Run_IMP(TestErr *self, TestBatchRunner *runner) {
-    TestBatchRunner_Plan(runner, (TestBatch*)self, 5);
+    TestBatchRunner_Plan(runner, (TestBatch*)self, 1);
     test_To_String(runner);
-    test_threads(runner);
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/98ef222d/runtime/core/Clownfish/Test/TestThreads.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestThreads.c 
b/runtime/core/Clownfish/Test/TestThreads.c
new file mode 100644
index 0000000..054f9f0
--- /dev/null
+++ b/runtime/core/Clownfish/Test/TestThreads.c
@@ -0,0 +1,28 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define CFISH_USE_SHORT_NAMES
+#define TESTCFISH_USE_SHORT_NAMES
+
+#include "Clownfish/Test/TestThreads.h"
+
+#include "Clownfish/Class.h"
+
+TestThreads*
+TestThreads_new() {
+    return (TestThreads*)Class_Make_Obj(TESTTHREADS);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/98ef222d/runtime/core/Clownfish/Test/TestThreads.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Test/TestThreads.cfh 
b/runtime/core/Clownfish/Test/TestThreads.cfh
new file mode 100644
index 0000000..8406ab5
--- /dev/null
+++ b/runtime/core/Clownfish/Test/TestThreads.cfh
@@ -0,0 +1,28 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel TestClownfish;
+
+class Clownfish::Test::TestThreads
+    inherits Clownfish::TestHarness::TestBatch {
+
+    inert incremented TestThreads*
+    new();
+
+    void
+    Run(TestThreads *self, TestBatchRunner *runner);
+}
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/98ef222d/runtime/perl/t/core/050-threads.t
----------------------------------------------------------------------
diff --git a/runtime/perl/t/core/050-threads.t 
b/runtime/perl/t/core/050-threads.t
new file mode 100644
index 0000000..48d636f
--- /dev/null
+++ b/runtime/perl/t/core/050-threads.t
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use strict;
+use warnings;
+
+use Clownfish::Test;
+my $success = Clownfish::Test::run_tests("Clownfish::Test::TestThreads");
+
+exit($success ? 0 : 1);
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/98ef222d/runtime/perl/xs/XSBind.c
----------------------------------------------------------------------
diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c
index d7c5e88..de8b310 100644
--- a/runtime/perl/xs/XSBind.c
+++ b/runtime/perl/xs/XSBind.c
@@ -25,6 +25,8 @@
 #include "Clownfish/CharBuf.h"
 #include "Clownfish/LockFreeRegistry.h"
 #include "Clownfish/Method.h"
+#include "Clownfish/Test/TestThreads.h"
+#include "Clownfish/TestHarness/TestBatchRunner.h"
 #include "Clownfish/Util/StringHelper.h"
 #include "Clownfish/Util/NumberUtils.h"
 #include "Clownfish/Util/Memory.h"
@@ -959,3 +961,11 @@ CFISH_LFReg_To_Host_IMP(cfish_LockFreeRegistry *self) {
     return host_obj;
 }
 
+/*********************** Clownfish::Test::TestThreads ***********************/
+
+void
+TESTCFISH_TestThreads_Run_IMP(testcfish_TestThreads *self,
+                              cfish_TestBatchRunner *runner) {
+    CFISH_TestBatchRunner_Plan(runner, (cfish_TestBatch*)self, 0);
+}
+

Reply via email to