[pypy-commit] pypy reverse-debugger: First I/O test passes again
arigo
pypy.commits at gmail.com
Fri Jun 17 15:56:59 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: reverse-debugger
Changeset: r85218:9d04b62f7fde
Date: 2016-06-17 21:57 +0200
http://bitbucket.org/pypy/pypy/changeset/9d04b62f7fde/
Log: First I/O test passes again
diff --git a/rpython/rtyper/lltypesystem/lloperation.py b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -569,9 +569,7 @@
'revdb_send_answer': LLOp(),
'revdb_change_time': LLOp(),
'revdb_get_value': LLOp(sideeffects=False),
- ## 'revdb_set_value': LLOp(),
- ## 'revdb_identityhash': LLOp(),
- ## 'revdb_get_unique_id': LLOp(sideeffects=False),
+ 'revdb_get_unique_id': LLOp(sideeffects=False),
## 'revdb_track_object': LLOp(),
}
# ***** Run test_lloperation after changes. *****
diff --git a/rpython/translator/revdb/ancillary.py b/rpython/translator/revdb/ancillary.py
new file mode 100644
--- /dev/null
+++ b/rpython/translator/revdb/ancillary.py
@@ -0,0 +1,53 @@
+import os, sys
+from rpython.tool.udir import udir
+
+
+def build(tmpdir):
+ import cffi
+ ffibuilder = cffi.FFI()
+
+ ffibuilder.cdef("""
+ int ancil_send_fds(int, const int *, unsigned);
+ int ancil_recv_fds(int, int *, unsigned);
+ """)
+
+ local_dir = os.path.dirname(os.path.abspath(__file__))
+ src_dir = os.path.join(local_dir, 'src-revdb')
+
+ ffibuilder.set_source("_ancillary_cffi", """
+ #include <ancillary.h>
+ """, include_dirs=[src_dir],
+ sources=[os.path.join(src_dir, 'fd_send.c'),
+ os.path.join(src_dir, 'fd_recv.c')])
+
+ ffibuilder.compile(tmpdir=tmpdir, verbose=True)
+
+def import_():
+ tmpdir = str(udir.ensure('ancillary', dir=1))
+ old_sys_path = sys.path[:]
+ sys.path.insert(0, tmpdir)
+ try:
+ import _ancillary_cffi
+ except ImportError:
+ build(tmpdir)
+ import _ancillary_cffi
+ sys.path[:] = old_sys_path
+ return _ancillary_cffi.ffi, _ancillary_cffi.lib
+
+
+def send_fds(pipe_num, fd_list):
+ ffi, lib = import_()
+ if lib.ancil_send_fds(pipe_num, fd_list, len(fd_list)) < 0:
+ raise OSError(ffi.errno, "ancil_send_fds() failed")
+
+def recv_fds(pipe_num, fd_count):
+ ffi, lib = import_()
+ p = ffi.new("int[]", fd_count)
+ result = lib.ancil_recv_fds(pipe_num, p, fd_count)
+ if result < 0:
+ raise OSError(ffi.errno, "ancil_recv_fds() failed")
+ return [p[i] for i in xrange(result)]
+
+
+if __name__ == '__main__':
+ import_()
diff --git a/rpython/translator/revdb/revmsg.py b/rpython/translator/revdb/revmsg.py
new file mode 100644
--- /dev/null
+++ b/rpython/translator/revdb/revmsg.py
@@ -0,0 +1,62 @@
+import struct
+
+
+INIT_VERSION_NUMBER = 0xd80100
+
+CMD_FORK = -1
+CMD_QUIT = -2
+CMD_FORWARD = -3
+
+ANSWER_INIT = -20
+ANSWER_STD = -21
+ANSWER_FORKED = -22
+ANSWER_AT_END = -23
+
+
+class Message(object):
+ def __init__(self, cmd, arg1=0, arg2=0, arg3=0, extra=""):
+ self.cmd = cmd
+ self.arg1 = arg1
+ self.arg2 = arg2
+ self.arg3 = arg3
+ self.extra = extra
+
+ def __eq__(self, other):
+ return (self.cmd == other.cmd and
+ self.arg1 == other.arg1 and
+ self.arg2 == other.arg2 and
+ self.arg3 == other.arg3 and
+ self.extra == other.extra)
+
+ def __ne__(self, other):
+ return not (self == other)
+
+
+class ReplayProcess(object):
+ def __init__(self, stdin, stdout):
+ self.stdin = stdin
+ self.stdout = stdout
+
+ def send(self, msg):
+ binary = struct.pack("iLqqq", msg.cmd, len(msg.extra),
+ msg.arg1, msg.arg2, msg.arg3)
+ self.stdin.write(binary + msg.extra)
+
+ def recv(self):
+ binary = self.stdout.read(struct.calcsize("iLqqq"))
+ cmd, size, arg1, arg2, arg3 = struct.unpack("iLqqq", binary)
+ extra = self.stdout.read(size) if size > 0 else ""
+ return Message(cmd, arg1, arg2, arg3, extra)
+
+ def expect(self, cmd, arg1=0, arg2=0, arg3=0, extra=""):
+ msg = self.recv()
+ assert msg.cmd == cmd
+ if arg1 is not Ellipsis:
+ assert msg.arg1 == arg1
+ if arg2 is not Ellipsis:
+ assert msg.arg2 == arg2
+ if arg3 is not Ellipsis:
+ assert msg.arg3 == arg3
+ if extra is not Ellipsis:
+ assert msg.extra == extra
+ return msg
diff --git a/rpython/translator/revdb/src-revdb/fd_send.c b/rpython/translator/revdb/src-revdb/fd_send.c
new file mode 100644
--- /dev/null
+++ b/rpython/translator/revdb/src-revdb/fd_send.c
@@ -0,0 +1,92 @@
+/***************************************************************************
+ * libancillary - black magic on Unix domain sockets
+ * (C) Nicolas George
+ * fd_send.c - sending file descriptors
+ ***************************************************************************/
+
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _XPG4_2 /* Solaris sucks */
+# define _XPG4_2
+#endif
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <assert.h>
+#if defined(__FreeBSD__)
+# include <sys/param.h> /* FreeBSD sucks */
+#endif
+
+#include "ancillary.h"
+
+int
+ancil_send_fds_with_buffer(int sock, const int *fds, unsigned n_fds, void *buffer)
+{
+ struct msghdr msghdr;
+ char nothing = '!';
+ struct iovec nothing_ptr;
+ struct cmsghdr *cmsg;
+ int i;
+
+ nothing_ptr.iov_base = ¬hing;
+ nothing_ptr.iov_len = 1;
+ msghdr.msg_name = NULL;
+ msghdr.msg_namelen = 0;
+ msghdr.msg_iov = ¬hing_ptr;
+ msghdr.msg_iovlen = 1;
+ msghdr.msg_flags = 0;
+ msghdr.msg_control = buffer;
+ msghdr.msg_controllen = sizeof(struct cmsghdr) + sizeof(int) * n_fds;
+ cmsg = CMSG_FIRSTHDR(&msghdr);
+ cmsg->cmsg_len = msghdr.msg_controllen;
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ for(i = 0; i < n_fds; i++)
+ ((int *)CMSG_DATA(cmsg))[i] = fds[i];
+ return(sendmsg(sock, &msghdr, 0) >= 0 ? 0 : -1);
+}
+
+#ifndef SPARE_SEND_FDS
+int
+ancil_send_fds(int sock, const int *fds, unsigned n_fds)
+{
+ ANCIL_FD_BUFFER(ANCIL_MAX_N_FDS) buffer;
+
+ assert(n_fds <= ANCIL_MAX_N_FDS);
+ return(ancil_send_fds_with_buffer(sock, fds, n_fds, &buffer));
+}
+#endif /* SPARE_SEND_FDS */
+
+#ifndef SPARE_SEND_FD
+int
+ancil_send_fd(int sock, int fd)
+{
+ ANCIL_FD_BUFFER(1) buffer;
+
+ return(ancil_send_fds_with_buffer(sock, &fd, 1, &buffer));
+}
+#endif /* SPARE_SEND_FD */
diff --git a/rpython/translator/revdb/src-revdb/revdb.c b/rpython/translator/revdb/src-revdb/revdb.c
--- a/rpython/translator/revdb/src-revdb/revdb.c
+++ b/rpython/translator/revdb/src-revdb/revdb.c
@@ -529,12 +529,11 @@
static void command_forward(rpy_revdb_command_t *cmd)
{
- if (cmd->arg1 < rpy_revdb.stop_point_seen) {
- fprintf(stderr, "CMD_FORWARD: target time %lld < current time %lld\n",
- (long long)cmd->arg1, (long long)rpy_revdb.stop_point_seen);
+ if (cmd->arg1 < 0) {
+ fprintf(stderr, "CMD_FORWARD: negative step\n");
exit(1);
}
- rpy_revdb.stop_point_break = cmd->arg1;
+ rpy_revdb.stop_point_break = stopped_time + cmd->arg1;
pending_after_forward = &answer_std;
}
diff --git a/rpython/translator/revdb/test/test_basic.py b/rpython/translator/revdb/test/test_basic.py
--- a/rpython/translator/revdb/test/test_basic.py
+++ b/rpython/translator/revdb/test/test_basic.py
@@ -1,5 +1,5 @@
import py
-import os, sys
+import os, sys, subprocess
import re, array, struct
from rpython.tool.udir import udir
from rpython.translator.interactive import Translation
@@ -8,11 +8,8 @@
from rpython.rlib.rarithmetic import intmask
from rpython.rtyper.annlowlevel import cast_gcref_to_instance
from rpython.rtyper.lltypesystem import lltype, llmemory
-"""
-These tests require pexpect (UNIX-only).
-http://pexpect.sourceforge.net/
-"""
-import pexpect
+
+from rpython.translator.revdb.revmsg import *
class RDB(object):
@@ -211,19 +208,18 @@
assert rdb.done()
+
+
+
+
class InteractiveTests(object):
- EOF = pexpect.EOF
- def replay(self, **kwds):
- kwds.setdefault('timeout', 10)
- child = pexpect.spawn(str(self.exename),
- ['--revdb-replay', str(self.rdbname)], **kwds)
- child.logfile = sys.stdout
- def expectx(s):
- child.expect(re.escape(s))
- assert not hasattr(child, 'expectx')
- child.expectx = expectx
- return child
+ def replay(self):
+ child = subprocess.Popen(
+ [str(self.exename), '--revdb-replay', str(self.rdbname)],
+ stdin = subprocess.PIPE,
+ stdout = subprocess.PIPE)
+ return ReplayProcess(child.stdin, child.stdout)
class TestSimpleInterpreter(InteractiveTests):
@@ -246,14 +242,12 @@
def test_go(self):
child = self.replay()
- child.expectx('stop_points=3\r\n'
- '(3)$ ')
- child.sendline('__go 1')
- child.expectx('(1)$ ')
- child.sendline('')
- child.expectx('(1)$ ')
- child.sendline('__go 52')
- child.expectx('(3)$ ')
+ child.expect(ANSWER_INIT, INIT_VERSION_NUMBER, 3)
+ child.expect(ANSWER_STD, 1, Ellipsis)
+ child.send(Message(CMD_FORWARD, 2))
+ child.expect(ANSWER_STD, 3, Ellipsis)
+ child.send(Message(CMD_FORWARD, 2))
+ child.expect(ANSWER_AT_END)
def test_help(self):
child = self.replay()
More information about the pypy-commit
mailing list