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

cleaned up and commented test_multiping.py

parent 1d555e72
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
"""TEST""" """
Test for multiping.py
"""
import unittest import unittest
import pexpect import pexpect
from collections import defaultdict from collections import defaultdict
from mininet.log import setLogLevel
class testMultiPing( unittest.TestCase ): class testMultiPing( unittest.TestCase ):
"Test ping with single switch topology (common code)."
def testMultiPing( self ): def testMultiPing( self ):
"""Verify that each target is pinged at least once, and
that pings to 'real' targets are successful and unknown targets fail"""
p = pexpect.spawn( 'python -m mininet.examples.multiping' ) p = pexpect.spawn( 'python -m mininet.examples.multiping' )
opts = [] opts = [ "Host (h\d+) \(([\d.]+)\) will be pinging ips: ([\d\. ]+)",
opts.append( "Host (h\d+) \(([\d.]+)\) will be pinging ips: ([\d. ]+)" ) "(h\d+): ([\d.]+) -> ([\d.]+) \d packets transmitted, (\d) received",
opts.append( "(h\d+): ([\d.]+) -> ([\d.]+) \d packets transmitted, (\d) received" ) pexpect.EOF ]
opts.append( pexpect.EOF )
pings = defaultdict( list ) pings = defaultdict( list )
while True: while True:
index = p.expect( opts ) index = p.expect( opts )
...@@ -39,10 +40,9 @@ def testMultiPing( self ): ...@@ -39,10 +40,9 @@ def testMultiPing( self ):
pass pass
else: else:
break break
self.assertTrue( len(pings) > 0 ) self.assertTrue( len( pings ) > 0 )
for t in pings.values(): for t in pings.values():
self.assertEqual( len( t ), 0 ) self.assertEqual( len( t ), 0 )
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