6 files changed, 179 insertions(+)
viff/test/sfdl/and.sfdl          |   18 ++++++++++++
viff/test/sfdl/billionaires.sfdl |   19 +++++++++++++
viff/test/sfdl/kds.sfdl          |   21 ++++++++++++++
viff/test/sfdl/median.sfdl       |   48 +++++++++++++++++++++++++++++++++
viff/test/sfdl/millionaires.sfdl |   19 +++++++++++++
viff/test/sfdl/test_examples.py  |   54 ++++++++++++++++++++++++++++++++++++++


# HG changeset patch
# User Martin Geisler <[EMAIL PROTECTED]>
# Date 1227518476 -3600
# Node ID 4c16d331284ddcdffcc690c1703c769a16fa7519
# Parent  d94925dfcd0f2ff83dc0cbf4efe7e9455fef6fd5
Test parsing of SFDL example programs.
The examples are downloaded from the FairPlay project:

  http://www.cs.huji.ac.il/project/Fairplay/fairplay.html

The millionaires.sfdl file (original name was Millionaires.txt) has
been edited slightly by replacing "&" with "&&" since "&" is not a
valid operator in SFDL 2.0 (the syntax changed from SFDL 1.0).

diff --git a/viff/test/sfdl/and.sfdl b/viff/test/sfdl/and.sfdl
new file mode 100644
--- /dev/null
+++ b/viff/test/sfdl/and.sfdl
@@ -0,0 +1,18 @@
+/*
+ * Compute AND of two byte 
+ */
+program And {
+       const N=8;
+       type Byte = Int<N>;
+       type AliceInput = Byte;
+       type BobInput = Byte;
+       type AliceOutput = Byte; 
+       type BobOutput = Byte; 
+       type Input = struct {AliceInput alice,  BobInput bob};
+       type Output = struct {AliceOutput alice, BobOutput bob};
+
+       function Output output(Input input) {
+           output.alice = (input.bob && input.alice);
+           output.bob = (input.bob && input.alice);
+       }
+}
diff --git a/viff/test/sfdl/billionaires.sfdl b/viff/test/sfdl/billionaires.sfdl
new file mode 100644
--- /dev/null
+++ b/viff/test/sfdl/billionaires.sfdl
@@ -0,0 +1,19 @@
+/*
+ * Check which of two Billionaires is richer
+ */
+program Billionaires {
+        type int = Int<32>; // 32-bit integer
+       type AliceInput = int;
+       type BobInput = int;
+       type AliceOutput = Boolean; 
+       type BobOutput = Boolean;
+       type Output = struct {AliceOutput alice,
+            BobOutput bob};
+       type Input = struct {AliceInput alice,
+            BobInput bob};
+
+       function Output output(Input input) {
+            output.alice = (input.alice > input.bob);
+            output.bob = (input.bob > input.alice);
+       }
+}
diff --git a/viff/test/sfdl/kds.sfdl b/viff/test/sfdl/kds.sfdl
new file mode 100644
--- /dev/null
+++ b/viff/test/sfdl/kds.sfdl
@@ -0,0 +1,21 @@
+/*
+ * Alice accesses an entry in Bob's keyed-DB 
+ */
+program Keyed_DB_Search {
+    const DBsize = 16;
+    type Key = Int<6>;
+    type Data = Int<24>;
+    type Pair = struct {Key key, Data data};
+    type AliceInput = Key;
+    type BobInput = Pair[DBsize];
+    type AliceOutput = Data;
+    type Output = struct {AliceOutput alice};
+    type Input = struct {AliceInput alice, BobInput bob};
+
+    function Output output(Input input) {
+       var Key i ;
+       for (i = 0 to DBsize-1)
+          if (input.alice == input.bob[i].key)
+               output.alice = input.bob[i].data;
+    }
+}
diff --git a/viff/test/sfdl/median.sfdl b/viff/test/sfdl/median.sfdl
new file mode 100644
--- /dev/null
+++ b/viff/test/sfdl/median.sfdl
@@ -0,0 +1,48 @@
+/*
+ * Compute the Median of two sorted arrays
+ */
+program Median {
+
+// Constants
+
+const inp_size = 10;
+
+// Type Definitions
+
+type Elem  =  Int<16>;
+type AliceInput = Elem[inp_size];
+type AliceOutput = Int<16>;
+type BobInput = Elem[inp_size];
+type BobOutput = Int<16>;
+type Input = struct {AliceInput alice, BobInput bob};
+type Output = struct {AliceOutput alice, BobOutput bob};
+
+// Function Definitions
+
+// This is the main function
+function Output output(Input input) {
+
+   var Int<8> i;
+   var Int<8> ai;
+   var Int<8> bi;
+
+   ai=0;
+   bi=0;
+
+   for (i = 1 to inp_size-1) {
+      if (input.alice[ai] >= input.bob[bi])
+         bi = bi + 1;
+      else
+         ai = ai + 1;
+   }
+         
+   if (input.alice[ai] < input.bob[bi]) {
+      output.alice = input.alice[ai];
+      output.bob= input.alice[ai];
+   } else {
+      output.alice = input.bob[bi];
+      output.bob = input.bob[bi];
+   }
+}
+
+}
diff --git a/viff/test/sfdl/millionaires.sfdl b/viff/test/sfdl/millionaires.sfdl
new file mode 100644
--- /dev/null
+++ b/viff/test/sfdl/millionaires.sfdl
@@ -0,0 +1,19 @@
+/*
+ * Check which of two Millionaires is richer
+ */
+program Millionaires {
+        type int = Int<4>; // 4-bit integer
+       type AliceInput = int;
+       type BobInput = int;
+       type AliceOutput = Boolean; 
+       type BobOutput = Boolean;
+       type Output = struct {AliceOutput alice,
+            BobOutput bob};
+       type Input = struct {AliceInput alice,
+            BobInput bob};
+
+       function Output output(Input input) {
+            output.alice = (input.alice > input.bob);
+            output.bob = (input.bob > input.alice);
+       }
+}
diff --git a/viff/test/sfdl/test_examples.py b/viff/test/sfdl/test_examples.py
new file mode 100644
--- /dev/null
+++ b/viff/test/sfdl/test_examples.py
@@ -0,0 +1,54 @@
+# Copyright 2008 VIFF Development Team.
+#
+# This file is part of VIFF, the Virtual Ideal Functionality Framework.
+#
+# VIFF is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License (LGPL) as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# VIFF is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+# Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+from twisted.trial.unittest import TestCase
+
+try:
+    from pyparsing import ParseException, ParseFatalException
+    from viff.sfdl.grammar import SFDLGrammar
+except ImportError:
+    SFDLGrammar = None
+
+class ParsingMixin:
+    def assertParse(self, path):
+        fullpath = os.path.join(os.path.dirname(__file__), path)
+        g = SFDLGrammar()
+        result = g.program.parseFile(fullpath)
+        # Check that we got at least something.
+        self.assertNotEquals(result.asList(), [])
+
+class TestParsing(TestCase, ParsingMixin):
+
+    def test_and(self):
+        self.assertParse("and.sfdl")
+
+    def test_millionaires(self):
+        self.assertParse("millionaires.sfdl")
+
+    def test_billionaires(self):
+        self.assertParse("billionaires.sfdl")
+
+    def test_kds(self):
+        self.assertParse("kds.sfdl")
+
+    def test_median(self):
+        self.assertParse("median.sfdl")
+
+
+if SFDLGrammar is None:
+    TestParsing.skip = "Could not import SFDLGrammar, missing pyparsing?"
_______________________________________________
viff-patches mailing list
viff-patches@viff.dk
http://lists.viff.dk/listinfo.cgi/viff-patches-viff.dk

Reply via email to