diff options
author | 2024-08-09 21:05:10 +0100 | |
---|---|---|
committer | 2024-08-12 15:44:39 +0000 | |
commit | 3ad282d75dba70238e9cfcb6b28676d8eb13dd1c (patch) | |
tree | 37da33dff302a64ba961fd393f7f8fdfe6c8bc92 | |
parent | 606f8a4172734d4833641a2bef4b85b262ecef39 (diff) |
Link libraries with unstable ABIs statically into libnativebridge-tests.
It incorrectly used art_test_internal_library_defaults, which requires
setting NATIVELOADER_DEFAULT_NAMESPACE_LIBS to work.
It still links several test libraries dynamically, but that works fine
since they're pushed with the test.
Add a test config to enable pushing the test libraries. It's the same
as art-gtests-target-standalone-template.xml, except `append-bitness`
isn't passed to the file pusher, which apparently disables pushing the
whole test directory.
Test: atest libnativebridge-tests
Test: readelf -d out/target/product/vsoc_x86_64/testcases/libnativebridge-tests/x86_64/libnativebridge-tests64
-> Check that no unstable libraries like libc++.so are linked
dynamically.
Bug: 357950167
Change-Id: I406d030312889c668ce0b7489e17b99c06070698
-rw-r--r-- | libnativebridge/tests/Android.bp | 54 | ||||
-rw-r--r-- | libnativebridge/tests/libnativebridge-tests.xml | 41 |
2 files changed, 67 insertions, 28 deletions
diff --git a/libnativebridge/tests/Android.bp b/libnativebridge/tests/Android.bp index 9f6c84cbc4..76c5e27104 100644 --- a/libnativebridge/tests/Android.bp +++ b/libnativebridge/tests/Android.bp @@ -102,21 +102,11 @@ cc_test { name: "libnativebridge-tests", defaults: [ "art_defaults", - "art_test_internal_library_defaults", + "art_standalone_test_defaults", ], - target: { - linux: { - cflags: [ - // gtest issue - "-Wno-used-but-marked-unused", - "-Wno-deprecated", - "-Wno-missing-noreturn", - ], - }, - }, - isolated: true, + test_config: "libnativebridge-tests.xml", srcs: [ "NativeBridgeTest.cpp", @@ -144,35 +134,43 @@ cc_test { "NativeBridge7CriticalNative_test.cpp", ], - shared_libs: [ + static_libs: [ "libbase", - "liblog", "libnativebridge", + ], + shared_libs: [ + "liblog", "libnativebridge6prezygotefork", "libnativebridge7criticalnative", - - // Ideally these would only need to be listed in data_libs, but they - // are dlopen'd by libnativebridge, not by libnativebridge-tests, - // and the linker can't find them relative to /system/lib64/libnativebridge.so. - // Linking them here causes them to be loaded from alongside - // libnativebridge-tests when it is executed, and then the later dlopen - // returns the handle to the already-loaded library. - "libnativebridge-test-case", - "libnativebridge2-test-case", - "libnativebridge3-test-case", - "libnativebridge6-test-case", - "libnativebridge7-test-case", ], data_libs: [ + "libnativebridge6prezygotefork", + "libnativebridge7criticalnative", + + // These are dlopen'd by libnativebridge, not libnativebridge-tests, but + // the former is statically linked into the latter, so the linker will + // find them next to the test binary. "libnativebridge-test-case", "libnativebridge2-test-case", "libnativebridge3-test-case", "libnativebridge6-test-case", "libnativebridge7-test-case", - "libnativebridge6prezygotefork", - "libnativebridge7criticalnative", ], + target: { + linux: { + cflags: [ + // gtest issue + "-Wno-used-but-marked-unused", + "-Wno-deprecated", + "-Wno-missing-noreturn", + ], + }, + android: { + shared_libs: ["libdl_android"], // libnativebridge dependency + }, + }, + test_suites: [ "general-tests", ], diff --git a/libnativebridge/tests/libnativebridge-tests.xml b/libnativebridge/tests/libnativebridge-tests.xml new file mode 100644 index 0000000000..d4266a7d0c --- /dev/null +++ b/libnativebridge/tests/libnativebridge-tests.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2021 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. +--> +<configuration description="Runs libnativebridge-tests."> + <option name="config-descriptor:metadata" key="mainline-param" value="com.google.android.art.apex" /> + <option name="config-descriptor:metadata" key="mainline-param" value="com.android.art.apex" /> + + <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer"> + <option name="cleanup" value="true" /> + <option name="push" value="libnativebridge-tests->/data/local/tmp/libnativebridge-tests" /> + </target_preparer> + + <test class="com.android.tradefed.testtype.GTest" > + <option name="native-test-device-path" value="/data/local/tmp" /> + <option name="module-name" value="libnativebridge-tests" /> + </test> + + <!-- When this test is run in a Mainline context (e.g. with `mts-tradefed`), only enable it if + one of the Mainline modules below is present on the device used for testing. --> + <object type="module_controller" class="com.android.tradefed.testtype.suite.module.MainlineTestModuleController"> + <!-- ART Mainline Module (internal version). --> + <option name="mainline-module-package-name" value="com.google.android.art" /> + <!-- ART Mainline Module (external (AOSP) version). --> + <option name="mainline-module-package-name" value="com.android.art" /> + </object> + + <!-- Only run tests if the device under test is SDK version 31 (Android 12) or above. --> + <object type="module_controller" class="com.android.tradefed.testtype.suite.module.Sdk31ModuleController" /> +</configuration> |