Statistics
| Branch: | Tag: | Revision:

mininet / examples / test / test_cpu.py @ c5da46f1

History | View | Annotate | Download (1.04 KB)

1
#!/usr/bin/env python
2

    
3
"""
4
Test for cpu.py
5
"""
6

    
7
import unittest
8
import pexpect
9
import sys
10

    
11
class testCPU( unittest.TestCase ):
12

    
13
    prompt = 'mininet>'
14

    
15
    @unittest.skipIf( '-quick' in sys.argv, 'long test' )
16
    def testCPU( self ):
17
        "Verify that CPU utilization is monotonically decreasing for each scheduler"
18
        p = pexpect.spawn( 'python -m mininet.examples.cpu' )
19
        opts = [ '([a-z]+)\t([\d\.]+)%\t([\d\.]+)', pexpect.EOF ]
20
        scheds = []
21
        while True:
22
            index = p.expect( opts, timeout=600 )
23
            if index == 0:
24
                sched = p.match.group( 1 ) 
25
                cpu = float( p.match.group( 2 ) )
26
                bw = float( p.match.group( 3 ) )
27
                if sched not in scheds:
28
                    scheds.append( sched )
29
                    previous_bw = 10 ** 4 # 10 GB/s
30
                self.assertTrue( bw < previous_bw )
31
                previous_bw = bw
32
            else:
33
                break
34

    
35
        self.assertTrue( len( scheds ) > 0 )
36

    
37
if __name__ == '__main__':
38
    unittest.main()