viff

view viff/test/test_basic_runtime.py @ 1538:9d4f9551644c

Added computation-id option.

This changeset adds a command line option to VIFF allowing users to
specify a computation id.

Prior to this changeset, any computation involving pseudo-random
secret sharing (which for the time being boils down to computations
done with the PassiveRuntime) could only be run one time using the
same set of VIFF player configuration files. If more than one
computation was executed with the same set of configuration files, the
security of the system would be broken.

With this changeset, multiple computations can be run securely with
the same set of configuration files as long as each computation is run
with a unique computation id.
author Tomas Toft <ttoft at cs.au.dk>
date Wed Aug 11 16:09:32 2010 +0200 (21 months ago)
parents 26f7a133172a
children
line source
1 # Copyright 2008, 2009 VIFF Development Team.
2 #
3 # This file is part of VIFF, the Virtual Ideal Functionality Framework.
4 #
5 # VIFF is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License (LGPL) as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # VIFF is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
18 from twisted.internet.defer import Deferred, gatherResults
20 from viff.test.util import RuntimeTestCase, protocol
23 class ProgramCounterTest(RuntimeTestCase):
24 """Program counter tests."""
26 @protocol
27 def test_initial_value(self, runtime):
28 self.assertEquals(runtime.program_counter, [0, 0])
30 @protocol
31 def test_synchronize(self, runtime):
32 """Test whether synchronize increases the program counter.
34 Every synchronize operation should have its unique program
35 counter."""
36 self.assertEquals(runtime.program_counter, [0, 0])
37 runtime.synchronize()
38 self.assertEquals(runtime.program_counter, [0, 1])
39 runtime.synchronize()
40 self.assertEquals(runtime.program_counter, [0, 2])
42 @protocol
43 def test_callback(self, runtime):
44 """Test a scheduled callback.
46 The callback should see the program counter as it was when the
47 callback was added and not the current value.
48 """
50 def verify_program_counter(_):
51 # The callback is run with its own sub-program counter.
52 self.assertEquals(runtime.program_counter, [0, 1, 0])
54 d = Deferred()
56 self.assertEquals(runtime.program_counter, [0, 0])
58 # Scheduling a callback increases the program counter.
59 runtime.schedule_callback(d, verify_program_counter)
60 self.assertEquals(runtime.program_counter, [0, 1])
62 # Now trigger verify_program_counter.
63 d.callback(None)
65 @protocol
66 def test_multiple_callbacks(self, runtime):
68 d1 = Deferred()
69 d2 = Deferred()
71 def verify_program_counter(_, count):
72 self.assertEquals(runtime.program_counter, [0, count, 0])
74 def method_a(runtime):
75 # No calls to schedule_callback yet.
76 self.assertEquals(runtime.program_counter, [0, 0])
78 runtime.schedule_callback(d1, verify_program_counter, 1)
79 runtime.schedule_callback(d2, verify_program_counter, 2)
81 method_a(runtime)
83 # Trigger verify_program_counter.
84 d1.callback(None)
85 d2.callback(None)
87 return gatherResults([d1, d2])
89 @protocol
90 def test_multi_send(self, runtime):
91 """Test sending multiple times from a Runtime method."""
93 # First send a couple of times to everybody.
94 for peer_id in range(1, self.num_players+1):
95 if peer_id != runtime.id:
96 pc = tuple(runtime.program_counter)
97 runtime.protocols[peer_id].sendData(pc, 42, "100")
98 runtime.protocols[peer_id].sendData(pc, 42, "200")
99 runtime.protocols[peer_id].sendData(pc, 42, "300")
101 # Then receive the data.
102 deferreds = []
103 for peer_id in range(1, self.num_players+1):
104 if peer_id != runtime.id:
105 d100 = Deferred().addCallback(self.assertEquals, "100")
106 d200 = Deferred().addCallback(self.assertEquals, "200")
107 d300 = Deferred().addCallback(self.assertEquals, "300")
108 runtime._expect_data(peer_id, 42, d100)
109 runtime._expect_data(peer_id, 42, d200)
110 runtime._expect_data(peer_id, 42, d300)
111 deferreds.extend([d100, d200, d300])
113 return gatherResults(deferreds)