Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / mininet / examples / test / test_multipoll.py
1 #!/usr/bin/env python
2
3 """
4 Test for multipoll.py
5 """
6
7 import unittest
8 from mininet.util import pexpect
9
10 class testMultiPoll( unittest.TestCase ):
11
12     def testMultiPoll( self ):
13         "Verify that we receive one ping per second per host"
14         p = pexpect.spawn( 'python -m mininet.examples.multipoll' )
15         opts = [ "\*\*\* (h\d) :" ,
16                  "(h\d+): \d+ bytes from",
17                  "Monitoring output for (\d+) seconds",
18                  pexpect.EOF ]
19         pings, seconds = {}, -1
20         while True:
21             index = p.expect( opts )
22             if index == 0:
23                 name = p.match.group( 1 )
24                 pings[ name ] = 0
25             elif index == 1:
26                 name = p.match.group( 1 )
27                 pings[ name ] += 1
28             elif index == 2:
29                 seconds = int( p.match.group( 1 ) )
30             else:
31                 break
32         self.assertTrue( len( pings ) > 0 )
33         # make sure we have received at least one ping per second
34         for count in pings.values():
35             self.assertTrue( count >= seconds,
36                              '%d pings < %d seconds' % ( count, seconds ) )
37
38 if __name__ == '__main__':
39     unittest.main()