Statistics
| Branch: | Tag: | Revision:

mininet / examples / test / test_cpu.py @ e113f8ed

History | View | Annotate | Download (1.39 KB)

1
#!/usr/bin/env python
2

    
3
"""
4
Test for cpu.py
5

6
results format:
7

8
    sched   cpu client MB/s
9

10
    cfs 45.00%  13254.669841
11
    cfs 40.00%  11822.441399
12
    cfs 30.00%  5112.963009
13
    cfs 20.00%  3449.090009
14
    cfs 10.00%  2271.741564
15

16
"""
17

    
18
import unittest
19
import pexpect
20
import sys
21

    
22
class testCPU( unittest.TestCase ):
23

    
24
    prompt = 'mininet>'
25

    
26
    @unittest.skipIf( '-quick' in sys.argv, 'long test' )
27
    def testCPU( self ):
28
        "Verify that CPU utilization is monotonically decreasing for each scheduler"
29
        p = pexpect.spawn( 'python -m mininet.examples.cpu' )
30
        # matches each line from results( shown above )
31
        opts = [ '([a-z]+)\t([\d\.]+)%\t([\d\.]+)',
32
                 pexpect.EOF ]
33
        scheds = []
34
        while True:
35
            index = p.expect( opts, timeout=600 )
36
            if index == 0:
37
                sched = p.match.group( 1 )
38
                cpu = float( p.match.group( 2 ) )
39
                bw = float( p.match.group( 3 ) )
40
                if sched not in scheds:
41
                    scheds.append( sched )
42
                else:
43
                    self.assertTrue( bw < previous_bw,
44
                                     "%f should be less than %f\n" %
45
                                     ( bw, previous_bw ) )
46
                previous_bw = bw
47
            else:
48
                break
49

    
50
        self.assertTrue( len( scheds ) > 0 )
51

    
52
if __name__ == '__main__':
53
    unittest.main()