aboutsummaryrefslogtreecommitdiff
blob: 1e50e52936b1ca8f3d9fb60bc402f1257afb1c75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from cStringIO import StringIO
from pypy.config.support import detect_number_of_processors
import os, sys, py

cpuinfo = """
processor\t: 0

processor\t: 1
vendor_id\t: GenuineIntel
cpu family\t: 6
model\t\t: 37
model name\t: Intel(R) Core(TM) i7 CPU       L 620  @ 2.00GHz
stepping\t: 2

processor\t: 2
vendor_id\t: GenuineIntel
cpu family\t: 6
model\t\t: 37
model name\t: Intel(R) Core(TM) i7 CPU       L 620  @ 2.00GHz
stepping\t: 2

processor\t: 3
vendor_id\t: GenuineIntel
cpu family\t: 6
model\t\t: 37
model name\t: Intel(R) Core(TM) i7 CPU       L 620  @ 2.00GHz
stepping\t: 2
cpu MHz\t\t: 1199.000
cache size\t: 4096 KB
physical id\t: 0
siblings\t: 4
"""

class FakeEnviron:
    def __init__(self, value):
        self._value = value
    def get(self, varname):
        assert varname == 'MAKEFLAGS'
        return self._value

def test_cpuinfo():
    if sys.platform != 'linux2':
        py.test.skip("linux only")
    saved = os.environ
    try:
        os.environ = FakeEnviron(None)
        assert detect_number_of_processors(StringIO(cpuinfo)) == 3
        assert detect_number_of_processors('random crap that does not exist') == 1
        os.environ = FakeEnviron('-j2')
        assert detect_number_of_processors(StringIO(cpuinfo)) == 1
    finally:
        os.environ = saved