/rev/0fb5d4da2f1e
changeset: 1201:0fb5d4da2f1e
user: Marcel Keller <[email protected]>
date: Fri Jul 17 16:24:03 2009 +0200
summary: Merged.
diffstat:
.hgignore | 1 +
doc/unit-testing.txt | 13 ++++++++++---
setup.py | 1 +
twisted/plugins/viff_reactor.py | 21 +++++++++++++++++++++
viff/paillier.py | 3 +++
viff/passive.py | 5 +++--
viff/runtime.py | 6 +++---
viff/test/__init__.py | 5 +----
viff/test/test_signed_field.py | 3 ---
viff/test/util.py | 15 ++++++++++++++-
10 files changed, 57 insertions(+), 16 deletions(-)
diffs (199 lines):
diff -r 5da110d6e5b2 -r 0fb5d4da2f1e .hgignore
--- a/.hgignore Thu Jul 16 12:25:22 2009 +0200
+++ b/.hgignore Fri Jul 17 16:24:03 2009 +0200
@@ -18,6 +18,7 @@
# Trial output directory.
_trial_temp
+dropin.cache
# Benchmarking data.
profile.data
diff -r 5da110d6e5b2 -r 0fb5d4da2f1e doc/unit-testing.txt
--- a/doc/unit-testing.txt Thu Jul 16 12:25:22 2009 +0200
+++ b/doc/unit-testing.txt Fri Jul 17 16:24:03 2009 +0200
@@ -45,10 +45,10 @@
If it fails with an ImportError, then please double-check that your
``PYTHONPATH`` is setup correctly.
-Now simply execute ``trial viff`` to run the unit tests. You should
-get output similar to this::
+Now simply execute ``trial --reactor viff viff`` to run the unit
+tests. You should get output similar to this::
- % trial viff
+ % trial --reactor viff viff
Seeding random generator with random seed 4658
Running 65 tests.
viff.test.test_active_runtime
@@ -149,6 +149,13 @@
would be cluttered with long of traceback messages, making it
difficult to notice new *unexpected* failures.
+.. warning::
+
+ Always run ``trial`` with the ``--reactor viff`` arguments. This
+ ensures that the tests are run with the special VIFF reactor. The
+ tests currently cannot be run without this reactor, but we might
+ lift this restriction in the future.
+
Writing Unit Tests
------------------
diff -r 5da110d6e5b2 -r 0fb5d4da2f1e setup.py
--- a/setup.py Thu Jul 16 12:25:22 2009 +0200
+++ b/setup.py Fri Jul 17 16:24:03 2009 +0200
@@ -84,6 +84,7 @@
],
license=viff.__license__,
packages=['viff', 'viff.test', 'viff.libs'],
+ package_data={'viff': ['../twisted/plugins/viff_reactor.py']},
platforms=['any'],
classifiers=[
'Development Status :: 3 - Alpha',
diff -r 5da110d6e5b2 -r 0fb5d4da2f1e twisted/plugins/viff_reactor.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/twisted/plugins/viff_reactor.py Fri Jul 17 16:24:03 2009 +0200
@@ -0,0 +1,21 @@
+# Copyright 2009 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/>.
+
+# This will register the VIFF reactor so that "trial --reactor viff"
+# can install it.
+from twisted.application.reactors import Reactor
+viff = Reactor('viff', 'viff.reactor', 'The re-entrent VIFF reactor.')
diff -r 5da110d6e5b2 -r 0fb5d4da2f1e viff/paillier.py
--- a/viff/paillier.py Thu Jul 16 12:25:22 2009 +0200
+++ b/viff/paillier.py Fri Jul 17 16:24:03 2009 +0200
@@ -56,6 +56,9 @@
def encrypt(m, (n, g)):
r = rand.randint(1, long(n))
+ return encrypt_r(m, r, (n, g))
+
+def encrypt_r(m, r, (n, g)):
nsq = n*n
return (pow(g, m, nsq)*pow(r, n, nsq)) % nsq
diff -r 5da110d6e5b2 -r 0fb5d4da2f1e viff/passive.py
--- a/viff/passive.py Thu Jul 16 12:25:22 2009 +0200
+++ b/viff/passive.py Fri Jul 17 16:24:03 2009 +0200
@@ -19,6 +19,8 @@
"""Passively secure VIFF runtime."""
+import operator
+
from viff import shamir
from viff.runtime import Runtime, increment_pc, Share, ShareList, gather_shares
from viff.prss import prss, prss_lsb, prss_zero, prss_multi
@@ -163,8 +165,7 @@
"Number of coefficients and shares should be equal."
def computation(shares, coefficients):
- summands = [shares[i] * coefficients[i] for i in
range(len(shares))]
- return reduce(lambda x, y: x + y, summands)
+ return sum(map(operator.mul, shares, coefficients))
result = gather_shares(shares)
result.addCallback(computation, coefficients)
diff -r 5da110d6e5b2 -r 0fb5d4da2f1e viff/runtime.py
--- a/viff/runtime.py Thu Jul 16 12:25:22 2009 +0200
+++ b/viff/runtime.py Fri Jul 17 16:24:03 2009 +0200
@@ -812,7 +812,7 @@
"""Put deferred and data into the queue if the ViffReactor is running.
Otherwise, just execute the callback."""
- if (self.using_viff_reactor):
+ if self.using_viff_reactor:
self.deferred_queue.append((deferred, data))
else:
deferred.callback(data)
@@ -844,10 +844,10 @@
# setting the number to n makes the reactor called
# only every n-th time
- if (self.activation_counter >= 2):
+ if self.activation_counter >= 2:
self.depth_counter += 1
- if (self.depth_counter > self.max_depth):
+ if self.depth_counter > self.max_depth:
# Record the maximal depth reached.
self.max_depth = self.depth_counter
diff -r 5da110d6e5b2 -r 0fb5d4da2f1e viff/test/__init__.py
--- a/viff/test/__init__.py Thu Jul 16 12:25:22 2009 +0200
+++ b/viff/test/__init__.py Fri Jul 17 16:24:03 2009 +0200
@@ -1,4 +1,4 @@
-# Copyright 2007, 2008 VIFF Development Team.
+# Copyright 2007, 2008, 2009 VIFF Development Team.
#
# This file is part of VIFF, the Virtual Ideal Functionality Framework.
#
@@ -14,6 +14,3 @@
#
# 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 viff.reactor
-viff.reactor.install()
diff -r 5da110d6e5b2 -r 0fb5d4da2f1e viff/test/test_signed_field.py
--- a/viff/test/test_signed_field.py Thu Jul 16 12:25:22 2009 +0200
+++ b/viff/test/test_signed_field.py Fri Jul 17 16:24:03 2009 +0200
@@ -15,9 +15,6 @@
# 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 system packages.
-import sys
-
from twisted.trial.unittest import TestCase
# Import VIFF packages.
diff -r 5da110d6e5b2 -r 0fb5d4da2f1e viff/test/util.py
--- a/viff/test/util.py Thu Jul 16 12:25:22 2009 +0200
+++ b/viff/test/util.py Fri Jul 17 16:24:03 2009 +0200
@@ -111,7 +111,14 @@
raise self.failureException(msg)
def setUp(self):
- """Configure and connect three Runtimes."""
+ """Configure and connect three Runtimes.
+
+ .. warning::
+
+ Subclasses that override this method *must* remember to do
+ a super-call to it. Otherwise the runtimes wont be
+ connected and :meth:`tearDown` wont work.
+ """
# Our standard 65 bit Blum prime
self.Zp = GF(30916444023318367583)
@@ -141,6 +148,12 @@
interrupted by a C{TimeoutError}, and so we do it here in all
cases to avoid leaving scheduled calls lying around in the
reactor.
+
+ .. warning::
+
+ Subclasses that override this method *must* remember to do
+ a super-call to it. Otherwise the runtimes wont be
+ disconnected and your test case will hang.
"""
for protocol in self.protocols.itervalues():
protocol.transport.close()
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk