diff options
author | 2024-05-07 16:55:00 -0700 | |
---|---|---|
committer | 2024-05-15 23:02:29 +0000 | |
commit | 3f3ac2c75b1cef76ef2af73371880cce8ec43455 (patch) | |
tree | 41bf31be76db0293dc1926c224881958baffc309 | |
parent | a57f3e98e7ef099e491785bfa5935374ce116b03 (diff) |
Use isolated: true instead of test_per_src: true in libnativebridge_tests
libnativebridge_tests uses test_per_src: true to avoid running
multiple tests in the same process. gtest_isolated uses separate
processes for each test, but without the various incompatibilities
caused by test_per_src. Switch to isolated: true instead.
Create a temporary directory in the constructor of the shared
NativeBridgeTest base class instead and put the code_cache directory
inside it to keep the tests from trying to modify the current
directory.
Also add the tests to TEST_MAPPING and remove the preupload check.
Bug: 189484095
Test: atest --host libnativebridge_tests
Test: atest libnativebridge_tests
Flag: TEST_ONLY
Change-Id: Iea522c1895f1f5996b10e545c44d6b00bda1ee3d
20 files changed, 125 insertions, 89 deletions
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg index c5b3c9c18d..d43a1e90ba 100644 --- a/PREUPLOAD.cfg +++ b/PREUPLOAD.cfg @@ -3,10 +3,6 @@ check_generated_tests_up_to_date = tools/test_presubmit.py hidden_api_txt_checksorted_hook = ${REPO_ROOT}/tools/platform-compat/hiddenapi/checksorted_sha.sh ${PREUPLOAD_COMMIT} ${REPO_ROOT} -# TODO(b/189484095): Port libnativebridge tests to atest and enable in presubmit -# so we don't need the custom runtests script and this check. -check_libnativebridge_test_field = libnativebridge/tests/preupload_check_test_tag.sh ${PREUPLOAD_COMMIT_MESSAGE} ${PREUPLOAD_FILES} - check_expectation_jsons = tools/check_presubmit_json_expectations.sh ${REPO_ROOT} ${PREUPLOAD_FILES} [Builtin Hooks] diff --git a/TEST_MAPPING b/TEST_MAPPING index 3f5c50f694..3d144250fd 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -4305,6 +4305,9 @@ }, { "name": "art-run-test-2273-checker-unreachable-intrinsics" + }, + { + "name": "libnativebridge-tests" } ] } diff --git a/libnativebridge/tests/Android.bp b/libnativebridge/tests/Android.bp index ca054516f6..85bdf9967c 100644 --- a/libnativebridge/tests/Android.bp +++ b/libnativebridge/tests/Android.bp @@ -27,8 +27,9 @@ cc_defaults { name: "libnativebridge-test-case-defaults", defaults: [ "art_defaults", - "art_test_defaults", + "art_test_common_defaults", ], + host_supported: true, // TODO(mast): Split up art_gtest_defaults so that it can be used for the // following without pulling in lots of libs. target: { @@ -115,19 +116,10 @@ cc_test { }, }, - // native_bridge.cc doesn't support reloading the native bridge after - // unloading, so each test needs to be its own process. - test_per_src: true, - - // Disable pre-submit host unit-testing for this test module, as - // it is not compatible with TradeFed (because of the use of the - // `test_per_src` feature above) and meant to be executed with the - // `runtests.sh` script instead. - test_options: { - unit_test: false, - }, + isolated: true, srcs: [ + "NativeBridgeTest.cpp", "NativeBridgeApi.c", "CodeCacheCreate_test.cpp", "CodeCacheExists_test.cpp", @@ -153,8 +145,25 @@ cc_test { ], shared_libs: [ + "libbase", "liblog", "libnativebridge", + "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: [ "libnativebridge-test-case", "libnativebridge2-test-case", "libnativebridge3-test-case", @@ -163,7 +172,10 @@ cc_test { "libnativebridge6prezygotefork", "libnativebridge7criticalnative", ], - header_libs: ["libbase_headers"], + + test_suites: [ + "general-tests", + ], } // Very basic tests in CTS to verify backed-by API coverage of the exported API diff --git a/libnativebridge/tests/CodeCacheCreate_test.cpp b/libnativebridge/tests/CodeCacheCreate_test.cpp index 1bd309c5c8..57b1abc4c5 100644 --- a/libnativebridge/tests/CodeCacheCreate_test.cpp +++ b/libnativebridge/tests/CodeCacheCreate_test.cpp @@ -26,25 +26,25 @@ namespace android { // exist. TEST_F(NativeBridgeTest, CodeCacheCreate) { // Make sure that code_cache does not exist - rmdir(kCodeCache); + rmdir(codeCache()); struct stat st; - ASSERT_EQ(-1, stat(kCodeCache, &st)); + ASSERT_EQ(-1, stat(codeCache(), &st)); ASSERT_EQ(ENOENT, errno); // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary, nullptr)); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_FALSE(NativeBridgeError()); // Check that code_cache was created - ASSERT_EQ(0, stat(kCodeCache, &st)); + ASSERT_EQ(0, stat(codeCache(), &st)); ASSERT_TRUE(S_ISDIR(st.st_mode)); // Clean up UnloadNativeBridge(); - ASSERT_EQ(0, rmdir(kCodeCache)); + ASSERT_EQ(0, rmdir(codeCache())); ASSERT_FALSE(NativeBridgeError()); } diff --git a/libnativebridge/tests/CodeCacheExists_test.cpp b/libnativebridge/tests/CodeCacheExists_test.cpp index 8ba01586b5..c740bec79c 100644 --- a/libnativebridge/tests/CodeCacheExists_test.cpp +++ b/libnativebridge/tests/CodeCacheExists_test.cpp @@ -27,26 +27,26 @@ namespace android { TEST_F(NativeBridgeTest, CodeCacheExists) { // Make sure that code_cache does not exists struct stat st; - ASSERT_EQ(-1, stat(kCodeCache, &st)); + ASSERT_EQ(-1, stat(codeCache(), &st)); ASSERT_EQ(ENOENT, errno); // Create the code_cache - ASSERT_EQ(0, mkdir(kCodeCache, S_IRWXU | S_IRWXG | S_IXOTH)); + ASSERT_EQ(0, mkdir(codeCache(), S_IRWXU | S_IRWXG | S_IXOTH)); // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary, nullptr)); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_FALSE(NativeBridgeError()); // Check that the code cache is still there - ASSERT_EQ(0, stat(kCodeCache, &st)); + ASSERT_EQ(0, stat(codeCache(), &st)); ASSERT_TRUE(S_ISDIR(st.st_mode)); // Clean up UnloadNativeBridge(); - ASSERT_EQ(0, rmdir(kCodeCache)); + ASSERT_EQ(0, rmdir(codeCache())); ASSERT_FALSE(NativeBridgeError()); } diff --git a/libnativebridge/tests/CodeCacheStatFail_test.cpp b/libnativebridge/tests/CodeCacheStatFail_test.cpp index 4ea519ee96..768f07944c 100644 --- a/libnativebridge/tests/CodeCacheStatFail_test.cpp +++ b/libnativebridge/tests/CodeCacheStatFail_test.cpp @@ -26,26 +26,26 @@ namespace android { // Tests that the bridge is initialized without errors if the code_cache is // existed as a file. TEST_F(NativeBridgeTest, CodeCacheStatFail) { - int fd = creat(kCodeCache, O_RDWR); - ASSERT_NE(-1, fd); - close(fd); - - struct stat st; - ASSERT_EQ(-1, stat(kCodeCacheStatFail, &st)); - ASSERT_EQ(ENOTDIR, errno); - - // Init - ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary, nullptr)); - ASSERT_TRUE(PreInitializeNativeBridge(kCodeCacheStatFail, "isa")); - ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); - ASSERT_TRUE(NativeBridgeAvailable()); - ASSERT_FALSE(NativeBridgeError()); - - // Clean up - UnloadNativeBridge(); - - ASSERT_FALSE(NativeBridgeError()); - unlink(kCodeCache); + int fd = creat(codeCache(), O_RDWR); + ASSERT_NE(-1, fd); + close(fd); + + struct stat st; + ASSERT_EQ(-1, stat(codeCacheStatFail(), &st)); + ASSERT_EQ(ENOTDIR, errno); + + // Init + ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary, nullptr)); + ASSERT_TRUE(PreInitializeNativeBridge(codeCacheStatFail(), "isa")); + ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); + ASSERT_TRUE(NativeBridgeAvailable()); + ASSERT_FALSE(NativeBridgeError()); + + // Clean up + UnloadNativeBridge(); + + ASSERT_FALSE(NativeBridgeError()); + unlink(codeCache()); } } // namespace android diff --git a/libnativebridge/tests/CompleteFlow_test.cpp b/libnativebridge/tests/CompleteFlow_test.cpp index b033792301..a4a6f20df9 100644 --- a/libnativebridge/tests/CompleteFlow_test.cpp +++ b/libnativebridge/tests/CompleteFlow_test.cpp @@ -24,7 +24,7 @@ TEST_F(NativeBridgeTest, CompleteFlow) { // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); @@ -41,7 +41,7 @@ TEST_F(NativeBridgeTest, CompleteFlow) { ASSERT_FALSE(NativeBridgeError()); // Clean-up code_cache - ASSERT_EQ(0, rmdir(kCodeCache)); + ASSERT_EQ(0, rmdir(codeCache())); } } // namespace android diff --git a/libnativebridge/tests/NativeBridge2Signal_test.cpp b/libnativebridge/tests/NativeBridge2Signal_test.cpp index 0573a5a680..a1663caeba 100644 --- a/libnativebridge/tests/NativeBridge2Signal_test.cpp +++ b/libnativebridge/tests/NativeBridge2Signal_test.cpp @@ -25,7 +25,7 @@ TEST_F(NativeBridgeTest, V2_Signal) { // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary2, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); @@ -34,7 +34,7 @@ TEST_F(NativeBridgeTest, V2_Signal) { ASSERT_NE(nullptr, NativeBridgeGetSignalHandler(SIGSEGV)); // Clean-up code_cache - ASSERT_EQ(0, rmdir(kCodeCache)); + ASSERT_EQ(0, rmdir(codeCache())); } } // namespace android diff --git a/libnativebridge/tests/NativeBridge3CreateNamespace_test.cpp b/libnativebridge/tests/NativeBridge3CreateNamespace_test.cpp index db7dd31cfb..2b709e05ab 100644 --- a/libnativebridge/tests/NativeBridge3CreateNamespace_test.cpp +++ b/libnativebridge/tests/NativeBridge3CreateNamespace_test.cpp @@ -22,7 +22,7 @@ TEST_F(NativeBridgeTest, V3_CreateNamespace) { // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary3, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); @@ -32,7 +32,7 @@ TEST_F(NativeBridgeTest, V3_CreateNamespace) { 0, nullptr, nullptr)); // Clean-up code_cache - ASSERT_EQ(0, rmdir(kCodeCache)); + ASSERT_EQ(0, rmdir(codeCache())); } } // namespace android diff --git a/libnativebridge/tests/NativeBridge3GetError_test.cpp b/libnativebridge/tests/NativeBridge3GetError_test.cpp index afd0a7d511..e74e664881 100644 --- a/libnativebridge/tests/NativeBridge3GetError_test.cpp +++ b/libnativebridge/tests/NativeBridge3GetError_test.cpp @@ -22,7 +22,7 @@ TEST_F(NativeBridgeTest, V3_GetError) { // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary3, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); @@ -31,7 +31,7 @@ TEST_F(NativeBridgeTest, V3_GetError) { ASSERT_EQ(nullptr, NativeBridgeGetError()); // Clean-up code_cache - ASSERT_EQ(0, rmdir(kCodeCache)); + ASSERT_EQ(0, rmdir(codeCache())); } } // namespace android diff --git a/libnativebridge/tests/NativeBridge3InitAnonymousNamespace_test.cpp b/libnativebridge/tests/NativeBridge3InitAnonymousNamespace_test.cpp index f82c9e9e4c..2449939362 100644 --- a/libnativebridge/tests/NativeBridge3InitAnonymousNamespace_test.cpp +++ b/libnativebridge/tests/NativeBridge3InitAnonymousNamespace_test.cpp @@ -22,7 +22,7 @@ TEST_F(NativeBridgeTest, V3_InitAnonymousNamespace) { // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary3, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); @@ -31,7 +31,7 @@ TEST_F(NativeBridgeTest, V3_InitAnonymousNamespace) { ASSERT_EQ(true, NativeBridgeInitAnonymousNamespace(nullptr, nullptr)); // Clean-up code_cache - ASSERT_EQ(0, rmdir(kCodeCache)); + ASSERT_EQ(0, rmdir(codeCache())); } } // namespace android diff --git a/libnativebridge/tests/NativeBridge3IsPathSupported_test.cpp b/libnativebridge/tests/NativeBridge3IsPathSupported_test.cpp index 4cbc0e8758..fd162c099d 100644 --- a/libnativebridge/tests/NativeBridge3IsPathSupported_test.cpp +++ b/libnativebridge/tests/NativeBridge3IsPathSupported_test.cpp @@ -22,7 +22,7 @@ TEST_F(NativeBridgeTest, V3_IsPathSupported) { // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary3, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); @@ -31,7 +31,7 @@ TEST_F(NativeBridgeTest, V3_IsPathSupported) { ASSERT_EQ(true, NativeBridgeIsPathSupported(nullptr)); // Clean-up code_cache - ASSERT_EQ(0, rmdir(kCodeCache)); + ASSERT_EQ(0, rmdir(codeCache())); } } // namespace android diff --git a/libnativebridge/tests/NativeBridge3LoadLibraryExt_test.cpp b/libnativebridge/tests/NativeBridge3LoadLibraryExt_test.cpp index 3d6676811a..eeb27e8431 100644 --- a/libnativebridge/tests/NativeBridge3LoadLibraryExt_test.cpp +++ b/libnativebridge/tests/NativeBridge3LoadLibraryExt_test.cpp @@ -22,7 +22,7 @@ TEST_F(NativeBridgeTest, V3_LoadLibraryExt) { // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary3, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); @@ -31,7 +31,7 @@ TEST_F(NativeBridgeTest, V3_LoadLibraryExt) { ASSERT_EQ(nullptr, NativeBridgeLoadLibraryExt(nullptr, 0, nullptr)); // Clean-up code_cache - ASSERT_EQ(0, rmdir(kCodeCache)); + ASSERT_EQ(0, rmdir(codeCache())); } } // namespace android diff --git a/libnativebridge/tests/NativeBridge3UnloadLibrary_test.cpp b/libnativebridge/tests/NativeBridge3UnloadLibrary_test.cpp index a366edcdce..39bf251f65 100644 --- a/libnativebridge/tests/NativeBridge3UnloadLibrary_test.cpp +++ b/libnativebridge/tests/NativeBridge3UnloadLibrary_test.cpp @@ -22,7 +22,7 @@ TEST_F(NativeBridgeTest, V3_UnloadLibrary) { // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary3, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); @@ -31,7 +31,7 @@ TEST_F(NativeBridgeTest, V3_UnloadLibrary) { ASSERT_EQ(0, NativeBridgeUnloadLibrary(nullptr)); // Clean-up code_cache - ASSERT_EQ(0, rmdir(kCodeCache)); + ASSERT_EQ(0, rmdir(codeCache())); } } // namespace android diff --git a/libnativebridge/tests/NativeBridge6PreZygoteFork_test.cpp b/libnativebridge/tests/NativeBridge6PreZygoteFork_test.cpp index ba6a007a93..b40e7bd79e 100644 --- a/libnativebridge/tests/NativeBridge6PreZygoteFork_test.cpp +++ b/libnativebridge/tests/NativeBridge6PreZygoteFork_test.cpp @@ -23,7 +23,7 @@ TEST_F(NativeBridgeTest, V6_PreZygoteFork) { // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary6, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); diff --git a/libnativebridge/tests/NativeBridge7CriticalNative_test.cpp b/libnativebridge/tests/NativeBridge7CriticalNative_test.cpp index 5662214f40..a8c9bb65c4 100644 --- a/libnativebridge/tests/NativeBridge7CriticalNative_test.cpp +++ b/libnativebridge/tests/NativeBridge7CriticalNative_test.cpp @@ -23,7 +23,7 @@ TEST_F(NativeBridgeTest, V7_CriticalNative) { // Init ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary7, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); - ASSERT_TRUE(PreInitializeNativeBridge(".", "isa")); + ASSERT_TRUE(PreInitializeNativeBridge(appDataDir(), "isa")); ASSERT_TRUE(NativeBridgeAvailable()); ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); ASSERT_TRUE(NativeBridgeAvailable()); diff --git a/libnativebridge/tests/NativeBridgeTest.cpp b/libnativebridge/tests/NativeBridgeTest.cpp new file mode 100644 index 0000000000..633ff79fcb --- /dev/null +++ b/libnativebridge/tests/NativeBridgeTest.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2024 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 <stdint.h> +#include <stdio.h> + +extern "C" bool GetInitialArgs(const char*** args, size_t* num_args) { + // Disable default parallelism to make debugging easier, these tests are small. + static const char* initial_args[1] = {"-j1"}; + *args = initial_args; + *num_args = 1; + return true; +} diff --git a/libnativebridge/tests/NativeBridgeTest.h b/libnativebridge/tests/NativeBridgeTest.h index 6413233006..782e58424b 100644 --- a/libnativebridge/tests/NativeBridgeTest.h +++ b/libnativebridge/tests/NativeBridgeTest.h @@ -19,12 +19,13 @@ #define LOG_TAG "NativeBridge_test" -#include <nativebridge/native_bridge.h> +#include <android-base/file.h> #include <gtest/gtest.h> +#include <nativebridge/native_bridge.h> + +#include <string> constexpr const char* kNativeBridgeLibrary = "libnativebridge-test-case.so"; -constexpr const char* kCodeCache = "./code_cache"; -constexpr const char* kCodeCacheStatFail = "./code_cache/temp"; constexpr const char* kNativeBridgeLibrary2 = "libnativebridge2-test-case.so"; constexpr const char* kNativeBridgeLibrary3 = "libnativebridge3-test-case.so"; constexpr const char* kNativeBridgeLibrary6 = "libnativebridge6-test-case.so"; @@ -33,6 +34,23 @@ constexpr const char* kNativeBridgeLibrary7 = "libnativebridge7-test-case.so"; namespace android { class NativeBridgeTest : public testing::Test { + protected: + NativeBridgeTest() : tempDir() { + appDataDir_ = std::string(tempDir.path); + codeCache_ = appDataDir_ + "/code_cache"; + codeCacheStatFail_ = codeCache_ + "/temp"; + } + + const char* appDataDir() { return appDataDir_.c_str(); } + + const char* codeCache() { return codeCache_.c_str(); } + + const char* codeCacheStatFail() { return codeCacheStatFail_.c_str(); } + + TemporaryDir tempDir; + std::string appDataDir_; + std::string codeCache_; + std::string codeCacheStatFail_; }; }; // namespace android diff --git a/libnativebridge/tests/preupload_check_test_tag.sh b/libnativebridge/tests/preupload_check_test_tag.sh deleted file mode 100755 index 1c8cd4b62c..0000000000 --- a/libnativebridge/tests/preupload_check_test_tag.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# A simple preupload check that the runtests.sh script has been run for the -# libnativebridge tests if that library has been changed. -# TODO(b/189484095): Port these tests to atest and enable in presubmit so we -# don't need the custom script to run them. - -commit_message="$1" -shift - -nativebridge_change=false -for file; do - [[ $file = libnativebridge/* ]] && nativebridge_change=true -done - -if $nativebridge_change; then - if grep '^Test: art/libnativebridge/tests/runtests.sh' <<< $commit_message ; then :; else - echo "Please run art/libnativebridge/tests/runtests.sh and add the tag:" 1>&2 - echo "Test: art/libnativebridge/tests/runtests.sh [--skip-host|--skip-target]" 1>&2 - exit 1 - fi -fi diff --git a/test/utils/regen-test-files b/test/utils/regen-test-files index 6f30c50a9a..cedf354882 100755 --- a/test/utils/regen-test-files +++ b/test/utils/regen-test-files @@ -253,6 +253,7 @@ art_gtest_user_module_names = [ "art_standalone_odrefresh_tests", "art_standalone_runtime_tests", "art_standalone_sigchain_tests", + "libnativebridge-tests", "libnativeloader_test", ] @@ -272,6 +273,7 @@ art_gtest_module_names = sorted(art_gtest_user_module_names + art_gtest_eng_only # removing them from this set (in order to promote them to # presubmits). art_gtest_postsubmit_only_module_names = [ + "libnativebridge-tests", ] # ART gtests supported in MTS that do not need root access to the device. |