Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / mininet / examples / test / test_cpu.py
1 #!/usr/bin/env python
2
3 """
4 Test for cpu.py
5
6 results format:
7
8 sched   cpu     received bits/sec
9 cfs     50%     8.14e+09
10 cfs     40%     6.48e+09
11 cfs     30%     4.56e+09
12 cfs     20%     2.84e+09
13 cfs     10%     1.29e+09
14
15 """
16
17 import unittest
18 from mininet.util import pexpect
19 import sys
20
21 class testCPU( unittest.TestCase ):
22
23     prompt = 'mininet>'
24
25     @unittest.skipIf( '-quick' in sys.argv, 'long test' )
26     def testCPU( self ):
27         "Verify that CPU utilization is monotonically decreasing for each scheduler"
28         p = pexpect.spawn( 'python -m mininet.examples.cpu', timeout=300 )
29         # matches each line from results( shown above )
30         opts = [ '([a-z]+)\t([\d\.]+)%\t([\d\.e\+]+)',
31                  pexpect.EOF ]
32         scheds = []
33         while True:
34             index = p.expect( opts )
35             if index == 0:
36                 sched = p.match.group( 1 )
37                 cpu = float( p.match.group( 2 ) )
38                 bw = float( p.match.group( 3 ) )
39                 if sched not in scheds:
40                     scheds.append( sched )
41                 else:
42                     self.assertTrue( bw < previous_bw,
43                                      "%e should be less than %e\n" %
44                                      ( bw, previous_bw ) )
45                 previous_bw = bw
46             else:
47                 break
48
49         self.assertTrue( len( scheds ) > 0 )
50
51 if __name__ == '__main__':
52     unittest.main()