Add a method for Robolectric host testing#199
Open
kruton wants to merge 5 commits into
Open
Conversation
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.
There was a problem hiding this comment.
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 byTerminalWasmplus 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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This uses Chicory to compile the libvterm library into a .wasm file and interpret it during runtime.