Statistics
| Branch: | Tag: | Revision:

mininet / examples / test / test_cpu.py @ c5da46f1

History | View | Annotate | Download (1.04 KB)

1 a46fae06 Brian O'Connor
#!/usr/bin/env python
2
3 94abeeab Brian O'Connor
"""
4
Test for cpu.py
5
"""
6 a46fae06 Brian O'Connor
7
import unittest
8
import pexpect
9 c5da46f1 Brian O'Connor
import sys
10 a46fae06 Brian O'Connor
11
class testCPU( unittest.TestCase ):
12
13
    prompt = 'mininet>'
14
15 c5da46f1 Brian O'Connor
    @unittest.skipIf( '-quick' in sys.argv, 'long test' )
16 a46fae06 Brian O'Connor
    def testCPU( self ):
17 94abeeab Brian O'Connor
        "Verify that CPU utilization is monotonically decreasing for each scheduler"
18 a46fae06 Brian O'Connor
        p = pexpect.spawn( 'python -m mininet.examples.cpu' )
19 94abeeab Brian O'Connor
        opts = [ '([a-z]+)\t([\d\.]+)%\t([\d\.]+)', pexpect.EOF ]
20 a46fae06 Brian O'Connor
        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()