From 3ad282d75dba70238e9cfcb6b28676d8eb13dd1c Mon Sep 17 00:00:00 2001 From: Martin Stjernholm Date: Fri, 9 Aug 2024 21:05:10 +0100 Subject: 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 --- libnativebridge/tests/Android.bp | 54 ++++++++++++------------- libnativebridge/tests/libnativebridge-tests.xml | 41 +++++++++++++++++++ 2 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 libnativebridge/tests/libnativebridge-tests.xml 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 @@ + + + +