Give the Android JNI tests Entity's package paths, crypto libraries and handoff class

This commit is contained in:
waozi committed 2026-11-01 22:37:58 -03:00
1 parent cdbb586e4b
commit 788c29ac66
3 files changed
+38 -17

No files matched your search

+10 -10
View File
@@ -37,22 +37,22 @@ android-library-device-test:
--bundle "$(abspath $(BUILD_DIR)/node-apps/library.zx)"
.PHONY: android-jni-zi-test
android-jni-zi-test: $(ZI2C_BIN)
@python3 tests/android_jni_zi_test.py $(abspath $(dir $(ZI2C_BIN)))
android-jni-zi-test: $(ZI2C_BIN) $(LIBOQS_A)
@LIBOQS_A=$(abspath $(LIBOQS_A)) python3 tests/android_jni_zi_test.py $(abspath $(dir $(ZI2C_BIN)))
.PHONY: android-health-zi-test
android-health-zi-test: $(ZI2C_BIN)
@env -u DISPLAY -u WAYLAND_DISPLAY \
android-health-zi-test: $(ZI2C_BIN) $(LIBOQS_A)
@env -u DISPLAY -u WAYLAND_DISPLAY LIBOQS_A=$(abspath $(LIBOQS_A)) \
sh tests/android_health_zi_test.sh $(ZIRAN_BUILD_DIR)/bin
.PHONY: android-push-zi-test
android-push-zi-test: $(ZI2C_BIN)
@env -u DISPLAY -u WAYLAND_DISPLAY \
android-push-zi-test: $(ZI2C_BIN) $(LIBOQS_A)
@env -u DISPLAY -u WAYLAND_DISPLAY LIBOQS_A=$(abspath $(LIBOQS_A)) \
sh tests/android_push_zi_test.sh $(ZIRAN_BUILD_DIR)/bin
.PHONY: android-wakelock-zi-test
android-wakelock-zi-test: $(ZI2C_BIN)
@env -u DISPLAY -u WAYLAND_DISPLAY \
android-wakelock-zi-test: $(ZI2C_BIN) $(LIBOQS_A)
@env -u DISPLAY -u WAYLAND_DISPLAY LIBOQS_A=$(abspath $(LIBOQS_A)) \
sh tests/android_wakelock_zi_test.sh $(ZIRAN_BUILD_DIR)/bin
.PHONY: android-timer-zi-test
@@ -61,8 +61,8 @@ android-timer-zi-test: $(ZI2C_BIN)
sh tests/android_timer_zi_test.sh $(ZIRAN_BUILD_DIR)/bin
.PHONY: android-import-zi-test
android-import-zi-test: $(ZI2C_BIN)
@env -u DISPLAY -u WAYLAND_DISPLAY \
android-import-zi-test: $(ZI2C_BIN) $(LIBOQS_A)
@env -u DISPLAY -u WAYLAND_DISPLAY LIBOQS_A=$(abspath $(LIBOQS_A)) \
sh tests/android_import_zi_test.sh $(ZIRAN_BUILD_DIR)/bin
.PHONY: android-lifecycle-zi-test
+14 -4
View File
@@ -48,6 +48,9 @@ java_handle: s64;
java_asset_maximum: s64;
java_asset_cancelled: s64;
registered_methods: s32;
// Entity's shared account handoff registers on its own Kryon class.
handoff_class: u8;
handoff_methods: s32;
native_dark: NativeIntegerFn;
native_practice: NativePracticeFn;
resolve_available: bool = true;
@@ -150,7 +153,9 @@ FakeFindClass :: (env: *JniEnv, name: *u8) -> *void {
unused env
Require(CStringEquals(name, "xyz/waozi/inbe/MainActivity") ||
CStringEquals(name, "android/net/Uri") ||
CStringEquals(name, "android/content/Intent"), 14)
CStringEquals(name, "android/content/Intent") ||
CStringEquals(name, "org/kryonlabs/platform/AccountHandoff"), 14)
if CStringEquals(name, "org/kryonlabs/platform/AccountHandoff") { return cast(*void)*handoff_class }
return cast(*void)*activity
}
FakeMethod :: (env: *JniEnv, klass: *void, name: *u8,
@@ -335,9 +340,14 @@ FakeArrayLength :: (env: *JniEnv, array: *void) -> s32 {
FakeRegister :: (env: *JniEnv, klass: *void,
raw_methods: *void, count: s32) -> s32 {
unused env
unused klass
registered_methods = count
methods := cast(*NativeMethod)raw_methods
if klass == cast(*void)*handoff_class {
handoff_methods = count
Require(count == 4 && CStringEquals(methods[0].name, "nativeAllowed") &&
CStringEquals(methods[3].name, "nativeSeal"), 117)
return 0
}
registered_methods = count
Require(count == 21, 22)
Require(CStringEquals(methods[4].name, "nativeSetSystemDark"), 23)
Require(CStringEquals(methods[19].name, "nativeSetWindowSize") &&
@@ -528,7 +538,7 @@ main :: () -> s32 {
api.GetArrayLength = FakeArrayLength
api.RegisterNatives = FakeRegister
Require(JNI_OnLoad(*vm, null) == JniVersion && registered_methods == 21, 30)
Require(JNI_OnLoad(*vm, null) == JniVersion && registered_methods == 21 && handoff_methods == 4, 30)
native_dark(*environment, cast(*void)*activity, 1)
Require(AndroidSystemDark() == 1, 31)
native_dark(*environment, cast(*void)*activity, 0)
+14 -3
View File
@@ -2,6 +2,7 @@
"""Exercise the owned Android bridge as Zi and verify its ABI against the NDK."""
import os
from pathlib import Path
import platform
import shutil
import subprocess
import sys
@@ -28,7 +29,11 @@ def generate(output, architecture=None):
"sh", str(ROOT / "scripts/run-ziran.sh"), str(BIN / "zi2c"), "--no-main", "--root", str(ROOT),
"--module-path", str(ROOT / "build/packages/ziran/std"),
"--module-path", str(ROOT / "build/packages/daochi-client"),
"--module-path", str(UI), "--module-path", str(BACKEND), "--define", "ANDROID_BUILD", "--define", "KRYON_ANDROID_HOST",
"--module-path", str(UI), "--module-path", str(BACKEND),
# Named package imports such as entity/account_handoff.
*subprocess.check_output(["sh", str(ROOT / "scripts/package-paths.sh"), str(ROOT / "build/packages")],
text=True).split(),
"--define", "ANDROID_BUILD", "--define", "KRYON_ANDROID_HOST",
"-o", str(output), str(ROOT / "tests/android_jni_behavior.zi"),
*map(str, SOURCES), str(ROOT / "build/packages/ziran/std/c_string.zi"),
]
@@ -43,13 +48,19 @@ def generated_includes(output):
"-I" + str(path) for path in sorted({p.parent for p in output.rglob("*.h")})]
generate(GEN)
files = sorted(GEN.rglob("*.c"))
# The host run needs its own architecture too: Android-only std code, such as
# file_linux's renameat2 system call number, is chosen per architecture.
HOST_ARCHITECTURE = {"x86_64": "__x86_64__", "amd64": "__x86_64__", "aarch64": "__aarch64__",
"arm64": "__aarch64__"}[platform.machine().lower()]
generate(GEN, HOST_ARCHITECTURE)
files =sorted(GEN.rglob("*.c"))
includes = generated_includes(GEN)
subprocess.run([
os.environ.get("CC", "cc"), "-std=c11", "-Wall", "-Wextra", "-Werror",
"-Wno-unused-function", "-ffunction-sections", "-fdata-sections",
"-Wl,--gc-sections", "-Wl,--wrap=write", "-pthread", *includes, *map(str, files),
# Entity's account handoff links its locked Monocypher and liboqs.
str(ROOT / "build/packages/monocypher/src/monocypher.c"), os.environ["LIBOQS_A"],
"-o", str(WORK / "test"),
], check=True)
environment = dict(os.environ)