diff options
| author | 2022-11-17 11:27:45 -0800 | |
|---|---|---|
| committer | 2022-12-08 18:04:58 +0000 | |
| commit | 474f318add83fbfa746b96904368da6e6c0a65dc (patch) | |
| tree | 52ce1dd5ec0086e976412c2868019d22cd20522b | |
| parent | 1ee0290eed24868826ad99678cc58eee425ecba8 (diff) | |
| parent | daa9be44dcdc6a9b46db23a5e0bc0008c09a074c (diff) | |
Snap tm-dev to android13-tests-dev
Bug:259849956
Merge ab/9299233
Merged-In: I347582df87e2bce0142d0210519f013d060a0180
Change-Id: I7276ba4aab3068af89c3f2a048fad58ae445407a
| -rw-r--r-- | dex2oat/dex2oat_cts_test.cc | 45 | ||||
| -rw-r--r-- | libartbase/base/common_art_test.h | 4 | ||||
| -rw-r--r-- | libnativeloader/native_loader_test.cpp | 24 | ||||
| -rw-r--r-- | libnativeloader/public_libraries.cpp | 6 | ||||
| -rw-r--r-- | runtime/dex2oat_environment_test.h | 74 | ||||
| -rw-r--r-- | test/924-threads/src/art/Test924.java | 24 |
6 files changed, 132 insertions, 45 deletions
diff --git a/dex2oat/dex2oat_cts_test.cc b/dex2oat/dex2oat_cts_test.cc index 41c7015090..254126446d 100644 --- a/dex2oat/dex2oat_cts_test.cc +++ b/dex2oat/dex2oat_cts_test.cc @@ -14,11 +14,54 @@ * limitations under the License. */ +#include "base/file_utils.h" #include "dex2oat_environment_test.h" namespace art { -class Dex2oatCtsTest : public Dex2oatEnvironmentTest {}; +class Dex2oatCtsTest : public CommonArtTest, public Dex2oatScratchDirs { + public: + void SetUp() override { + CommonArtTest::SetUp(); + Dex2oatScratchDirs::SetUp(android_data_); + } + + void TearDown() override { + Dex2oatScratchDirs::TearDown(); + CommonArtTest::TearDown(); + } + + protected: + // Stripped down counterpart to Dex2oatEnvironmentTest::Dex2Oat that only adds + // enough arguments for our purposes. + int Dex2Oat(const std::vector<std::string>& dex2oat_args, + std::string* output, + std::string* error_msg) { + // This command line should work regardless of bitness, ISA, etc. + std::vector<std::string> argv = {std::string(kAndroidArtApexDefaultPath) + "/bin/dex2oat"}; + argv.insert(argv.end(), dex2oat_args.begin(), dex2oat_args.end()); + + // We must set --android-root. + const char* android_root = getenv("ANDROID_ROOT"); + CHECK(android_root != nullptr); + argv.push_back("--android-root=" + std::string(android_root)); + + // We need dex2oat to actually log things. + auto post_fork_fn = []() { return setenv("ANDROID_LOG_TAGS", "*:d", 1) == 0; }; + ForkAndExecResult res = ForkAndExec(argv, post_fork_fn, output); + if (res.stage != ForkAndExecResult::kFinished) { + *error_msg = strerror(errno); + ::testing::AssertionFailure() << "Failed to finish dex2oat invocation: " << *error_msg; + } + + if (!res.StandardSuccess()) { + // We cannot use ASSERT_TRUE since the method returns an int and not void. + ::testing::AssertionFailure() << "dex2oat fork/exec failed: " << *error_msg; + } + + return res.status_code; + } +}; // Run dex2oat with --enable-palette-compilation-hooks to force calls to // PaletteNotify{Start,End}Dex2oatCompilation. diff --git a/libartbase/base/common_art_test.h b/libartbase/base/common_art_test.h index 6124ed9e2a..bd06043907 100644 --- a/libartbase/base/common_art_test.h +++ b/libartbase/base/common_art_test.h @@ -139,6 +139,8 @@ class CommonArtTestImpl { static void TearDownAndroidDataDir(const std::string& android_data, bool fail_on_error); + static void ClearDirectory(const char* dirpath, bool recursive = true); + // Get the names of the libcore modules. virtual std::vector<std::string> GetLibCoreModuleNames() const; @@ -231,8 +233,6 @@ class CommonArtTestImpl { std::unique_ptr<const DexFile> LoadExpectSingleDexFile(const char* location); - void ClearDirectory(const char* dirpath, bool recursive = true); - // Open a file (allows reading of framework jars). std::vector<std::unique_ptr<const DexFile>> OpenDexFiles(const char* filename); diff --git a/libnativeloader/native_loader_test.cpp b/libnativeloader/native_loader_test.cpp index 9648713e70..1dc778abcd 100644 --- a/libnativeloader/native_loader_test.cpp +++ b/libnativeloader/native_loader_test.cpp @@ -31,6 +31,7 @@ namespace android { namespace nativeloader { using ::testing::Eq; +using ::testing::MatchesRegex; using ::testing::NotNull; using ::testing::StrEq; using internal::ConfigEntry; @@ -224,7 +225,7 @@ class NativeLoaderTest_Create : public NativeLoaderTest { EXPECT_CALL(*mock, NativeBridgeInitialized()).Times(testing::AnyNumber()); EXPECT_CALL(*mock, mock_create_namespace( - Eq(IsBridged()), StrEq(expected_namespace_name), nullptr, + Eq(IsBridged()), MatchesRegex(expected_namespace_name), nullptr, StrEq(expected_library_path), expected_namespace_flags, StrEq(expected_permitted_path), NsEq(expected_parent_namespace.c_str()))) .WillOnce(Return(TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE(dex_path.c_str())))); @@ -344,7 +345,7 @@ TEST_P(NativeLoaderTest_Create, UnbundledVendorApp) { expected_permitted_path = expected_permitted_path + ":/vendor/" LIB_DIR; expected_shared_libs_to_platform_ns = default_public_libraries() + ":" + llndk_libraries_vendor(); - expected_link_with_vndk_ns = true; + expected_link_with_vndk_ns = !get_vndk_version(/*is_product_vndk=*/false).empty(); SetExpectations(); RunTest(); } @@ -375,13 +376,28 @@ TEST_P(NativeLoaderTest_Create, UnbundledProductApp) { is_shared = false; if (is_product_vndk_version_defined()) { - expected_namespace_name = "vendor-classloader-namespace"; + expected_namespace_name = "(vendor|product)-classloader-namespace"; expected_library_path = expected_library_path + ":/product/" LIB_DIR ":/system/product/" LIB_DIR; expected_permitted_path = expected_permitted_path + ":/product/" LIB_DIR ":/system/product/" LIB_DIR; + expected_link_with_vndk_product_ns = true; + + // The handling of extended libraries for product apps changed in the + // M-2022-10 release of the ART module (https://r.android.com/2194871). + // Since this test is in CTS for T, we need to accept both new and old + // behaviour, i.e. with and without the extended public libraries appended + // at the end. Skip the EXPECT_CALL in + // NativeLoaderTest_Create::SetExpectations and create a more lenient + // variant of it here. + expected_link_with_platform_ns = false; expected_shared_libs_to_platform_ns = default_public_libraries() + ":" + llndk_libraries_product(); - expected_link_with_vndk_product_ns = true; + EXPECT_CALL(*mock, + mock_link_namespaces(Eq(IsBridged()), + _, + NsEq("system"), + ::testing::StartsWith(expected_shared_libs_to_platform_ns))) + .WillOnce(Return(true)); } SetExpectations(); RunTest(); diff --git a/libnativeloader/public_libraries.cpp b/libnativeloader/public_libraries.cpp index ffebe0b4c7..433a9095ef 100644 --- a/libnativeloader/public_libraries.cpp +++ b/libnativeloader/public_libraries.cpp @@ -212,6 +212,9 @@ static std::string InitExtendedPublicLibraries() { } static std::string InitLlndkLibrariesVendor() { + if (get_vndk_version(/*is_product_vndk=*/false).empty()) { + return ""; + } std::string config_file = kLlndkLibrariesFile; InsertVndkVersionStr(&config_file, false); auto sonames = ReadConfig(config_file, always_true); @@ -237,6 +240,9 @@ static std::string InitLlndkLibrariesProduct() { } static std::string InitVndkspLibrariesVendor() { + if (get_vndk_version(/*is_product_vndk=*/false).empty()) { + return ""; + } std::string config_file = kVndkLibrariesFile; InsertVndkVersionStr(&config_file, false); auto sonames = ReadConfig(config_file, always_true); diff --git a/runtime/dex2oat_environment_test.h b/runtime/dex2oat_environment_test.h index 964b7f3fff..e867c4f915 100644 --- a/runtime/dex2oat_environment_test.h +++ b/runtime/dex2oat_environment_test.h @@ -41,21 +41,17 @@ namespace art { static constexpr bool kDebugArgs = false; -// Test class that provides some helpers to set a test up for compilation using dex2oat. -class Dex2oatEnvironmentTest : public CommonRuntimeTest { +class Dex2oatScratchDirs { public: - void SetUp() override { - CommonRuntimeTest::SetUp(); - const ArtDexFileLoader dex_file_loader; - + void SetUp(const std::string& android_data) { // Create a scratch directory to work from. // Get the realpath of the android data. The oat dir should always point to real location // when generating oat files in dalvik-cache. This avoids complicating the unit tests // when matching the expected paths. - UniqueCPtr<const char[]> android_data_real(realpath(android_data_.c_str(), nullptr)); + UniqueCPtr<const char[]> android_data_real(realpath(android_data.c_str(), nullptr)); ASSERT_TRUE(android_data_real != nullptr) - << "Could not get the realpath of the android data" << android_data_ << strerror(errno); + << "Could not get the realpath of the android data" << android_data << strerror(errno); scratch_dir_.assign(android_data_real.get()); scratch_dir_ += "/Dex2oatEnvironmentTest"; @@ -67,6 +63,41 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { odex_dir_ = odex_oat_dir_ + "/" + std::string(GetInstructionSetString(kRuntimeISA)); ASSERT_EQ(0, mkdir(odex_dir_.c_str(), 0700)); + } + + void TearDown() { + CommonArtTest::ClearDirectory(odex_dir_.c_str()); + ASSERT_EQ(0, rmdir(odex_dir_.c_str())); + + CommonArtTest::ClearDirectory(odex_oat_dir_.c_str()); + ASSERT_EQ(0, rmdir(odex_oat_dir_.c_str())); + + CommonArtTest::ClearDirectory(scratch_dir_.c_str()); + ASSERT_EQ(0, rmdir(scratch_dir_.c_str())); + } + + // Scratch directory, for dex and odex files (oat files will go in the + // dalvik cache). + const std::string& GetScratchDir() const { return scratch_dir_; } + + // Odex directory is the subdirectory in the scratch directory where odex + // files should be located. + const std::string& GetOdexDir() const { return odex_dir_; } + + private: + std::string scratch_dir_; + std::string odex_oat_dir_; + std::string odex_dir_; +}; + +// Test class that provides some helpers to set a test up for compilation using dex2oat. +class Dex2oatEnvironmentTest : public Dex2oatScratchDirs, public CommonRuntimeTest { + public: + void SetUp() override { + CommonRuntimeTest::SetUp(); + Dex2oatScratchDirs::SetUp(android_data_); + + const ArtDexFileLoader dex_file_loader; // Verify the environment is as we expect std::vector<uint32_t> checksums; @@ -122,15 +153,7 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { } void TearDown() override { - ClearDirectory(odex_dir_.c_str()); - ASSERT_EQ(0, rmdir(odex_dir_.c_str())); - - ClearDirectory(odex_oat_dir_.c_str()); - ASSERT_EQ(0, rmdir(odex_oat_dir_.c_str())); - - ClearDirectory(scratch_dir_.c_str()); - ASSERT_EQ(0, rmdir(scratch_dir_.c_str())); - + Dex2oatScratchDirs::TearDown(); CommonRuntimeTest::TearDown(); } @@ -165,18 +188,6 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { return GetTestDexFileName("Nested"); } - // Scratch directory, for dex and odex files (oat files will go in the - // dalvik cache). - const std::string& GetScratchDir() const { - return scratch_dir_; - } - - // Odex directory is the subdirectory in the scratch directory where odex - // files should be located. - const std::string& GetOdexDir() const { - return odex_dir_; - } - int Dex2Oat(const std::vector<std::string>& dex2oat_args, std::string* output, std::string* error_msg) { @@ -232,11 +243,6 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { return res.status_code; } - - private: - std::string scratch_dir_; - std::string odex_oat_dir_; - std::string odex_dir_; }; } // namespace art diff --git a/test/924-threads/src/art/Test924.java b/test/924-threads/src/art/Test924.java index e97c9c6b35..355572044f 100644 --- a/test/924-threads/src/art/Test924.java +++ b/test/924-threads/src/art/Test924.java @@ -337,6 +337,19 @@ public class Test924 { } } + private static List<String> filterForThread(Object[] thread_messages, String thread_name) { + List<String> messageListForThread = new ArrayList<String>(); + + for (int i = 0; i < thread_messages.length; i++) { + String message = (String)thread_messages[i]; + if (message.startsWith("Thread(" + thread_name + ")")) { + messageListForThread.add(message); + } + } + + return messageListForThread; + } + private static void doTestEvents() throws Exception { enableThreadEvents(true); @@ -354,21 +367,24 @@ public class Test924 { } } }; - Thread t = new Thread(r, "EventTestThread"); + String thread_name = "EventTestThread"; + Thread t = new Thread(r, thread_name); System.out.println("Constructed thread"); Thread.yield(); Thread.sleep(100); - System.out.println(Arrays.toString(getThreadEventMessages())); + + // Check that there are no events related to EventTestThread that we just created. + System.out.println(filterForThread(getThreadEventMessages(), thread_name).toString()); t.start(); cdl1.await(); - System.out.println(Arrays.toString(getThreadEventMessages())); + System.out.println(filterForThread(getThreadEventMessages(), thread_name).toString()); cdl2.countDown(); t.join(); - System.out.println(Arrays.toString(getThreadEventMessages())); + System.out.println(filterForThread(getThreadEventMessages(), thread_name).toString()); System.out.println("Thread joined"); |