This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit 0b973727f5407b525899ae2966bb8f5c1ed42625
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 20 01:15:08 2026 -0600
tymuxd: keep the session scrollback in its terminal's store
The daemon kept two rings: a 256-entry termpty ring, to merge wrapped
rows and resize, and the memfd page store its clients map, fed row by
row through the termpty backlog hook. On a resize, termpty took the
wrapped newest entry back from its own ring to wrap it again, but the
page store kept its copy: clients saw the partial line twice. The new
live test (80 -> 40 -> 120 -> 80 columns) read a 200-column line as
280 cells.
The daemon's termpty now makes its store with the memfd backing, sized
to the session's 10000 lines, and PAGE, MAP, NOTIFY, ATTACHED and the
client holds use it. Retraction on resize goes through that one store,
which fixes the duplicate partial line on resize. The hook, its extends
flag and the 256-entry ring are gone. Its view keeps only the head
mapped, and the daemon's 1 s timer follows the head before maintaining
the store, so the pages beyond it are exactly those no client holds.
A clear (CSI 3 J) or RIS in the session now empties its scrollback for
the clients too, as in a normal terminal; the store before this change
ignored them. A live test checks that the old lines are gone, the new
ones arrive, and only the pages the client maps stay raw.
tybenchd -i 5 1000000, median of 5, taskset -c 2-5, interleaved:
before 0.342 / 0.344 / 0.343 s, after 0.339 / 0.346 / 0.339 s.
Daemon VmRSS in kB, tymux new on a pty at 80x24, private
XDG_RUNTIME_DIR, one client, 9 s after the workload, interleaved:
seq 1 10000: before 15712 15840 15744, after 16004 16012 16028
80-column text: before 19016 19140 19028, after 18836 18680 18832
seq grows by about 260 kB: the ring is now as long as the scrollback
(10241 entries of 16 bytes), and the view keeps the widths of the
pages it released. 80-column text shrinks by about 270 kB, as its
rows are no longer kept a second time in the 256-entry ring.
---
src/bin/backlog.c | 10 ++-
src/bin/backlog.h | 8 ++
src/bin/backlog_store.c | 4 +-
src/bin/backlog_store.h | 1 -
src/bin/termd_tymux.c | 75 ++++++----------
src/bin/termd_tymux.h | 6 +-
src/bin/termpty.c | 201 +-----------------------------------------
src/bin/termpty.h | 19 +---
src/bin/tytest.c | 6 +-
src/bin/tytest_tymux.c | 226 ++++++++++++++++++++++++++++++++++++++++++++++++
src/bin/tytest_tymux.h | 2 +
src/bin/unit_tests.h | 4 +-
tests/meson.build | 3 +-
13 files changed, 287 insertions(+), 278 deletions(-)
diff --git a/src/bin/backlog.c b/src/bin/backlog.c
index 0400c3f5..277696dd 100644
--- a/src/bin/backlog.c
+++ b/src/bin/backlog.c
@@ -293,7 +293,8 @@ _backlog_size_set(Termpty *ty, size_t size, uint32_t first_id)
backlog_store_scrollback_set(ty->backlog_store, size);
else
{
- ty->backlog_store = backlog_store_new("termpty", BACKLOG_STORE_ANON,
+ ty->backlog_store = backlog_store_new("termpty",
+ ty->backlog_store_backing,
size);
if (!ty->backlog_store)
{
@@ -322,6 +323,13 @@ termpty_backlog_size_set(Termpty *ty, size_t size)
_backlog_size_set(ty, size, 0);
}
+void
+termpty_backlog_store_backing_set(Termpty *ty, BacklogStoreBacking backing)
+{
+ EINA_SAFETY_ON_TRUE_RETURN(ty->backlog_store != NULL);
+ ty->backlog_store_backing = backing;
+}
+
void
termpty_backlog_external_push(Termpty *ty, Termcell *cells, ssize_t w)
{
diff --git a/src/bin/backlog.h b/src/bin/backlog.h
index da7a8346..fbd1e38f 100644
--- a/src/bin/backlog.h
+++ b/src/bin/backlog.h
@@ -1,6 +1,9 @@
#ifndef TERMINOLOGY_BACKLOG_H_
#define TERMINOLOGY_BACKLOG_H_ 1
+#include "termsrv.h"
+#include "backlog_store.h"
+
void termpty_save_register(Termpty *ty);
void termpty_save_unregister(Termpty *ty);
@@ -14,6 +17,11 @@ termpty_backlog_free(Termpty *ty);
* no store: its ring is sized to size once, and keeps that size. */
void
termpty_backlog_size_set(Termpty *ty, size_t size);
+/* The backing of the store that the next termpty_backlog_size_set() makes,
+ * BACKLOG_STORE_ANON unless set. Call it before the store exists: a store
+ * keeps the backing it was made with. */
+void
+termpty_backlog_store_backing_set(Termpty *ty, BacklogStoreBacking backing);
ssize_t
termpty_backlog_length(Termpty *ty);
diff --git a/src/bin/backlog_store.c b/src/bin/backlog_store.c
index 327f50cc..9f4aeb79 100644
--- a/src/bin/backlog_store.c
+++ b/src/bin/backlog_store.c
@@ -785,7 +785,7 @@ backlog_store_append(BacklogStore *bs, const Termcell *cells, ssize_t w,
TermSrvBacklogPage *head = NULL;
BacklogStorePage *head_page = NULL;
uint32_t n = 0, cur_w, add, first_id;
- Eina_Bool grew = EINA_FALSE, added = EINA_FALSE;
+ Eina_Bool added = EINA_FALSE;
EINA_SAFETY_ON_NULL_RETURN_VAL(bs, EINA_FALSE);
EINA_SAFETY_ON_TRUE_RETURN_VAL(w < 0 || (w > 0 && !cells), EINA_FALSE);
@@ -808,7 +808,6 @@ backlog_store_append(BacklogStore *bs, const Termcell *cells, ssize_t w,
}
if (join && n > 0)
{
- grew = EINA_TRUE;
cur_w = head_page->widths[n - 1];
add = MIN((size_t)w, TERMSRV_BACKLOG_ENTRY_MAX_CELLS - cur_w);
if (add > 0)
@@ -862,7 +861,6 @@ backlog_store_append(BacklogStore *bs, const Termcell *cells, ssize_t w,
saved->cells = (Termcell *)_page_cells(head, bs->geo.header_size) +
bs->head_cells - saved->w;
saved->added = add;
- saved->extended = grew;
saved->pages_changed = added || (first_id != bs->first_id);
}
return EINA_TRUE;
diff --git a/src/bin/backlog_store.h b/src/bin/backlog_store.h
index c279901f..236d1e9d 100644
--- a/src/bin/backlog_store.h
+++ b/src/bin/backlog_store.h
@@ -48,7 +48,6 @@ typedef struct
Termcell *cells; /* the newest entry, in the head */
uint32_t w; /* its width */
uint32_t added; /* the cells of the row it took */
- Eina_Bool extended; /* the row grew the newest entry */
Eina_Bool pages_changed; /* a page was added or evicted */
} BacklogStoreSaved;
diff --git a/src/bin/termd_tymux.c b/src/bin/termd_tymux.c
index 05d0b32a..72b57f18 100644
--- a/src/bin/termd_tymux.c
+++ b/src/bin/termd_tymux.c
@@ -11,7 +11,7 @@
#include "config.h"
#include "termpty.h"
#include "termsrv.h"
-#include "backlog_store.h"
+#include "backlog.h"
#include "termd_tymux.h"
_Static_assert(sizeof(Termcell) == sizeof(TermSrvCell),
@@ -62,7 +62,6 @@ typedef struct
struct tag_TermDTymux
{
Termpty *pty;
- BacklogStore *backlog;
Config *config;
int shm_fd;
TermSrvShmHeader *shm;
@@ -72,7 +71,6 @@ struct tag_TermDTymux
Ecore_Animator *notify_anim;
Ecore_Timer *backlog_timer;
Eina_Bool dirty : 1;
- Eina_Bool backlog_append_failed : 1;
};
static uint64_t
@@ -255,8 +253,8 @@ _flush_and_notify(TermDTymux *td)
td->notify_anim = NULL;
}
- notify.first_page_id = backlog_store_first_id(td->backlog);
- notify.page_count = backlog_store_count(td->backlog);
+ notify.first_page_id = backlog_store_first_id(ty->backlog_store);
+ notify.page_count = backlog_store_count(ty->backlog_store);
EINA_LIST_FOREACH(td->clients, l, client)
_client_pages_prune(client);
@@ -290,26 +288,6 @@ _cb_pty_change(void *data)
td->notify_anim = ecore_animator_add(_cb_notify_anim, td);
}
-/* Called synchronously whenever a line permanently enters the daemon's own
- * backlog (termpty_text_save_top()), i.e. potentially many times between
- * two animator ticks under a flood such as `seq 1 1000000`. The page store
- * is the scrollback clients map; the daemon's termpty only keeps
- * TERMD_TYMUX_PTY_BACKLOG entries, to merge wrapped rows. */
-static void
-_cb_pty_backlog(void *data, Termpty *ty, const Termcell *cells, ssize_t w, Eina_Bool extends)
-{
- TermDTymux *td = data;
-
- if (!backlog_store_append(td->backlog, cells, w,
- extends ? BACKLOG_STORE_EXTEND : BACKLOG_STORE_NEW,
- ty->hl.size != 0, NULL) &&
- !td->backlog_append_failed)
- {
- ERR("cannot store the backlog in pages");
- td->backlog_append_failed = EINA_TRUE;
- }
-}
-
static void
_cb_pty_title(void *data)
{
@@ -369,8 +347,8 @@ _client_attach(Client *client, TermSrvAttachMode mode)
if (termsrv_send_attached(client->fd, td->shm_fd, ty->w, ty->h,
ty->pid > 0 ? ty->pid : -1,
- backlog_store_first_id(td->backlog),
- backlog_store_count(td->backlog)) < 0)
+ backlog_store_first_id(ty->backlog_store),
+ backlog_store_count(ty->backlog_store)) < 0)
{
_client_del(client);
return;
@@ -429,7 +407,7 @@ _client_page_held(const Client *client, uint32_t page_id)
static void
_client_pages_prune(Client *client)
{
- BacklogStore *backlog = client->td->backlog;
+ BacklogStore *backlog = client->td->pty->backlog_store;
uint32_t first = backlog_store_first_id(backlog);
while (client->held_pages &&
@@ -467,15 +445,15 @@ static void
_client_page_send(Client *client, uint32_t page_id)
{
TermSrvMsgBacklogPageId reply = { page_id };
- TermDTymux *td = client->td;
+ BacklogStore *backlog = client->td->pty->backlog_store;
size_t length;
int page_fd;
QueuedFd *queued;
_client_pages_prune(client);
- if (!backlog_store_page_exists(td->backlog, page_id))
+ if (!backlog_store_page_exists(backlog, page_id))
return;
- page_fd = backlog_store_page_fd(td->backlog, page_id);
+ page_fd = backlog_store_page_fd(backlog, page_id);
if (page_fd < 0)
{
_client_page_refuse(client, &reply);
@@ -523,7 +501,7 @@ _client_page_send(Client *client, uint32_t page_id)
client->held_pages = eina_list_sorted_insert(client->held_pages,
_page_id_cmp,
(void *)(uintptr_t)page_id);
- backlog_store_hold(td->backlog, page_id);
+ backlog_store_hold(backlog, page_id);
}
static void
@@ -533,14 +511,14 @@ _client_page_release(Client *client, uint32_t page_id)
return;
client->held_pages = eina_list_remove(client->held_pages,
(void *)(uintptr_t)page_id);
- backlog_store_release(client->td->backlog, page_id);
+ backlog_store_release(client->td->pty->backlog_store, page_id);
}
static void
_client_map_send(Client *client, const TermSrvMsgBacklogMapReq *req)
{
unsigned char buf[TERMSRV_MAX_MSG_PAYLOAD];
- uint32_t len = backlog_store_map_write(client->td->backlog,
+ uint32_t len = backlog_store_map_write(client->td->pty->backlog_store,
req->first_page_id, req->count,
buf, sizeof(buf));
@@ -722,7 +700,10 @@ _cb_backlog_timer(void *data)
{
TermDTymux *td = data;
- backlog_store_maintain(td->backlog, ecore_time_get());
+ /* Nothing reads the daemon's ring between resizes: follow the head here,
+ * so that its view lets go of the heads it left. */
+ termpty_backlog_follow(td->pty);
+ backlog_store_maintain(td->pty->backlog_store, ecore_time_get());
return ECORE_CALLBACK_RENEW;
}
@@ -740,18 +721,8 @@ termd_tymux_new(const char *name, const char *cmd)
td->config = calloc(1, sizeof(Config));
if (!td->config)
goto err;
- td->config->scrollback = TERMD_TYMUX_PTY_BACKLOG;
td->config->term_type = TERM_TYPE_XTERM_256COLOR;
- td->backlog = backlog_store_new(name, BACKLOG_STORE_MEMFD,
- TERMD_TYMUX_SCROLLBACK);
- if (!td->backlog)
- goto err;
- td->backlog_timer = ecore_timer_add(BACKLOG_MAINTAIN_SECONDS,
- _cb_backlog_timer, td);
- if (!td->backlog_timer)
- goto err;
-
snprintf(memfd_name, sizeof(memfd_name), "tymux-%s", name);
td->shm_fd = memfd_create(memfd_name, MFD_CLOEXEC);
if (td->shm_fd < 0)
@@ -786,7 +757,18 @@ termd_tymux_new(const char *name, const char *cmd)
td->pty->cb.bell.data = ""
td->pty->cb.exited.func = _cb_pty_exited;
td->pty->cb.exited.data = ""
- termpty_backlog_hook_set(td->pty, _cb_pty_backlog, td);
+ /* termpty_new() made no store for the scrollback of 0 it was given:
+ * the session's is in memfds, for the clients to map */
+ termpty_backlog_store_backing_set(td->pty, BACKLOG_STORE_MEMFD);
+ td->pty->backlog_head_only = 1;
+ td->config->scrollback = TERMD_TYMUX_SCROLLBACK;
+ termpty_backlog_size_set(td->pty, TERMD_TYMUX_SCROLLBACK);
+ if (!td->pty->backlog_store)
+ goto err;
+ td->backlog_timer = ecore_timer_add(BACKLOG_MAINTAIN_SECONDS,
+ _cb_backlog_timer, td);
+ if (!td->backlog_timer)
+ goto err;
_screen_flush(td);
return td;
@@ -828,7 +810,6 @@ termd_tymux_free(TermDTymux *td)
munmap(td->shm, TERMSRV_SHM_TOTAL_SIZE);
if (td->shm_fd >= 0)
close(td->shm_fd);
- backlog_store_free(td->backlog);
free(td->config);
free(td);
}
diff --git a/src/bin/termd_tymux.h b/src/bin/termd_tymux.h
index 20a3d2eb..c3eaafed 100644
--- a/src/bin/termd_tymux.h
+++ b/src/bin/termd_tymux.h
@@ -3,13 +3,9 @@
typedef struct tag_TermDTymux TermDTymux;
-/* Lines of scrollback the page store keeps for the clients. */
+/* Lines of scrollback the session keeps, in the pages clients map. */
#define TERMD_TYMUX_SCROLLBACK 10000
-/* Entries the daemon's own termpty keeps: enough to merge wrapped rows and
- * to resize its terminal, the pages being the scrollback. */
-#define TERMD_TYMUX_PTY_BACKLOG 256
-
/* Start the shell (cmd, or the user's shell if NULL) on a new pty whose
* screen is published in shared memory. The main loop is quit when the
* shell exits. Returns NULL on failure. */
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 49af9bea..d5a22c77 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -1126,9 +1126,6 @@ termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max)
/* a page sealed may be compressed, even if nothing reads the ring */
if (saved.pages_changed)
termpty_backlog_maintain_wake();
- if (ty->backlog_hook.func)
- ty->backlog_hook.func(ty->backlog_hook.data, ty, cells, w,
- saved.extended);
}
@@ -1358,15 +1355,6 @@ termpty_cell_get(Termpty *ty, int y_requested, int x_requested)
return cells + x_requested;
}
-void
-termpty_backlog_hook_set(Termpty *ty,
- void (*func) (void *data, Termpty *ty, const Termcell *cells, ssize_t w, Eina_Bool extends),
- void *data)
-{
- ty->backlog_hook.func = func;
- ty->backlog_hook.data = ""
-}
-
void
termpty_write_hook_set(Termpty *ty,
Eina_Bool (*func) (void *data, Termpty *ty, const char *input, int len),
@@ -4914,86 +4902,6 @@ _ty_write_hook_capture(void *data, Termpty *ty EINA_UNUSED, const char *input, i
return EINA_TRUE;
}
-typedef struct
-{
- int count;
- Eina_Bool last_extends;
-} Ty_Backlog_Capture;
-
-static void
-_ty_backlog_hook_capture(void *data, Termpty *ty EINA_UNUSED, const Termcell *cells, ssize_t w, Eina_Bool extends)
-{
- Ty_Backlog_Capture *capture = data;
-
- capture->count++;
- capture->last_extends = extends;
- assert(cells);
- assert(w >= 0);
-}
-
-/* Test: termpty_text_save_top() calls the backlog hook exactly once per
- * call that saves a row, whether it starts a new backlog entry or extends
- * the wrapped entry already at its top -- so a caller replaying the hook's
- * calls through termpty_text_save_top() reproduces the same merge. */
-int
-tytest_backlog_hook(void)
-{
- Termpty ty;
- Termcell cells[10];
- Ty_Backlog_Capture capture = { 0, EINA_TRUE };
- int j;
-
- _ty_test_init(&ty, 10, 5);
- termpty_backlog_size_set(&ty, 20);
- memset(cells, 0, sizeof(cells));
- /* a full-width row: termpty_line_length() trims trailing empty cells,
- * so cells[9] (checked below) must be non-empty to count as the last
- * cell of a 10-wide row. */
- for (j = 0; j < 10; j++)
- cells[j].codepoint = 'a';
- /* the row saved by this call ends up at the top of the backlog with its
- * last cell autowrapped, so the *next* save extends it instead of
- * starting a new entry. */
- cells[9].att.autowrapped = 1;
-
- termpty_backlog_hook_set(&ty, _ty_backlog_hook_capture, &capture);
- termpty_text_save_top(&ty, cells, 10);
- assert(capture.count == 1);
- assert(capture.last_extends == EINA_FALSE);
- assert(termpty_backlog_length(&ty) == 1);
-
- /* extends the entry saved above instead of starting a new one --
- * termpty_backlog_length() counts screen rows, and the merged entry now
- * spans two of them, but the hook must still fire, once, for the
- * extension. Its own last cell is not autowrapped, so nothing after it
- * merges further. */
- cells[9].att.autowrapped = 0;
- termpty_text_save_top(&ty, cells, 10);
- assert(capture.count == 2);
- assert(capture.last_extends == EINA_TRUE);
- assert(termpty_backlog_length(&ty) == 2);
-
- termpty_text_save_top(&ty, cells, 10);
- assert(capture.count == 3);
- assert(capture.last_extends == EINA_FALSE);
- assert(termpty_backlog_length(&ty) == 3);
-
- /* a blank row has no cells to report and is reported all the same */
- memset(cells, 0, sizeof(cells));
- termpty_text_save_top(&ty, cells, 10);
- assert(capture.count == 4);
- assert(capture.last_extends == EINA_FALSE);
- assert(termpty_backlog_length(&ty) == 4);
-
- termpty_backlog_hook_set(&ty, NULL, NULL);
- termpty_text_save_top(&ty, cells, 10);
- assert(capture.count == 4);
- assert(termpty_backlog_length(&ty) == 5);
-
- _ty_test_shutdown(&ty);
- return 0;
-}
-
/* Test: an entry wider than the screen, as the line a tymux client
* rebuilds from wire chunks is, is counted by the rows it wraps over by
* termpty_text_save_top() itself, the way termpty_backlog_length() counts
@@ -5470,63 +5378,27 @@ tytest_termpty_store_links(void)
return 0;
}
-/* Test: a logical line spanning several wrapped rows arrives intact on the
- * other end when every hook call is replayed through
- * termpty_text_save_top() again: the hook reports each row (not the merged
- * Termsave), each row at most the screen width wide, so a client rebuilds
- * the exact same merged entry instead of only the first physical row of the
- * wrapped line. A blank row after it is replayed as a blank entry. */
-static void
-_ty_backlog_hook_replay(void *data, Termpty *ty EINA_UNUSED, const Termcell *cells, ssize_t w, Eina_Bool extends EINA_UNUSED)
-{
- Termpty *dst = data;
-
- termpty_text_save_top(dst, (Termcell *)cells, w);
-}
-
-typedef struct
-{
- int new_entries;
- int extensions;
-} Ty_Backlog_Extends_Count;
-
-static void
-_ty_backlog_hook_count_extends(void *data, Termpty *ty EINA_UNUSED, const Termcell *cells EINA_UNUSED, ssize_t w EINA_UNUSED, Eina_Bool extends)
-{
- Ty_Backlog_Extends_Count *count = data;
-
- if (extends)
- count->extensions++;
- else
- count->new_entries++;
-}
-
/* Test: a logical line wrapped over more rows than the backlog ring has
- * entries still merges into one entry, the hook reporting every row after
- * the first as an extension. The daemon of tymux keeps a ring of 256
- * entries and relies on this to feed its page store. */
+ * entries still merges into one entry, as it only ever extends the
+ * newest one. */
int
-tytest_backlog_hook_long_wrap(void)
+tytest_backlog_long_wrap(void)
{
enum { RING = 256, WRAPPED_ROWS = 300 };
Termpty ty_storage, *ty = &ty_storage;
Termcell cells[10];
- Ty_Backlog_Extends_Count count = { 0, 0 };
const Termsave *ts;
int i, j;
_ty_test_init(ty, 10, 5);
termpty_backlog_size_set(ty, RING);
- termpty_backlog_hook_set(ty, _ty_backlog_hook_count_extends, &count);
memset(cells, 0, sizeof(cells));
for (j = 0; j < 10; j++)
cells[j].codepoint = 'a';
for (i = 0; i < RING + 20; i++)
termpty_text_save_top(ty, cells, 10);
- assert(count.new_entries == RING + 20 && count.extensions == 0);
- count.new_entries = 0;
for (i = 0; i < WRAPPED_ROWS; i++)
{
for (j = 0; j < 10; j++)
@@ -5534,8 +5406,6 @@ tytest_backlog_hook_long_wrap(void)
cells[9].att.autowrapped = (i < WRAPPED_ROWS - 1);
termpty_text_save_top(ty, cells, 10);
}
- assert(count.new_entries == 1);
- assert(count.extensions == WRAPPED_ROWS - 1);
termpty_backlog_follow(ty);
ts = BACKLOG_ROW_GET(ty, 1);
@@ -5549,77 +5419,14 @@ tytest_backlog_hook_long_wrap(void)
for (j = 0; j < 10; j++)
cells[j].codepoint = 'z';
termpty_text_save_top(ty, cells, 10);
- assert(count.new_entries == 2);
- assert(count.extensions == WRAPPED_ROWS - 1);
termpty_backlog_follow(ty);
+ assert(BACKLOG_ROW_GET(ty, 1)->w == 10);
assert(BACKLOG_ROW_GET(ty, 2)->w == 10 * WRAPPED_ROWS);
- termpty_backlog_hook_set(ty, NULL, NULL);
_ty_test_shutdown(ty);
return 0;
}
-int
-tytest_backlog_hook_wrap_replay(void)
-{
- Termpty src, dst;
- Termcell cells[10];
- const Termsave *src_ts, *dst_ts;
- int i;
-
- _ty_test_init(&src, 10, 5);
- _ty_test_init(&dst, 10, 5);
- termpty_backlog_size_set(&src, 20);
- termpty_backlog_size_set(&dst, 20);
-
- termpty_backlog_hook_set(&src, _ty_backlog_hook_replay, &dst);
-
- /* three screen-width rows of a single wrapped logical line: the first
- * two carry the autowrap flag on their last cell. */
- for (i = 0; i < 3; i++)
- {
- int j;
-
- memset(cells, 0, sizeof(cells));
- for (j = 0; j < 10; j++)
- cells[j].codepoint = (unsigned int)('0' + i);
- if (i < 2)
- cells[9].att.autowrapped = 1;
- termpty_text_save_top(&src, cells, 10);
- }
-
- /* the whole line merged into one backlog entry on both sides, spanning
- * the three screen-width rows it was made of */
- assert(termpty_backlog_length(&src) == 3);
- assert(termpty_backlog_length(&dst) == 3);
-
- {
- Termpty *ty = &src;
- src_ts = BACKLOG_ROW_GET(ty, 1);
- }
- {
- Termpty *ty = &dst;
- dst_ts = BACKLOG_ROW_GET(ty, 1);
- }
- assert(src_ts->w == 30);
- assert(dst_ts->w == 30);
- for (i = 0; i < 30; i++)
- assert(src_ts->cells[i].codepoint == dst_ts->cells[i].codepoint);
-
- memset(cells, 0, sizeof(cells));
- termpty_text_save_top(&src, cells, 10);
- {
- Termpty *ty = &dst;
- assert(termpty_backlog_length(&dst) == termpty_backlog_length(&src));
- termpty_backlog_follow(ty);
- assert(BACKLOG_ROW_GET(ty, 1)->w == 0);
- }
-
- _ty_test_shutdown(&src);
- _ty_test_shutdown(&dst);
- return 0;
-}
-
/* Test: termpty_write() calls the hook when one is set, instead of
* queuing the data for the real pty fd, and falls through to the real
* pty write buffer once the hook is cleared. */
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index b9fe3bf7..d649e243 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -247,6 +247,8 @@ struct tag_Termpty
size_t backsize, backpos;
/* the scrollback asked for, in lines, which the store rounds up */
size_t backlog_scrollback;
+ /* the BacklogStoreBacking of the store termpty_backlog_size_set() makes */
+ int backlog_store_backing;
/* this beacon in the backlog tells about the top line in screen
* coordinates that maps to a line in the backlog */
Backlog_Beacon backlog_beacon;
@@ -257,10 +259,6 @@ struct tag_Termpty
Eina_Bool (*func) (void *data, Termpty *ty, const char *input, int len);
void *data;
} write_hook;
- struct {
- void (*func) (void *data, Termpty *ty, const Termcell *cells, ssize_t w, Eina_Bool extends);
- void *data;
- } backlog_hook;
struct {
int curid;
Eina_Hash *blocks;
@@ -448,19 +446,6 @@ void termpty_write_hook_set(Termpty *ty,
Eina_Bool (*func) (void *data, Termpty *ty, const char *input, int len),
void *data);
-/* Called every time termpty_text_save_top() saves a row into the backlog,
- * whether it starts a new backlog entry or extends the wrapped entry
- * already at its top. CELLS/W are the row exactly as passed to
- * termpty_text_save_top() (after autowrap marking), not the possibly wider
- * merged Termsave it ends up part of: replaying every call through
- * termpty_text_save_top() again reproduces the same backlog, and each call
- * is at most the screen width wide. EXTENDS tells which of the two it was:
- * EINA_TRUE when the row was merged into the entry already at the top,
- * EINA_FALSE when it started a new entry. A NULL FUNC clears the hook. */
-void termpty_backlog_hook_set(Termpty *ty,
- void (*func) (void *data, Termpty *ty, const Termcell *cells, ssize_t w, Eina_Bool extends),
- void *data);
-
void termpty_resize(Termpty *ty, int new_w, int new_h);
void termpty_resize_tabs(Termpty *ty, int old_w, int new_w);
void termpty_backscroll_adjust(Termpty *ty, int *scroll);
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index e807ff1e..90f1b3ef 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -37,9 +37,7 @@ static struct {
} _tytests[] = {
{ "dummy", tytest_dummy },
{ "write_hook", tytest_write_hook},
- { "backlog_hook", tytest_backlog_hook},
- { "backlog_hook_wrap_replay", tytest_backlog_hook_wrap_replay},
- { "backlog_hook_long_wrap", tytest_backlog_hook_long_wrap},
+ { "backlog_long_wrap", tytest_backlog_long_wrap},
{ "backlog_clear_ids", tytest_backlog_clear_ids},
{ "backlog_view_head_only", tytest_backlog_view_head_only},
{ "backlog_wide_entry_rows", tytest_backlog_wide_entry_rows},
@@ -252,6 +250,8 @@ static const struct {
{ "tymux_live_pages_busy", tytest_tymux_live_pages_busy},
{ "tymux_live_window", tytest_tymux_live_window},
{ "tymux_live_compress", tytest_tymux_live_compress},
+ { "tymux_live_resize_no_dup", tytest_tymux_live_resize_no_dup},
+ { "tymux_live_clear", tytest_tymux_live_clear},
#endif
{ NULL, NULL},
};
diff --git a/src/bin/tytest_tymux.c b/src/bin/tytest_tymux.c
index 51dae5cb..447279b9 100644
--- a/src/bin/tytest_tymux.c
+++ b/src/bin/tytest_tymux.c
@@ -1159,3 +1159,229 @@ tytest_tymux_live_compress(void)
{
return tytest_tymux_live_run(_live_compress_body);
}
+
+#define NO_DUP_WIDE 200
+#define NO_DUP_FIRST 101
+#define NO_DUP_LINES 5
+
+typedef struct
+{
+ Termpty *ty;
+ int cols;
+} Screen_Cols_Wait;
+
+static Eina_Bool
+_screen_cols_done(void *data)
+{
+ Screen_Cols_Wait *wait = data;
+
+ return wait->ty->w == wait->cols && wait->ty->h == SCREEN_ROWS;
+}
+
+static void
+_cells_text_append(Eina_Strbuf *buf, const Termcell *cells, ssize_t w)
+{
+ ssize_t i;
+
+ for (i = 0; i < w; i++)
+ {
+ char utf8[8];
+ Eina_Unicode codepoint = cells[i].codepoint;
+ int len;
+
+ if (codepoint == 0 || (codepoint & 0x80000000)) codepoint = ' ';
+ len = codepoint_to_utf8(codepoint, utf8);
+ eina_strbuf_append_length(buf, utf8, len);
+ }
+}
+
+static Eina_List *
+_lines_end(Eina_List *lines, Eina_Strbuf *line)
+{
+ char *text = eina_strbuf_string_steal(line);
+ size_t len = strlen(text);
+
+ while (len > 0 && text[len - 1] == ' ') len--;
+ text[len] = '\0';
+ return eina_list_append(lines, text);
+}
+
+/* The logical lines of the client of ty, oldest first: its backlog entries
+ * then its screen rows, a row whose last cell wraps joining the next one. */
+static Eina_List *
+_logical_lines(Termpty *ty)
+{
+ Eina_List *lines = NULL;
+ Eina_Strbuf *line = eina_strbuf_new();
+ Eina_Bool wrapped = EINA_FALSE;
+ int y, n = _backlog_entries(ty);
+
+ assert(line);
+ for (y = n; y >= 1; y--)
+ {
+ const Termsave *ts;
+
+ _backlog_entry_show(ty, y);
+ ts = _backlog_row(ty, y);
+ _cells_text_append(line, ts->cells, ts->w);
+ wrapped = ts->w > 0 && ts->cells[ts->w - 1].att.autowrapped;
+ if (!wrapped) lines = _lines_end(lines, line);
+ }
+ for (y = 0; y < ty->h; y++)
+ {
+ const Termcell *cells;
+ ssize_t w = 0;
+
+ cells = termpty_cellrow_get(ty, y, &w);
+ if (!cells) break;
+ _cells_text_append(line, cells, w);
+ wrapped = cells[ty->w - 1].att.autowrapped;
+ if (!wrapped) lines = _lines_end(lines, line);
+ }
+ if (wrapped) lines = _lines_end(lines, line);
+ eina_strbuf_free(line);
+ return lines;
+}
+
+/* The wide line, then each number, appear exactly once, in that order */
+static Eina_Bool
+_no_dup_done(void *data)
+{
+ Termpty *ty = data;
+ Eina_List *lines = _logical_lines(ty), *l;
+ char expected[NO_DUP_LINES + 1][NO_DUP_WIDE + 1];
+ int k, last = -1;
+ Eina_Bool ok = EINA_TRUE;
+ char *text;
+
+ memset(expected[0], '0', NO_DUP_WIDE - 1);
+ expected[0][NO_DUP_WIDE - 1] = '7';
+ expected[0][NO_DUP_WIDE] = '\0';
+ for (k = 1; k <= NO_DUP_LINES; k++)
+ snprintf(expected[k], sizeof(expected[k]), "%d", NO_DUP_FIRST + k - 1);
+ for (k = 0; k <= NO_DUP_LINES && ok; k++)
+ {
+ int i = 0, found = -1, count = 0;
+
+ EINA_LIST_FOREACH(lines, l, text)
+ {
+ if (!strcmp(text, expected[k]))
+ {
+ count++;
+ found = i;
+ }
+ i++;
+ }
+ ok = count == 1 && found > last;
+ last = found;
+ }
+ EINA_LIST_FREE(lines, text)
+ free(text);
+ return ok;
+}
+
+/* A resize takes the wrapped newest backlog entry back to wrap it again:
+ * the clients must not see it twice. */
+static int
+_live_resize_no_dup_body(void)
+{
+ static const int widths[] = { 40, 120, 80 };
+ TermTymux *ts;
+ Termpty *ty;
+ Screen_Cols_Wait wait;
+ unsigned int i;
+
+ assert(tytest_tymux_start(SESSION, 80, 24, &ts, &ty));
+ termtymux_resize(ts, 80, SCREEN_ROWS);
+ assert(tytest_tymux_wait(_screen_rows_done, ty, 5.0));
+ assert(tytest_tymux_wait(_prompt_done, ty, 5.0));
+ assert(tytest_tymux_type(ts, ty, "printf '%0200d\\n' 7; seq 101 105\n"));
+ assert(tytest_tymux_wait(_prompt_done, ty, 5.0));
+ assert(tytest_tymux_wait(_no_dup_done, ty, 5.0));
+
+ wait.ty = ty;
+ for (i = 0; i < EINA_C_ARRAY_LENGTH(widths); i++)
+ {
+ wait.cols = widths[i];
+ termtymux_resize(ts, widths[i], SCREEN_ROWS);
+ assert(tytest_tymux_wait(_screen_cols_done, &wait, 5.0));
+ assert(tytest_tymux_wait(_prompt_done, ty, 5.0));
+ }
+ assert(tytest_tymux_wait(_no_dup_done, ty, 5.0));
+
+ tytest_tymux_stop(ts);
+ return 0;
+}
+
+int
+tytest_tymux_live_resize_no_dup(void)
+{
+ return tytest_tymux_live_run(_live_resize_no_dup_body);
+}
+
+#define CLEAR_FIRST 5001
+#define CLEAR_LAST 11000
+#define RESET_FIRST 7001
+
+static Eina_Bool
+_reset_done(void *data)
+{
+ return _backlog_find(data, "7010") != 0;
+}
+
+/* CSI 3 J, then RIS, empty the session's scrollback: the client sees the
+ * old pages evicted, as the new store goes on from their ids, and only the
+ * pages it holds stay raw in the daemon, none held for a page that went. */
+static int
+_live_clear_body(void)
+{
+ TermTymux *ts;
+ Termpty *ty;
+ Compress_Wait wait;
+ char last[256];
+ uint32_t head_id;
+
+ assert(tytest_tymux_start(SESSION, 80, 24, &ts, &ty));
+ termpty_backlog_viewport_set(ts->shadow_pty, 0);
+ termtymux_resize(ts, 80, SCREEN_ROWS);
+ assert(tytest_tymux_wait(_screen_rows_done, ty, 5.0));
+ assert(tytest_tymux_wait(_prompt_done, ty, 5.0));
+ assert(tytest_tymux_type(ts, ty, "seq 1 3000\n"));
+ assert(tytest_tymux_wait(_seq_done, ty, 20.0));
+ head_id = ts->view->pages[ts->view->pages_count - 1].id;
+
+ assert(tytest_tymux_type(ts, ty, "printf '\\033[3J'; seq -f '%g"
+ COMPRESS_PAD "' 5001 11000; echo " WINDOW_MARKER
+ "; seq 1 30\n"));
+ assert(tytest_tymux_wait(_window_marker_done, ty, 30.0));
+ assert(ts->view->pages[0].id > head_id);
+ assert(ts->view->pages_count >
+ BACKLOG_KEEP_BEHIND + BACKLOG_RELEASE_HYSTERESIS);
+ termpty_backlog_viewport_set(ts->shadow_pty, 0);
+ assert(tytest_tymux_wait(_window_bottom_done, ts, 10.0));
+ wait.ts = ts;
+ assert(tytest_tymux_wait(_compress_memfds_done, &wait, 30.0));
+
+ termpty_backlog_viewport_set(ts->shadow_pty, termpty_backlog_length(ty));
+ assert(_backlog_run_padded(ty, CLEAR_LAST, COMPRESS_PAD) ==
+ CLEAR_LAST - CLEAR_FIRST + 1);
+ assert(_backlog_find(ty, "1500") == 0);
+
+ head_id = ts->view->pages[ts->view->pages_count - 1].id;
+ termpty_backlog_viewport_set(ts->shadow_pty, 0);
+ assert(tytest_tymux_type(ts, ty, "printf '\\033c'; seq 7001 7030\n"));
+ assert(tytest_tymux_wait(_reset_done, ty, 10.0));
+ assert(ts->view->pages[0].id > head_id);
+ snprintf(last, sizeof(last), "%d" COMPRESS_PAD, CLEAR_LAST);
+ assert(_backlog_find(ty, last) == 0);
+ assert(_backlog_run(ty, RESET_FIRST + 9) >= 9);
+
+ tytest_tymux_stop(ts);
+ return 0;
+}
+
+int
+tytest_tymux_live_clear(void)
+{
+ return tytest_tymux_live_run(_live_clear_body);
+}
diff --git a/src/bin/tytest_tymux.h b/src/bin/tytest_tymux.h
index 8f938892..c9152c25 100644
--- a/src/bin/tytest_tymux.h
+++ b/src/bin/tytest_tymux.h
@@ -49,5 +49,7 @@ int tytest_tymux_live_pages(void);
int tytest_tymux_live_pages_busy(void);
int tytest_tymux_live_window(void);
int tytest_tymux_live_compress(void);
+int tytest_tymux_live_resize_no_dup(void);
+int tytest_tymux_live_clear(void);
#endif
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 78dccfe6..56d5ff8f 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -7,9 +7,7 @@ typedef int (*tytest_func)(void);
/* list of tests */
int tytest_dummy(void);
int tytest_write_hook(void);
-int tytest_backlog_hook(void);
-int tytest_backlog_hook_wrap_replay(void);
-int tytest_backlog_hook_long_wrap(void);
+int tytest_backlog_long_wrap(void);
int tytest_backlog_clear_ids(void);
int tytest_backlog_view_head_only(void);
int tytest_backlog_wide_entry_rows(void);
diff --git a/tests/meson.build b/tests/meson.build
index e4dbda62..3b18d3e5 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -102,7 +102,8 @@ if tests
tytest,
args: ['tymux_live_backlog', 'tymux_live_pages',
'tymux_live_pages_busy', 'tymux_live_window',
- 'tymux_live_compress'],
+ 'tymux_live_compress', 'tymux_live_resize_no_dup',
+ 'tymux_live_clear'],
depends: [tymuxd],
timeout: 120)
endif
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.