Skip to content

Add a method for Robolectric host testing#199

Open
kruton wants to merge 5 commits into
connectbot:mainfrom
kruton:wasm-libvterm
Open

Add a method for Robolectric host testing#199
kruton wants to merge 5 commits into
connectbot:mainfrom
kruton:wasm-libvterm

Conversation

@kruton
Copy link
Copy Markdown
Member

@kruton kruton commented Apr 25, 2026

This uses Chicory to compile the libvterm library into a .wasm file and interpret it during runtime.

kruton added 3 commits April 25, 2026 11:24
Move the native library to its own location so we can make a separate
implementation that uses WASM. It will be slower than native, but will
help with host-based testing.
Add a WebAssembly based backend that is more portable than the native
library. It works by using Chicory which can use wasm bytecode directly
in the JVM.
Determine how much slower the wasm backend from the native code.
Copilot AI review requested due to automatic review settings April 25, 2026 19:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a WASM-based libvterm backend (via Chicory + wasm2class) and a Robolectric shadow to enable host JVM/Robolectric testing without requiring a host JNI library, while also modularizing the codebase into interface/native/wasm subprojects and adding benchmarks.

Changes:

  • Split code into new Gradle modules (lib-intf, lib-native, lib-wasm) and wire them into the build.
  • Add a Robolectric shadow (ShadowTerminalNative) backed by TerminalWasm plus a small WASM backend test suite.
  • Add JNI-side damage batching support to reduce per-rect JNI call overhead, and add JMH benchmarks.

Reviewed changes

