fix
[oweals/gnunet.git] / src / integration-tests / test_integration_connection_values_tcp.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 if os.name == "nt":
40   tmp = os.getenv ("TEMP")
41 else:
42   tmp = "/tmp"
43
44 #definitions
45
46 testname = "test_integration_connection_value"
47 verbose = True
48 check_timeout = 180
49
50
51 def cleanup ():
52     shutil.rmtree (os.path.join (tmp, "c_normal_client"), True)
53
54
55 def success_cont (check):
56     global success 
57     success = True;
58
59 def fail_cont (check):    
60     global success 
61     success= False;
62     check.evaluate(True)        
63
64
65 def check_connect ():
66   check = Check (test)
67   check.add (EqualStatisticsCondition (client, 'transport', '# peers connected', client,  'core', '# neighbour entries allocated'))
68   check.add (EqualStatisticsCondition (client, 'transport', '# peers connected', client,  'core', '# peers connected'))
69   check.add (EqualStatisticsCondition (client, 'core', '# neighbour entries allocated', client,  'core', '# peers connected'))
70   check.add (EqualStatisticsCondition (client, 'transport', '# peers connected', client, 'topology', '# peers connected'))
71   check.add (EqualStatisticsCondition (client, 'topology', '# peers connected', client, 'core', '# peers connected'))
72   
73   while True:
74         check.reset()
75         res = check.run_once (None, None)
76         print "Values are equal"
77         check.evaluate (False)
78 #if (False == res):
79 #       break
80         time.sleep (5)
81         
82
83 # Test execution
84
85 def run ():
86         global success
87         global test
88         global client
89
90         
91         success = False
92         
93         test = Test ('test_integration_connection_value', verbose)
94         
95         client = Peer(test, './confs/c_normal_client_tcp.conf');
96         client.start();
97         
98         if (client.started == True):
99             test.p ('Peers started, running check')
100             check_connect ()
101                 
102         client.stop ()
103         
104         cleanup ()
105         
106         if (success == False):
107                 print ('Test failed')
108                 return False 
109         else:
110                 return True
111
112     
113 try:
114     run ()
115 except (KeyboardInterrupt, SystemExit):    
116     print 'Test interrupted'
117     client.stop ()
118     cleanup ()
119 if (success == False):
120         sys.exit(1)   
121 else:
122         sys.exit(0)    
123             
124