summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Martin Stjernholm <mast@google.com> 2025-03-14 20:08:15 +0000
committer Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-03-21 11:25:34 -0700
commit3e4b2425a399a213def476775c0fc7c845bdebfb (patch)
treed6b2ec52d909ed71ed00f209710dade7a04dffee
parent7ff689c7a1d5efc2dd5e05e66a57a614d136b24b (diff)
Fix libartpalette MCTS tests to not link the runtime statically.
Since the test starts up a VM, it'll load the boot classpath and among other things register various internal native methods, which aren't stable APIs. That may lead to problems if libart is linked statically since the boot classpath is loaded from device and could potentially be more recent than the libart instance in the test (on devices that don't take Mainline modules). Hence avoid art_standalone_gtest_defaults and instead link libnativehelper dynamically to start the VM using libart on the device. Note that earlier work in https://r.android.com/2375894 and https://r.android.com/2384058 got rid of the direct dependency on the runtime in the test (i.e. the art::CommonRuntimeTest inheritance), but we still brought in runtime init code that got executed from JNI_CreateJavaVM. This (again) disables the JNI test on host. It's possible to solve but not worth the effort (see comment in palette_test.cc). Test: `atest art_standalone_libartpalette_tests` with a planted libart-vs-BCP inconsistency based on b/402238495 Bug: 404306250 Change-Id: I99817670ba58272cb9ef7df7e216a3df637472d3
-rw-r--r--libartpalette/Android.bp33
-rw-r--r--libartpalette/apex/palette_test.cc25
-rw-r--r--test/Android.bp4
3 files changed, 50 insertions, 12 deletions
diff --git a/libartpalette/Android.bp b/libartpalette/Android.bp
index 89607219cc..29ce22bcc4 100644
--- a/libartpalette/Android.bp
+++ b/libartpalette/Android.bp
@@ -141,8 +141,7 @@ art_cc_defaults {
},
}
-// Version of ART gtest `art_libartpalette_tests` for host.
-// TODO(b/192274705): Remove this module when the migration to standalone ART gtests is complete.
+// Version of API coverage test for host.
art_cc_test {
name: "art_libartpalette_tests",
defaults: [
@@ -153,17 +152,41 @@ art_cc_test {
device_supported: false,
}
-// Standalone version of ART gtest `art_libartpalette_tests`, not bundled with the ART APEX on
-// target.
+// MCTS test for API coverage. This test starts a VM to check the JNI
+// notification callbacks, so it should not use art_standalone_gtest_defaults,
+// which statically links a runtime via libart-gtest.
art_cc_test {
name: "art_standalone_libartpalette_tests",
defaults: [
- "art_standalone_gtest_defaults",
+ "art_standalone_test_defaults",
"art_libartpalette_tests_defaults",
],
+ static_libs: [
+ "libartbase-testing",
+ "libartpalette",
+ ],
+ shared_libs: [
+ "liblog",
+ // Bypass stubs to get access to the platform-only JniInvocation APIs.
+ // They're not NDK APIs, but have the same stability requirements.
+ "libnativehelper#impl",
+ ],
test_config_template: ":art-gtests-target-standalone-cts-template",
test_suites: [
"cts",
+ "general-tests",
"mcts-art",
+ "mts-art",
],
+
+ // Duplicated from art_standalone_gtest_defaults
+ compile_multilib: "both",
+ multilib: {
+ lib32: {
+ suffix: "32",
+ },
+ lib64: {
+ suffix: "64",
+ },
+ },
}
diff --git a/libartpalette/apex/palette_test.cc b/libartpalette/apex/palette_test.cc
index 1c4d133b65..a72e523365 100644
--- a/libartpalette/apex/palette_test.cc
+++ b/libartpalette/apex/palette_test.cc
@@ -23,12 +23,13 @@
#include <cstring>
-#include "base/common_art_test.h"
+#include "base/testing.h"
#include "gtest/gtest.h"
#ifdef ART_TARGET_ANDROID
#include "android-modules-utils/sdk_level.h"
#include "android/api-level.h"
+#include "nativehelper/JniInvocation.h"
#endif
namespace {
@@ -92,16 +93,25 @@ TEST_F(PaletteClientTest, Ashmem) {
#endif
}
-class PaletteClientJniTest : public art::CommonArtTest {};
-
-TEST_F(PaletteClientJniTest, JniInvocation) {
+TEST_F(PaletteClientTest, JniInvocation) {
+#ifndef ART_TARGET_ANDROID
+ // On host we need to use the runtime linked into the test to start a VM (e.g.
+ // by inheriting CommonArtTest), while on device it needs to launch the
+ // runtime through libnativehelper. Let's not bother on host since this test
+ // is only for native API coverage on device.
+ GTEST_SKIP() << "Will only spin up a VM on Android";
+#else
bool enabled;
EXPECT_EQ(PALETTE_STATUS_OK, PaletteShouldReportJniInvocations(&enabled));
+ // Load the default JNI_CreateJavaVM implementation, i.e., libart.so.
+ JniInvocation jni_invocation;
+ ASSERT_TRUE(jni_invocation.Init(/*library=*/ nullptr));
+
std::string boot_class_path_string =
- GetClassPathOption("-Xbootclasspath:", GetLibCoreDexFileNames());
- std::string boot_class_path_locations_string =
- GetClassPathOption("-Xbootclasspath-locations:", GetLibCoreDexLocations());
+ art::testing::GetClassPathOption("-Xbootclasspath:", art::testing::GetLibCoreDexFileNames());
+ std::string boot_class_path_locations_string = art::testing::GetClassPathOption(
+ "-Xbootclasspath-locations:", art::testing::GetLibCoreDexLocations());
JavaVMOption options[] = {
{.optionString = boot_class_path_string.c_str(), .extraInfo = nullptr},
@@ -123,6 +133,7 @@ TEST_F(PaletteClientJniTest, JniInvocation) {
PaletteNotifyEndJniInvocation(env);
EXPECT_EQ(JNI_OK, jvm->DestroyJavaVM());
+#endif
}
TEST_F(PaletteClientTest, SetTaskProfiles) {
diff --git a/test/Android.bp b/test/Android.bp
index d3084fe7d2..76559a92c4 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -363,6 +363,10 @@ art_cc_defaults {
},
},
static_libs: [
+ // This dependency links the whole runtime statically into the test. Note that the boot
+ // classpath is not (normally) bundled with the test, so if the runtime is used to actually
+ // start a VM it may load the boot classpath from the device. Depending on the test
+ // configuration, that may not be in sync with the statically linked runtime.
"libart-gtest",
],
version_script: ":art-standalone-gtest-version",