adding first draft of tests for all examples, they need comments and clean up, some could be made more rebust

This commit is contained in:
Brian O'Connor
2013-09-11 14:45:46 -07:00
parent 5a646a0d20
commit a46fae0687
20 changed files with 914 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env python
"""TEST"""
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 ):
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 )
pings = {}
while True:
index = p.expect( opts )
if index == 0:
name = p.match.group(1)
pings[ name ] = 0
elif index == 1:
name = p.match.group(1)
transmitted = p.match.group(2)
received = p.match.group(3)
self.assertEqual( received, transmitted )
pings[ name ] += 1
else:
break
self.assertTrue( len(pings) > 0 )
for count in pings.values():
self.assertEqual( count, 1 )
def testPopen( self ):
self.pingTest( 'mininet.examples.popen' )
def testPopenPoll( self ):
self.pingTest( 'mininet.examples.popenpoll')
if __name__ == '__main__':
setLogLevel( 'warning' )
unittest.main()