Skip to content
Snippets Groups Projects
Commit 213b7c57 authored by Brian O'Connor's avatar Brian O'Connor
Browse files

cleaned up and commented test_popen.py

parent b9b1f2e7
No related branches found
No related tags found
No related merge requests found
#!/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 @@ def pingTest( self, name ): ...@@ -26,11 +25,13 @@ def pingTest( self, name ):
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 )
...@@ -38,8 +39,7 @@ def testPopen( self ): ...@@ -38,8 +39,7 @@ def testPopen( self ):
self.pingTest( 'mininet.examples.popen' ) self.pingTest( 'mininet.examples.popen' )
def testPopenPoll( self ): def testPopenPoll( self ):
self.pingTest( 'mininet.examples.popenpoll') self.pingTest( 'mininet.examples.popenpoll' )
if __name__ == '__main__': if __name__ == '__main__':
setLogLevel( 'warning' )
unittest.main() unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment