additional tests for `do catch` structure
authorRomain Chanoir <romain.chanoir@viacesi.fr>
Wed, 24 Jan 2018 20:37:21 +0000 (21:37 +0100)
committerRomain Chanoir <romain.chanoir@viacesi.fr>
Tue, 27 Mar 2018 21:17:46 +0000 (17:17 -0400)
Signed-off-by: Romain Chanoir <romain.chanoir@viacesi.fr>

tests/sav/test_catch_multi_threaded.res [new file with mode: 0644]
tests/test_catch_multi_threaded.nit [new file with mode: 0644]

diff --git a/tests/sav/test_catch_multi_threaded.res b/tests/sav/test_catch_multi_threaded.res
new file mode 100644 (file)
index 0000000..04f734e
--- /dev/null
@@ -0,0 +1,10 @@
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
+caught 100000 aborts
diff --git a/tests/test_catch_multi_threaded.nit b/tests/test_catch_multi_threaded.nit
new file mode 100644 (file)
index 0000000..42795f4
--- /dev/null
@@ -0,0 +1,56 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed 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.
+
+# Test the multi-threaded dynamic `do catch` mechanism
+import pthreads
+
+# A Thread that does a lot of `do catch`
+class CatchThread
+       super Thread
+
+       var x = 100000
+       var caught = 0
+
+       redef fun main do
+               do
+                       rec_do_catch
+               catch
+               end
+               print "caught {caught} aborts"
+               return null
+       end
+
+       fun rec_do_catch do
+               do
+                       x -= 1
+                       if x > 0 then
+                               rec_do_catch
+                       else
+                               abort
+                       end
+               catch
+                       self.caught += 1
+                       abort
+               end
+       end
+end
+
+var ts = new Array[CatchThread]
+var nb_threads = 10
+for i in [0..nb_threads[ do
+       var t = new CatchThread
+       ts.add(t)
+       t.start
+end
+for t in ts do t.join