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