| 1 |
import os, py |
| 2 |
from rpython.memory.gc import env |
| 3 |
from rpython.rlib.rarithmetic import r_uint |
| 4 |
from rpython.tool.udir import udir |
| 5 |
|
| 6 |
|
| 7 |
class FakeEnviron: |
| 8 |
def __init__(self, value): |
| 9 |
self._value = value |
| 10 |
def get(self, varname): |
| 11 |
assert varname == 'FOOBAR' |
| 12 |
return self._value |
| 13 |
|
| 14 |
def check_equal(x, y): |
| 15 |
assert x == y |
| 16 |
assert type(x) == type(y) |
| 17 |
|
| 18 |
def test_get_total_memory_darwin(): |
| 19 |
|
| 20 |
BIG = 2 * env.addressable_size |
| 21 |
SMALL = env.addressable_size / 2 |
| 22 |
assert env.addressable_size == env.get_total_memory_darwin(0) |
| 23 |
assert env.addressable_size == env.get_total_memory_darwin(-1) |
| 24 |
assert env.addressable_size == env.get_total_memory_darwin(BIG) |
| 25 |
assert SMALL == env.get_total_memory_darwin(SMALL) |
| 26 |
|
| 27 |
def test_get_total_memory(): |
| 28 |
|
| 29 |
assert env.get_total_memory() > 1024*1024 |
| 30 |
|
| 31 |
def test_read_from_env(): |
| 32 |
saved = os.environ |
| 33 |
try: |
| 34 |
os.environ = FakeEnviron(None) |
| 35 |
check_equal(env.read_from_env('FOOBAR'), 0) |
| 36 |
check_equal(env.read_uint_from_env('FOOBAR'), r_uint(0)) |
| 37 |
check_equal(env.read_float_from_env('FOOBAR'), 0.0) |
| 38 |
|
| 39 |
os.environ = FakeEnviron('') |
| 40 |
check_equal(env.read_from_env('FOOBAR'), 0) |
| 41 |
check_equal(env.read_uint_from_env('FOOBAR'), r_uint(0)) |
| 42 |
check_equal(env.read_float_from_env('FOOBAR'), 0.0) |
| 43 |
|
| 44 |
os.environ = FakeEnviron('???') |
| 45 |
check_equal(env.read_from_env('FOOBAR'), 0) |
| 46 |
check_equal(env.read_uint_from_env('FOOBAR'), r_uint(0)) |
| 47 |
check_equal(env.read_float_from_env('FOOBAR'), 0.0) |
| 48 |
|
| 49 |
os.environ = FakeEnviron('1') |
| 50 |
check_equal(env.read_from_env('FOOBAR'), 1) |
| 51 |
check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1)) |
| 52 |
check_equal(env.read_float_from_env('FOOBAR'), 1.0) |
| 53 |
|
| 54 |
os.environ = FakeEnviron('12345678') |
| 55 |
check_equal(env.read_from_env('FOOBAR'), 12345678) |
| 56 |
check_equal(env.read_uint_from_env('FOOBAR'), r_uint(12345678)) |
| 57 |
check_equal(env.read_float_from_env('FOOBAR'), 12345678.0) |
| 58 |
|
| 59 |
os.environ = FakeEnviron('1234B') |
| 60 |
check_equal(env.read_from_env('FOOBAR'), 1234) |
| 61 |
check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1234)) |
| 62 |
check_equal(env.read_float_from_env('FOOBAR'), 1234.0) |
| 63 |
|
| 64 |
os.environ = FakeEnviron('1.5') |
| 65 |
check_equal(env.read_float_from_env('FOOBAR'), 1.5) |
| 66 |
|
| 67 |
os.environ = FakeEnviron('1.5Kb') |
| 68 |
check_equal(env.read_from_env('FOOBAR'), 1536) |
| 69 |
check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1536)) |
| 70 |
check_equal(env.read_float_from_env('FOOBAR'), 0.0) |
| 71 |
|
| 72 |
os.environ = FakeEnviron('1.5mB') |
| 73 |
check_equal(env.read_from_env('FOOBAR'), int(1.5*1024*1024)) |
| 74 |
check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1.5*1024*1024)) |
| 75 |
check_equal(env.read_float_from_env('FOOBAR'), 0.0) |
| 76 |
|
| 77 |
os.environ = FakeEnviron('1.5g') |
| 78 |
check_equal(env.read_from_env('FOOBAR'), int(1.5*1024*1024*1024)) |
| 79 |
check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1.5*1024*1024*1024)) |
| 80 |
check_equal(env.read_float_from_env('FOOBAR'), 0.0) |
| 81 |
|
| 82 |
finally: |
| 83 |
os.environ = saved |
| 84 |
|
| 85 |
def test_get_total_memory_linux2(): |
| 86 |
filepath = udir.join('get_total_memory_linux2') |
| 87 |
filepath.write("""\ |
| 88 |
MemTotal: 1976804 kB |
| 89 |
MemFree: 32200 kB |
| 90 |
Buffers: 144092 kB |
| 91 |
Cached: 1385196 kB |
| 92 |
SwapCached: 8408 kB |
| 93 |
Active: 1181436 kB |
| 94 |
etc. |
| 95 |
""") |
| 96 |
result = env.get_total_memory_linux2(str(filepath)) |
| 97 |
assert result == 1976804 * 1024 |
| 98 |
|
| 99 |
def test_get_total_memory_linux2_32bit_limit(): |
| 100 |
filepath = udir.join('get_total_memory_linux2') |
| 101 |
filepath.write("""\ |
| 102 |
MemTotal: 3145728 kB |
| 103 |
etc. |
| 104 |
""") |
| 105 |
saved = env.addressable_size |
| 106 |
try: |
| 107 |
env.addressable_size = float(2**31) |
| 108 |
result = env.get_total_memory_linux2(str(filepath)) |
| 109 |
check_equal(result, float(2**31)) |
| 110 |
|
| 111 |
env.addressable_size = float(2**32) |
| 112 |
result = env.get_total_memory_linux2(str(filepath)) |
| 113 |
check_equal(result, float(3145728 * 1024)) |
| 114 |
finally: |
| 115 |
env.addressable_size = saved |
| 116 |
|
| 117 |
def test_estimate_best_nursery_size_linux2(): |
| 118 |
filepath = udir.join('estimate_best_nursery_size_linux2') |
| 119 |
filepath.write("""\ |
| 120 |
processor : 0 |
| 121 |
vendor_id : GenuineIntel |
| 122 |
cpu family : 6 |
| 123 |
model : 37 |
| 124 |
model name : Intel(R) Core(TM) i5 CPU M 540 @ 2.53GHz |
| 125 |
stepping : 5 |
| 126 |
cpu MHz : 1199.000 |
| 127 |
cache size : 3072 KB |
| 128 |
physical id : 0 |
| 129 |
siblings : 4 |
| 130 |
core id : 0 |
| 131 |
cpu cores : 2 |
| 132 |
apicid : 0 |
| 133 |
initial apicid : 0 |
| 134 |
fpu : yes |
| 135 |
fpu_exception : yes |
| 136 |
cpuid level : 11 |
| 137 |
wp : yes |
| 138 |
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 popcnt aes lahf_lm ida arat tpr_shadow vnmi flexpriority ept vpid |
| 139 |
bogomips : 5054.78 |
| 140 |
clflush size : 64 |
| 141 |
cache_alignment : 64 |
| 142 |
address sizes : 36 bits physical, 48 bits virtual |
| 143 |
power management: |
| 144 |
|
| 145 |
processor : 1 |
| 146 |
vendor_id : GenuineIntel |
| 147 |
cpu family : 6 |
| 148 |
model : 37 |
| 149 |
model name : Intel(R) Core(TM) i5 CPU M 540 @ 2.53GHz |
| 150 |
stepping : 5 |
| 151 |
cpu MHz : 2534.000 |
| 152 |
cache size : 3072 KB |
| 153 |
physical id : 0 |
| 154 |
siblings : 4 |
| 155 |
core id : 0 |
| 156 |
cpu cores : 2 |
| 157 |
apicid : 1 |
| 158 |
initial apicid : 1 |
| 159 |
fpu : yes |
| 160 |
etc. |
| 161 |
""") |
| 162 |
result = env.get_L2cache_linux2_cpuinfo(str(filepath)) |
| 163 |
assert result == 3072 * 1024 |
| 164 |
|
| 165 |
def test_estimate_nursery_s390x(): |
| 166 |
filepath = udir.join('estimate_best_nursery_size_linux2') |
| 167 |
filepath.write("""\ |
| 168 |
vendor_id : IBM/S390 |
| 169 |
# processors : 2 |
| 170 |
bogomips per cpu: 20325.00 |
| 171 |
... |
| 172 |
cache2 : level=2 type=Data scope=Private size=2048K line_size=256 associativity=8 |
| 173 |
cache3 : level=2 type=Instruction scope=Private size=2048K line_size=256 associativity=8 |
| 174 |
... |
| 175 |
""") |
| 176 |
result = env.get_L2cache_linux2_cpuinfo_s390x(str(filepath)) |
| 177 |
assert result == 2048 * 1024 |
| 178 |
|
| 179 |
filepath = udir.join('estimate_best_nursery_size_linux3') |
| 180 |
filepath.write("""\ |
| 181 |
vendor_id : IBM/S390 |
| 182 |
# processors : 2 |
| 183 |
bogomips per cpu: 9398.00 |
| 184 |
... |
| 185 |
cache2 : level=2 type=Unified scope=Private size=1536K line_size=256 associativity=12 |
| 186 |
cache3 : level=3 type=Unified scope=Shared size=24576K line_size=256 associativity=12 |
| 187 |
... |
| 188 |
""") |
| 189 |
result = env.get_L2cache_linux2_cpuinfo_s390x(str(filepath), label='cache3') |
| 190 |
assert result == 24576 * 1024 |
| 191 |
result = env.get_L2cache_linux2_cpuinfo_s390x(str(filepath), label='cache2') |
| 192 |
assert result == 1536 * 1024 |