summaryrefslogtreecommitdiff
path: root/tests/snapshot_scroll_arena_test.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 11:31:50 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 11:31:50 +0300
commitacd338ea33de36d223cc6d301712eed4a9501e6c (patch)
treed93c46a97e2ed4e8a86e3402de5f847cdc144ec8 /tests/snapshot_scroll_arena_test.c
parentf97c3a585e2efc1d0a4bc10e6ac04b96ee6428ea (diff)
Fix snapshot storage and allocation failure correctness
Account for cluster records discarded by snapshot scrolling, propagate snapshot allocation failures with an empty retryable view, and allocate resized screens before mutating visible state. Add bounded-memory and allocation-failure regressions, and update the saved diagnostic and audit report.
Diffstat (limited to 'tests/snapshot_scroll_arena_test.c')
-rw-r--r--tests/snapshot_scroll_arena_test.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/snapshot_scroll_arena_test.c b/tests/snapshot_scroll_arena_test.c
new file mode 100644
index 0000000..7da6507
--- /dev/null
+++ b/tests/snapshot_scroll_arena_test.c
@@ -0,0 +1,29 @@
+/* Include snapshot.c to inspect its private arena accounting. The static
+ * library supplies the terminal implementation; this translation unit's
+ * snapshot symbols satisfy the test's references before the archive is read.
+ */
+#include <assert.h>
+#include "../src/snapshot.c"
+
+int main(void)
+{
+ struct term_options options = { .size = { 8, 24 }, .scrollback = 5 };
+ struct term *t = term_new(&options);
+ struct term_snapshot *s = term_snapshot_new();
+ assert(t && s && term_snapshot_update(s, t));
+
+ const char line[] = "e\xcc\x81\r\n";
+ for (int i = 0; i < 10000; i++) {
+ term_feed(t, line, sizeof(line) - 1, 0);
+ assert(term_snapshot_update(s, t));
+ }
+
+ /* A fixed viewport holds fewer than 24 * 8 cluster records at once.
+ * Dead records are compacted before they can dominate this arena. */
+ assert(term_history_rows(t) == 5);
+ assert(s->arena_len < 8192);
+
+ term_snapshot_free(s);
+ term_free(t);
+ return 0;
+}