cleaned up and commented test_popen.py
This commit is contained in:
@@ -1,21 +1,20 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
"""TEST"""
|
"""
|
||||||
|
Test for popen.py and popenpoll.py
|
||||||
|
"""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import pexpect
|
import pexpect
|
||||||
from collections import defaultdict
|
|
||||||
from mininet.log import setLogLevel
|
|
||||||
|
|
||||||
class testPopen( unittest.TestCase ):
|
class testPopen( unittest.TestCase ):
|
||||||
"Test ping with single switch topology (common code)."
|
|
||||||
|
|
||||||
def pingTest( self, name ):
|
def pingTest( self, name ):
|
||||||
|
"Verify that there are no dropped packets for each host"
|
||||||
p = pexpect.spawn( 'python -m %s' % name )
|
p = pexpect.spawn( 'python -m %s' % name )
|
||||||
opts = []
|
opts = [ "<(h\d+)>: PING ",
|
||||||
opts.append( "<(h\d+)>: PING " )
|
"<(h\d+)>: (\d+) packets transmitted, (\d+) received",
|
||||||
opts.append( "<(h\d+)>: (\d+) packets transmitted, (\d+) received" )
|
pexpect.EOF ]
|
||||||
opts.append( pexpect.EOF )
|
|
||||||
pings = {}
|
pings = {}
|
||||||
while True:
|
while True:
|
||||||
index = p.expect( opts )
|
index = p.expect( opts )
|
||||||
@@ -26,11 +25,13 @@ class testPopen( unittest.TestCase ):
|
|||||||
name = p.match.group(1)
|
name = p.match.group(1)
|
||||||
transmitted = p.match.group(2)
|
transmitted = p.match.group(2)
|
||||||
received = p.match.group(3)
|
received = p.match.group(3)
|
||||||
|
# verify no dropped packets
|
||||||
self.assertEqual( received, transmitted )
|
self.assertEqual( received, transmitted )
|
||||||
pings[ name ] += 1
|
pings[ name ] += 1
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
self.assertTrue( len(pings) > 0 )
|
self.assertTrue( len(pings) > 0 )
|
||||||
|
# verify that each host has gotten results
|
||||||
for count in pings.values():
|
for count in pings.values():
|
||||||
self.assertEqual( count, 1 )
|
self.assertEqual( count, 1 )
|
||||||
|
|
||||||
@@ -41,5 +42,4 @@ class testPopen( unittest.TestCase ):
|
|||||||
self.pingTest( 'mininet.examples.popenpoll' )
|
self.pingTest( 'mininet.examples.popenpoll' )
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setLogLevel( 'warning' )
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user