viff

changeset 767:f993269c2660

Test case for memory allocation.
author Martin Geisler <mg@daimi.au.dk>
date Tue, 20 May 2008 14:21:34 +0200
parents c8810dc507f3
children 9be4b49842ad 6d95d1bab2aa
files viff/test/test_memory.py
diffstat 1 files changed, 52 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/viff/test/test_memory.py	Tue May 20 14:21:34 2008 +0200
     1.3 @@ -0,0 +1,52 @@
     1.4 +# Copyright 2008 VIFF Development Team.
     1.5 +#
     1.6 +# This file is part of VIFF, the Virtual Ideal Functionality Framework.
     1.7 +#
     1.8 +# VIFF is free software: you can redistribute it and/or modify it
     1.9 +# under the terms of the GNU Lesser General Public License (LGPL) as
    1.10 +# published by the Free Software Foundation, either version 3 of the
    1.11 +# License, or (at your option) any later version.
    1.12 +#
    1.13 +# VIFF is distributed in the hope that it will be useful, but WITHOUT
    1.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    1.15 +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
    1.16 +# Public License for more details.
    1.17 +#
    1.18 +# You should have received a copy of the GNU Lesser General Public
    1.19 +# License along with VIFF. If not, see <http://www.gnu.org/licenses/>.
    1.20 +
    1.21 +from viff.field import GF256
    1.22 +from viff.runtime import Share
    1.23 +from viff.test.util import RuntimeTestCase, protocol
    1.24 +
    1.25 +class MemoryTest(RuntimeTestCase):
    1.26 +    """Tests that memory is freed when the expected data has
    1.27 +    arrived."""
    1.28 +
    1.29 +    def check_empty(self, _, runtime):
    1.30 +        """Check that all protocols are empty."""
    1.31 +        for p in runtime.protocols.itervalues():
    1.32 +            self.assertEquals(p.incoming_data, {})
    1.33 +
    1.34 +    @protocol
    1.35 +    def test_empty_incoming_data(self, runtime):
    1.36 +        """Check that a single sharing does not leak memory."""
    1.37 +        if runtime.id == 1:
    1.38 +            x = runtime.shamir_share([1], self.Zp, 10)
    1.39 +        else:
    1.40 +            x = runtime.shamir_share([1], self.Zp)
    1.41 +
    1.42 +        def check(_):
    1.43 +            for p in runtime.protocols.itervalues():
    1.44 +                self.assertEquals(p.incoming_data, {})
    1.45 +
    1.46 +        x.addCallback(self.check_empty, runtime)
    1.47 +        return x
    1.48 +
    1.49 +    @protocol
    1.50 +    def test_intermediate_released(self, runtime):
    1.51 +        """Check that a complex calculation does not leak memory."""
    1.52 +        x, y, z = runtime.shamir_share([1, 2, 3], self.Zp, runtime.id)
    1.53 +        w = x * y + z
    1.54 +        w.addCallback(self.check_empty, runtime)
    1.55 +        return w