Skip to content

tests: Modernize Android and HotSpot JVM test infrastructure - #423

Open
mnalmahmud wants to merge 6 commits into
frida-packages:mainfrom
mnalmahmud:improve-test-infra
Open

mnalmahmud wants to merge 6 commits into
frida-packages:mainfrom
mnalmahmud:improve-test-infra

Conversation

@mnalmahmud

@mnalmahmud mnalmahmud commented Nov 20, 2026 •

Copy link
Copy Markdown

Summary

Modernizes the test runner, Makefiles, and GitHub Actions CI so the test suite runs cleanly and reliably across Android API 26–36 and HotSpot JVM (JDK 8, 11, and 17).

Related PRs (each independent on main):

Commits

  1. jvm: Fix JDK 8 lookup and code cache sweep
    • Drop unused Method::jmethod_id symbol entries absent in Temurin JDK 8 builds.
    • Guard optional UseCompiler and NMethodSweeper::_sweep_started in forceSweep() so reverting methods on JDK 8 and under -Xint does not hang.
  2. tests: Parse script messages with json-glib
    • Move JSON parsing of Frida script messages out of Script.java (org.json, Android-only) into test/runner.c using json-glib, and fail loudly on getNextMessage() timeout instead of returning null.
  3. tests: Support Android API levels up to 36
    • Clamp APP_PLATFORM in test/Application.mk to the NDK's max supported API level and handle major.minor API versions in test/Makefile.
    • Implement multi-handler sigchain dispatch in test/runner.c so ART's implicit null-check and stack-overflow handlers chain properly.
    • Expand the Android CI matrix to API 26–36 with fail-fast: false, auto-detect the latest build-tools, cache downloaded dependencies, rebuild frida-java-bridge.js when bridge sources change, use adb push --sync, dump scoped logcat on failure, and support filtering test classes via TestRunner arguments.
  4. tests: Work around Stalker slab allocation failure
    • Install a GumMemoryHooks fallback in test/runner.c when gum_memory_allocate_near() fails under Android 15+ / frida-gum 17.x (frida/frida-gum#793), and call Stalker.unfollow() before send() in MethodTest.
  5. tests: Add HotSpot JVM test runner and CI
    • Extend test/runner.c to launch HotSpot via JNI_CreateJavaVM on non-Android Linux hosts, handle HotSpot's Modified UTF-8 via GetStringChars + g_utf16_to_utf8, and defer script-load completion to a G_PRIORITY_LOW idle callback so Script.nextTick() hooks settle before new Script() returns.
    • Guard Android-only tests via TestRunner.isAndroid() / TestRunner.getAndroidApiLevel().
    • Rename targets symmetrically (make check-android, make check-jvm, develop-*, check-*-gdb) and update README.md.
    • Add a jvm CI matrix covering Temurin JDK 8, 11, and 17.
  6. ci: Modernize workflows and add job timeouts
    • Upgrade GitHub Actions to Node 24 releases (checkout@v7, setup-node@v7, setup-java@v6, cache@v6), add node --check and tsc --noEmit to linting.yml, add explicit job timeouts, and terminate orphaned emulator crashpad_handler processes on script exit (ReactiveCircus/android-emulator-runner#385).

Verification

Drop unused Method::jmethod_id symbol entries that are absent in
Temurin JDK 8 builds.

Check the optional UseCompiler flag before invoking code cache sweeps so
reverting methods under -Xint does not hang waiting on a sweeper thread
that HotSpot never starts.

On JDK 8 (which lacks NMethodSweeper::force_sweep()), look up the
optional NMethodSweeper::_sweep_started flag and claim it inside a
safepoint instead of checking _should_sweep == 0. In OpenJDK 8,
_should_sweep stays set to 1 while compiler threads are idle, so
checking _should_sweep skipped sweep_code_cache() indefinitely. Also
use Int64.add() and Int64.compare() when tracking traversal counts.
Parse Frida script JSON messages in runner.c using json-glib (already
linked via libfrida-gumjs.a) instead of org.json in Script.java, and
fail fast with an explicit IllegalStateException on script message
timeout.

This ensures uniform payload serialization across Android and HotSpot
JVM (matching string, boolean, number, array, object, and null values)
without depending on Android's built-in org.json implementation.
Bring the Android test runner, Makefiles, and GitHub Actions workflow up
to date for modern Android API levels and improve reliability:

- Clamp APP_PLATFORM in test/Application.mk to the NDK's maximum
  supported API level from meta/platforms.json and handle major.minor
  API levels across test/Application.mk and test/Makefile for platform
  paths, sysroot, and d8 --min-api.
- Implement multi-handler sigchain support in test/runner.c so ART's
  implicit null-check and stack-overflow fault handlers are dispatched
  and chained properly to any previous signal handler.
- Expand the CI matrix to API levels 26-36 with fail-fast disabled,
  auto-detect the latest installed build-tools directory, remove the
  stale x86 exclusion, and cache downloaded test dependencies.
- Rebuild build/frida-java-bridge.js whenever bridge sources change,
  deploy once in `make check` using `adb push --sync` with an explicit
  libartpalette.so prerequisite, use atomic `curl -fsSL` downloads (with
  Maven Central for hamcrest-core), pass `-o` to `unzip`, fix watch
  quoting and LD_PRELOAD, dump scoped crash/warning logcat since the
  test start timestamp on failure, and allow filtering test classes via
  TestRunner args.
Install a 64-bit Linux GumMemoryHooks allocator in test/runner.c that
probes a 64 MiB window before mapping Stalker slabs, working around
gum_data_slab_new() NULL dereferences on Android API 35-36
(frida/frida-gum#793).

Also call Stalker.unfollow() before send() in
MethodTest.callCanBeTraced() so teardown is not traced into extra slabs.
Run the test suite on HotSpot JVM in addition to Android ART across
supported LTS releases (JDK 8, 11, and 17):

- Extend test/runner.c to launch HotSpot via JNI_CreateJavaVM on
  non-Android platforms, guarding Android-only sigchain and
  AttachCurrentThread differences with #ifdef __ANDROID__, fixing
  destroy_weak_ref's GDestroyNotify signature for OpenJDK jni.h,
  converting script sources via GetStringChars + g_utf16_to_utf8 (since
  HotSpot GetStringUTFChars emits Modified UTF-8 for surrogate pairs
  like the ESM package header), and deferring script-load completion to
  a G_PRIORITY_LOW idle callback so pending Script.nextTick() hook
  installations finish before new Script() returns.
- Add TestRunner.isAndroid() and TestRunner.getAndroidApiLevel() so
  ClassRegistryTest and MethodTest compile and run on HotSpot without
  android.jar, selecting Android-only suites (ClassCreationTest and
  PerformTest) only on Android.
- Rename Android Makefile/CI targets, variables, and build outputs
  symmetrically (build-android, deploy-android, run-android,
  watch-android, debug-android, check-android, check-android-gdb,
  develop-android, android, tests-android.dex) alongside HotSpot
  targets (build-jvm, run-jvm, watch-jvm, debug-jvm, check-jvm,
  check-jvm-gdb, develop-jvm, jvm) and update README.md accordingly.
- Add a `jvm` matrix job on ubuntu-latest with Temurin JDK 8, 11, and
  17 running `make check-jvm` (both interpreter and JIT modes).
Upgrade GitHub Actions to their Node 24 releases (actions/checkout@v7,
actions/setup-node@v7, actions/setup-java@v6, and actions/cache@v6)
across both workflows, and modernize the linting workflow to Node 22
with JavaScript syntax (`node --check`) and TypeScript declaration
(`tsc --noEmit`) verification.

Set explicit timeout-minutes on all CI jobs (30m for android, 15m for
jvm, 10m for lint) so hung runs fail promptly instead of blocking for
GitHub Actions' 6-hour default, and clean up orphaned emulator
crashpad_handler processes on script exit so emulator termination does
not hang after tests finish.
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.

1 participant