d70da54936f08b3dc52a54e9029849f63e1ac853
[oweals/gnunet.git] / src / integration-tests / test_mem_consumption.py
1 #!/usr/bin/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_clique"
47 verbose = True
48 check_timeout = 180
49
50
51 def cleanup ():
52     shutil.rmtree (os.path.join (tmp, "c_bootstrap_server"), True)
53     shutil.rmtree (os.path.join (tmp, "c_no_nat_client"), True)
54     shutil.rmtree (os.path.join (tmp, "c_no_nat_client_2"), True)
55
56
57         
58 def check_disconnect ():
59   check = Check (test)
60   check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
61   check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',1))  
62   check.add (StatisticsCondition (client, 'core', '# peers connected',1))
63   check.add (StatisticsCondition (client, 'topology', '# peers connected',1))
64   check.add (StatisticsCondition (client, 'fs', '# peers connected',1))
65   
66   check.add (StatisticsCondition (server, 'transport', '# peers connected',1))
67   check.add (StatisticsCondition (server, 'core', '# neighbour entries allocated',1))  
68   check.add (StatisticsCondition (server, 'core', '# peers connected',1))
69   check.add (StatisticsCondition (server, 'topology', '# peers connected',1))
70   check.add (StatisticsCondition (server, 'fs', '# peers connected',1))
71   
72   check.run_blocking (check_timeout, None, None)
73
74
75
76 def check_connect ():
77   check = Check (test)
78   check.add (StatisticsCondition (client, 'transport', '# peers connected',2))
79   check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',2))  
80   check.add (StatisticsCondition (client, 'core', '# peers connected',2))
81   check.add (StatisticsCondition (client, 'topology', '# peers connected',2))
82   check.add (StatisticsCondition (client, 'fs', '# peers connected',2))
83
84   check.add (StatisticsCondition (client2, 'transport', '# peers connected',2))
85   check.add (StatisticsCondition (client2, 'core', '# neighbour entries allocated',2))  
86   check.add (StatisticsCondition (client2, 'core', '# peers connected',2))
87   check.add (StatisticsCondition (client2, 'topology', '# peers connected',2))
88   check.add (StatisticsCondition (client2, 'fs', '# peers connected',2))
89   
90   check.add (StatisticsCondition (server, 'transport', '# peers connected',2))
91   check.add (StatisticsCondition (server, 'core', '# neighbour entries allocated',2))  
92   check.add (StatisticsCondition (server, 'core', '# peers connected',2))
93   check.add (StatisticsCondition (server, 'topology', '# peers connected',2))
94   check.add (StatisticsCondition (server, 'fs', '# peers connected',2))  
95   
96   check.run_blocking (check_timeout, None, None)
97
98
99 # Test execution
100
101 def run ():
102     global success
103     global test
104     global server
105     global client
106     global client2      
107     restarts = 0
108     iterations = 4
109     success = False
110     
111     test = Test ('test_memory_consumption', verbose)
112     server = Peer(test, './confs/c_bootstrap_server_w_massif.conf');
113     server.start();
114     client = Peer(test, './confs/c_no_nat_client.conf');
115     client.start();
116     
117     while (restarts < iterations):
118        print 'Iteration #' + str (restarts) + ' of ' + str (restarts)
119        restarts += 1
120        client2 = Peer(test, './confs/c_no_nat_client_2.conf');
121        client2.start(); 
122        if ((client.started == True) and (client2.started == True) and (server.started == True)):
123            test.p ('Peers started, waiting for clique connection')
124            check_connect ()
125            test.p ('All peers connected, stopping client2')   
126            client2.stop ()
127            check_disconnect ()
128            test.p ('Peer disconnected')
129
130     print str (iterations) + " Iteration executed" 
131     server.stop ()    
132     client.stop ()    
133     cleanup ()
134     
135 try:
136     run ()
137 except (KeyboardInterrupt, SystemExit):    
138     print 'Test interrupted'
139     server.stop ()
140     client.stop ()
141     client2.stop ()
142     cleanup ()
143 if (success == False):
144         sys.exit(1)   
145 else:
146         sys.exit(0)    
147             
148