diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/817-hiddenapi/expected-stdout.txt | 2 | ||||
-rw-r--r-- | test/817-hiddenapi/libarttest_api.cc | 29 | ||||
-rw-r--r-- | test/817-hiddenapi/libarttest_api.h | 28 | ||||
-rw-r--r-- | test/817-hiddenapi/run.py | 3 | ||||
-rw-r--r-- | test/817-hiddenapi/src-art/Main.java | 2 | ||||
-rw-r--r-- | test/817-hiddenapi/test_native.cc | 11 | ||||
-rw-r--r-- | test/Android.bp | 86 | ||||
-rw-r--r-- | test/Android.run-test.mk | 30 | ||||
-rw-r--r-- | test/common/libarttest_external.cc | 32 | ||||
-rwxr-xr-x | test/default_run.py | 9 | ||||
-rw-r--r-- | test/knownfailures.json | 1 |
11 files changed, 176 insertions, 57 deletions
diff --git a/test/817-hiddenapi/expected-stdout.txt b/test/817-hiddenapi/expected-stdout.txt index 8db7853696..3fc3bce6bd 100644 --- a/test/817-hiddenapi/expected-stdout.txt +++ b/test/817-hiddenapi/expected-stdout.txt @@ -1,2 +1,2 @@ JNI_OnLoad called -JNI_OnLoad called +JNI_OnLoad in libarttest_external.cc called diff --git a/test/817-hiddenapi/libarttest_api.cc b/test/817-hiddenapi/libarttest_api.cc new file mode 100644 index 0000000000..35995f2dfe --- /dev/null +++ b/test/817-hiddenapi/libarttest_api.cc @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2025 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. + */ + +#include "libarttest_api.h" + +#include "runtime.h" + +namespace art { +namespace test_817_hiddenapi { + +void SetDedupeHiddenApiWarnings(bool value) { + Runtime::Current()->SetDedupeHiddenApiWarnings(value); +} + +} // namespace test_817_hiddenapi +} // namespace art diff --git a/test/817-hiddenapi/libarttest_api.h b/test/817-hiddenapi/libarttest_api.h new file mode 100644 index 0000000000..cb0d5b4311 --- /dev/null +++ b/test/817-hiddenapi/libarttest_api.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2025 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. + */ + +#ifndef ART_TEST_817_HIDDENAPI_LIBARTTEST_API_H_ +#define ART_TEST_817_HIDDENAPI_LIBARTTEST_API_H_ + +namespace art { +namespace test_817_hiddenapi { + +void SetDedupeHiddenApiWarnings(bool value); + +} // namespace test_817_hiddenapi +} // namespace art + +#endif // ART_TEST_817_HIDDENAPI_LIBARTTEST_API_H_ diff --git a/test/817-hiddenapi/run.py b/test/817-hiddenapi/run.py index 0ebb768cc9..6855da1d81 100644 --- a/test/817-hiddenapi/run.py +++ b/test/817-hiddenapi/run.py @@ -1,5 +1,3 @@ -#!/bin/bash -# # Copyright 2022 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +14,7 @@ def run(ctx, args): + args.testlib += [args.testlib[0] + "_external"] ctx.default_run(args) # On gcstress configurations, an extra "JNI_OnUnload called" line may diff --git a/test/817-hiddenapi/src-art/Main.java b/test/817-hiddenapi/src-art/Main.java index 6c46deadb1..77af8b15cc 100644 --- a/test/817-hiddenapi/src-art/Main.java +++ b/test/817-hiddenapi/src-art/Main.java @@ -39,7 +39,7 @@ public class Main { m.invoke(null); // Create a new native library which 'childLoader' can load. - String absoluteLibraryPath = getNativeLibFileName(args[0]); + String absoluteLibraryPath = getNativeLibFileName(args[1]); // Do the test for JNI code. m = cls.getDeclaredMethod("testNative", String.class); diff --git a/test/817-hiddenapi/test_native.cc b/test/817-hiddenapi/test_native.cc index d99fb06220..9d15ffd668 100644 --- a/test/817-hiddenapi/test_native.cc +++ b/test/817-hiddenapi/test_native.cc @@ -14,12 +14,13 @@ * limitations under the License. */ -#include "jni.h" - #include <android-base/logging.h> +#include <jni.h> +#include <nativehelper/ScopedUtfChars.h> + +#include <iostream> -#include "nativehelper/ScopedUtfChars.h" -#include "runtime.h" +#include "libarttest_api.h" namespace art { @@ -52,7 +53,7 @@ extern "C" JNIEXPORT jboolean JNICALL Java_TestCase_testAccessInternal(JNIEnv* e } extern "C" JNIEXPORT void JNICALL Java_TestCase_dedupeHiddenApiWarnings(JNIEnv*, jclass) { - Runtime::Current()->SetDedupeHiddenApiWarnings(true); + art::test_817_hiddenapi::SetDedupeHiddenApiWarnings(true); } } // namespace art diff --git a/test/Android.bp b/test/Android.bp index a0e2f5980d..d33c9b7935 100644 --- a/test/Android.bp +++ b/test/Android.bp @@ -538,31 +538,6 @@ java_defaults { ], } -art_cc_test_library { - name: "libarttest", - defaults: ["libarttest-defaults"], - shared_libs: [ - "libart", - "libdexfile#impl", - "libprofile", - "libartbase", - ], -} - -art_cc_test_library { - name: "libarttestd", - defaults: [ - "art_debug_defaults", - "libarttest-defaults", - ], - shared_libs: [ - "libartd", - "libdexfiled#impl", - "libprofiled", - "libartbased", - ], -} - art_cc_defaults { name: "libnativebridgetest-defaults", defaults: ["art_test_defaults"], @@ -944,7 +919,7 @@ cc_defaults { "692-vdex-inmem-loader/vdex_inmem_loader.cc", "720-thread-priority/thread_priority.cc", "800-smali/jni.cc", - "817-hiddenapi/test_native.cc", + "817-hiddenapi/libarttest_api.cc", "855-native/throws_exception.cc", "909-attach-agent/disallow_debugging.cc", "993-breakpoints-non-debuggable/native_attach_agent.cc", @@ -976,6 +951,65 @@ cc_defaults { ], } +art_cc_test_library { + name: "libarttest", + defaults: ["libarttest-defaults"], + shared_libs: [ + "libart", + "libdexfile#impl", + "libprofile", + "libartbase", + ], +} + +art_cc_test_library { + name: "libarttestd", + defaults: [ + "art_debug_defaults", + "libarttest-defaults", + ], + shared_libs: [ + "libartd", + "libdexfiled#impl", + "libprofiled", + "libartbased", + ], +} + +// "External" native code for run tests. Unlike libarttest(d), this library is +// not installed in the com_android_art namespace, so it cannot access ART +// internals. It's instead installed in a location that will be available as +// java.library.path in run tests, and it can call functions in +// libarttest(d).so. +cc_defaults { + name: "libarttest_external-defaults", + defaults: ["art_test_defaults"], + srcs: [ + "817-hiddenapi/test_native.cc", + "common/libarttest_external.cc", + ], + shared_libs: [ + "libbase", + "liblog", + "libnativehelper", + ], +} + +art_cc_test_library { + name: "libarttest_external", + defaults: ["libarttest_external-defaults"], + shared_libs: ["libarttest"], +} + +art_cc_test_library { + name: "libarttestd_external", + defaults: [ + "art_debug_defaults", + "libarttest_external-defaults", + ], + shared_libs: ["libarttestd"], +} + java_library { name: "art_cts_jvmti_test_library", visibility: [ diff --git a/test/Android.run-test.mk b/test/Android.run-test.mk index f4fdd10ef0..5c1624181b 100644 --- a/test/Android.run-test.mk +++ b/test/Android.run-test.mk @@ -30,23 +30,15 @@ TEST_ART_RUN_TEST_DEPENDENCIES := \ # images (all images as we sync only once). ART_TEST_TARGET_RUN_TEST_DEPENDENCIES := $(TESTING_ART_APEX) $(TARGET_CORE_IMG_OUTS) -# Also need libartagent. -ART_TEST_TARGET_RUN_TEST_DEPENDENCIES += libartagent-target libartagentd-target - -# Also need libtiagent. -ART_TEST_TARGET_RUN_TEST_DEPENDENCIES += libtiagent-target libtiagentd-target - -# Also need libtistress. -ART_TEST_TARGET_RUN_TEST_DEPENDENCIES += libtistress-target libtistressd-target - -# Also need libarttest. -ART_TEST_TARGET_RUN_TEST_DEPENDENCIES += libarttest-target libarttestd-target - -# Also need libnativebridgetest. -ART_TEST_TARGET_RUN_TEST_DEPENDENCIES += libnativebridgetest-target libnativebridgetestd-target - -# Also need signal_dumper. -ART_TEST_TARGET_RUN_TEST_DEPENDENCIES += signal_dumper-target +# Also need these other libs and binaries. +ART_TEST_TARGET_RUN_TEST_DEPENDENCIES += \ + libartagent-target libartagentd-target \ + libtiagent-target libtiagentd-target \ + libtistress-target libtistressd-target \ + libarttest-target libarttestd-target \ + libarttest_external-target libarttestd_external-target \ + libnativebridgetest-target libnativebridgetestd-target \ + signal_dumper-target # All tests require the host executables. The tests also depend on the core images, but on # specific version depending on the compiler. @@ -62,6 +54,8 @@ ART_TEST_HOST_RUN_TEST_DEPENDENCIES := \ $(ART_TEST_LIST_host_$(ART_HOST_ARCH)_libartagentd) \ $(ART_TEST_LIST_host_$(ART_HOST_ARCH)_libarttest) \ $(ART_TEST_LIST_host_$(ART_HOST_ARCH)_libarttestd) \ + $(ART_TEST_LIST_host_$(ART_HOST_ARCH)_libarttest_external) \ + $(ART_TEST_LIST_host_$(ART_HOST_ARCH)_libarttestd_external) \ $(ART_TEST_LIST_host_$(ART_HOST_ARCH)_libnativebridgetest) \ $(ART_TEST_LIST_host_$(ART_HOST_ARCH)_libnativebridgetestd) \ $(ART_HOST_OUT_SHARED_LIBRARIES)/libicu_jni$(ART_HOST_SHLIB_EXTENSION) \ @@ -84,6 +78,8 @@ ART_TEST_HOST_RUN_TEST_DEPENDENCIES += \ $(ART_TEST_LIST_host_$(2ND_ART_HOST_ARCH)_libartagentd) \ $(ART_TEST_LIST_host_$(2ND_ART_HOST_ARCH)_libarttest) \ $(ART_TEST_LIST_host_$(2ND_ART_HOST_ARCH)_libarttestd) \ + $(ART_TEST_LIST_host_$(2ND_ART_HOST_ARCH)_libarttest_external) \ + $(ART_TEST_LIST_host_$(2ND_ART_HOST_ARCH)_libarttestd_external) \ $(ART_TEST_LIST_host_$(2ND_ART_HOST_ARCH)_libnativebridgetest) \ $(ART_TEST_LIST_host_$(2ND_ART_HOST_ARCH)_libnativebridgetestd) \ $(2ND_ART_HOST_OUT_SHARED_LIBRARIES)/libicu_jni$(ART_HOST_SHLIB_EXTENSION) \ diff --git a/test/common/libarttest_external.cc b/test/common/libarttest_external.cc new file mode 100644 index 0000000000..21bd080c60 --- /dev/null +++ b/test/common/libarttest_external.cc @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2025 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. + */ + +#include <jni.h> + +#include <iostream> + +namespace art { + +// Override JNI_OnLoad in libarttest(d).so. +extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM*, void*) { + std::cout << "JNI_OnLoad in libarttest_external.cc called" << std::endl; + return JNI_VERSION_1_6; +} + +// Override JNI_OnUnload in libarttest(d).so. +extern "C" JNIEXPORT void JNI_OnUnload(JavaVM*, void*) {} + +} // namespace art diff --git a/test/default_run.py b/test/default_run.py index fa6341a31d..86e4996ca1 100755 --- a/test/default_run.py +++ b/test/default_run.py @@ -978,10 +978,11 @@ def default_run(ctx, args, **kwargs): # installation. LD_LIBRARY_PATH = f"{ANDROID_ROOT}/{LIBRARY_DIRECTORY}" - # This adds libarttest(d).so to the default linker namespace when dalvikvm - # is run from /apex/com.android.art/bin. Since that namespace is essentially - # an alias for the com_android_art namespace, that gives libarttest(d).so - # full access to the internal ART libraries. + # This adds libarttest(d).so and various other test libraries to the default + # linker namespace when dalvikvm is run from /apex/com.android.art/bin. + # Since that namespace is essentially an alias for the com_android_art + # namespace, that gives libarttest(d).so full access to the internal ART + # libraries. LD_LIBRARY_PATH = f"/data/{TEST_DIRECTORY}/com.android.art/lib{SUFFIX64}:{LD_LIBRARY_PATH}" dlib = ("" if TEST_IS_NDEBUG else "d") art_test_internal_libraries = [ diff --git a/test/knownfailures.json b/test/knownfailures.json index 74be03cedc..d6ea226808 100644 --- a/test/knownfailures.json +++ b/test/knownfailures.json @@ -1444,7 +1444,6 @@ "tests": ["150-loadlibrary", "656-annotation-lookup-generic-jni", "674-hiddenapi", - "817-hiddenapi", "900-hello-plugin"], "variant": "target", "bug": "b/186654484", |