Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r76464:a8f27887f7d9
Date: 2015-03-19 10:11 +0100
http://bitbucket.org/pypy/pypy/changeset/a8f27887f7d9/

Log:    Tests for issue #2001. Only failure is in
        TestIncrementalMiniMarkGC.test_limited_memory_linux.

diff --git a/rpython/translator/c/test/test_newgc.py 
b/rpython/translator/c/test/test_newgc.py
--- a/rpython/translator/c/test/test_newgc.py
+++ b/rpython/translator/c/test/test_newgc.py
@@ -2,6 +2,7 @@
 import inspect
 import os
 import sys
+import subprocess
 
 import py
 
@@ -50,8 +51,8 @@
             t.viewcg()
         exename = t.compile()
 
-        def run(s, i):
-            data = py.process.cmdexec("%s %s %d" % (exename, s, i))
+        def run(s, i, runner=subprocess.check_output):
+            data = runner([str(exename), str(s), str(i)])
             data = data.strip()
             if data == 'MEMORY-ERROR':
                 raise MemoryError
@@ -115,11 +116,11 @@
             cls.c_allfuncs.close_isolate()
             cls.c_allfuncs = None
 
-    def run(self, name, *args):
+    def run(self, name, *args, **kwds):
         if not args:
             args = (-1, )
         print 'Running %r)' % name
-        res = self.c_allfuncs(name, *args)
+        res = self.c_allfuncs(name, *args, **kwds)
         num = self.name_to_func[name]
         if self.funcsstr[num]:
             return res
@@ -1524,6 +1525,57 @@
         res = self.run("nongc_opaque_attached_to_gc")
         assert res == 0
 
+    def define_limited_memory(self):
+        class A(object):
+            def __init__(self, next):
+                self.next = next
+        def g(i):
+            a = None
+            while i != 0:
+                a = A(a)
+                i -= 1
+            return 0
+        def f(i):
+            try:
+                return g(i)
+            except MemoryError:
+                g(20)       # allocate some more stuff, but exit
+                return 42
+        return f
+
+    def test_limited_memory(self):
+        import random
+        #
+        def myrunner(args):
+            env = os.environ.copy()
+            env['PYPY_GC_MAX'] = '%dKB' % gcmax
+            return subprocess.check_output(args, env=env)
+        #
+        for i in range(10):
+            gcmax = random.randrange(50000, 100000)
+            print gcmax
+            res = self.run("limited_memory", -1, runner=myrunner)
+            assert res == 42
+
+    define_limited_memory_linux = define_limited_memory
+
+    def test_limited_memory_linux(self):
+        if not sys.platform.startswith('linux'):
+            py.test.skip("linux only")
+        #
+        import random
+        #
+        def myrunner(args):
+            args1 = ['/bin/bash', '-c', 'ulimit -v %d && %s' %
+                     (ulimitv, ' '.join(args),)]
+            return subprocess.check_output(args1)
+        #
+        for i in range(10):
+            ulimitv = random.randrange(50000, 100000)
+            print ulimitv
+            res = self.run("limited_memory_linux", -1, runner=myrunner)
+            assert res == 42
+
 
 class TestIncrementalMiniMarkGC(TestMiniMarkGC):
     gcpolicy = "incminimark"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to