cleaned up and commented test_multipoll.py
This commit is contained in:
@@ -1,22 +1,21 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
"""TEST"""
|
"""
|
||||||
|
Test for multipoll.py
|
||||||
|
"""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import pexpect
|
import pexpect
|
||||||
from collections import defaultdict
|
|
||||||
from mininet.log import setLogLevel
|
|
||||||
|
|
||||||
class testMultiPoll( unittest.TestCase ):
|
class testMultiPoll( unittest.TestCase ):
|
||||||
"Test ping with single switch topology (common code)."
|
|
||||||
|
|
||||||
def testMultiPoll( self ):
|
def testMultiPoll( self ):
|
||||||
|
"Verify that we receive one ping per second per host"
|
||||||
p = pexpect.spawn( 'python -m mininet.examples.multipoll' )
|
p = pexpect.spawn( 'python -m mininet.examples.multipoll' )
|
||||||
opts = []
|
opts = [ "\*\*\* (h\d) :" ,
|
||||||
opts.append( "\*\*\* (h\d) :" )
|
"(h\d+): \d+ bytes from",
|
||||||
opts.append( "(h\d+): \d+ bytes from" )
|
"Monitoring output for (\d+) seconds",
|
||||||
opts.append( "Monitoring output for (\d+) seconds" )
|
pexpect.EOF ]
|
||||||
opts.append( pexpect.EOF )
|
|
||||||
pings = {}
|
pings = {}
|
||||||
while True:
|
while True:
|
||||||
index = p.expect( opts )
|
index = p.expect( opts )
|
||||||
@@ -30,11 +29,10 @@ class testMultiPoll( unittest.TestCase ):
|
|||||||
seconds = int( p.match.group( 1 ) )
|
seconds = int( p.match.group( 1 ) )
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
self.assertTrue( len(pings) > 0 )
|
self.assertTrue( len( pings ) > 0 )
|
||||||
# make sure we have received at least one ping per second
|
# make sure we have received at least one ping per second
|
||||||
for count in pings.values():
|
for count in pings.values():
|
||||||
self.assertTrue( count >= seconds )
|
self.assertTrue( count >= seconds )
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setLogLevel( 'warning' )
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user