Copilot reviewed 25 out of 98 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
settings.gradle.kts Includes new subprojects (lib-intf, lib-native, lib-wasm, benchmark).
lib/src/test/java/org/connectbot/terminal/ReviewModeTest.kt Updates Compose UI test rule import to junit4 v2 API.
lib/src/test/java/org/connectbot/terminal/AccessibilityOverlayTest.kt Updates Compose UI test rule import to junit4 v2 API.
lib/src/main/java/org/connectbot/terminal/TerminalNative.kt Removes old in-module JNI backend (moved to lib-native).
lib/src/main/cpp/CMakeLists.txt Points JNI build at the lib-native C++ sources instead of local copies.
lib/build.gradle.kts Switches host JNI build dependency to :lib-native task; adds project deps.
lib-wasm/src/test/kotlin/org/connectbot/terminal/wasm/TerminalWasmTest.kt Adds basic unit tests validating the WASM backend behavior.
lib-wasm/src/main/kotlin/org/connectbot/terminal/wasm/ShadowTerminalNative.kt Adds Robolectric shadow to replace TerminalNative with TerminalWasm.
lib-wasm/src/main/cpp/CMakeLists.txt Adds WASI CMake config to produce libvterm.wasm.
lib-wasm/build.gradle.kts Adds WASI build + wasm2class AOT pipeline and publishes termlib-host.
lib-native/src/main/kotlin/org/connectbot/terminal/TerminalNative.kt Adds new TerminalNative backend module implementing TerminalBackend.
lib-native/src/main/cpp/mutf8.h Introduces MUTF-8 conversion header for JNI string interop.
lib-native/src/main/cpp/mutf8.cpp Implements UTF-8 <-> MUTF-8 conversion functions.
lib-native/src/main/cpp/libvterm/vterm.pc.in Adds pkg-config template (vendored libvterm support files).
lib-native/src/main/cpp/libvterm/t/run-test.pl Adds upstream libvterm test runner script.
lib-native/src/main/cpp/libvterm/t/92lp1640917.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/90vttest_02-screen-4.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/90vttest_02-screen-3.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/90vttest_02-screen-2.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/90vttest_02-screen-1.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/90vttest_01-movement-4.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/90vttest_01-movement-3.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/90vttest_01-movement-2.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/90vttest_01-movement-1.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/69screen_sb_clear.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/69screen_reflow.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/68screen_termprops.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/67screen_dbl_wh.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/66screen_extent.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/65screen_protect.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/64screen_pen.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/63screen_resize.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/62screen_damage.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/61screen_unicode.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/60screen_ascii.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/40state_selection.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/32state_flow.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/31state_rep.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/30state_pen.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/29state_fallback.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/28state_dbl_wh.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/27state_reset.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/26state_query.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/25state_input.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/22state_save.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/21state_tabstops.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/20state_wrapping.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/18state_termprops.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/17state_mouse.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/16state_resize.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/15state_mode.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/14state_encoding.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/12state_scroll.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/11state_movecursor.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/10state_putglyph.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/03encoding_utf8.test Adds upstream libvterm test.
lib-native/src/main/cpp/libvterm/t/02parser.test Adds upstream libvterm parser test.
lib-native/src/main/cpp/libvterm/src/utf8.h Adds vendored UTF-8 helper header used by keyboard/mouse code.
lib-native/src/main/cpp/libvterm/src/rect.h Adds vendored rectangle helper header.
lib-native/src/main/cpp/libvterm/src/mouse.c Adds vendored mouse reporting implementation.
lib-native/src/main/cpp/libvterm/src/keyboard.c Adds vendored keyboard encoding implementation.
lib-native/src/main/cpp/libvterm/src/fullwidth.inc Adds vendored fullwidth table include.
lib-native/src/main/cpp/libvterm/src/encoding/uk.inc Adds vendored UK encoding include.
lib-native/src/main/cpp/libvterm/src/encoding/DECdrawing.inc Adds vendored DEC drawing encoding include.
lib-native/src/main/cpp/libvterm/src/encoding.c Adds vendored encoding implementation.
lib-native/src/main/cpp/libvterm/include/vterm_keycodes.h Adds vendored keycode definitions header.
lib-native/src/main/cpp/libvterm/bin/unterm.c Adds vendored debugging tool source.
lib-native/src/main/cpp/libvterm/Makefile Adds vendored build/test Makefile.
lib-native/src/main/cpp/libvterm/LICENSE Adds vendored libvterm MIT license.
lib-native/src/main/cpp/libvterm/CONTRIBUTING Adds vendored contribution doc.
lib-native/src/main/cpp/Terminal.h Adds JNI terminal header changes for damage batching.
lib-native/src/main/cpp/Terminal.cpp Implements damage batching for JNI callback reduction.
lib-native/src/main/cpp/CMakeLists.txt Adds dedicated native CMake build for :lib-native.
lib-native/build.gradle.kts Adds host JNI build tasks (cmakeConfigureHost/cmakeBuildHost).
lib-intf/src/main/kotlin/org/connectbot/terminal/TerminalCallbacks.kt Makes callback/data types public and adds damageBatch default method.
lib-intf/src/main/kotlin/org/connectbot/terminal/TerminalBackend.kt Introduces common backend interface plus scan helpers.
lib-intf/src/main/kotlin/org/connectbot/terminal/CellRun.kt Makes CellRun public to support shared backends.
lib-intf/build.gradle.kts Adds JVM library module build config for interface project.
gradle/libs.versions.toml Adds Chicory, wasm2class, JMH, and kotlin-jvm plugin entries.
build.gradle.kts Registers new plugins (kotlin-jvm, publish, wasm2class, jmh) for subprojects.
benchmark/src/jmh/kotlin/org/connectbot/terminal/benchmark/TerminalBackendBenchmark.kt Adds benchmarks comparing native vs WASM backends.
benchmark/build.gradle.kts Adds JMH module wiring + JNI library path setup.
README.md Documents Robolectric host testing via termlib-host and the shadow.
Comments suppressed due to low confidence (1)

lib-native/src/main/cpp/Terminal.cpp:710

  • When the damage batch buffer is full, the current damage rect is dropped: the code flushes the existing batch but never appends the rect that triggered the overflow, so one repaint region is lost. After flushing, add the current (startRow/endRow/startCol/endCol) quad to the now-empty buffer (or flush first, then enqueue, then continue).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/build.gradle.kts Outdated
kruton added 2 commits April 26, 2026 19:29
This allows people to use libterm for Robolectric testing without a lot
of native code setup that is annoying. Should run fast enough for that
purpose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants