Debian Codegraph @

rpython/config/test/test_support.py

raw symbols SCIP
1
2 from cStringIO import StringIO
3 from rpython.config import support
4 import os, sys, py
5
6 cpuinfo = """
7 processor\t: 0
8
9 processor\t: 1
10 vendor_id\t: GenuineIntel
11 cpu family\t: 6
12 model\t\t: 37
13 model name\t: Intel(R) Core(TM) i7 CPU L 620 @ 2.00GHz
14 stepping\t: 2
15
16 processor\t: 2
17 vendor_id\t: GenuineIntel
18 cpu family\t: 6
19 model\t\t: 37
20 model name\t: Intel(R) Core(TM) i7 CPU L 620 @ 2.00GHz
21 stepping\t: 2
22
23 processor\t: 3
24 vendor_id\t: GenuineIntel
25 cpu family\t: 6
26 model\t\t: 37
27 model name\t: Intel(R) Core(TM) i7 CPU L 620 @ 2.00GHz
28 stepping\t: 2
29 cpu MHz\t\t: 1199.000
30 cache size\t: 4096 KB
31 physical id\t: 0
32 siblings\t: 4
33 """
34
35 class FakeEnviron:
36 def __init__(self, value):
37 self._value = value
38 def get(self, varname):
39 assert varname == 'MAKEFLAGS'
40 return self._value
41
42 def test_cpuinfo_linux():
43 if not sys.platform.startswith('linux'):
44 py.test.skip("linux only")
45 saved = os.environ
46 try:
47 os.environ = FakeEnviron(None)
48 assert support.detect_number_of_processors(StringIO(cpuinfo)) == 3
49 assert support.detect_number_of_processors('random crap that does not exist') == 1
50 os.environ = FakeEnviron('-j2')
51 assert support.detect_number_of_processors(StringIO(cpuinfo)) == 1
52 finally:
53 os.environ = saved
54
55 def test_cpuinfo_sysctl():
56 if sys.platform != 'darwin' and not sys.platform.startswith('freebsd'):
57 py.test.skip('mac and bsd only')
58 saved_func = support.sysctl_get_cpu_count
59 saved = os.environ
60 def count(cmd):
61 if sys.platform == 'darwin':
62 assert cmd == '/usr/sbin/sysctl'
63 else:
64 assert cmd == '/sbin/sysctl'
65 return 42
66 try:
67 support.sysctl_get_cpu_count = count
68 os.environ = FakeEnviron(None)
69 assert support.detect_number_of_processors() == 42
70 os.environ = FakeEnviron('-j2')
71 assert support.detect_number_of_processors() == 1
72 finally:
73 os.environ = saved
74 support.sysctl_get_cpu_count = saved_func
75
76 def test_sysctl_get_cpu_count():
77 if sys.platform != 'darwin' and not sys.platform.startswith('freebsd'):
78 py.test.skip('mac and bsd only')
79 cmd = '/usr/sbin/sysctl' if sys.platform != 'darwin' else '/sbin/sysctl'
80 assert support.sysctl_get_cpu_count(cmd) > 0 # hopefully
81 assert support.sysctl_get_cpu_count(cmd, "false") == 1