Separate test of write and read so we can test threading

This commit is contained in:
Kovid Goyal 2023-11-05 11:22:39 +05:30
parent 34164dc341
commit afcffc03b1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 33 additions and 22 deletions

View File

@ -4441,29 +4441,35 @@ WRAP0(bell)
#define MODEFUNC(name) MND(name, METH_NOARGS) MND(set_##name, METH_O) #define MODEFUNC(name) MND(name, METH_NOARGS) MND(set_##name, METH_O)
static PyObject* static PyObject*
test_write_data(Screen *screen, PyObject *args) { test_create_write_buffer(Screen *screen UNUSED, PyObject *args UNUSED) {
const uint8_t *data; Py_ssize_t sz; size_t s;
PyObject *dump_callback = NULL; uint8_t *buf = vt_parser_create_write_buffer(screen->vt_parser, &s);
if (!PyArg_ParseTuple(args, "y#|O", &data, &sz, &dump_callback)) return NULL; return PyMemoryView_FromMemory((char*)buf, s, PyBUF_WRITE);
}
monotonic_t now = monotonic(); static PyObject*
while (sz) { test_commit_write_buffer(Screen *screen, PyObject *args) {
size_t s; RAII_PY_BUFFER(srcbuf); RAII_PY_BUFFER(destbuf);
uint8_t *buf = vt_parser_create_write_buffer(screen->vt_parser, &s); if (!PyArg_ParseTuple(args, "y*y*", &srcbuf, &destbuf)) return NULL;
s = MIN(s, (size_t)sz); size_t s = MIN(srcbuf.len, destbuf.len);
memcpy(buf, data, s); memcpy(destbuf.buf, srcbuf.buf, s);
vt_parser_commit_write(screen->vt_parser, s); vt_parser_commit_write(screen->vt_parser, s);
data += s; sz -= s; return PyLong_FromSize_t(s);
ParseData pd = {.dump_callback=dump_callback,.now=now}; }
if (dump_callback) parse_worker_dump(screen, &pd, true);
else parse_worker(screen, &pd, true); static PyObject*
} test_parse_written_data(Screen *screen, PyObject *args) {
ParseData pd = {.now=monotonic()};
if (!PyArg_ParseTuple(args, "|O", &pd.dump_callback)) return NULL;
if (pd.dump_callback && pd.dump_callback != Py_None) parse_worker_dump(screen, &pd, true);
else parse_worker(screen, &pd, true);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyMethodDef methods[] = { static PyMethodDef methods[] = {
METHODB(test_write_data, METH_VARARGS), METHODB(test_create_write_buffer, METH_NOARGS),
METHODB(test_commit_write_buffer, METH_VARARGS),
METHODB(test_parse_written_data, METH_VARARGS),
MND(line_edge_colors, METH_NOARGS) MND(line_edge_colors, METH_NOARGS)
MND(line, METH_O) MND(line, METH_O)
MND(dump_lines_with_attrs, METH_O) MND(dump_lines_with_attrs, METH_O)

View File

@ -24,8 +24,13 @@ from kitty.utils import read_screen_size
from kitty.window import process_remote_print, process_title_from_child from kitty.window import process_remote_print, process_title_from_child
def parse_bytes(screen, data): def parse_bytes(screen, data, dump_callback=None):
return screen.test_write_data(data) data = memoryview(data)
while data:
dest = screen.test_create_write_buffer()
s = screen.test_commit_write_buffer(data, dest)
data = data[s:]
screen.test_parse_written_data(dump_callback)
class Callbacks: class Callbacks:
@ -324,7 +329,7 @@ class PTY:
break break
bytes_read += len(data) bytes_read += len(data)
self.received_bytes += data self.received_bytes += data
self.screen.test_write_data(data) parse_bytes(self.screen, data)
return bytes_read return bytes_read
def wait_till(self, q, timeout=10): def wait_till(self, q, timeout=10):

View File

@ -37,7 +37,7 @@ class TestParser(BaseTest):
if isinstance(x, str): if isinstance(x, str):
x = x.encode('utf-8') x = x.encode('utf-8')
cmds = tuple(('draw', x) if isinstance(x, str) else tuple(map(cnv, x)) for x in cmds) cmds = tuple(('draw', x) if isinstance(x, str) else tuple(map(cnv, x)) for x in cmds)
s.test_write_data(x, cd) parse_bytes(s, x, cd)
current = '' current = ''
q = [] q = []
for args in cd: for args in cd: