second try
[vsorcdistro/.git] / mininet / examples / test / test_limit.py
1 #!/usr/bin/env python
2
3 """
4 Test for limit.py
5 """
6
7 import unittest
8 from mininet.util import pexpect
9 import sys
10
11 class testLimit( unittest.TestCase ):
12
13     @unittest.skipIf( '-quick' in sys.argv, 'long test' )
14     def testLimit( self ):
15         "Verify that CPU limits are within a 2% tolerance of limit for each scheduler"
16         p = pexpect.spawn( 'python -m mininet.examples.limit' )
17         opts = [ '\*\*\* Testing network ([\d\.]+) Mbps',
18                  '\*\*\* Results: \[([\d\., ]+)\]',
19                  pexpect.EOF ]
20         count = 0
21         bw = 0
22         tolerance = 2
23         while True:
24             index = p.expect( opts )
25             if index == 0:
26                 bw = float( p.match.group( 1 ) )
27                 count += 1
28             elif index == 1:
29                 results = p.match.group( 1 )
30                 for x in results.split( ',' ):
31                     result = float( x )
32                     self.assertTrue( result < bw + tolerance )
33                     self.assertTrue( result > bw - tolerance )
34             else:
35                 break
36
37         self.assertTrue( count > 0 )
38
39 if __name__ == '__main__':
40     unittest.main()