[pypy-svn] r15522 - in pypy/dist/pypy/rpython/memory: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Aug 2 20:47:23 CEST 2005
Author: cfbolz
Date: Tue Aug 2 20:47:19 2005
New Revision: 15522
Modified:
pypy/dist/pypy/rpython/memory/simulator.py
pypy/dist/pypy/rpython/memory/test/test_simulator.py
Log:
added a size of RAM to the memory simulator to be able to simulate out
of memory situations.
Modified: pypy/dist/pypy/rpython/memory/simulator.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/simulator.py (original)
+++ pypy/dist/pypy/rpython/memory/simulator.py Tue Aug 2 20:47:19 2005
@@ -3,6 +3,7 @@
# all addresses in the simulator are just ints
+
# possible chars in status are:
# 'u': uninitialized
# 'i': initialized
@@ -50,9 +51,12 @@
assert len(self.memory) == self.size
class MemorySimulator(object):
- def __init__(self):
+ size_of_simulated_ram = 64 * 1024 * 1024
+ def __init__(self, ram_size = None):
self.blocks = []
self.freememoryaddress = 4
+ if ram_size is not None:
+ self.size_of_simulated_ram = ram_size
def find_block(self, address):
lo = 0
@@ -72,6 +76,8 @@
result = self.freememoryaddress
self.blocks.append(MemoryBlock(result, size))
self.freememoryaddress += size
+ if self.freememoryaddress > self.size_of_simulated_ram:
+ raise MemorySimulatorError, "out of memory"
return result
def free(self, baseaddress):
Modified: pypy/dist/pypy/rpython/memory/test/test_simulator.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_simulator.py (original)
+++ pypy/dist/pypy/rpython/memory/test/test_simulator.py Tue Aug 2 20:47:19 2005
@@ -1,5 +1,9 @@
import py
-from pypy.rpython.memory.simulator import *
+from pypy.rpython.memory.simulator import MemoryBlock, MemorySimulator
+from pypy.rpython.memory.simulator import MemorySimulatorError
+from pypy.rpython.memory import simulator
+
+import struct
class TestMemoryBlock(object):
def test_getsetbyte(self):
@@ -55,3 +59,10 @@
assert simulator.getstruct("iii", addr1) == (1, 2, 3)
assert simulator.getstruct("iii", addr1 + 500) == (1, 2, 3)
assert simulator.getstruct("iii", addr2) == (1, 2, 3)
+
+ def test_out_of_memory(self):
+ sim = MemorySimulator(1 * 1024 * 1024)
+ def f():
+ for i in xrange(10000000):
+ sim.malloc(4096)
+ py.test.raises(MemorySimulatorError, f)
More information about the Pypy-commit
mailing list