summaryrefslogtreecommitdiff
path: root/ravenwood
diff options
context:
space:
mode:
author Makoto Onuki <omakoto@google.com> 2024-11-05 09:35:18 -0800
committer Makoto Onuki <omakoto@google.com> 2024-11-05 11:11:11 -0800
commit371ac3f2a79ad9ffbdb7fd5a25127ae68c92bb7a (patch)
tree6901d520f6528939969a2dffb101e560f9e427cd /ravenwood
parentf1e6d28a32844b2bf408e1b890141c083dc56dc5 (diff)
Switch back to Java android.util.Log
- Log is an important class, so this should always work even when globalInitOnce fails(). - Also handle $RAVENWOOD_LOG_OUT at the very first. Flag: EXEMPT host test change only Fix: 377377826 Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh Test: RAVENWOOD_LOG_OUT=$(tty) atest RavenwoodBivalentTest # and make sure the log is printed on console. Change-Id: I7c4aea4e12f983a28acb1768ac7ccbf8795b64da
Diffstat (limited to 'ravenwood')
-rw-r--r--ravenwood/Android.bp11
-rw-r--r--ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodNativeLoader.java2
-rw-r--r--ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java6
-rw-r--r--ravenwood/runtime-jni/ravenwood_initializer.cpp50
-rw-r--r--ravenwood/runtime-jni/ravenwood_runtime.cpp20
5 files changed, 66 insertions, 23 deletions
diff --git a/ravenwood/Android.bp b/ravenwood/Android.bp
index b3f78ab30021..4731cfbfc935 100644
--- a/ravenwood/Android.bp
+++ b/ravenwood/Android.bp
@@ -279,6 +279,15 @@ cc_defaults {
shared_libs: [
"liblog",
],
+ visibility: ["//visibility:private"],
+}
+
+cc_library_host_shared {
+ name: "libravenwood_initializer",
+ defaults: ["ravenwood_jni_defaults"],
+ srcs: [
+ "runtime-jni/ravenwood_initializer.cpp",
+ ],
}
// We need this as a separate library because we need to overload the
@@ -301,7 +310,6 @@ cc_library_host_shared {
"libutils",
"libcutils",
],
- visibility: ["//frameworks/base"],
}
// For collecting the *stats.csv files in a known directory under out/host/linux-x86/testcases/.
@@ -659,6 +667,7 @@ android_ravenwood_libgroup {
],
jni_libs: [
// Libraries has to be loaded in the following order
+ "libravenwood_initializer",
"libravenwood_sysprop",
"libravenwood_runtime",
"libandroid_runtime",
diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodNativeLoader.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodNativeLoader.java
index d29b93c0c171..a208d6dce2ce 100644
--- a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodNativeLoader.java
+++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodNativeLoader.java
@@ -40,7 +40,7 @@ public final class RavenwoodNativeLoader {
* See frameworks/base/core/jni/platform/host/HostRuntime.cpp
*/
private static final Class<?>[] sLibandroidClasses = {
- android.util.Log.class,
+// android.util.Log.class, // Not using native log: b/377377826
android.os.Parcel.class,
android.os.Binder.class,
android.os.SystemProperties.class,
diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java
index 28c262d53ff1..e22701840665 100644
--- a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java
+++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java
@@ -86,6 +86,7 @@ public class RavenwoodRuntimeEnvironmentController {
}
private static final String MAIN_THREAD_NAME = "RavenwoodMain";
+ private static final String LIBRAVENWOOD_INITIALIZER_NAME = "ravenwood_initializer";
private static final String RAVENWOOD_NATIVE_SYSPROP_NAME = "ravenwood_sysprop";
private static final String RAVENWOOD_NATIVE_RUNTIME_NAME = "ravenwood_runtime";
private static final String RAVENWOOD_BUILD_PROP =
@@ -152,10 +153,13 @@ public class RavenwoodRuntimeEnvironmentController {
}
sInitialized = true;
+ // Some process-wide initialization. (maybe redirect stdout/stderr)
+ RavenwoodCommonUtils.loadJniLibrary(LIBRAVENWOOD_INITIALIZER_NAME);
+
// We haven't initialized liblog yet, so directly write to System.out here.
RavenwoodCommonUtils.log(TAG, "globalInit()");
- // Load libravenwood_sysprop first
+ // Load libravenwood_sysprop before other libraries that may use SystemProperties.
var libProp = RavenwoodCommonUtils.getJniLibraryPath(RAVENWOOD_NATIVE_SYSPROP_NAME);
System.load(libProp);
RavenwoodRuntimeNative.reloadNativeLibrary(libProp);
diff --git a/ravenwood/runtime-jni/ravenwood_initializer.cpp b/ravenwood/runtime-jni/ravenwood_initializer.cpp
new file mode 100644
index 000000000000..89fb7c3c3510
--- /dev/null
+++ b/ravenwood/runtime-jni/ravenwood_initializer.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /*
+ * This file is compiled into a single SO file, which we load at the very first.
+ * We can do process-wide initialization here.
+ */
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "jni_helper.h"
+
+static void maybeRedirectLog() {
+ auto ravenwoodLogOut = getenv("RAVENWOOD_LOG_OUT");
+ if (ravenwoodLogOut == NULL) {
+ return;
+ }
+ ALOGI("RAVENWOOD_LOG_OUT set. Redirecting output to %s", ravenwoodLogOut);
+
+ // Redirect stdin / stdout to /dev/tty.
+ int ttyFd = open(ravenwoodLogOut, O_WRONLY | O_APPEND);
+ if (ttyFd == -1) {
+ ALOGW("$RAVENWOOD_LOG_OUT is set to %s, but failed to open: %s ", ravenwoodLogOut,
+ strerror(errno));
+ return;
+ }
+ dup2(ttyFd, 1);
+ dup2(ttyFd, 2);
+}
+
+extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) {
+ ALOGI("%s: JNI_OnLoad", __FILE__);
+
+ maybeRedirectLog();
+ return JNI_VERSION_1_4;
+}
diff --git a/ravenwood/runtime-jni/ravenwood_runtime.cpp b/ravenwood/runtime-jni/ravenwood_runtime.cpp
index 5b75e9854758..c1993f691686 100644
--- a/ravenwood/runtime-jni/ravenwood_runtime.cpp
+++ b/ravenwood/runtime-jni/ravenwood_runtime.cpp
@@ -180,24 +180,6 @@ static jint Linux_gettid(JNIEnv* env, jobject) {
return syscall(__NR_gettid);
}
-static void maybeRedirectLog() {
- auto ravenwoodLogOut = getenv("RAVENWOOD_LOG_OUT");
- if (ravenwoodLogOut == NULL) {
- return;
- }
- ALOGI("RAVENWOOD_LOG_OUT set. Redirecting output to %s", ravenwoodLogOut);
-
- // Redirect stdin / stdout to /dev/tty.
- int ttyFd = open(ravenwoodLogOut, O_WRONLY);
- if (ttyFd == -1) {
- ALOGW("$RAVENWOOD_LOG_OUT is set to %s, but failed to open: %s ", ravenwoodLogOut,
- strerror(errno));
- return;
- }
- dup2(ttyFd, 1);
- dup2(ttyFd, 2);
-}
-
// ---- Registration ----
extern void register_android_system_OsConstants(JNIEnv* env);
@@ -218,8 +200,6 @@ static const JNINativeMethod sMethods[] =
};
extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) {
- maybeRedirectLog();
-
ALOGI("%s: JNI_OnLoad", __FILE__);
JNIEnv* env = GetJNIEnvOrDie(vm);