Author: Armin Rigo <[email protected]>
Branch: sandbox-2
Changeset: r97089:1296060ecad0
Date: 2019-08-07 18:24 +0200
http://bitbucket.org/pypy/pypy/changeset/1296060ecad0/
Log: in-progress: fixing the tests
diff --git a/rpython/translator/sandbox/sandboxio.py
b/rpython/translator/sandbox/sandboxio.py
--- a/rpython/translator/sandbox/sandboxio.py
+++ b/rpython/translator/sandbox/sandboxio.py
@@ -110,6 +110,12 @@
length = _unpack_one_ptr(self._read(_ptr_size))[0]
return self._read(length)
+ def write_buffer(self, ptr, bytes_data):
+ g = self.child_stdin
+ g.write("W" + _pack_two_ptrs(ptr.addr, len(bytes_data)))
+ g.write(bytes_data)
+ # g.flush() not necessary here
+
def write_result(self, result):
g = self.child_stdin
if result is None:
diff --git a/rpython/translator/sandbox/test/test_sandbox.py
b/rpython/translator/sandbox/test/test_sandboxio.py
rename from rpython/translator/sandbox/test/test_sandbox.py
rename to rpython/translator/sandbox/test/test_sandboxio.py
--- a/rpython/translator/sandbox/test/test_sandbox.py
+++ b/rpython/translator/sandbox/test/test_sandboxio.py
@@ -23,6 +23,14 @@
signal.alarm(0)
signal.signal(signal.SIGALRM, signal.SIG_DFL)
+class OUT(object):
+ def __init__(self, raw):
+ self.raw = raw
+
+class RAW(object):
+ def __init__(self, raw):
+ self.raw = raw
+
_NO_RESULT = object()
def expect(sandio, fnname, expected_args, result=_NO_RESULT):
@@ -34,11 +42,23 @@
assert type(arg) is Ptr
arg_str = sandio.read_charp(arg, len(expected_arg) + 100)
assert arg_str == expected_arg
+ elif type(expected_arg) is OUT:
+ assert type(arg) is Ptr
+ sandio.write_buffer(arg, expected_arg.raw)
+ elif type(expected_arg) is RAW:
+ assert type(arg) is Ptr
+ arg_str = sandio.read_buffer(arg, len(expected_arg.raw))
+ assert arg_str == expected_arg.raw
else:
assert arg == expected_arg
if result is not _NO_RESULT:
sandio.write_result(result)
+def expect_done(sandio):
+ with py.test.raises(EOFError):
+ sandio.read_message()
+ sandio.close()
+
def compile(f, gc='ref', **kwds):
t = Translation(f, backend='c', sandbox=True, gc=gc,
check_str_without_nul=True, **kwds)
@@ -62,9 +82,7 @@
sandio = run_in_subprocess(exe)
expect(sandio, "open(pii)i", ("/tmp/foobar", os.O_RDONLY, 0777), 77)
expect(sandio, "dup(i)i", (77,), 78)
- with py.test.raises(EOFError):
- sandio.read_message()
- sandio.close()
+ expect_done(sandio)
def test_open_dup_rposix():
from rpython.rlib import rposix
@@ -78,10 +96,8 @@
exe = compile(entry_point)
sandio = run_in_subprocess(exe)
expect(sandio, "open(pii)i", ("/tmp/foobar", os.O_RDONLY, 0777), 77)
- expect(sandio, "dup(i)i", (77, True), 78)
- with py.test.raises(EOFError):
- sandio.read_message()
- sandio.close()
+ expect(sandio, "dup(i)i", (77,), 78)
+ expect_done(sandio)
def test_read_write():
def entry_point(argv):
@@ -95,15 +111,13 @@
return 0
exe = compile(entry_point)
- g, f = run_in_subprocess(exe)
- expect(f, g, "ll_os.ll_os_open", ("/tmp/foobar", os.O_RDONLY, 0777), 77)
- expect(f, g, "ll_os.ll_os_read", (77, 123), "he\x00llo")
- expect(f, g, "ll_os.ll_os_write", (77, "world\x00!\x00"), 42)
- expect(f, g, "ll_os.ll_os_close", (77,), None)
- g.close()
- tail = f.read()
- f.close()
- assert tail == ""
+ sandio = run_in_subprocess(exe)
+ expect(sandio, "open(pii)i", ("/tmp/foobar", os.O_RDONLY, 0777), 77)
+ expect(sandio, "read(ipi)i", (77, OUT("he\x00llo"), 123), len("he\x00llo"))
+ sz = len("world\x00!\x00")
+ expect(sandio, "write(ipi)i", (77, RAW("world\x00!\x00"), sz), 42)
+ expect(sandio, "close(i)i", (77,), 0)
+ expect_done(sandio)
def test_dup2_access():
def entry_point(argv):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit