From 002aca7141e7baf488b02f330b307f059c47a84d Mon Sep 17 00:00:00 2001 From: Martin Stjernholm Date: Mon, 4 Mar 2024 16:48:02 +0000 Subject: Revert "libnativebridge_test: link non-public libs statically" and fix the CTS test to only call exported APIs. Reverts commit 7f5b3d89f21edd958ddb9d7bd01e03c77bd5425a. CTS tests need to link the libraries they test dynamically, and this test only tests exported stable APIs. The standalone CTS test config template includes NativeBridgeModuleController, so the test won't run in a translated environment (which has no proxy for this library and hence caused the error that prompted commit 7f5b3d89f21edd958ddb9d7bd01e03c77bd5425a). The test also used to test some non-exported APIs, which it shouldn't do in CTS. This changes it to use art_standalone_test_defaults, which doesn't have the test_for attributes that made it bypass the stub. Also reuse the trivial API-only tests for libnativebridge_lazy, and give them a more apt name for the new use. Test: atest art_libnativebridge_cts_tests \ libnativebridge-lazy-tests Test: art/libnativebridge/tests/runtests.sh Bug: 327407752 Bug: 328653757 Change-Id: Ib56148f1a651a9ffa3045bc401cc625e6f42416b Merged-In: Ib56148f1a651a9ffa3045bc401cc625e6f42416b (cherry picked from commit a87f1265e210615f7c90151f04a104a38067c196) --- libnativebridge/tests/Android.bp | 51 +++++--------------- libnativebridge/tests/libnativebridge_api_test.cpp | 55 ++++++++++++++++++++++ .../tests/libnativebridge_lazy_test.cpp | 54 --------------------- 3 files changed, 66 insertions(+), 94 deletions(-) create mode 100644 libnativebridge/tests/libnativebridge_api_test.cpp delete mode 100644 libnativebridge/tests/libnativebridge_lazy_test.cpp (limited to 'libnativebridge/tests') diff --git a/libnativebridge/tests/Android.bp b/libnativebridge/tests/Android.bp index f1725fc278..008ef5ccdf 100644 --- a/libnativebridge/tests/Android.bp +++ b/libnativebridge/tests/Android.bp @@ -82,14 +82,13 @@ cc_test_library { defaults: ["libnativebridge-test-case-defaults"], } -cc_defaults { - name: "libnativebridge-tests-defaults", +cc_test { + name: "libnativebridge-tests", defaults: [ "art_defaults", "art_test_defaults", ], - // TODO(mast): Split up art_gtest_defaults so that it can be used for the - // following without pulling in lots of libs. + target: { linux: { cflags: [ @@ -100,11 +99,6 @@ cc_defaults { ], }, }, -} - -cc_test { - name: "libnativebridge-tests", - defaults: ["libnativebridge-tests-defaults"], // native_bridge.cc doesn't support reloading the native bridge after // unloading, so each test needs to be its own process. @@ -154,35 +148,14 @@ cc_test { header_libs: ["libbase_headers"], } -// Variant of libnativebridge-tests that is part of CTS to verify backed-by API -// coverage. +// Very basic tests in CTS to verify backed-by API coverage of the exported API +// in libnativebridge.map.txt. cc_test { name: "art_libnativebridge_cts_tests", - defaults: [ - "art_standalone_test_defaults", - "libnativebridge-tests-defaults", - ], - - // TODO(b/189484095): Pick only a subset of the tests in - // libnativebridge-tests that don't require the native bridge lib to be - // loaded, to avoid the problems with test_per_src and pushing the extra - // libnativebridge*-test-case.so files to device through tradefed. - srcs: [ - // ValidNameNativeBridge_test.cpp needs to be first due to global state - // had_error that isn't reset between tests. - "ValidNameNativeBridge_test.cpp", - "NeedsNativeBridge_test.cpp", - "UnavailableNativeBridge_test.cpp", - ], - static_libs: [ - "libdl_android", - "libnativebridge", - ], - shared_libs: [ - "liblog", - ], - header_libs: ["libbase_headers"], - + defaults: ["art_standalone_test_defaults"], + shared_libs: ["libnativebridge"], + static_libs: ["libbase"], + srcs: ["libnativebridge_api_test.cpp"], test_config_template: ":art-gtests-target-standalone-cts-template", test_suites: [ "cts", @@ -193,12 +166,10 @@ cc_test { cc_test { name: "libnativebridge-lazy-tests", - defaults: ["libnativebridge-tests-defaults"], - host_supported: false, - test_suites: ["device-tests"], + defaults: ["art_standalone_test_defaults"], static_libs: [ "libbase", "libnativebridge_lazy", ], - srcs: ["libnativebridge_lazy_test.cpp"], + srcs: ["libnativebridge_api_test.cpp"], } diff --git a/libnativebridge/tests/libnativebridge_api_test.cpp b/libnativebridge/tests/libnativebridge_api_test.cpp new file mode 100644 index 0000000000..037587cd81 --- /dev/null +++ b/libnativebridge/tests/libnativebridge_api_test.cpp @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#include +#include + +#include "nativebridge/native_bridge.h" + +namespace android { + +class NativeBridgeApiTest : public ::testing::Test {}; + +// Test the exported API in libnativebridge and libnativebridge_lazy. +// The testing we can do here is limited since there's no exported API to +// actually load the native bridge, but we only need to test the trivial +// wrappers. + +TEST_F(NativeBridgeApiTest, NeedsNativeBridge) { + EXPECT_FALSE(NeedsNativeBridge(ABI_STRING)); +} + +TEST_F(NativeBridgeApiTest, PreInitializeNativeBridge) { + EXPECT_FALSE(PreInitializeNativeBridge(nullptr, "")); +} + +TEST_F(NativeBridgeApiTest, NativeBridgeAvailable) { + EXPECT_FALSE(NativeBridgeAvailable()); +} + +TEST_F(NativeBridgeApiTest, NativeBridgeInitialized) { + EXPECT_FALSE(NativeBridgeInitialized()); +} + +TEST_F(NativeBridgeApiTest, NativeBridgeGetTrampoline) { + EXPECT_EQ(nullptr, NativeBridgeGetTrampoline(nullptr, nullptr, nullptr, 0)); +} + +TEST_F(NativeBridgeApiTest, NativeBridgeGetError) { + EXPECT_STREQ("native bridge is not initialized", NativeBridgeGetError()); +} + +}; // namespace android diff --git a/libnativebridge/tests/libnativebridge_lazy_test.cpp b/libnativebridge/tests/libnativebridge_lazy_test.cpp deleted file mode 100644 index e1d66f53df..0000000000 --- a/libnativebridge/tests/libnativebridge_lazy_test.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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. - */ - -#include -#include - -#include "nativebridge/native_bridge.h" - -namespace android { - -class NativeBridgeLazyTest : public ::testing::Test {}; - -// The testing we can do here is limited since there's no exported API to -// actually load the native bridge, but we only need to test the trivial -// wrappers. - -TEST_F(NativeBridgeLazyTest, NeedsNativeBridge) { - EXPECT_FALSE(NeedsNativeBridge(ABI_STRING)); -} - -TEST_F(NativeBridgeLazyTest, PreInitializeNativeBridge) { - EXPECT_FALSE(PreInitializeNativeBridge(nullptr, "")); -} - -TEST_F(NativeBridgeLazyTest, NativeBridgeAvailable) { - EXPECT_FALSE(NativeBridgeAvailable()); -} - -TEST_F(NativeBridgeLazyTest, NativeBridgeInitialized) { - EXPECT_FALSE(NativeBridgeInitialized()); -} - -TEST_F(NativeBridgeLazyTest, NativeBridgeGetTrampoline) { - EXPECT_EQ(nullptr, NativeBridgeGetTrampoline(nullptr, nullptr, nullptr, 0)); -} - -TEST_F(NativeBridgeLazyTest, NativeBridgeGetError) { - EXPECT_STREQ("native bridge is not initialized", NativeBridgeGetError()); -} - -}; // namespace android -- cgit v1.2.3-59-g8ed1b