[pypy-svn] r45466 - pypy/dist/pypy/translator/sandbox/test

arigo at codespeak.net arigo at codespeak.net
Thu Aug 2 19:55:09 CEST 2007


Author: arigo
Date: Thu Aug  2 19:55:09 2007
New Revision: 45466

Modified:
   pypy/dist/pypy/translator/sandbox/test/test_sandlib.py
Log:
A test just for fun: the sandboxed process calls the external function
foobar().  Clearly, translating code using foobar() only works when
sandboxing.


Modified: pypy/dist/pypy/translator/sandbox/test/test_sandlib.py
==============================================================================
--- pypy/dist/pypy/translator/sandbox/test/test_sandlib.py	(original)
+++ pypy/dist/pypy/translator/sandbox/test/test_sandlib.py	Thu Aug  2 19:55:09 2007
@@ -1,5 +1,6 @@
 import os, StringIO
 from pypy.tool.sourcetools import func_with_new_name
+from pypy.rpython.lltypesystem import rffi
 from pypy.translator.sandbox.sandlib import SandboxedProc
 from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc
 from pypy.translator.interactive import Translation
@@ -26,6 +27,10 @@
     do_read  = _make_method("read")
     do_write = _make_method("write")
     do_close = _make_method("close")
+    do_foobar = _make_method("foobar")
+
+    TYPES = SandboxedProc.TYPES.copy()
+    TYPES["foobar"] = "s", "i"
 
 
 def test_lib():
@@ -56,6 +61,22 @@
     proc.handle_forever()
     assert proc.seen == len(proc.expected)
 
+def test_foobar():
+    foobar = rffi.llexternal("foobar", [rffi.CCHARP], rffi.LONG)
+    def entry_point(argv):
+        s = rffi.str2charp(argv[1]); n = foobar(s); rffi.free_charp(s)
+        s = rffi.str2charp(argv[n]); n = foobar(s); rffi.free_charp(s)
+        return n
+    t = Translation(entry_point, backend='c', standalone=True, sandbox=True)
+    exe = t.compile()
+
+    proc = MySandboxedProc([exe, 'spam', 'egg'], expected = [
+        ("foobar", ("spam",), 2),
+        ("foobar", ("egg",), 0),
+        ])
+    proc.handle_forever()
+    assert proc.seen == len(proc.expected)
+
 def test_simpleio():
     def entry_point(argv):
         print "Please enter a number:"



More information about the Pypy-commit mailing list