From a8b205d3fd95af7cd24475afef403db24a62fe43 Mon Sep 17 00:00:00 2001 From: Delja Date: Sun, 2 Aug 2020 18:11:44 -0400 Subject: [PATCH] tests: Add a test to show contracts in parallel execution Signed-off-by: Delja --- tests/contracts_threaded.nit | 50 ++++++++++++++++++++++++++++++++ tests/sav/contracts_threaded.res | 4 +++ 2 files changed, 54 insertions(+) create mode 100644 tests/contracts_threaded.nit create mode 100644 tests/sav/contracts_threaded.res diff --git a/tests/contracts_threaded.nit b/tests/contracts_threaded.nit new file mode 100644 index 0000000000..7ff949e3b1 --- /dev/null +++ b/tests/contracts_threaded.nit @@ -0,0 +1,50 @@ +# 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. + +# This test shows the verification of contracts in a parallel execution. + +import pthreads + +fun foo is + threaded + expect(contract_foo) +do + print "Foo" +end + +fun bar(thread_name: String) +is + threaded + expect(contract_bar(thread_name)) +do + print "Bar called from {thread_name}" +end + +fun contract_foo: Bool +do + sys.nanosleep(3,0) + print("Foo contract") + return true +end + +fun contract_bar(thread_name: String): Bool +do + print("Bar contract called from {thread_name}") + return true +end + + +foo +bar("Main thread") +sys.nanosleep(4,0) diff --git a/tests/sav/contracts_threaded.res b/tests/sav/contracts_threaded.res new file mode 100644 index 0000000000..9d815b52a8 --- /dev/null +++ b/tests/sav/contracts_threaded.res @@ -0,0 +1,4 @@ +Foo contract +Foo +Bar contract called from Main thread +Bar called from Main thread