diff options
6 files changed, 30 insertions, 20 deletions
diff --git a/Ravenwood.bp b/Ravenwood.bp index 2df6d5811d44..4e360759c137 100644 --- a/Ravenwood.bp +++ b/Ravenwood.bp @@ -197,6 +197,9 @@ android_ravenwood_libgroup { "mockito-ravenwood-prebuilt", "inline-mockito-ravenwood-prebuilt", ], + jni_libs: [ + "libandroid_runtime", + ], } android_ravenwood_libgroup { diff --git a/core/java/android/util/Log.java b/core/java/android/util/Log.java index b33214dffb7e..8358b9a51adb 100644 --- a/core/java/android/util/Log.java +++ b/core/java/android/util/Log.java @@ -72,8 +72,11 @@ import java.net.UnknownHostException; * a positive value may be considered as a successful invocation. */ @android.ravenwood.annotation.RavenwoodKeepWholeClass -@android.ravenwood.annotation.RavenwoodNativeSubstitutionClass( - "com.android.platform.test.ravenwood.nativesubstitution.Log_host") +@android.ravenwood.annotation.RavenwoodClassLoadHook( + "com.android.platform.test.ravenwood.runtimehelper.ClassLoadHook.onClassLoaded") +// Uncomment the following annotation to switch to the Java substitution version. +//@android.ravenwood.annotation.RavenwoodNativeSubstitutionClass( +// "com.android.platform.test.ravenwood.nativesubstitution.Log_host") public final class Log { /** @hide */ @IntDef({ASSERT, ERROR, WARN, INFO, DEBUG, VERBOSE}) diff --git a/ravenwood/Android.bp b/ravenwood/Android.bp index 53897e14ecd6..41a4a1ad1ccb 100644 --- a/ravenwood/Android.bp +++ b/ravenwood/Android.bp @@ -47,6 +47,7 @@ java_library { ], libs: [ "framework-minus-apex.ravenwood", + "ravenwood-junit", ], visibility: ["//visibility:private"], } diff --git a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodUtils.java b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodUtils.java index b736a7662bd4..37ceac601e37 100644 --- a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodUtils.java +++ b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodUtils.java @@ -73,9 +73,9 @@ public class RavenwoodUtils { return; } } - throw new UnsatisfiedLinkError("Library " + libname + " no found in " + throw new UnsatisfiedLinkError("Library " + libname + " not found in " + "java.library.path: " + path); - } catch (Exception e) { + } catch (Throwable e) { dumpFiles(System.out); throw e; } @@ -96,6 +96,10 @@ public class RavenwoodUtils { listFiles(out, gparent, ""); } } + + var gparent = new File("../..").getCanonicalFile(); + out.println("# ../..=" + gparent); + listFiles(out, gparent, ""); } catch (Throwable th) { out.println("Error: " + th.toString()); th.printStackTrace(out); diff --git a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/Log_host.java b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/Log_host.java index 5930a14cdec8..f301b9c46b0e 100644 --- a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/Log_host.java +++ b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/nativesubstitution/Log_host.java @@ -22,6 +22,13 @@ import com.android.internal.os.RuntimeInit; import java.io.PrintStream; +/** + * Ravenwood "native substitution" class for {@link android.util.Log}. + * + * {@link android.util.Log} already uses the actual native code and doesn't use this class. + * In order to switch to this Java implementation, uncomment the @RavenwoodNativeSubstitutionClass + * annotation on {@link android.util.Log}. + */ public class Log_host { public static boolean isLoggable(String tag, @Level int level) { diff --git a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/runtimehelper/ClassLoadHook.java b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/runtimehelper/ClassLoadHook.java index 1e120305fa2d..cc94090d9ec7 100644 --- a/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/runtimehelper/ClassLoadHook.java +++ b/ravenwood/runtime-helper-src/framework/com/android/platform/test/ravenwood/runtimehelper/ClassLoadHook.java @@ -15,8 +15,9 @@ */ package com.android.platform.test.ravenwood.runtimehelper; +import android.platform.test.ravenwood.RavenwoodUtils; + import java.io.File; -import java.io.PrintStream; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -27,8 +28,6 @@ import java.util.ArrayList; * load other JNI or do other set up here. */ public class ClassLoadHook { - private static PrintStream sOut = System.out; - /** * If true, we won't load `libandroid_runtime` * @@ -36,7 +35,7 @@ public class ClassLoadHook { * so we need a way to remove the dependency. */ private static final boolean SKIP_LOADING_LIBANDROID = "1".equals(System.getenv( - "HOSTTEST_SKIP_LOADING_LIBANDROID")); + "RAVENWOOD_SKIP_LOADING_LIBANDROID")); public static final String CORE_NATIVE_CLASSES = "core_native_classes"; public static final String ICU_DATA_PATH = "icu.data.path"; @@ -44,7 +43,7 @@ public class ClassLoadHook { public static final String GRAPHICS_NATIVE_CLASSES = "graphics_native_classes"; public static final String VALUE_N_A = "**n/a**"; - public static final String LIBANDROID_RUNTIME_NAME = "libandroid_runtime"; + public static final String LIBANDROID_RUNTIME_NAME = "android_runtime"; private static String sInitialDir = new File("").getAbsolutePath(); @@ -68,7 +67,7 @@ public class ClassLoadHook { } private static void log(String message) { - sOut.println("ClassLoadHook: " + message); + System.out.println("ClassLoadHook: " + message); } private static void log(String fmt, Object... args) { @@ -92,13 +91,6 @@ public class ClassLoadHook { } } - private static void loadJniLibrary(String name) { - final String path = sInitialDir + "/lib64/" + name + ".so"; - System.out.println("Loading " + path + " ..."); - System.load(path); - System.out.println("Done loading " + path); - } - private static boolean sLoadFrameworkNativeCodeCalled = false; /** @@ -115,7 +107,7 @@ public class ClassLoadHook { // libandroid_runtime uses Java's system properties to decide what JNI methods to set up. // Set up these properties for host-side tests. - if ("1".equals(System.getenv("HOSTTEST_DUMP_PROPERTIES"))) { + if ("1".equals(System.getenv("RAVENWOOD_DUMP_PROPERTIES"))) { log("Java system properties:"); dumpSystemProperties(); } @@ -141,7 +133,7 @@ public class ClassLoadHook { setProperty(ICU_DATA_PATH, VALUE_N_A); setProperty(KEYBOARD_PATHS, VALUE_N_A); - loadJniLibrary(LIBANDROID_RUNTIME_NAME); + RavenwoodUtils.loadJniLibrary(LIBANDROID_RUNTIME_NAME); } /** @@ -156,7 +148,7 @@ public class ClassLoadHook { }; /** - * @return if a given method is a native method or not. + * @return if a given class has any native method or not. */ private static boolean hasNativeMethod(Class<?> clazz) { for (var method : clazz.getDeclaredMethods()) { |