fix memleak
[oweals/gnunet.git] / src / integration-tests / test_integration_connection_values_tcp_udp.py.in
1 #!@PYTHON@
2 #    This file is part of GNUnet.
3 #    (C) 2010 Christian Grothoff (and other contributing authors)
4 #
5 #    GNUnet is free software; you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License as published
7 #    by the Free Software Foundation; either version 2, or (at your
8 #    option) any later version.
9 #
10 #    GNUnet is distributed in the hope that it will be useful, but
11 #    WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #    General Public License for more details.
14 #
15 #    You should have received a copy of the GNU General Public License
16 #    along with GNUnet; see the file COPYING.  If not, write to the
17 #    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 #    Boston, MA 02111-1307, USA.
19 #
20
21 #
22 # This test starts 3 peers and expects bootstrap and a connected clique
23 #
24 # Conditions for successful exit:
25 # Both peers have 1 connected peer in transport, core, topology, fs 
26
27 import sys
28 import os
29 import subprocess
30 import re
31 import shutil
32 import time
33 from gnunet_testing import Peer
34 from gnunet_testing import Test
35 from gnunet_testing import Check
36 from gnunet_testing import Condition
37 from gnunet_testing import * 
38  
39
40 #definitions
41
42 testname = "test_integration_connection_value"
43 verbose = True
44 check_timeout = 180
45
46 if os.name == "nt":
47   tmp = os.getenv ("TEMP")
48 else:
49   tmp = "/tmp"
50
51 def cleanup ():
52     shutil.rmtree (os.path.join (tmp, "c_normal_client"), True)
53
54 def success_cont (check):
55     global success 
56     success = True;
57
58 def fail_cont (check):    
59     global success 
60     success= False;
61     check.evaluate(True)        
62
63
64 def check_connect ():
65   check = Check (test)
66   check.add (EqualStatisticsCondition (client, 'transport', '# peers connected', client,  'core', '# neighbour entries allocated'))
67   check.add (EqualStatisticsCondition (client, 'transport', '# peers connected', client,  'core', '# peers connected'))
68   check.add (EqualStatisticsCondition (client, 'core', '# neighbour entries allocated', client,  'core', '# peers connected'))
69   check.add (EqualStatisticsCondition (client, 'transport', '# peers connected', client, 'topology', '# peers connected'))
70   check.add (EqualStatisticsCondition (client, 'topology', '# peers connected', client, 'core', '# peers connected'))
71   
72   while True:
73         check.reset()
74         res = check.run_once (None, None)
75         print "Values are equal"
76         check.evaluate (False)
77 #if (False == res):
78 #       break
79         time.sleep (5)
80         
81
82 # Test execution
83
84 def run ():
85         global success
86         global test
87         global client
88
89         
90         success = False
91         
92         test = Test ('test_integration_connection_value', verbose)
93         
94         client = Peer(test, './confs/c_normal_client_tcp_udp.conf');
95         client.start();
96         
97         if (client.started == True):
98             test.p ('Peers started, running check')
99             check_connect ()
100                 
101         client.stop ()
102         
103         cleanup ()
104         
105         if (success == False):
106                 print ('Test failed')
107                 return False 
108         else:
109                 return True
110
111     
112 try:
113     run ()
114 except (KeyboardInterrupt, SystemExit):    
115     print 'Test interrupted'
116     client.stop ()
117     cleanup ()
118 if (success == False):
119         sys.exit(1)   
120 else:
121         sys.exit(0)    
122             
123