File: test_multipoll.py

package info (click to toggle)
mininet 2.3.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,588 kB
  • sloc: python: 11,181; ansic: 1,332; sh: 967; makefile: 87
file content (39 lines) | stat: -rwxr-xr-x 1,211 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python

"""
Test for multipoll.py
"""

import unittest
from mininet.util import pexpect

class testMultiPoll( unittest.TestCase ):

    def testMultiPoll( self ):
        "Verify that we receive one ping per second per host"
        p = pexpect.spawn( 'python -m mininet.examples.multipoll' )
        opts = [ "\*\*\* (h\d) :" ,
                 "(h\d+): \d+ bytes from",
                 "Monitoring output for (\d+) seconds",
                 pexpect.EOF ]
        pings, seconds = {}, -1
        while True:
            index = p.expect( opts )
            if index == 0:
                name = p.match.group( 1 )
                pings[ name ] = 0
            elif index == 1:
                name = p.match.group( 1 )
                pings[ name ] += 1
            elif index == 2:
                seconds = int( p.match.group( 1 ) )
            else:
                break
        self.assertTrue( len( pings ) > 0 )
        # make sure we have received at least one ping per second
        for count in pings.values():
            self.assertTrue( count >= seconds,
                             '%d pings < %d seconds' % ( count, seconds ) )

if __name__ == '__main__':
    unittest.main()