From 3f3ac2c75b1cef76ef2af73371880cce8ec43455 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 7 May 2024 16:55:00 -0700 Subject: 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 --- libnativebridge/tests/NativeBridgeTest.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'libnativebridge/tests/NativeBridgeTest.h') 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 +#include #include +#include + +#include 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 -- cgit v1.2.3-59-g8ed1b